Exemplo n.º 1
0
        /// <summary>
        /// Creates and returns a Cuboid as DCEL with the given dimensions, centered in the world coordinate system.
        /// </summary>
        /// <param name="dimensionX">Width in X-dimension.</param>
        /// <param name="dimensionY">Height in Y-dimension.</param>
        /// <param name="dimensionZ">Depth in Z-dimension.</param>
        /// <returns></returns>
        public static Geometry CreateCuboidGeometry(float dimensionX, float dimensionY, float dimensionZ)
        {
            //check input
            if (dimensionX <= 0 || dimensionY <= 0 || dimensionZ <= 0)
            {
                throw new ArgumentException("The dimension values can not be <= 0");
            }

            var xPos = dimensionX / 2.0f;
            var yPos = dimensionY / 2.0f;
            var zPos = dimensionZ / 2.0f;

            var outlineRectangle = new PolyBoundary //CCW
            {
                Points = new List <float3>
                {
                    new float3(-xPos, yPos, -zPos),
                    new float3(-xPos, -yPos, -zPos),
                    new float3(xPos, -yPos, -zPos),
                    new float3(xPos, yPos, -zPos)
                },
                IsOuter = true
            };

            var outlinesCube = new List <PolyBoundary> {
                outlineRectangle
            };
            var cuboid = new Geometry(outlinesCube);

            cuboid.Extrude2DPolygon(dimensionZ, false);

            return(cuboid);
        }
Exemplo n.º 2
0
        // Init is called on startup.
        public override void Init()
        {
            var outlineOne = new PolyBoundary //CCW!!
            {
                Points = new List <float3>
                {
                    new float3(1, 0, 0),
                    new float3(1.25f, 0.5f, 0.5f),
                    new float3(1, 1, 1),
                    new float3(0, 1, 1),
                    new float3(-0.25f, 0.5f, 0.5f),
                    new float3(0, 0, 0)
                },
                IsOuter = true
            };

            var outlineOneHole = new PolyBoundary //CW!!
            {
                Points = new List <float3>
                {
                    new float3(0.75f, 0.25f, 0.25f),
                    new float3(0.25f, 0.25f, 0.25f),
                    new float3(0.25f, 0.75f, 0.75f),
                    new float3(0.75f, 0.75f, 0.75f)
                },
                IsOuter = false
            };

            var outlineTwo = new PolyBoundary //CCW!!
            {
                Points = new List <float3>
                {
                    new float3(1, 0, 0),
                    new float3(1, 0.707f, 0.707f),
                    new float3(0, 0.707f, 0.707f),
                    new float3(0, 0, 0)
                },
                IsOuter = true
            };

            var outlineThree = new PolyBoundary //CCW!!
            {
                Points = new List <float3>
                {
                    new float3(0, 0, 0),
                    new float3(1, 0, 1),
                    new float3(0, 0.5f, 0.5f)
                },
                IsOuter = true
            };

            var geomOutlinesOne = new List <PolyBoundary> {
                outlineOne, outlineOneHole
            };
            var geomOne = new Geometry(geomOutlinesOne);

            geomOne.Extrude2DPolygon(0.5f, true);
            geomOne.Triangulate();
            var meshOne = new JometriMesh(geomOne);

            var geomCubeOutlines = new List <PolyBoundary> {
                outlineTwo
            };
            var geomCube = new Geometry(geomCubeOutlines);

            geomCube.Extrude2DPolygon(1, false);
            //geomCube.Extrude2DPolygon(1, true);
            geomCube.Triangulate();
            var cube = new JometriMesh(geomCube);

            var geomTriangleOutlines = new List <PolyBoundary> {
                outlineThree
            };
            var geomTri = new Geometry(geomTriangleOutlines);

            geomTri.Triangulate();
            var triangle = new JometriMesh(geomTri);

            ////////////////// Fill SceneNode ////////////////////////////////
            var parentNode = new SceneNode
            {
                Components = new List <SceneComponent>(),
                Children   = new ChildList()
            };

            var parentTrans = new Transform
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(0, 0, 0)
            };

            parentNode.Components.Add(parentTrans);

            var sceneNodeCOne = new SceneNode {
                Components = new List <SceneComponent>()
            };

            var meshCOne = new Mesh
            {
                Vertices  = meshOne.Vertices,
                Triangles = meshOne.Triangles,
                Normals   = meshOne.Normals,
            };

            var tranC = new Transform
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(0, 0, 0)
            };

            sceneNodeCOne.Components.Add(tranC);
            sceneNodeCOne.Components.Add(meshCOne);
            ///////////////////////////////////////////////////////////
            var sceneNodeCCube = new SceneNode {
                Components = new List <SceneComponent>()
            };

            var meshCCube = new Mesh
            {
                Vertices  = cube.Vertices,
                Triangles = cube.Triangles,
                Normals   = cube.Normals,
            };
            var tranCube = new Transform
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(-2, -1, 0)
            };

            sceneNodeCCube.Components.Add(tranCube);
            sceneNodeCCube.Components.Add(meshCCube);
            //////////////////////////////////////////////////////////////////
            var sceneNodeCTri = new SceneNode {
                Components = new List <SceneComponent>()
            };

            var meshCTri = new Mesh
            {
                Vertices  = triangle.Vertices,
                Triangles = triangle.Triangles,
                Normals   = triangle.Normals,
            };
            var tranTri = new Transform
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(1.5f, -1, 0)
            };

            sceneNodeCTri.Components.Add(tranTri);
            sceneNodeCTri.Components.Add(meshCTri);
            //////////////////////////////////////////////////////////////////

            parentNode.Children.Add(sceneNodeCTri);
            parentNode.Children.Add(sceneNodeCOne);
            parentNode.Children.Add(sceneNodeCCube);
            var sc = new SceneContainer {
                Children = new List <SceneNode> {
                    parentNode
                }
            };

            _renderer = new SceneRendererForward(sc);

            // Set the clear color for the back buffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(0, 1, 1, 1);
        }