Extracting Mesh Geometry From Imported WRL, Texture Mapping Lost

When I import a WRL file via script, the texture mapping with the corresponding jpg works fine. But if I extract the mesh geometry and then add that mesh back to the doc, only vertex colors remain, no mesh texture. Is there a way to include the texture mapping when I extract the mesh geometry?

Thanks,
Sam

Hi Sam,

The texture mapping is not stored on the geometry. Rather, it is stored on the runtime object’s attributes.

– Dale

Is there a way I can copy all of one object’s runtime attributes to another? Preferably via their IDs?

Thanks,
Sam

Can you post your vrml file?

Hi Dale,

Here’s an example

Thanks,
Sam

Boot.zip (19.6 MB)

Well, I don’t see any texture mapping. But I do see a material that uses a color texture.So perhaps all you need to do is assign the material from the source object, Rhino.DocObjects.ObjectAttributes.MaterialIndex, to the newly created target object.

– Dale

Okay, make sense now. Though I’m having trouble setting MaterialIndex. It seems to get set in code, but then in the document the material is still being set by the layer. How might I change the following code to address this?

Thanks,
Sam

Dim MeshrhObject = Doc.Objects.Find(MeshID) Dim MaterialIndexStored = MeshrhObject.Attributes.MaterialIndex Dim NewMeshID = Doc.Objects.AddMesh(Mesh) Dim NewMeshrhObject = Doc.Objects.Find(MeshID) NewMeshrhObject.Attributes.MaterialIndex = MaterialIndexStored NewMeshrhObject.CommitChanges()

How about this:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var go = new GetObject();
  go.SetCommandPrompt("Select object to copy");
  go.Get();
  if (go.CommandResult() == Result.Success)
  {
    var obj = go.Object(0).Object();
    if (null != obj)
    {
      var geo = obj.Geometry;
      if (null != geo)
      {
        doc.Objects.Add(geo, obj.Attributes);
        doc.Views.Redraw();
      }
    }
  }
  return Result.Success;
}

– D

1 Like

Worked great, thanks!

Sam