コード例 #1
0
        // remove SO from scene.
        // bDestroy means that SO is actually deleted, otherwise just added
        // to internal Deleted set, so it can be recovered by undo.
        public void RemoveSceneObject(SceneObject so, bool bDestroy)
        {
            DebugUtil.Log(1, "[Scene.AddSceneObject] removing {0} (destroy: {1})", so.Name, bDestroy);

            if (vSelected.Contains(so))
            {
                Deselect(so);
            }
            vObjects.Remove(so);
            OnSceneChanged(so, SceneChangeType.Removed);

            if (so.RootGameObject != null)
            {
                if (bDestroy)
                {
                    SceneUtil.DestroySO(so);
                }
                else
                {
                    // add to deleted set
                    vDeleted.Add(so);
                    deleted_objects.AddChild(so.RootGameObject, true);
                    so.RootGameObject.SetVisible(false);
                }
            }
        }
コード例 #2
0
        void update_last_hit(SculptCurveTool tool, Ray3f ray)
        {
            SORayHit soHit;

            // stick brush to target if we have one
            if (tool.BrushTarget != null)
            {
                Vector3d hitPos, hitNormal;
                bool     bHit = tool.BrushTarget.RayIntersect(ray, out hitPos, out hitNormal);
                if (bHit)
                {
                    lastHitPosW = (Vector3f)hitPos;
                }
            }
            else if (in_draw)
            {
                lastHitPosW = curDrawFrameW.RayPlaneIntersection(ray.Origin, ray.Direction, 2);
            }
            else if (SceneUtil.FindNearestRayIntersection(tool.Targets, ray, out soHit))
            {
                lastHitPosW = soHit.hitPos;
            }
            else
            {
                Frame3f f = new Frame3f(lastHitPosW, context.ActiveCamera.Forward());
                lastHitPosW = f.RayPlaneIntersection(ray.Origin, ray.Direction, 2);
            }
        }
コード例 #3
0
 virtual public void SetLocalFrame(Frame3f newFrame, CoordSpace eSpace)
 {
     SceneUtil.SetSOLocalFrame(this, eSpace, newFrame);
     increment_timestamp();
     if (OnTransformModified != null)
     {
         OnTransformModified(this);
     }
 }
コード例 #4
0
ファイル: ToolManager.cs プロジェクト: xiaodelea/frame3Sharp
        public bool ActivateTool(ToolSide eSide)
        {
            int nSide = (int)eSide;

            if (activeType[nSide] == null || activeBuilder[nSide] == null)
            {
                return(false);
            }

            // deactivate existing tool? I guess.
            if (activeTool[nSide] != null)
            {
                DeactivateTool(eSide);
            }

            // try to build tool for current selection
            List <SceneObject> selected = SceneUtil.FindObjectsOfType <SceneObject>(SceneManager.Scene.Selected, true);

            if (selected.Count > 1)
            {
                if (activeBuilder[nSide].IsSupported(ToolTargetType.MultipleObject, selected))
                {
                    activeTool[nSide] = activeBuilder[nSide].Build(SceneManager.Scene, selected);
                }
            }
            else if (selected.Count == 1)
            {
                if (activeBuilder[nSide].IsSupported(ToolTargetType.SingleObject, selected))
                {
                    activeTool[nSide] = activeBuilder[nSide].Build(SceneManager.Scene, selected);
                }
            }

            // if we did not get an active tool in above block, try starting Scene-level tool
            if (activeTool[nSide] == null)
            {
                var all_objects = SceneUtil.FindObjectsOfType <SceneObject>(SceneManager.Scene.SceneObjects, true);
                if (activeBuilder[nSide].IsSupported(ToolTargetType.Scene, all_objects))
                {
                    activeTool[nSide] = activeBuilder[nSide].Build(SceneManager.Scene, all_objects);
                }
            }

            if (activeTool[nSide] != null)
            {
                activeTool[nSide].Setup();
                SendOnToolActivationChanged(activeTool[nSide], eSide, true);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
ファイル: GroupSO.cs プロジェクト: xiaodelea/frame3Sharp
        public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;
            if (SelectionMode == SelectionModes.NoSelection)
            {
                return(false);
            }

            bool bHit = SceneUtil.FindNearestRayIntersection(vChildren, ray, out hit);

            if (bHit && SelectionMode == SelectionModes.SelectGroup)
            {
                hit.hitSO = this;
            }
            return(bHit);
        }
コード例 #6
0
ファイル: GroupSO.cs プロジェクト: ZeroLu/frame3Sharp
        public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;
            if (EnableSelection == false)
            {
                return(false);
            }

            bool bHit = SceneUtil.FindNearestRayIntersection(vChildren, ray, out hit);

            if (bHit)
            {
                hit.hitSO = this;
            }
            return(bHit);
        }
コード例 #7
0
 private void collect_type_in_children <T>(SOCollection groupSO, bool bVisibleOnly, List <T> collection) where T : class
 {
     foreach (var child in groupSO.GetChildren())
     {
         if (child is T)
         {
             if (bVisibleOnly == false || SceneUtil.IsVisible(child))
             {
                 collection.Add(child as T);
             }
         }
         if (child is SOCollection)
         {
             collect_type_in_children(child as SOCollection, bVisibleOnly, collection);
         }
     }
 }
コード例 #8
0
        virtual public void BeginTransformation()
        {
            curChange                   = new TransformGizmoChange();
            curChange.parentSO          = new WeakReference(Target);
            curChange.parentBefore      = GetLocalFrame(CoordSpace.SceneCoords);
            curChange.parentScaleBefore = GetLocalScale();

            if (target.IsTemporary)
            {
                curChange.childSOs = new List <TransformableSO>();
                SceneUtil.FindAllPersistentTransformableChildren(target, curChange.childSOs);
                curChange.before      = new List <Frame3f>();
                curChange.scaleBefore = new List <Vector3f>();
                foreach (TransformableSO so in curChange.childSOs)
                {
                    curChange.before.Add(so.GetLocalFrame(CoordSpace.SceneCoords));
                    curChange.scaleBefore.Add(UnityUtil.GetFreeLocalScale(so.RootGameObject));
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Find SceneObjects of a given type. If bSelected == true, only considers selected
        /// SOs. By default will descend into groups.
        /// </summary>
        public List <T> FindSceneObjectsOfType <T>(bool bSelected = false, bool bDescendGroups = true, bool bVisibleOnly = false) where T : class
        {
            List <T>           result = new List <T>();
            List <SceneObject> source = (bSelected) ? vSelected : vObjects;

            foreach (var so in source)
            {
                if (so is T)
                {
                    if (bVisibleOnly == false || SceneUtil.IsVisible(so))
                    {
                        result.Add(so as T);
                    }
                }
                if (bDescendGroups && so is SOCollection)
                {
                    collect_type_in_children(so as SOCollection, bVisibleOnly, result);
                }
            }
            return(result);
        }
コード例 #10
0
 virtual public Frame3f GetLocalFrame(CoordSpace eSpace)
 {
     return(SceneUtil.GetSOLocalFrame(this, eSpace));
 }
コード例 #11
0
        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
                });
            }
        }
コード例 #12
0
ファイル: GroupSO.cs プロジェクト: ly774508966/frame3Sharp
 virtual public AxisAlignedBox3f GetLocalBoundingBox()
 {
     return(SceneUtil.GetLocalBoundingBox(vChildren.Cast <SceneObject>()));
 }