Beispiel #1
0
        // add the meshes we have read into SceneObjects list to the given Scene
        public void AppendReadMeshesToScene(FScene scene, bool bSaveHistory)
        {
            if (ImportBehavior == ImportMode.AsMeshReference)
            {
                MeshReferenceSO ref_group = GetMeshReference(scene.DefaultMeshSOMaterial);

                var change = new AddSOChange()
                {
                    scene = scene, so = ref_group
                };
                if (bSaveHistory)
                {
                    scene.History.PushChange(change);
                }
                else
                {
                    change.Apply();
                }
            }
            else
            {
                foreach (ImportedObject obj in SceneObjects)
                {
                    DMeshSO meshSO = new DMeshSO();
                    meshSO.Create(obj.mesh, (obj.material == null) ? scene.DefaultMeshSOMaterial : obj.material);
                    meshSO.Name = UniqueNames.GetNext("ImportMesh");

                    var change = new AddSOChange()
                    {
                        scene = scene, so = meshSO
                    };
                    if (bSaveHistory)
                    {
                        scene.History.PushChange(change);
                    }
                    else
                    {
                        change.Apply();
                    }
                }
            }
        }
Beispiel #2
0
        // converts input GameObject into a DMeshSO. Original GameObject is not used by DMeshSO,
        // so it can be destroyed.
        // [TODO] transfer materials!!
        public static SceneObject WrapMeshGameObject(GameObject wrapGO, FContext context, bool bDestroyOriginal, bool bPreserveColor = true)
        {
            SOMaterial overrideMaterial = null;

            if (bPreserveColor)
            {
                if (wrapGO.GetMaterial() != null)
                {
                    overrideMaterial = MaterialUtil.FromUnityMaterial(wrapGO.GetMaterial());
                }
            }
            var wrapperSO = ImportExistingUnityMesh(wrapGO, context.Scene, true, true, true,
                                                    (mesh, material) => {
                DMeshSO gso     = new DMeshSO();
                var useMaterial = (overrideMaterial != null) ? overrideMaterial : material;
                return(gso.Create(UnityUtil.UnityMeshToDMesh(mesh, false), useMaterial));
            });

            if (bDestroyOriginal)
            {
                wrapGO.Destroy();
            }
            return(wrapperSO);
        }
Beispiel #3
0
 public RemoveTrianglesChange(DMeshSO target, RemoveTrianglesMeshChange change)
 {
     Target     = target;
     MeshChange = change;
 }
Beispiel #4
0
 public RemoveTrianglesChange(DMeshSO target)
 {
     Target = target;
 }
Beispiel #5
0
 public override OpStatus Cull()
 {
     Target = null;
     Before = After = null;
     return(OpStatus.Success);
 }
Beispiel #6
0
 public override OpStatus Cull()
 {
     Target     = null;
     MeshChange = null;
     return(OpStatus.Success);
 }
Beispiel #7
0
 public UpdateVerticesChange(DMeshSO target, ModifyVerticesMeshChange change)
 {
     Target     = target;
     MeshChange = change;
 }
 public BakeScalingChangeOp(DMeshSO target)
 {
     Target     = target;
     LocalScale = target.GetLocalScale();
 }
Beispiel #9
0
 public AddTrianglesChange(DMeshSO target, AddTrianglesMeshChange change)
 {
     Target     = target;
     MeshChange = change;
 }
 public static void Emit(this SceneSerializer s, IOutputStream o, DMeshSO so)
 {
     o.AddAttribute(IOStrings.ASOType, IOStrings.TypeDMesh);
     EmitDMeshSO(s, o, so);
 }
Beispiel #11
0
 public TrivialViewMeshManager(DMeshSO sourceSO)
 {
     SourceSO = sourceSO;
 }
Beispiel #12
0
 public LinearDecompViewMeshManager(DMeshSO sourceSO)
 {
     SourceSO          = sourceSO;
     displayComponents = new List <DisplayMeshComponent>();
 }
 public CurveSelectFacesTool build_tool(FScene scene, DMeshSO meshSO)
 {
     return(new CurveSelectFacesTool(scene, meshSO));
 }
