示例#1
0
        public void EndDraw()
        {
            if (preview.Curve.ArcLength > 2 * SamplingRate)
            {
                if (EmitNewCurveF == null)
                {
                    // store undo/redo record for new primitive
                    SOMaterial  mat     = (CurveMaterialF == null) ? scene.DefaultCurveSOMaterial : CurveMaterialF();
                    PolyCurveSO CurveSO = preview.BuildSO(mat, 1.0f);
                    scene.History.PushChange(
                        new AddSOChange()
                    {
                        scene = scene, so = CurveSO, bKeepWorldPosition = false
                    });

                    // link ?
                    if (AttachCurveToSurface)
                    {
                        scene.History.PushChange(
                            new SOAddFrameLinkChangeOp(CurveSO, Target as TransformableSO));
                    }

                    scene.History.PushInteractionCheckpoint();
                }
                else
                {
                    EmitNewCurveF(preview);
                }
            }

            preview.Destroy();
            preview = null;

            //SavedSettings.Save("DrawSurfaceCurveTool_width", width);
        }
示例#2
0
        public CylinderSO Create(SOMaterial defaultMaterial)
        {
            cylinder = new GameObject(UniqueNames.GetNext("Cylinder"));
            AssignSOMaterial(defaultMaterial);       // need to do this to setup BaseSO material stack

            Material useMaterial = CurrentMaterial;

            topCap = AppendMeshGO("topCap",
                                  MeshGenerators.CreateDisc(radius, 1, 16),
                                  useMaterial, cylinder);
            topCap.transform.localPosition += 0.5f * height * Vector3.up;

            bottomCap = AppendMeshGO("bottomCap",
                                     MeshGenerators.CreateDisc(radius, 1, 16),
                                     useMaterial, cylinder);
            bottomCap.transform.RotateAround(Vector3.zero, Vector3.right, 180.0f);
            bottomCap.transform.localPosition -= 0.5f * height * Vector3.up;

            body = AppendMeshGO("body",
                                MeshGenerators.CreateCylider(radius, height, 16),
                                useMaterial, cylinder);
            body.transform.localPosition -= 0.5f * height * Vector3.up;

            update_shift();
            cylinder.transform.position += centerShift;

            increment_timestamp();
            return(this);
        }
        // https://en.wikipedia.org/wiki/Wavefront_.obj_file#Material_template_library
        SOMaterial build_material(string sSourceFilePath, g3.GenericMaterial mIn)
        {
            OBJMaterial objMat = mIn as OBJMaterial;

            // TODO handle other types?

            if (objMat.illum < 0 || objMat.illum == 1 || objMat.illum == 2)
            {
                SOMaterial sceneMat = new SOMaterial()
                {
                    Name     = objMat.name,
                    Type     = SOMaterial.MaterialType.TextureMap,
                    RGBColor = toColor(objMat.DiffuseColor, objMat.Alpha)
                };

                if (objMat.map_Kd != null && objMat.map_Kd != "")
                {
                    Texture2D tex = load_texture(sSourceFilePath, objMat.map_Kd);
                    sceneMat.MainTexture = tex;
                    if (objMat.Kd == GenericMaterial.Invalid)
                    {
                        sceneMat.RGBColor = Colorf.White;
                    }
                }
                return(sceneMat);
            }

            return(null);
        }
示例#4
0
        // https://en.wikipedia.org/wiki/Wavefront_.obj_file#Material_template_library
        SOMaterial build_material(string sSourceFilePath, g3.GenericMaterial mIn)
        {
            OBJMaterial objMat = mIn as OBJMaterial;
            // TODO handle other types?

            int lightmodel = objMat.illum;

            if (lightmodel > 2)     // [RMS] we don't support these anyway, but don't want to ignore these materials...
            {
                lightmodel = 2;
            }
            if (lightmodel < 0 || lightmodel == 0 || lightmodel == 1 || lightmodel == 2)
            {
                SOMaterial sceneMat = new SOMaterial()
                {
                    Name     = objMat.name,
                    Type     = SOMaterial.MaterialType.TextureMap,
                    RGBColor = toColor(objMat.DiffuseColor, objMat.Alpha)
                };

                if (objMat.map_Kd != null && objMat.map_Kd != "")
                {
                    Texture2D tex = load_texture(sSourceFilePath, objMat.map_Kd);
                    sceneMat.MainTexture = tex;
                    if (objMat.Kd == GenericMaterial.Invalid)
                    {
                        sceneMat.RGBColor = Colorf.White;
                    }
                }
                return(sceneMat);
            }

            return(null);
        }
