示例#1
0
        public void AddInstance(Rhino.Geometry.Transform transform)
        {
            foreach (GltfMeshMaterialPair pair in  meshMaterialPairs)
            {
                Rhino.Geometry.Mesh rhinoMesh = pair.RhinoMesh.DuplicateMesh();

                rhinoMesh.Transform(GltfUtils.YupToZup * transform);

                rhinoMesh.TextureCoordinates.ReverseTextureCoordinates(1);

                Guid objectId = doc.Objects.AddMesh(rhinoMesh);

                Rhino.DocObjects.RhinoObject rhinoObject = doc.Objects.Find(objectId);

                Rhino.Render.RenderMaterial material = converter.GetMaterial(pair.MaterialIndex);

                if (rhinoObject != null && material != null)
                {
                    rhinoObject.RenderMaterial            = material;
                    rhinoObject.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;
                    rhinoObject.Attributes.Name           = pair.Name;

                    rhinoObject.CommitChanges();
                }
            }
        }
示例#2
0
        public List <ObjectExportData> SanitizeRhinoObjects(IEnumerable <RhinoObject> rhinoObjects)
        {
            List <ObjectExportData> explodedObjects = new List <ObjectExportData>();

            foreach (var rhinoObject in rhinoObjects)
            {
                if (rhinoObject.ObjectType == ObjectType.InstanceReference && rhinoObject is InstanceObject instanceObject)
                {
                    List <RhinoObject> pieces = new List <RhinoObject>();
                    List <Rhino.Geometry.Transform> transforms = new List <Rhino.Geometry.Transform>();

                    ExplodeRecursive(instanceObject, Rhino.Geometry.Transform.Identity, pieces, transforms);

                    foreach (var item in pieces.Zip(transforms, (rObj, trans) => (rhinoObject: rObj, trans)))
                    {
                        explodedObjects.Add(new ObjectExportData()
                        {
                            Object         = item.rhinoObject,
                            Transform      = item.trans,
                            RenderMaterial = GetObjectMaterial(item.rhinoObject),
                        });
                    }
                }
                else
                {
                    explodedObjects.Add(new ObjectExportData()
                    {
                        Object         = rhinoObject,
                        RenderMaterial = GetObjectMaterial(rhinoObject),
                    });
                }
            }

            //Remove Unmeshable
            explodedObjects.RemoveAll(x => !x.Object.IsMeshable(Rhino.Geometry.MeshType.Any));

            foreach (var item in explodedObjects)
            {
                //Mesh

                if (item.Object.ObjectType == ObjectType.SubD && item.Object.Geometry is Rhino.Geometry.SubD subd)
                {
                    if (options.SubDExportMode == SubDMode.ControlNet)
                    {
                        Rhino.Geometry.Mesh mesh = Rhino.Geometry.Mesh.CreateFromSubDControlNet(subd);

                        mesh.Transform(item.Transform);

                        item.Meshes = new Rhino.Geometry.Mesh[] { mesh };
                    }
                    else
                    {
                        int level = options.SubDLevel;

                        Rhino.Geometry.Mesh mesh = Rhino.Geometry.Mesh.CreateFromSubD(subd, level);

                        mesh.Transform(item.Transform);

                        item.Meshes = new Rhino.Geometry.Mesh[] { mesh };
                    }
                }
                else
                {
                    Rhino.Geometry.MeshingParameters parameters = item.Object.GetRenderMeshParameters();

                    if (item.Object.MeshCount(Rhino.Geometry.MeshType.Render, parameters) == 0)
                    {
                        item.Object.CreateMeshes(Rhino.Geometry.MeshType.Render, parameters, false);
                    }

                    List <Rhino.Geometry.Mesh> meshes = new List <Rhino.Geometry.Mesh>(item.Object.GetMeshes(Rhino.Geometry.MeshType.Render));

                    foreach (Rhino.Geometry.Mesh mesh in meshes)
                    {
                        mesh.EnsurePrivateCopy();
                        mesh.Transform(item.Transform);
                    }

                    //Remove bad meshes
                    meshes.RemoveAll(x => x == null || !MeshIsValidForExport(x));

                    item.Meshes = meshes.ToArray();
                }
            }

            //Remove meshless objects
            explodedObjects.RemoveAll(x => x.Meshes.Length == 0);

            return(explodedObjects);
        }