public override void Run(RenderControl render)
        {
            var material = MeshStandardMaterial.Create("workpiece");

            material.SetColor(new Vector3(0.9f));
            material.SetFaceSide(EnumFaceSide.DoubleSide);

            var shape = ShapeBuilder.MakeCylinder(GP.YOZ(), 5, 50, 0);

            mWorkpiece = BrepSceneNode.Create(shape, material, null);

            render.ShowSceneNode(mWorkpiece);

            {
                var coord     = new GAx2(new GPnt(0, 0, 5), GP.DZ());
                var toolShape = ShapeBuilder.MakeCone(coord, 0, 2, 5, 0);
                render.ShowShape(toolShape, Vector3.Blue);
            }


            render.ShowSceneNode(mMotionTrail);

            mLength = 0;
            mTheta  = 0;
        }
示例#2
0
        GroupSceneNode CreateFrames(double width, double height, double deep, double radius)
        {
            var baseSketch = CreateSketch(radius, deep);

            //TopLeft
            var s11 = Project(baseSketch, new GPnt(0, 0, height), new GDir(-1, 0, -1), GP.DZ());
            //BottomLeft
            var s20 = Project(baseSketch, GP.Origin(), new GDir(-1, 0, 1), GP.DZ());
            //BottomRight
            var s12 = Project(s20, new GPnt(width, 0, 0), new GDir(1, 0, 1), GP.DX());
            //TopRight
            var s21 = Project(s11, new GPnt(width, 0, height), new GDir(-1, 0, 1), GP.DX());

            var frame1 = FeatureTool.Loft(s11, s20, false);
            var frame2 = FeatureTool.Loft(s20, s12, false);
            var frame3 = FeatureTool.Loft(s12, s21, false);
            var frame4 = FeatureTool.Loft(s21, s11, false);

            var frameMaterial = MeshStandardMaterial.Create("window-frame");

            frameMaterial.SetColor(Vector3.LightGray);
            frameMaterial.SetMetalness(0.5f);
            frameMaterial.SetFaceSide(EnumFaceSide.DoubleSide);

            var group = new GroupSceneNode();

            group.AddNode(BrepSceneNode.Create(frame1, frameMaterial, null));
            group.AddNode(BrepSceneNode.Create(frame2, frameMaterial, null));
            group.AddNode(BrepSceneNode.Create(frame3, frameMaterial, null));
            group.AddNode(BrepSceneNode.Create(frame4, frameMaterial, null));

            return(group);
        }