示例#5
0
        public virtual MeshSO Create(SimpleMesh mesh, SOMaterial setMaterial)
        {
            Mesh umesh = UnityUtil.SimpleMeshToUnityMesh(mesh, false);

            Create(umesh, setMaterial);
            return(this);
        }
示例#6
0
        public PivotSO Create(SOMaterial sphereMaterial, Material frameMaterial, int nSphereLayer = -1)
        {
            // [TODO] replace frame geometry with line renderer ?
            // [TODO] still cast shadows  (semitransparent objects don't cast shadows, apparently)
            // [TODO] maybe render solid when not obscured by objects? use raycast in PreRender?

            AssignSOMaterial(sphereMaterial);       // need to do this to setup BaseSO material stack

            pivot  = new GameObject(UniqueNames.GetNext("Pivot"));
            meshGO = AppendUnityPrimitiveGO("pivotMesh", PrimitiveType.Sphere, CurrentMaterial, pivot);
            meshGO.transform.localScale = 0.9f * Vector3.one;

            if (frameMaterial != null)
            {
                frameMesh = UnityUtil.CreateMeshGO("pivotFrame", "icon_meshes/axis_frame", 1.0f,
                                                   UnityUtil.MeshAlignOption.NoAlignment, frameMaterial, false);
                frameMesh.AddComponent <IgnoreMaterialChanges>();
                MaterialUtil.DisableShadows(frameMesh);
                AppendNewGO(frameMesh, pivot, false);
            }

            if (nSphereLayer >= 0)
            {
                meshGO.SetLayer(nSphereLayer);
            }

            increment_timestamp();
            return(this);
        }
示例#7
0
        public virtual PivotSO Create(SOMaterial shapeMaterial, SOMaterial frameMaterial = null, int nShapeLayer = -1)
        {
            // [TODO] replace frame geometry with line renderer ?
            // [TODO] still cast shadows  (semitransparent objects don't cast shadows, apparently)
            // [TODO] maybe render solid when not obscured by objects? use raycast in PreRender?

            AssignSOMaterial(shapeMaterial);       // need to do this to setup BaseSO material stack

            pivotGO = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("Pivot"));

            shapeGO = create_pivot_shape();
            AppendNewGO(shapeGO, pivotGO, false);

            pivotGO.AddChild(shapeGO);

            if (frameMaterial != null)
            {
                this.frameMaterial = frameMaterial;

                frameGO = UnityUtil.CreateMeshGO("pivotFrame", "icon_meshes/axis_frame", 1.0f,
                                                 UnityUtil.MeshAlignOption.NoAlignment, MaterialUtil.ToUnityMaterial(frameMaterial), false);
                MaterialUtil.SetIgnoreMaterialChanges(frameGO);
                MaterialUtil.DisableShadows(frameGO);
                AppendNewGO(frameGO, pivotGO, false);
            }

            if (nShapeLayer >= 0)
            {
                shapeGO.SetLayer(nShapeLayer);
            }

            increment_timestamp();
            return(this);
        }
示例#8
0
 override public void AssignSOMaterial(SOMaterial m)
 {
     if (AllowMaterialChanges)
     {
         base.AssignSOMaterial(m);
     }
 }
