public static Frame3f GetSOLocalFrame(SceneObject so, CoordSpace eSpace) { if (eSpace == CoordSpace.SceneCoords) { // new code maps object frame up to scene // [TODO] this is not the most efficient approach! can at least get the object // frame directly, and avoid first local-to-obj xform Frame3f objF = Frame3f.Identity; Frame3f result = SceneTransforms.ObjectToScene(so, objF); // [RMS] old code that mapped up to world, and then down to scene // Problem with this code is that it is unstable - if scene-to-world xform changes, // then scene frame will numerically change. Which is a problem. //Frame3f sceneW = UnityUtil.GetGameObjectFrame(so.GetScene().RootGameObject, CoordSpace.WorldCoords); //Frame3f objW = UnityUtil.GetGameObjectFrame(so.RootGameObject, CoordSpace.WorldCoords); //Frame3f result = sceneW.ToFrame(objW); //// world coords have scene scale applied, we don't want that in scene coords //if (so.GetScene().GetSceneScale() != 1.0f) // result = result.Scaled(1.0f / so.GetScene().GetSceneScale()); return(result); } else { return(UnityUtil.GetGameObjectFrame(so.RootGameObject, eSpace)); } }
private void OnTargetModified(SceneObject so) { if (IsValid) { Frame3f FrameS = SceneTransforms.ObjectToScene(Target, relativeF); Source.SetLocalFrame(FrameS, CoordSpace.SceneCoords); } }
private void OnTargetModified(TransformableSO so) { if (IsValid) { TransformableSO from = Source as TransformableSO; TransformableSO to = Target as TransformableSO; Frame3f FrameS = SceneTransforms.ObjectToScene(to, relativeF); from.SetLocalFrame(FrameS, CoordSpace.SceneCoords); } }
protected override void update_vertices(FScene s) { //if (Target.Timestamp == target_timestamp) // return; target_timestamp = Target.Timestamp; for (int i = 0; i < VertexCount; ++i) { LocalVertexRef r = SurfacePoints[i]; Vector3d vScene = SceneTransforms.ObjectToScene(Target, r.localPos); this[i] = vScene; } }
virtual public Box3f GetBoundingBox(CoordSpace eSpace) { Box3f box = new Box3f(GetLocalBoundingBox()); if (eSpace == CoordSpace.ObjectCoords) { return(box); } else if (eSpace == CoordSpace.SceneCoords) { return(SceneTransforms.ObjectToScene(this, box)); } else { box = SceneTransforms.ObjectToScene(this, box); return(GetScene().ToWorldBox(box)); } }
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 }); } }