示例#3
0
        public override void Run(RenderControl render)
        {
            var material = MeshStandardMaterial.Create("workpiece");

            material.SetColor(new Vector3(0.9f));
            material.SetFaceSide(EnumFaceSide.DoubleSide);

            var shape = ShapeBuilder.MakeCylinder(GP.YOZ(), 5, 50, 0);

            mWorkpiece = BrepSceneNode.Create(shape, material, null);

            render.ShowSceneNode(mWorkpiece);

            var coord     = new GAx2(new GPnt(0, 0, 5), GP.DZ());
            var toolShape = ShapeBuilder.MakeCone(coord, 0, 2, 5, 0);
            var toolNode  = render.ShowShape(toolShape, ColorTable.Blue);


            render.ShowSceneNode(mMotionTrail);


            // Initialize Animation
            mAnimation = new RigidAnimation();

            var rotation = Matrix4.makeRotationAxis(new Vector3(1, 0, 0), (float)Math.PI);
            var trf      = Matrix4.makeTranslation(-50, 0, 0) * rotation;

            mAnimation.Add(new MatrixAnimationClip(mWorkpiece, mWorkpiece.GetTransform(), trf, 0, 10));
            mAnimation.Add(new MatrixAnimationClip(toolNode, toolNode.GetTransform(), trf, 10, 15));
            mAnimation.Add(new RotateAnimationClip(toolNode, Vector3.UNIT_Z, (float)Math.PI * 4, 16, 20));
        }
        public override void Run(RenderControl render)
        {
            Random   rand   = new Random();
            GPntList points = new GPntList();

            for (int ii = 0; ii < 5; ++ii)
            {
                for (int jj = 0; jj < 5; ++jj)
                {
                    points.Add(new GPnt(ii, jj, rand.NextDouble()));
                }
            }

            var surf = SurfaceBuilder.PointsToBSplineSurface(points, 5);

            var material = MeshStandardMaterial.Create("plastic");

            material.SetRoughness(0.1f);
            material.SetMetalness(0.4f);
            material.SetColor(new Vector3(0.98f, 0.55f, 0.33f));
            material.SetFaceSide(EnumFaceSide.DoubleSide);
            var node = BrepSceneNode.Create(surf, material, null);

            render.ShowSceneNode(node);
        }
        public override void Run(RenderControl renderer)
        {
            string fileName = GetResourcePath("Holes.stp");
            var    shape    = StepIO.Open(fileName);

            if (shape == null)
            {
                return;
            }


            var face    = shape.FindChild(EnumTopoShapeType.Topo_FACE, 148);
            var surface = new ParametricSurface(face);

            var wireExp = new WireExplor(face);
            var wires   = wireExp.GetInnerWires();

            foreach (var wire in wires)
            {
                // Show wire
                renderer.ShowShape(wire, Vector3.Red);

                var curve     = new ParametricCurve(wire);
                var paramList = curve.SplitByUniformLength(1, 0.01);

                var  lines = new SegmentsSceneNode((uint)paramList.Count, Vector3.Green, 2);
                uint idx   = 0;
                foreach (var p in paramList)
                {
                    var pt       = curve.Value(p);
                    var pointSur = new ExtremaPointSurface();
                    if (pointSur.Initialize(surface, pt, GP.Resolution(), GP.Resolution()))
                    {
                        var uv     = pointSur.GetParameter(0);
                        var normal = surface.GetNormal(uv.X(), uv.Y());

                        lines.SetPositions(idx++, Vector3.From(pt), Vector3.From(pt.XYZ().Added(normal.XYZ())));
                    }
                }
                lines.UpdateBoundingBox();
                renderer.ShowSceneNode(lines);
            }

            // Show face
            var faceMaterial = MeshStandardMaterial.Create("pbr.face");

            faceMaterial.SetColor(Vector3.LightGray);
            faceMaterial.SetFaceSide(EnumFaceSide.DoubleSide);
            var faceNode = BrepSceneNode.Create(face, faceMaterial, null);

            faceNode.SetDisplayFilter(EnumShapeFilter.Face);
            renderer.ShowSceneNode(faceNode);
        }
示例#6
0
        BrepSceneNode CreateGlass(GAx2 ax, double width, double height, double thickness)
        {
            var shape = ShapeBuilder.MakeBox(ax, width, thickness, height);

            var frameMaterial = MeshStandardMaterial.Create("window-glass");

            frameMaterial.SetColor(ColorTable.Hex(0xAAAAAA));
            frameMaterial.SetFaceSide(EnumFaceSide.DoubleSide);
            frameMaterial.SetTransparent(true);
            frameMaterial.SetOpacity(0.5f);

            return(BrepSceneNode.Create(shape, frameMaterial, null));
        }