示例#9
0
        public PolyCurveSO Create(SOMaterial defaultMaterial)
        {
            if (curve == null)
            {
                LineGenerator gen = new LineGenerator()
                {
                    Start = Vector3.zero, End = 10.0f * Vector3.up, StepSize = 0.1f
                };
                gen.Generate();
                curve = new DCurve3();
                gen.Make(curve);
            }

            // assumes type identifier is something like BlahBlahSO
            root = new GameObject(UniqueNames.GetNext(Type.identifier.Remove(Type.identifier.Length - 2)));

            if (EnableLineRenderer)
            {
                LineRenderer ren = root.AddComponent <LineRenderer>();
                ren.startWidth    = ren.endWidth = 0.05f;
                ren.useWorldSpace = false;
            }

            AssignSOMaterial(defaultMaterial);       // need to do this to setup BaseSO material stack
            Material useMaterial = CurrentMaterial;

            Create_internal(useMaterial);

            UpdateGeometry();

            increment_timestamp();

            return(this);
        }
示例#10
0
        // parse file and create a set of MeshSO objects
        public bool ReadFile(string sPath)
        {
            sSourcePath = sPath;
            SomeMeshesTooLargeForUnityWarning = false;

            // read the input file

            DMesh3Builder build = new DMesh3Builder();

            StandardMeshReader reader = new StandardMeshReader()
            {
                MeshBuilder = build
            };

            reader.warningEvent += on_warning;

            ReadOptions options = new ReadOptions();

            options.ReadMaterials = true;
            LastReadResult        = reader.Read(sPath, options);
            if (LastReadResult.code != IOCode.Ok)
            {
                return(false);
            }

            // create the material set

            List <SOMaterial> vSOMaterials = new List <SOMaterial>();

            for (int k = 0; k < build.Materials.Count; ++k)
            {
                SOMaterial m = build_material(sPath, build.Materials[k]);
                vSOMaterials.Add(m);
            }

            // convert the read meshes into unity meshes

            SceneObjects = new List <ImportedObject>();
            for (int k = 0; k < build.Meshes.Count; ++k)
            {
                DMesh3 mesh = build.Meshes[k];

                int        matID      = build.MaterialAssignment[k];
                SOMaterial soMaterial =
                    (matID < 0 || matID >= vSOMaterials.Count) ? null : vSOMaterials[matID];

                if (SwapLeftRight)
                {
                    MeshTransforms.FlipLeftRightCoordSystems(mesh);
                }

                SceneObjects.Add(new ImportedObject()
                {
                    mesh = mesh, material = soMaterial
                });
            }

            return(SceneObjects.Count > 0);
        }
示例#11
0
 virtual public void AssignSOMaterial(SOMaterial m)
 {
     foreach (var so in vChildren)
     {
         so.AssignSOMaterial(m);
     }
     increment_timestamp();
 }
        public void Create(SOMaterial useMaterial, GameObject parent, float fMinDimension)
        {
            meshObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            meshObject.GetComponent <MeshRenderer>().material = MaterialUtil.ToUnityMaterial(useMaterial);
            bUpdatePending = true;

            meshObject.transform.SetParent(parent.transform, false);

            Height = Width = Depth = fMinDimension;
        }
示例#13
0
 public virtual PolyCurveSO BuildSO(SOMaterial material, float scale = 1.0f)
 {
     return((PolyCurveSO)BuildSO((curveIn) => {
         PolyCurveSO so = new PolyCurveSO()
         {
             Curve = curveIn
         };
         so.Create(material);
         return so;
     }, material, scale));
 }
        public void Create(SOMaterial useMaterial, GameObject parent, float fMinDimension)
        {
            meshObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            fMaterial mat = MaterialUtil.ToMaterialf(useMaterial);

            meshObject.SetMaterial(mat, true);
            bUpdatePending = true;

            meshObject.transform.SetParent(parent.transform, false);

            Height = Width = Depth = fMinDimension;
        }
