Extracting Mesh Geometry From Imported WRL, Texture Mapping Lost


#1

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


(Dale Fugier) #2

Hi Sam,

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

– Dale


#3

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

Thanks,
Sam


(Dale Fugier) #4

Can you post your vrml file?


#5

Hi Dale,

Here’s an example

Thanks,
Sam

Boot.zip (19.6 MB)


(Dale Fugier) #6

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


#7

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()

(Dale Fugier) #8

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


#9

Worked great, thanks!

Sam