示例#7
0
        public override void Run(RenderControl render)
        {
            var material = MeshStandardMaterial.Create("robot");

            material.SetColor(new Vector3(0.9f));
            material.SetFaceSide(EnumFaceSide.DoubleSide);
            material.SetOpacity(0.5f);
            material.SetTransparent(true);

            List <string> files = new List <string>();

            files.Add("Base.brep");
            files.Add("AXIS1.brep");
            files.Add("AXIS2.brep");
            files.Add("AXIS3.brep");
            files.Add("AXIS4.brep");
            files.Add("AXIS5.brep");
            files.Add("AXIS6.brep");

            var rootPath = GetResourcePath(@"models\6R\");

            double scale = 1;

            mRobot.AddJoint(EnumRobotJointType.Fixed, 0, 0, 200 * scale, 0);
            mRobot.AddJoint(EnumRobotJointType.Revolute, 0, 0, 130 * scale, 0);                               // Link1
            mRobot.AddJoint(EnumRobotJointType.Revolute, 90, 30, 0, 180, new RobotDH(90, 0, 480 * scale, 0)); // Link2
            mRobot.AddJoint(EnumRobotJointType.Revolute, 90, 0, 0, 270, new RobotDH(90, 0, 100 * scale, 0));  // Link3
            mRobot.AddJoint(EnumRobotJointType.Revolute, 0, 0, 380 * scale, 0);                               // Link4
            mRobot.AddJoint(EnumRobotJointType.Revolute, 270, 0, 0, 0);                                       // Link5
            mRobot.AddJoint(EnumRobotJointType.Revolute, 90, 0, 100 * scale, 0);                              // Link6

            mRobot.AddLink(0, BrepSceneNode.Create(BrepIO.Open(rootPath + files[0]), material, null, 0.1));
            //Link1
            mRobot.AddLink(1, BrepSceneNode.Create(BrepIO.Open(rootPath + files[1]), material, null, 0.1));
            //Link2
            mRobot.AddLink(2, BrepSceneNode.Create(BrepIO.Open(rootPath + files[2]), material, null, 0.1));
            ////Link3
            mRobot.AddLink(3, BrepSceneNode.Create(BrepIO.Open(rootPath + files[3]), material, null, 0.1));
            //Link4
            mRobot.AddLink(4, BrepSceneNode.Create(BrepIO.Open(rootPath + files[4]), material, null, 0.1));
            //Link5
            mRobot.AddLink(5, BrepSceneNode.Create(BrepIO.Open(rootPath + files[5]), material, null, 0.1));
            //Link6
            mRobot.AddLink(6, BrepSceneNode.Create(BrepIO.Open(rootPath + files[6]), material, null, 0.1));

            mRobot.ResetInitialState();

            render.ShowSceneNode(mRobot);

            render.ShowSceneNode(mMotionTrail);
        }
        void PrepareMaterials()
        {
            if (mRobotMaterial != null)
            {
                return;
            }

            mRobotMaterial = MeshStandardMaterial.Create("robot");
            mRobotMaterial.SetColor(ColorTable.Hex(0xEEFF22));
            mRobotMaterial.SetFaceSide(EnumFaceSide.DoubleSide);
            // mRobotMaterial.SetOpacity(0.5f);
            //mRobotMaterial.SetTransparent(true);

            mMaterial = MeshStandardMaterial.Create("hilight-robot");
            mMaterial.SetColor(ColorTable.Hex(0xFF0000));
            mMaterial.SetFaceSide(EnumFaceSide.DoubleSide);
        }
        public override void Run(RenderControl renderer)
        {
            var shape = ShapeIO.Open(GetResourcePath("hole/30-30.IGS"));

            if (shape == null)
            {
                return;
            }

            var edgeMaterial = BasicMaterial.Create("hole-edge");

            edgeMaterial.SetColor(ColorTable.Hex(0xFF0000));
            edgeMaterial.SetLineWidth(2);


            // 1. Find the exterial holes
            var holeExp = new HoleExplorLegacy();

            if (!holeExp.Initialize(shape))
            {
                return;
            }
            var holeNumber = holeExp.ComputeExteriorHoles();

            for (int ii = 0; ii < holeNumber; ++ii)
            {
                var wire     = holeExp.GetExteriorHoleWire(ii);
                var wireNode = BrepSceneNode.Create(wire, null, edgeMaterial);

                renderer.ShowSceneNode(wireNode);
            }

            // 2. Show the faces
            var material = MeshStandardMaterial.Create("hole-face");

            material.SetColor(ColorTable.Hex(0xBBAA33));
            material.SetRoughness(0.8f);
            material.SetFaceSide(EnumFaceSide.DoubleSide);

            var shapeNode = BrepSceneNode.Create(shape, material, null);

            shapeNode.SetDisplayFilter(EnumShapeFilter.Face);
            renderer.ShowSceneNode(shapeNode);
        }
示例#10
0
        public override void Run(RenderControl render)
        {
            var arrowMaterial = MeshPhongMaterial.Create("arrow");

            arrowMaterial.SetColor(ColorTable.Red);
            mArrow = ArrowWidget.Create(2, 10, arrowMaterial);
            mArrow.SetPickable(false);
            render.ShowSceneNode(mArrow);


            var shape = ShapeBuilder.MakeBox(GP.XOY(), 10, 20, 30);
            var mat   = MeshStandardMaterial.Create("ss");

            mat.SetColor(Vector3.LightGray);

            var node = BrepSceneNode.Create(shape, mat, null);

            render.ShowSceneNode(node);
        }
        public override void Run(RenderControl render)
        {
            var material = MeshStandardMaterial.Create("metal-double");

            material.SetColor(new Vector3(1.0f, 0.8f, 0.0f));
            material.SetMetalness(0.8f);
            material.SetRoughness(0.5f);
            material.SetFaceSide(EnumFaceSide.DoubleSide);


            var startPt = new GVec(0, 100, 0);
            var points  = new GPntList();

            points.Add(new GPnt(startPt.XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(0, 0, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(0, 100, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(-100, 100, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(-100, 300, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(100, 300, 150)).XYZ()));
            TopoShape path = SketchBuilder.MakePolygon(points, false);

            var sectionList = new TopoShapeList();

            GAx2      coord1   = new GAx2(new GPnt(startPt.Added(new GVec(-25, -25, 0)).XYZ()), GP.DY());
            TopoShape section1 = SketchBuilder.MakeRectangle(coord1, 50, 50, 10, false);

            render.ShowShape(section1, ColorTable.Red);
            render.ShowShape(path, ColorTable.Green);

            TopoShape pipe = FeatureTool.SweepByFrenet(section1, path, EnumSweepTransitionMode.RoundCorner,
                                                       false);
            BufferShape bs = new BufferShape(pipe, material, null, 0.1f);

            bs.Build();
            var node = new BrepSceneNode(bs);

            render.ShowSceneNode(node);
        }
示例#12
0
        public override void Run(RenderControl render)
        {
            var material = MeshStandardMaterial.Create("my-material");

            material.SetRoughness(0.75f);
            material.SetMetalness(0.1f);
            material.SetColor(ColorTable.Hex(0xFFC107));

            for (uint ii = 0; ii < 10; ++ii)
            {
                TopoShape shape = ShapeBuilder.MakePyramid(new GAx2(new GPnt(ii * 11, 0, 0), GP.DZ()), ii + 3, 5, 5 + ii);
                var       node  = BrepSceneNode.Create(shape, material, null);
                render.ShowSceneNode(node);
            }

            //var bottom = SketchBuilder.MakeRectangle(GP.XOY(), 10, 20, 2, false);
            //var shape2 = FeatureTool.Loft(bottom, new GPnt(5, 10, 10));

            //render.ShowShape(shape2, ColorTable.Blue);

            //var shape3 =  ShapeBuilder.MakeCone(GP.XOY(), 10, 0, 10, 0);
            //render.ShowShape(shape3, ColorTable.Blue);
        }
示例#13
0
        static void Main(string[] args)
        {
            var scene = new Scene
            {
                Background = new  Color(255, 0, 255).ToInt(),
                Name       = "My Scene"
            };

            var verts = new List <float[]>
            {
                new float[] { 0, 0, 0 },
                new float[] { 0, 0, 10.1234f },
                new float[] { 10, 0, 10 },
                new float[] { 10, 0, 0 }
            };

            var norms = new List <float[]>
            {
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 }
            };

            var vertices = Utilities.Flatten(verts).Cast <float>().ToList();//Geometry.ProcessVertexArray(verts);

            var normals = Utilities.Flatten(norms).Cast <float>().ToList();

            var face1 = new int[] { 0, 1, 2 };
            var face2 = new int[] { 0, 2, 3 };

            var faces = Geometry.ProcessFaceArray(new List <int[]> {
                { face1 }, { face2 }
            }, false, false);

            var geometry  = new Geometry(vertices, faces, normals);
            var geometry2 = new Geometry(vertices, faces, normals);
            var material  = MeshStandardMaterial.Default();

            var mesh = new Mesh
            {
                Geometry = geometry2,
                Material = material,
                Name     = "My Mesh"
            };

            //scene.Add(mesh);

            var material2 = MeshStandardMaterial.Default();

            material2.Roughness = 0.25;

            var mesh2 = new Mesh
            {
                Geometry = geometry,
                Material = material2,
                Position = new Vector3(20, 20, 20),
                Name     = "My Mesh2"
            };

            //scene.Add(mesh2);

            var material3 = MeshStandardMaterial.Default();

            var mesh3 = new Mesh
            {
                Geometry = geometry2,
                Material = material3,
                Position = new Vector3(30, 30, 30),
                Name     = "My Mesh3"
            };

            //scene.Add(mesh3);

            var line = new Line
            {
                Geometry = new Geometry(vertices),
                Material = new LineBasicMaterial {
                    Color = new Color(255, 0, 0).ToInt(), LineWidth = 20
                },
                Name = "My Curves"
            };

            //scene.Add(line);

            var colors = new List <int>
            {
                255, 0, 0,
                255, 255, 0,
                255, 0, 255,
                0, 255, 0
            };

            var pointsGeometry = new BufferGeometry
            {
                Attributes =
                {
                    { "position", new BufferAttribute
                        {
                            Array    = vertices.Cast <object>().ToArray(),
                            ItemSize = 3,
                            Type     = "Float32Array"
                        } },
                    { "color", new BufferAttribute
                        {
                            Array    = colors.Cast <object>().ToArray(),
                            ItemSize = 3,
                            Type     = "Uint8Array"
                        } }
                },
                BoundingSphere = new BufferGeometryBoundingSphere
                {
                    Center = new float[] { 0, 0, 0 },
                    Radius = 4
                }
            };

            var points = new Points
            {
                Geometry = pointsGeometry,
                Material = new PointsMaterial {
                    VertexColors = VertexColors.Vertex, Size = 10
                },
                Name = "My Points"
            };

            //scene.Add(points);

            var points2 = new Points
            {
                Geometry = pointsGeometry,
                Material = new PointsMaterial {
                    VertexColors = VertexColors.Vertex, Size = 10
                },
                Name = "My Points2"
            };

            //scene.Add(points2);

            var verts2 = new List <float[]>
            {
                new float[] { 0, 0, 0 },
                new float[] { 0, 0, 10 },
                new float[] { 10, 0, 10 },
                new float[] { 0, 0, 0 },
                new float[] { 10, 0, 10 },
                new float[] { 10, 0, 0 }
            };

            var norms2 = new List <float[]>
            {
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 }
            };

            var color2 = new List <float[]>
            {
                new float[] { 0, 0, 255 },
                new float[] { 0, 0, 255 },
                new float[] { 0, 0, 255 },
                new float[] { 255, 0, 0 },
                new float[] { 255, 0, 0 },
                new float[] { 255, 0, 0 },
            };

            var uv2 = new List <float[]>
            {
                new float[] { 0, 0 },
                new float[] { 1, 0.5f },
                new float[] { 1, 0 },
                new float[] { 0, 0 },
                new float[] { 0.5f, 1 },
                new float[] { 1, 0.5f }
            };

            var meshBG = new BufferGeometry
            {
                Attributes =
                {
                    { "position", new BufferAttribute
                        {
                            Array    = Utilities.OptimizeFloats(Utilities.Flatten(verts2).Cast <float>()).ToArray(),
                            ItemSize = 3,
                            Type     = BufferAttributeType.Float32Array.ToString()
                        } },
                    { "normal", new BufferAttribute
                        {
                            Array    = Utilities.Flatten(norms2),
                            ItemSize = 3,
                            Type     = BufferAttributeType.Float32Array.ToString()
                        } },
                    { "uv", new BufferAttribute
                        {
                            Array    = Utilities.Flatten(uv2),
                            ItemSize = 2,
                            Type     = BufferAttributeType.Float32Array.ToString()
                        } },
                    { "color", new BufferAttribute
                        {
                            Array    = Utilities.Flatten(color2),
                            ItemSize = 3,
                            Type     = BufferAttributeType.Float32Array.ToString()
                        } }
                },
                BoundingSphere = new BufferGeometryBoundingSphere
                {
                    Center = new float[] { 0, 0, 0 },
                    Radius = 5
                }
            };

            var mesh6 = new Mesh
            {
                Geometry = meshBG,
                Material = MeshStandardMaterial.Default(),
                Name     = "MeshfromBufferGeo"
            };

            (mesh6.Material as MeshStandardMaterial).VertexColors = VertexColors.Vertex;

            //scene.Add(mesh6);

            var verts3 = new object[]
            {
                0, 0, 0,
                0, 0, 10,
                10, 0, 10,
                10, 0, 0
            };

            var indexes = new object[] { 0, 1, 2, 0, 2, 3 };

            var norms3 = new object[]
            {
                0, 1, 0,
                0, 1, 0,
                0, 1, 0,
                0, 1, 0,
                0, 1, 0,
                0, 1, 0
            };

            var color3 = new object[]
            {
                0, 0, 255,
                0, 0, 255,
                0, 0, 255,
                255, 0, 0,
                255, 0, 0,
                255, 0, 0,
            };

            var uv3 = new object[]
            {
                0, 0,
                1, 0.5,
                1, 0,
                0, 0,
                0.5, 1,
                1, 0.5
            };

            var meshIBG = new BufferGeometry
            {
                Attributes =
                {
                    { "position", new BufferAttribute
                        {
                            Array    = verts3,
                            ItemSize = 3,
                            Type     = BufferAttributeType.Float32Array.ToString()
                        } },
                    { "index", new BufferAttribute
                        {
                            Array    = indexes,
                            ItemSize = 1,
                            Type     = BufferAttributeType.Int8Array.ToString()
                        } },
                    { "normal", new BufferAttribute
                        {
                            Array    = norms3,
                            ItemSize = 3,
                            Type     = BufferAttributeType.Float32Array.ToString()
                        } },
                    { "uv", new BufferAttribute
                        {
                            Array    = uv3,
                            ItemSize = 2,
                            Type     = BufferAttributeType.Float32Array.ToString()
                        } },
                    { "color", new BufferAttribute
                        {
                            Array    = color3,
                            ItemSize = 3,
                            Type     = BufferAttributeType.Float32Array.ToString()
                        } }
                },
                BoundingSphere = new BufferGeometryBoundingSphere
                {
                    Center = new float[] { 0, 0, 0 },
                    Radius = 5
                }
            };

            var mesh7 = new Mesh
            {
                Geometry = meshIBG,
                Material = MeshStandardMaterial.Default(),
                Name     = "MeshfromIndexedBufferGeo"
            };

            (mesh7.Material as MeshStandardMaterial).VertexColors = VertexColors.Vertex;

            //scene.Add(mesh7);

            var mesh4 = new Mesh
            {
                Geometry = geometry2,
                Material = material3,
                Position = new Vector3(30, 30, 30),
                Name     = "My Mesh4"
            };

            var sphereGeoAsChild = new SphereBufferGeometry
            {
                Radius         = 3,
                WidthSegments  = 22,
                HeightSegments = 22,
                PhiStart       = 0,
                PhiLength      = (float)Math.PI * 2,
                ThetaStart     = 0,
                ThetaLength    = (float)Math.PI * 2
            };

            var sphereMeshAsChild = new Mesh
            {
                Geometry = sphereGeoAsChild,
                Material = material,
                Position = new Vector3(-45, 10, 45),
                Name     = "My Sphere as a Child"
            };

            mesh4.Add(sphereMeshAsChild);
            //scene.Add(mesh4);

            var group = new Group();

            group.Add(mesh3);
            group.Add(mesh2);
            group.Add(mesh);

            //scene.Add(group);

            var group2 = new Group();

            group2.Add(mesh3);
            group2.Add(mesh2);
            group2.Add(mesh);

            //scene.Add(group2);

            var sphereGeometry = new SphereBufferGeometry
            {
                Radius         = 10,
                WidthSegments  = 10,
                HeightSegments = 5,
                PhiStart       = 0,
                PhiLength      = (float)Math.PI * 2,
                ThetaStart     = 0,
                ThetaLength    = (float)Math.PI * 2
            };

            var sphereMesh = new Mesh
            {
                Geometry = sphereGeometry,
                Material = material,
                Position = new Vector3(-45, 10, 45),
                Name     = "My Sphere"
            };

            //scene.Add(sphereMesh);

            #region Lights

            var pointLight = new PointLight
            {
                Color     = new Color(100, 100, 100).ToInt(),
                Decay     = 1,
                Intensity = 3,
                Name      = "My PointLight",
                Position  = new Vector3(10, 10, 10)
            };

            //scene.Add(pointLight);

            var ambientLight = new AmbientLight
            {
                Color     = new Color(255, 0, 255).ToInt(),
                Intensity = 5,
                Name      = "My AmbientLight"
            };

            //scene.Add(ambientLight);

            var targetObject = new Object3D {
                Position = new Vector3(3, 0, 0)
            };
            scene.Add(targetObject);

            var directionalLight = new DirectionalLight
            {
                Target   = targetObject,
                Position = new Vector3(-10, 10, 5),
                Name     = "My DirectionalLight"
            };

            scene.Add(directionalLight);

            var spotLight = new SpotLight
            {
                Target = new Object3D {
                    Position = new Vector3(3, 0, 3)
                },
                Position = new Vector3(20, 20, 0),
                Name     = "My SpotLight"
            };

            //scene.Add(spotLight);

            var hemiLight = new HemisphereLight
            {
                SkyColor    = new Color(0, 30, 255).ToInt(),
                GroundColor = new Color(30, 30, 30).ToInt(),
                Name        = "My HemisphereLight"
            };

            //scene.Add(hemiLight);

            #endregion

            //Console.WriteLine(geometry.ToJSON(true));

            Console.WriteLine(scene.ToJSON(false));

            Console.ReadLine();
        }
示例#14
0
        static void Main(string[] args)
        {
            var scene = new Scene
            {
                Background = new  Color(255, 0, 255).ToInt(),
                Name       = "My Scene"
            };

            var verts = new List <float[]>
            {
                new float[] { 0, 0, 0 },
                new float[] { 0, 0, 10.1234f },
                new float[] { 10, 0, 10 },
                new float[] { 10, 0, 0 }
            };

            var norms = new List <float[]>
            {
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 }
            };

            var vertices = Geometry.ProcessVertexArray(verts);

            var normals = Geometry.ProcessNormalArray(norms);

            var face = new int[] { 0, 1, 2, 3 };

            var faces = Geometry.ProcessFaceArray(new List <int[]> {
                { face }
            }, false, false);

            var geometry  = new Geometry(vertices, faces, normals);
            var geometry2 = new Geometry(vertices, faces, normals);
            var material  = MeshStandardMaterial.Default();

            var mesh = new Mesh
            {
                Geometry = geometry,
                Material = material,
                Name     = "My Mesh"
            };

            scene.Add(mesh);

            var material2 = MeshStandardMaterial.Default();

            material2.Roughness = 0.25;

            var mesh2 = new Mesh
            {
                Geometry = geometry,
                Material = material2,
                Position = new Vector3(20, 20, 20),
                Name     = "My Mesh2"
            };

            scene.Add(mesh2);

            var material3 = MeshStandardMaterial.Default();

            var mesh3 = new Mesh
            {
                Geometry = geometry2,
                Material = material3,
                Position = new Vector3(30, 30, 30),
                Name     = "My Mesh3"
            };

            scene.Add(mesh3);

            var line = new Line
            {
                Geometry = new Geometry(vertices),
                Material = new LineBasicMaterial {
                    Color = new Color(255, 0, 0).ToInt(), LineWidth = 20
                },
                Name = "My Curves"
            };

            scene.Add(line);

            var points = new Points
            {
                Geometry = new Geometry(vertices),
                Material = new PointsMaterial {
                    Color = new Color(255, 255, 255).ToInt()
                },
                Name = "My Points"
            };

            scene.Add(points);

            var group = new Group();

            group.Add(mesh3);
            group.Add(mesh2);
            group.Add(mesh);

            scene.Add(group);

            var group2 = new Group();

            group2.Add(mesh3);
            group2.Add(mesh2);
            group2.Add(mesh);

            scene.Add(group2);

            var sphereGeometry = new SphereGeometry
            {
                Radius         = 10,
                WidthSegments  = 10,
                HeightSegments = 5,
                PhiStart       = 0,
                PhiLength      = (float)Math.PI * 2,
                ThetaStart     = 0,
                ThetaLength    = (float)Math.PI * 2
            };

            var sphereMesh = new Mesh
            {
                Geometry = sphereGeometry,
                Material = material,
                Position = new Vector3(-45, 10, 45),
                Name     = "My Sphere"
            };

            scene.Add(sphereMesh);

            #region Lights

            var pointLight = new PointLight
            {
                Color     = new Color(100, 100, 100).ToInt(),
                Decay     = 1,
                Intensity = 3,
                Name      = "My PointLight",
                Position  = new Vector3(10, 10, 10)
            };

            scene.Add(pointLight);

            var ambientLight = new AmbientLight
            {
                Color     = new Color(255, 0, 255).ToInt(),
                Intensity = 5,
                Name      = "My AmbientLight"
            };

            scene.Add(ambientLight);

            var directionalLight = new DirectionalLight
            {
                Target = new Object3D {
                    Position = new Vector3(3, 0, 0)
                },
                Position = new Vector3(-10, 10, 5),
                Name     = "My DirectionalLight"
            };

            scene.Add(directionalLight);

            var spotLight = new SpotLight
            {
                Target = new Object3D {
                    Position = new Vector3(3, 0, 3)
                },
                Position = new Vector3(20, 20, 0),
                Name     = "My SpotLight"
            };

            scene.Add(spotLight);

            var hemiLight = new HemisphereLight
            {
                SkyColor    = new Color(0, 30, 255).ToInt(),
                GroundColor = new Color(30, 30, 30).ToInt(),
                Name        = "My HemisphereLight"
            };

            scene.Add(hemiLight);

            #endregion

            //Console.WriteLine(geometry.ToJSON(true));

            Console.WriteLine(scene.ToJSON(false));

            Console.ReadLine();
        }