示例#15
0
        public FScene(FContext context)
        {
            this.context = context;

            history       = new ChangeHistory();
            history_stack = new List <ChangeHistory>();
            TypeRegistry  = new SORegistry();

            initialize_scene_root();

            // initialize materials
            DefaultSOMaterial = new SOMaterial()
            {
                Name = "DefaultSO",
                Type = SOMaterial.MaterialType.StandardRGBColor, RGBColor = ColorUtil.StandardBeige
            };
            DefaultCurveSOMaterial = new SOMaterial()
            {
                Name = "DefaultCurveSO",
                Type = SOMaterial.MaterialType.UnlitRGBColor, RGBColor = Colorf.DarkSlateGrey
            };
            DefaultMeshSOMaterial = new SOMaterial()
            {
                Name = "DefaultMeshSO",
                Type = SOMaterial.MaterialType.PerVertexColor, RGBColor = Colorf.White
            };
            NewSOMaterial = new SOMaterial()
            {
                Name = "NewSO",
                Type = SOMaterial.MaterialType.StandardRGBColor, RGBColor = Colorf.CornflowerBlue
            };
            TransparentNewSOMaterial = new SOMaterial()
            {
                Name = "NewSO",
                Type = SOMaterial.MaterialType.TransparentRGBColor, RGBColor = new Colorf(Colorf.CornflowerBlue, 0.5f)
            };
            PivotSOMaterial = new SOMaterial()
            {
                Name = "PivotSO",
                Type = SOMaterial.MaterialType.TransparentRGBColor, RGBColor = ColorUtil.PivotYellow.SetAlpha(0.75f)
            };
            FrameSOMaterial = new SOMaterial()
            {
                Name = "PivotFrame",
                Type = SOMaterial.MaterialType.StandardRGBColor, RGBColor = ColorUtil.DarkGrey
            };

            SelectedMaterial = MaterialUtil.CreateStandardMaterial(ColorUtil.SelectionGold);
            FrameMaterial    = MaterialUtil.CreateStandardMaterial(ColorUtil.DarkGrey);
            PivotMaterial    = MaterialUtil.ToMaterialf(PivotSOMaterial);

            defaultPrimitiveType = SOTypes.Cylinder;
        }
示例#16
0
        public static SOMaterial CreateTransparentVariant(SOMaterial m, float fAlpha)
        {
            if (m.Type != MaterialType.StandardRGBColor)
            {
                throw new NotImplementedException("SOMaterial.CreateTransparentVariant only supports Standard materials");
            }
            SOMaterial copy = m.Clone();

            copy.Name    += "_Tr";
            copy.Type     = MaterialType.TransparentRGBColor;
            copy.RGBColor = new Colorf(copy.RGBColor, fAlpha);
            return(copy);
        }
示例#17
0
        public virtual DMeshSO Create(DMesh3 mesh, SOMaterial setMaterial)
        {
            AssignSOMaterial(setMaterial);       // need to do this to setup BaseSO material stack
            parentGO = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("DMesh"));

            this.mesh = mesh;
            on_mesh_changed();

            displayComponents = new List <DisplayMeshComponent>();
            validate_decomp();

            return(this);
        }
示例#18
0
        public virtual SceneObject BuildSO(Func <DCurve3, SceneObject> SOBuilderF, SOMaterial material, float scale = 1.0f)
        {
            // create shifted curve
            Vector3d vCenter      = curve.GetBoundingBox().Center;
            DCurve3  shifted      = bake_transform(-vCenter);
            Frame3f  shiftedFrame = new Frame3f((Vector3f)vCenter, Quaternionf.Identity);

            SceneObject so = SOBuilderF(shifted);

            so.SetLocalFrame(shiftedFrame, CoordSpace.WorldCoords);

            return(so);
        }
示例#19
0
        public virtual DMeshSO Create(DMesh3 mesh, SOMaterial setMaterial)
        {
            AssignSOMaterial(setMaterial);       // need to do this to setup BaseSO material stack
            parentGO = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("DMesh"));

            this.mesh = mesh;



            on_mesh_changed();
            validate_view_meshes();

            return(this);
        }
