Beispiel #1
0
        private DatasmithMeshInfo GenerateMeshInfo(Guid ObjectID, List <Mesh> Meshes, List <ObjectAttributes> Attributes)
        {
            DatasmithMeshInfo MeshInfo = null;

            if (GuidToHierarchyNodeDictionary.TryGetValue(ObjectID, out RhinoSceneHierarchyNode HierarchyNode))
            {
                Vector3d   PivotOffset     = FDatasmithRhinoMeshExporter.CenterMeshesOnPivot(Meshes);
                List <int> MaterialIndices = new List <int>(Attributes.Count);
                for (int AttributeIndex = 0; AttributeIndex < Attributes.Count; ++AttributeIndex)
                {
                    int MaterialIndex = GetMaterialIndexFromAttributes(HierarchyNode, Attributes[AttributeIndex]);
                    MaterialIndices.Add(MaterialIndex);
                }

                string Name  = FDatasmithFacadeElement.GetStringHash("M:" + HierarchyNode.Info.Name);
                string Label = HierarchyNode.Info.Label;

                MeshInfo = new DatasmithMeshInfo(Meshes, PivotOffset, MaterialIndices, Name, Label);
            }
            else
            {
                RhinoApp.WriteLine("Could not find the corresponding hierarchy node for the object ID: {0}", ObjectID);
            }

            return(MeshInfo);
        }
Beispiel #2
0
        private void ParseRhinoMeshes()
        {
            HashSet <RhinoObject> DocObjects = CollectExportedRhinoObjects(RhinoDocument, InstanceDefinitionHierarchyNodeDictionary.Values);

            // Make sure all render meshes are generated before attempting to export them.
            RhinoObject.GetRenderMeshes(DocObjects, /*okToCreate=*/ true, /*returnAllObjects*/ false);

            foreach (RhinoObject CurrentObject in DocObjects)
            {
                Mesh[] RenderMeshes = CurrentObject.GetMeshes(MeshType.Render);

                if (RenderMeshes != null && RenderMeshes.Length > 0)
                {
                    List <Mesh>             ExportedMeshes   = new List <Mesh>(RenderMeshes);
                    List <ObjectAttributes> MeshesAttributes = new List <ObjectAttributes>(RenderMeshes.Length);

                    BrepObject CurrentBrep = (CurrentObject as BrepObject);
                    if (CurrentBrep != null && CurrentBrep.HasSubobjectMaterials)
                    {
                        RhinoObject[] SubObjects = CurrentBrep.GetSubObjects();

                        for (int SubObjectIndex = 0; SubObjectIndex < SubObjects.Length; ++SubObjectIndex)
                        {
                            MeshesAttributes.Add(SubObjects[SubObjectIndex].Attributes);
                        }
                    }
                    else
                    {
                        for (int RenderMeshIndex = 0; RenderMeshIndex < RenderMeshes.Length; ++RenderMeshIndex)
                        {
                            MeshesAttributes.Add(CurrentObject.Attributes);
                        }
                    }

                    DatasmithMeshInfo MeshInfo = GenerateMeshInfo(CurrentObject.Id, ExportedMeshes, MeshesAttributes);
                    if (MeshInfo != null)
                    {
                        ObjectIdToMeshInfoDictionary[CurrentObject.Id] = MeshInfo;
                    }
                }
            }
        }
        private static FDatasmithFacadeActor ParseMeshActor(RhinoSceneHierarchyNode InNode, DatasmithRhinoSceneParser InSceneParser, DatasmithMeshInfo InMeshInfo)
        {
            string HashedActorName = FDatasmithFacadeActor.GetStringHash("A:" + InNode.Info.Name);
            FDatasmithFacadeActorMesh DatasmithActorMesh = new FDatasmithFacadeActorMesh(HashedActorName);

            DatasmithActorMesh.SetLabel(InNode.Info.Label);

            Transform OffsetTransform = Transform.Translation(InMeshInfo.PivotOffset);
            Transform WorldTransform  = Transform.Multiply(InNode.Info.WorldTransform, OffsetTransform);

            DatasmithActorMesh.SetWorldTransform(WorldTransform.ToFloatArray(false));

            string MeshName = FDatasmithFacadeElement.GetStringHash(InMeshInfo.Name);

            DatasmithActorMesh.SetMesh(MeshName);

            if (InNode.Info.bOverrideMaterial)
            {
                RhinoMaterialInfo MaterialInfo = InSceneParser.GetMaterialInfoFromMaterialIndex(InNode.Info.MaterialIndex);
                DatasmithActorMesh.AddMaterialOverride(MaterialInfo.Name, 0);
            }

            return(DatasmithActorMesh);
        }