Beispiel #14
0
 protected virtual SurfaceBrushTool new_tool(FScene scene, DMeshSO target)
 {
     return(new SurfaceBrushTool(scene, target));
 }
 protected virtual DMesh3 GetMeshForDMeshSO(DMeshSO meshSO)
 {
     return(new DMesh3(meshSO.Mesh, true));
 }
        public virtual ExportStatus Export(FScene scene, string filename)
        {
            int[]            vertexMap = new int[2048]; // temp
            List <WriteMesh> vMeshes   = new List <WriteMesh>();

            if (WriteFaceGroups)
            {
                throw new Exception("SceneMeshExporter.Export: writing face groups has not yet been implemented!");
            }

            // extract all the mesh data we want to export
            foreach (SceneObject so in scene.SceneObjects)
            {
                if (so.IsTemporary || so.IsSurface == false || SceneUtil.IsVisible(so) == false)
                {
                    continue;
                }
                if (SOFilterF != null && SOFilterF(so) == false)
                {
                    continue;
                }

                // if this SO has an internal mesh we can just copy, use it
                if (so is DMeshSO)
                {
                    DMeshSO meshSO = so as DMeshSO;

                    // todo: flags

                    // make a copy of mesh
                    DMesh3 m = new DMesh3(meshSO.Mesh, true);

                    // transform to scene coords and swap left/right
                    foreach (int vid in m.VertexIndices())
                    {
                        Vector3f v = (Vector3f)m.GetVertex(vid);
                        v = SceneTransforms.ObjectToScene(meshSO, v);
                        v = UnityUtil.SwapLeftRight(v);
                        m.SetVertex(vid, v);
                    }
                    m.ReverseOrientation();

                    vMeshes.Add(new WriteMesh(m, so.Name));
                }


                // Look for lower-level fGameObject items to export. By default
                // this is anything with a MeshFilter, override CollectGOChildren
                // or use GOFilterF to add restrictions
                List <fGameObject> vExports = CollectGOChildren(so);
                if (vExports.Count > 0)
                {
                    SimpleMesh m = new SimpleMesh();
                    m.Initialize(WriteNormals, WriteVertexColors, WriteUVs, WriteFaceGroups);
                    int groupCounter = 1;

                    foreach (fGameObject childgo in vExports)
                    {
                        if (GOFilterF != null && GOFilterF(so, childgo) == false)
                        {
                            continue;
                        }

                        if (AppendGOMesh(childgo, m, vertexMap, scene, groupCounter))
                        {
                            groupCounter++;
                        }
                    }

                    vMeshes.Add(new WriteMesh(m, so.Name));
                }
            }


            // ok, we are independent of Scene now and can write in bg thread
            if (WriteInBackgroundThreads)
            {
                ExportStatus status = new ExportStatus()
                {
                    Exporter = this, IsComputing = true
                };
                WriteOptions useOptions = Options;
                useOptions.ProgressFunc = (cur, max) => {
                    status.Progress    = cur;
                    status.MaxProgress = max;
                };
                BackgroundWriteThread t = new BackgroundWriteThread()
                {
                    Meshes      = vMeshes, options = useOptions, Filename = filename,
                    CompletionF = (result) => {
                        LastWriteStatus         = result.code;
                        LastErrorMessage        = result.message;
                        status.LastErrorMessage = result.message;
                        status.Ok          = (result.code == IOCode.Ok);
                        status.IsComputing = false;
                        if (BackgroundWriteCompleteF != null)
                        {
                            BackgroundWriteCompleteF(this, status);
                        }
                    }
                };
                t.Start();
                return(status);
            }
            else
            {
                IOWriteResult result = StandardMeshWriter.WriteFile(filename, vMeshes, Options);
                LastWriteStatus  = result.code;
                LastErrorMessage = result.message;
                return(new ExportStatus()
                {
                    Exporter = this, IsComputing = false,
                    Ok = (result.code == IOCode.Ok),
                    LastErrorMessage = result.message
                });
            }
        }
Beispiel #17
0
 public ReplaceTrianglesChange(DMeshSO target, RemoveTrianglesMeshChange remove, AddTrianglesMeshChange add)
 {
     RemoveChange = remove;
     AddChange    = add;
     Target       = target;
 }
Beispiel #18
0
 public ReplaceEntireMeshChange(DMeshSO target, DMesh3 before, DMesh3 after)
 {
     Target = target;
     Before = before;
     After  = after;
 }
Beispiel #19
0
 public SetVerticesChange(DMeshSO target, SetVerticesMeshChange change)
 {
     Target     = target;
     MeshChange = change;
 }