示例#20
0
        public SphereSO Create(SOMaterial defaultMaterial)
        {
            AssignSOMaterial(defaultMaterial);       // need to do this to setup BaseSO material stack

            sphere     = new GameObject(UniqueNames.GetNext("Sphere"));
            sphereMesh = AppendUnityPrimitiveGO("sphereMesh", PrimitiveType.Sphere, CurrentMaterial, sphere);
            sphereMesh.transform.localScale = new Vector3(2 * radius, 2 * radius, 2 * radius);

            update_shift();
            sphere.transform.position += centerShift;

            increment_timestamp();
            return(this);
        }
示例#21
0
        public BoxSO Create(SOMaterial defaultMaterial)
        {
            AssignSOMaterial(defaultMaterial);       // need to do this to setup BaseSO material stack

            box     = new GameObject(UniqueNames.GetNext("Box"));
            boxMesh = AppendUnityPrimitiveGO("boxMesh", PrimitiveType.Cube, CurrentMaterial, box);
            boxMesh.transform.localScale = new Vector3(width, height, depth);

            update_shift();
            box.transform.position += centerShift;

            increment_timestamp();
            return(this);
        }
示例#22
0
        public virtual DMeshSO Create(DMesh3 mesh, SOMaterial setMaterial)
        {
            AssignSOMaterial(setMaterial);       // need to do this to setup BaseSO material stack
            parentGO = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("DMesh"));

            this.mesh = mesh;

            //viewMeshes = new LinearDecompViewMeshManager(this);
            viewMeshes = new TrivialViewMeshManager(this);

            on_mesh_changed();
            viewMeshes.ValidateViewMeshes();

            return(this);
        }
示例#23
0
        public virtual MeshSO Create(Mesh mesh, SOMaterial setMaterial)
        {
            AssignSOMaterial(setMaterial);       // need to do this to setup BaseSO material stack

            parentGO = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("Mesh"));

            meshGO = new GameObject("mesh");
            meshGO.AddComponent <MeshFilter>();
            meshGO.SetMesh(mesh);
            meshGO.AddComponent <MeshCollider>().enabled  = false;
            meshGO.AddComponent <MeshRenderer>().material = CurrentMaterial;

            AppendNewGO(meshGO, (GameObject)parentGO, true);
            return(this);
        }
示例#24
0
 virtual public void AssignSOMaterial(SOMaterial m)
 {
     sceneMaterial        = m;
     displaySceneMaterial = MaterialUtil.ToMaterialf(m);
     if (vMaterialStack.Count > 0)
     {
         // material 0 is always our base material, higher levels of stack are
         // temp materials that will be popped eventually
         vMaterialStack[0] = displaySceneMaterial;
     }
     else
     {
         displayMaterial = displaySceneMaterial;
         set_material_internal(displayMaterial);
     }
     increment_timestamp();
 }
 /// <summary>
 /// Emit an SOMaterial as a MaterialStruct
 /// </summary>
 public static void EmitMaterial(this SceneSerializer s, IOutputStream o, SOMaterial mat)
 {
     o.BeginStruct(IOStrings.MaterialStruct);
     if (mat.Type == SOMaterial.MaterialType.StandardRGBColor)
     {
         o.AddAttribute(IOStrings.AMaterialType, IOStrings.AMaterialType_Standard);
         o.AddAttribute(IOStrings.AMaterialName, mat.Name);
         o.AddAttribute(IOStrings.AMaterialRGBColor, mat.RGBColor);
     }
     else if (mat.Type == SOMaterial.MaterialType.TransparentRGBColor)
     {
         o.AddAttribute(IOStrings.AMaterialType, IOStrings.AMaterialType_Transparent);
         o.AddAttribute(IOStrings.AMaterialName, mat.Name);
         o.AddAttribute(IOStrings.AMaterialRGBColor, mat.RGBColor);
     }
     o.EndStruct();
 }
示例#26
0
        public static SOMaterial FromUnityMaterial(Material unityMat)
        {
            SOMaterial soMat = new SOMaterial();

            soMat.Name     = unityMat.name;
            soMat.RGBColor = unityMat.color;
            if (unityMat.color.a == 1)
            {
                soMat.Type = SOMaterial.MaterialType.StandardRGBColor;
            }
            else
            {
                soMat.Type = SOMaterial.MaterialType.TransparentRGBColor;
            }

            return(soMat);
        }
示例#27
0
        void CreateNewCurve()
        {
            if (AttachCurveToSurface)
            {
                preview = new LocalCurvePreview(Target as TransformableSO);
            }
            else
            {
                preview = new CurvePreview();
            }

            preview.Closed = this.Closed;

            SOMaterial useMat = (CurveMaterialF == null) ? scene.DefaultCurveSOMaterial : CurveMaterialF();

            preview.Create(useMat, scene.RootGameObject,
                           (overlay) ? FPlatform.WidgetOverlayLayer : -1);
        }
示例#28
0
        public virtual void EndDraw()
        {
            in_draw = false;
            if (preview == null)
            {
                return;
            }
            if (preview.Curve.VertexCount > 2 && preview.Curve.ArcLength > 2 * SamplingRateScene)
            {
                // update Closed state because in some cases we change this during drawing
                // (ie when drawing multi-point curve, but closing at end)
                preview.Closed = this.Closed;

                if (EmitNewCurveF == null)
                {
                    // store undo/redo record for new primitive
                    SOMaterial  mat     = (CurveMaterialF == null) ? Scene.DefaultCurveSOMaterial : CurveMaterialF();
                    PolyCurveSO CurveSO = preview.BuildSO(mat, 1.0f);
                    Scene.History.PushChange(
                        new AddSOChange()
                    {
                        scene = Scene, so = CurveSO, bKeepWorldPosition = false
                    });

                    // link ?
                    if (AttachCurveToSurface)
                    {
                        Scene.History.PushChange(
                            new SOAddFrameLinkChangeOp(CurveSO, Target));
                    }

                    Scene.History.PushInteractionCheckpoint();
                }
                else
                {
                    EmitNewCurveF(preview);
                }
            }

            preview.Destroy();
            preview = null;

            //SavedSettings.Save("DrawSurfaceCurveTool_width", width);
        }
示例#29
0
        public virtual void RestoreMaterial(SceneObject so, TypedAttribSet attributes)
        {
            TypedAttribSet material = find_struct(attributes, IOStrings.MaterialStruct);

            if (material == null)
            {
                throw new Exception("SOFactory.RestoreMaterial: Material struct not found!");
            }


            SOMaterial mat        = new SOMaterial();
            bool       bKnownType = false;

            if (check_key_or_debug_print(material, IOStrings.AMaterialType))
            {
                string sType = material[IOStrings.AMaterialType] as string;
                if (sType == IOStrings.AMaterialType_Standard)
                {
                    mat.Type   = SOMaterial.MaterialType.StandardRGBColor;
                    bKnownType = true;
                }
                else if (sType == IOStrings.AMaterialType_Transparent)
                {
                    mat.Type   = SOMaterial.MaterialType.TransparentRGBColor;
                    bKnownType = true;
                }
            }
            if (bKnownType == false)
            {
                return;
            }

            if (check_key_or_debug_print(material, IOStrings.AMaterialName))
            {
                mat.Name = material[IOStrings.AMaterialName] as string;
            }

            if (check_key_or_debug_print(material, IOStrings.AMaterialRGBColor))
            {
                mat.RGBColor = (Colorf)material[IOStrings.AMaterialRGBColor];
            }

            so.AssignSOMaterial(mat);
        }
示例#30
0
        public MeshReferenceSO GetMeshReference(SOMaterial defaultMaterial)
        {
            MeshReferenceSO ref_group = new MeshReferenceSO();

            ref_group.MeshReferencePath = sSourcePath;
            ref_group.Create();
            ref_group.Name = UniqueNames.GetNext("MeshReference");

            foreach (ImportedObject obj in SceneObjects)
            {
                DMeshSO meshSO = new DMeshSO();
                meshSO.Create(obj.mesh,
                              (obj.material == null) ? defaultMaterial : obj.material);
                meshSO.Name = UniqueNames.GetNext("ImportMesh");
                ref_group.AddChild(meshSO);
            }

            return(ref_group);
        }