Exemple #1
0
        protected override void CreateGridInternal(Device device, float width, float depth, int xVerts, int zVerts)
        {
            var grid = GeometryGenerator.CreateGrid(width, depth, xVerts, zVerts);

            InitFromMeshData(device, grid);
            _meshCount = 1;
        }
Exemple #2
0
        protected override void CreateGeosphereInternal(Device device, float radius, SubdivisionCount numSubdivisions)
        {
            var geosphere = GeometryGenerator.CreateGeosphere(radius, numSubdivisions);

            InitFromMeshData(device, geosphere);
            _meshCount = 1;
        }
Exemple #3
0
        protected override void CreateSphereInternal(Device device, float radius, int slices, int stacks)
        {
            var sphere = GeometryGenerator.CreateSphere(radius, slices, stacks);

            InitFromMeshData(device, sphere);
            _meshCount = 1;
        }
Exemple #4
0
        protected override void CreateCylinderInternal(Device device, float bottomRadius, float topRadius, float height, int sliceCount, int stackCount)
        {
            var cylinder = GeometryGenerator.CreateCylinder(bottomRadius, topRadius, height, sliceCount, stackCount);

            InitFromMeshData(device, cylinder);
            _meshCount = 1;
        }
Exemple #5
0
        public static SkyObject Create(float radius)
        {
            var mesh = GeometryGenerator.CreateSphere(radius, 30, 30);

            return(new SkyObject(mesh.Vertices.Select(x => new InputLayouts.VerticeP(x.Position)).ToArray(),
                                 mesh.Indices.Select(x => (ushort)x).ToArray()));
        }
Exemple #6
0
        protected override void CreateBoxInternal(Device device, float width, float height, float depth)
        {
            var box = GeometryGenerator.CreateBox(width, height, depth);

            InitFromMeshData(device, box);
            _meshCount = 1;
        }
Exemple #7
0
        protected override void InitializeInternal()
        {
            base.InitializeInternal();
            var device = D3DApp11.I.D3DDevice;

            using (var r = CubeMapSRV.Resource) {
                r.DebugName = "sky cubemap";
            }

            var sphere   = GeometryGenerator.CreateSphere(_skySphereRadius, 30, 30);
            var vertices = sphere.Vertices.Select(v => v.Position).ToArray();
            var vbd      = new BufferDescription(
                VertPos.Stride * vertices.Length,
                ResourceUsage.Immutable,
                BindFlags.VertexBuffer,
                CpuAccessFlags.None,
                ResourceOptionFlags.None,
                0
                );

            _vb = new Buffer(device, DataStream.Create(vertices, false, false), vbd);

            _indexCount = sphere.Indices.Count;
            var ibd = new BufferDescription(
                _indexCount * sizeof(int),
                ResourceUsage.Immutable,
                BindFlags.IndexBuffer,
                CpuAccessFlags.None,
                ResourceOptionFlags.None,
                0
                );

            _ib = new Buffer(device, DataStream.Create(sphere.Indices.ToArray(), false, false), ibd);
        }
Exemple #8
0
        public VertigoContext(ShapeMode shapeMode = ShapeMode.SDF, IDrawCallBatcher batcher = null, MaterialPool materialPool = null)
        {
            if (batcher == null)
            {
                batcher = new DefaultDrawCallBatcher();
            }

            if (materialPool == null)
            {
                materialPool = DefaultMaterialPool;
            }

            this.defaultShapeMode = shapeMode;

            this.renderTextures          = new Stack <RenderTexture>();
            this.renderCalls             = new StructList <RenderCall>();
            this.renderTexturesToRelease = new LightList <RenderTexture>();

            this.batcher           = batcher;
            this.materialPool      = materialPool;
            this.stateStack        = new Stack <VertigoState>();
            this.position          = Vector3.zero;
            this.rotation          = Quaternion.identity;
            this.scale             = Vector3.one;
            this.shapeGenerator    = new ShapeGenerator();
            this.geometryGenerator = new GeometryGenerator();
            this.geometryCache     = new GeometryCache();
        }
Exemple #9
0
 public void InitGeometries()
 {
     meshTextured = GeometryGenerator.Sphere(1f, 4, 4);
     meshPure     = GeometryGenerator.Sphere(0.1f, 3, 3);
     // meshPlane = GeometryGenerator.Plane(0.2f, 0.2f, 2, 2);
     meshPlane = GeometryGenerator.Plane(0.2f, 0.2f, 2, 2);
 }
Exemple #10
0
        public override void Render(DrawingContext context, Rect viewRect, double zoom, Point leftTopPixel, bool isDarkTheme)
        {
            var pointCenter = Location.ToPixel(zoom);

            if (!viewRect.IntersectsWith(new Rect(pointCenter - MarkerSize, pointCenter + MarkerSize)))
            {
                return;
            }

            var basePoint = (Point)(Location.ToPixel(zoom) - leftTopPixel);

            context.DrawLine(CenterPen, basePoint - new Vector(5, 5), basePoint + new Vector(5, 5));
            context.DrawLine(CenterPen, basePoint - new Vector(-5, 5), basePoint + new Vector(-5, 5));

            if (zoom <= 6)
            {
                return;
            }

            if (cache == null || NeedUpdate || cachedZoom != zoom)
            {
                cache      = GeometryGenerator.MakeCircleGeometry(Location, Distance, zoom, 30);
                NeedUpdate = false;
                cachedZoom = zoom;
            }

            if (cache == null)
            {
                return;
            }
            if (cache.Transform is not TranslateTransform tt)
            {
                cache.Transform = new TranslateTransform(-leftTopPixel.X, -leftTopPixel.Y);
            }
Exemple #11
0
        private void BuildGeometryBuffers()
        {
            var box = GeometryGenerator.CreateBox(1, 1, 1);

            _boxVertexOffset = 0;

            _boxIndexCount = box.Indices.Count;

            _boxIndexOffset = 0;

            var vertices = new List <Basic32>();

            foreach (var vertex in box.Vertices)
            {
                vertices.Add(new Basic32(vertex.Position, vertex.Normal, vertex.TexC));
            }
            var vbd = new BufferDescription(Basic32.Stride * vertices.Count, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _boxVB = new Buffer(Device, new DataStream(vertices.ToArray(), false, false), vbd);

            var indices = box.Indices;
            var ibd     = new BufferDescription(sizeof(int) * indices.Count, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _boxIB = new Buffer(Device, new DataStream(indices.ToArray(), false, false), ibd);
        }
Exemple #12
0
 public TerrainRenderable(float width, float depth, uint xsubs, uint zsubs)
 {
     Width         = width;
     Depth         = depth;
     XSubdivisions = xsubs;
     ZSubdivisions = zsubs;
     GeometryGenerator.CreateGrid(width, depth, xsubs, zsubs, out Vertices, out Indices);
 }
Exemple #13
0
 public TerrainRenderable()
 {
     Width         = 100.0f;
     Depth         = 100.0f;
     XSubdivisions = 5;
     ZSubdivisions = 5;
     GeometryGenerator.CreateGrid(Width, Depth, XSubdivisions, ZSubdivisions, out Vertices, out Indices);
 }
 private void Start()
 {
     m_Camera = Camera.main;
     character = transform.GetChild(0).gameObject;
     m_MouseLook.Init(transform, transform);
     m_GeometryGenerator = LinesContainer.GetComponent<GeometryGenerator>();
     endX = m_GeometryGenerator.WarpFactors[1] * m_GeometryGenerator.StoryLineSizes[1].x * 0.95f;
     cylinderRadius = m_GeometryGenerator.WarpRadiuses[m_GeometryGenerator.StoryIndex] * 0.7f;
     MoveSpeed *= endX;
 }
        static void AddSphere(Camera camera, Sphere sphere)
        {
            Vec3[] positions;
            int[]  indices;
            GeometryGenerator.GenerateSphere(sphere.Radius, 4, 4, false, out positions, out indices);

            Mat4 transform = new Mat4(Mat3.Identity, sphere.Origin);

            camera.DebugGeometry.AddVertexIndexBuffer(positions, indices, transform, false, true);
        }
        static void AddSphere(Camera camera, Sphere sphere)
        {
            if (addSpherePositions == null)
            {
                GeometryGenerator.GenerateSphere(sphere.Radius, 8, 8, false, out addSpherePositions, out addSphereIndices);
            }

            Mat4 transform = new Mat4(Mat3.Identity, sphere.Origin);

            camera.DebugGeometry.AddVertexIndexBuffer(addSpherePositions, addSphereIndices, transform, false, true);
        }
Exemple #17
0
        private void BuildScreenQuadGeometryBuffers()
        {
            var quad = GeometryGenerator.CreateFullScreenQuad();

            var verts = quad.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)).ToList();
            var vbd   = new BufferDescription(Basic32.Stride * verts.Count, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _screenQuadVB = new Buffer(Device, new DataStream(verts.ToArray(), false, false), vbd);

            var ibd = new BufferDescription(sizeof(int) * quad.Indices.Count, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _screenQuadIB = new Buffer(Device, new DataStream(quad.Indices.ToArray(), false, false), ibd);
        }
Exemple #18
0
        private void DrawChildren(IDeviceContextHolder contextHolder, ICamera camera, SpecialRenderMode mode, Func <IRenderableObject, bool> filter = null)
        {
            if (!IsEnabled || filter?.Invoke(this) == false)
            {
                return;
            }
            if (mode == SpecialRenderMode.Reflection && !IsReflectable)
            {
                return;
            }
            if (camera != null && BoundingBox != null && !camera.Visible(BoundingBox.Value))
            {
                return;
            }

            UpdateLookAt();

            var c = Count;

            for (var i = 0; i < c; i++)
            {
                var child = this[i];
                if (child.IsEnabled)
                {
                    child.Draw(contextHolder, camera, mode, filter);
                }
            }

            if (HighlightBoundingBoxes && mode == SpecialRenderMode.SimpleTransparent)
            {
                if (_box == null)
                {
                    var box = GeometryGenerator.CreateLinesBox(new Vector3(1f));
                    _box = new DebugLinesObject(Matrix.Identity,
                                                box.Vertices.Select(x => new InputLayouts.VerticePC(x.Position, new Color4(1f, 1f, 0.5f, 0f))).ToArray(),
                                                box.Indices.ToArray());
                }

                for (var i = 0; i < c; i++)
                {
                    var child = this[i];
                    if (child.IsEnabled && child.BoundingBox.HasValue)
                    {
                        var bb = child.BoundingBox.Value;
                        _box.ParentMatrix = Matrix.Scaling(bb.GetSize()) * Matrix.Translation(bb.GetCenter());
                        _box.Draw(contextHolder, camera, SpecialRenderMode.Simple);
                    }
                }
            }
        }
        static void AddCone(Camera camera, Vec3 from, Vec3 to, float radius)
        {
            Vec3  direction = to - from;
            float length    = direction.Normalize();

            Vec3[] positions;
            int[]  indices;
            GeometryGenerator.GenerateCone(radius, length, 32, true, true, out positions, out indices);

            Quat rotation  = Quat.FromDirectionZAxisUp(direction);
            Mat4 transform = new Mat4(rotation.ToMat3(), from);

            camera.DebugGeometry.AddVertexIndexBuffer(positions, indices, transform, false, true);
        }
Exemple #20
0
        public static DebugLinesObject GetLinesBox(Matrix matrix, Vector3 size, Color4 color)
        {
            var vertices = new List <InputLayouts.VerticePC>();
            var indices  = new List <ushort>();

            var box = GeometryGenerator.CreateLinesBox(size);

            for (var i = 0; i < box.Vertices.Length; i++)
            {
                vertices.Add(new InputLayouts.VerticePC(box.Vertices[i].Position, color));
            }

            indices.AddRange(box.Indices);
            return(new DebugLinesObject(matrix, vertices.ToArray(), indices.ToArray()));
        }
        static void AddThicknessLine(Camera camera, Vec3 start, Vec3 end, float thickness)
        {
            Vec3  diff       = end - start;
            Vec3  direction  = diff.GetNormalize();
            Quat  rotation   = Quat.FromDirectionZAxisUp(direction);
            float length     = diff.Length();
            float thickness2 = thickness;

            Mat4 t = new Mat4(rotation.ToMat3() * Mat3.FromScale(new Vec3(length, thickness2, thickness2)),
                              (start + end) * .5f);

            if (addThicknessLinePositions == null)
            {
                GeometryGenerator.GenerateBox(new Vec3(1, 1, 1), out addThicknessLinePositions, out addThicknessLineIndices);
            }
            camera.DebugGeometry.AddVertexIndexBuffer(addThicknessLinePositions, addThicknessLineIndices, t, false, true);
        }
Exemple #22
0
        private void BuildShapeGeometryBuffers()
        {
            var box      = GeometryGenerator.CreateBox(1, 1, 1);
            var grid     = GeometryGenerator.CreateGrid(20, 30, 60, 40);
            var sphere   = GeometryGenerator.CreateSphere(0.5f, 20, 20);
            var cylinder = GeometryGenerator.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20);

            _boxVertexOffset      = 0;
            _gridVertexOffset     = box.Vertices.Count;
            _sphereVertexOffset   = _gridVertexOffset + grid.Vertices.Count;
            _cylinderVertexOffset = _sphereVertexOffset + sphere.Vertices.Count;

            _boxIndexCount      = box.Indices.Count;
            _gridIndexCount     = grid.Indices.Count;
            _sphereIndexCount   = sphere.Indices.Count;
            _cylinderIndexCount = cylinder.Indices.Count;

            _boxIndexOffset      = 0;
            _gridIndexOffset     = _boxIndexCount;
            _sphereIndexOffset   = _gridIndexOffset + _gridIndexCount;
            _cylinderIndexOffset = _sphereIndexOffset + _sphereIndexCount;

            var totalVertexCount = box.Vertices.Count + grid.Vertices.Count + sphere.Vertices.Count + cylinder.Vertices.Count;
            var totalIndexCount  = _boxIndexCount + _gridIndexCount + _sphereIndexCount + _cylinderIndexCount;

            var vertices = box.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)).ToList();

            vertices.AddRange(grid.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)));
            vertices.AddRange(sphere.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)));
            vertices.AddRange(cylinder.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)));

            var vbd = new BufferDescription(Basic32.Stride * totalVertexCount, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _shapesVB = new Buffer(Device, new DataStream(vertices.ToArray(), false, false), vbd);

            var indices = new List <int>();

            indices.AddRange(box.Indices);
            indices.AddRange(grid.Indices);
            indices.AddRange(sphere.Indices);
            indices.AddRange(cylinder.Indices);

            var ibd = new BufferDescription(sizeof(int) * totalIndexCount, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _shapesIB = new Buffer(Device, new DataStream(indices.ToArray(), false, false), ibd);
        }
Exemple #23
0
        private void BuildLandGeometryBuffers()
        {
            var grid     = GeometryGenerator.CreateGrid(160.0f, 160.0f, 50, 50);
            var vertices = new List <VertexPC>();

            foreach (var vertex in grid.Vertices)
            {
                var pos = vertex.Position;
                pos.Y = GetHeight(pos.X, pos.Z);
                Color4 color;

                if (pos.Y < -10.0f)
                {
                    color = new Color4(1.0f, 1.0f, 0.96f, 0.62f);
                }
                else if (pos.Y < 5.0f)
                {
                    color = new Color4(1.0f, 0.48f, 0.77f, 0.46f);
                }
                else if (pos.Y < 12.0f)
                {
                    color = new Color4(1.0f, 0.1f, 0.48f, 0.19f);
                }
                else if (pos.Y < 20.0f)
                {
                    color = new Color4(1.0f, 0.45f, 0.39f, 0.34f);
                }
                else
                {
                    color = new Color4(1, 1, 1, 1);
                }
                vertices.Add(new VertexPC(pos, color));
            }
            var vbd = new BufferDescription(VertexPC.Stride * vertices.Count, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _landVB = new Buffer(Device, new DataStream(vertices.ToArray(), false, false), vbd);

            var ibd = new BufferDescription(sizeof(int) * grid.Indices.Count, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _landIB         = new Buffer(Device, new DataStream(grid.Indices.ToArray(), false, false), ibd);
            _gridIndexCount = grid.Indices.Count;
        }
Exemple #24
0
        private void BuildBallGeometryBuffers()
        {
            var mesh = GeometryGenerator.CreateSphere(10, 30, 30);

            var vertices = new List <VertexPN>();

            foreach (var vertex in mesh.Vertices)
            {
                var pos = vertex.Position;
                vertices.Add(new VertexPN(pos, vertex.Normal, vertex.TexC));
            }
            var vbd = new D3D11.BufferDescription(VertexPN.Stride * vertices.Count, D3D11.ResourceUsage.Immutable, D3D11.BindFlags.VertexBuffer, D3D11.CpuAccessFlags.None, D3D11.ResourceOptionFlags.None, 0);

            _ballVB = new D3D11.Buffer(Device, DataStream.Create <VertexPN>(vertices.ToArray(), false, false), vbd);

            var ibd = new D3D11.BufferDescription(sizeof(int) * mesh.Indices.Count, D3D11.ResourceUsage.Immutable, D3D11.BindFlags.IndexBuffer, D3D11.CpuAccessFlags.None, D3D11.ResourceOptionFlags.None, 0);

            _ballIB         = new D3D11.Buffer(Device, DataStream.Create <Int32>(mesh.Indices.ToArray(), false, false), ibd);
            _ballIndexCount = mesh.Indices.Count;
        }
Exemple #25
0
    void CreateShpereObstacleMask()
    {
        if (!CreateObstacle)
        {
            return;
        }

        var geo_sphere = GeometryGenerator.Sphere(ObstaleRadius, 32, 32);

        ObstacleChild = new GameObject("sphere");
        ObstacleChild.transform.parent = this.gameObject.transform;
        var mesh_filter = ObstacleChild.AddComponent <MeshFilter>();

        mesh_filter.mesh = geo_sphere;
        ObstacleChild.transform.position = ObstaclePosition;
        var render = ObstacleChild.AddComponent <MeshRenderer>();

        render.material = new Material(Shader.Find("Specular"));

        int n = Mathf.CeilToInt(2 * ObstaleRadius);

        n = ISFUtils.CeilToMutiple(n, 8); // 保证 n 是  8 的倍数
        ObstacleRoundedRadius = n;
        Vector3 relative_center = new Vector3(n / 2, n / 2, n / 2);

        ObstacleMask = FFT.CreateRenderTexture3D(n, n, n);

        CS.SetVector("nozzle_center", relative_center);
        CS.SetFloat("nozzle_radius", ObstaleRadius);
        CS.SetTexture(kernelCreateShpereObstacleMask, "Nozzle", ObstacleMask);

        DispatchCS(kernelCreateShpereObstacleMask, true, ObstacleMask);

        ObstacleTopLeft = ISFUtils.VecSubScalar(ObstaclePosition, n);

        for (int i = 1; i < 10; ++i)
        {
            UpdateObstacle();
        }
    }
Exemple #26
0
        private void BuildLandGeometryBuffers()
        {
            var grid = GeometryGenerator.CreateGrid(160.0f, 160.0f, 50, 50);

            _landIndexCount = grid.Indices.Count;

            var vertices = new List <Basic32>();

            foreach (var v in grid.Vertices)
            {
                var p = new Vector3(v.Position.X, GetHillHeight(v.Position.X, v.Position.Z), v.Position.Z);
                var n = GetHillNormal(p.X, p.Z);
                vertices.Add(new Basic32(p, n, v.TexC));
            }
            var vbd = new BufferDescription(Basic32.Stride * vertices.Count, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _landVB = new Buffer(Device, new DataStream(vertices.ToArray(), false, false), vbd);

            var ibd = new BufferDescription(sizeof(int) * grid.Indices.Count, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _landIB = new Buffer(Device, new DataStream(grid.Indices.ToArray(), false, false), ibd);
        }
Exemple #27
0
        private void BuildLandGeometryBuffers()
        {
            GeometryGenerator.MeshData grid = GeometryGenerator.CreateGrid(160.0f, 160.0f, 50, 50);
            var vertices = new List <VertexPN>();

            foreach (var vertex in grid.Vertices)
            {
                var pos = vertex.Position;
                pos.Y = GetHillHeight(pos.X, pos.Z);

                var normal = GetHillNormal(pos.X, pos.Z);

                vertices.Add(new VertexPN(pos, normal, vertex.TexC));
            }
            var vbd = new D3D11.BufferDescription(VertexPN.Stride * vertices.Count, D3D11.ResourceUsage.Immutable, D3D11.BindFlags.VertexBuffer, D3D11.CpuAccessFlags.None, D3D11.ResourceOptionFlags.None, 0);

            _groundVB = new D3D11.Buffer(Device, DataStream.Create <VertexPN>(vertices.ToArray(), false, false), vbd);

            var ibd = new D3D11.BufferDescription(sizeof(int) * grid.Indices.Count, D3D11.ResourceUsage.Immutable, D3D11.BindFlags.IndexBuffer, D3D11.CpuAccessFlags.None, D3D11.ResourceOptionFlags.None, 0);

            _groundIB         = new D3D11.Buffer(Device, DataStream.Create <Int32>(grid.Indices.ToArray(), false, false), ibd);
            _groundIndexCount = grid.Indices.Count;
        }
Exemple #28
0
        public void DrawSuspensionDebugStuff(DeviceContextHolder holder, ICamera camera)
        {
            if (_suspensionLines == null)
            {
                _suspensionLines = new DebugLinesObject(Matrix.Identity, GetDebugSuspensionVertices(SuspensionsPack));
            }

            _suspensionLines.ParentMatrix = RootObject.Matrix;
            _suspensionLines.Draw(holder, camera, SpecialRenderMode.Simple);

            if (_wheelLfCon != default(Vector3))
            {
                if (_debugNode == null)
                {
                    _debugNode = new DebugObject(Matrix.Translation(_wheelLfCon), GeometryGenerator.CreateSphere(0.02f, 6, 6));
                }

                _debugNode.Transform    = Matrix.Translation(_wheelLfCon);
                _debugNode.ParentMatrix = RootObject.Matrix;

                holder.DeviceContext.OutputMerger.DepthStencilState = holder.States.DisabledDepthState;
                _debugNode.Draw(holder, camera, SpecialRenderMode.Simple);
            }
        }
Exemple #29
0
        private static BasicModel BuildFromMeshData(Device device, GeometryGenerator.MeshData mesh)
        {
            var ret = new BasicModel();

            var subset = new MeshGeometry.Subset {
                FaceCount = mesh.Indices.Count / 3,
                FaceStart = 0,
                VertexCount = mesh.Vertices.Count,
                VertexStart = 0
            };
            ret._subsets.Add(subset);

            var max = new Vector3(float.MinValue);
            var min = new Vector3(float.MaxValue);
            foreach (var vertex in mesh.Vertices) {
                max = Vector3.Maximize(max, vertex.Position);
                min = Vector3.Minimize(min, vertex.Position);
            }

            ret.BoundingBox = new BoundingBox(min, max);

            ret._vertices.AddRange(mesh.Vertices.Select(v => new PosNormalTexTan(v.Position, v.Normal, v.TexC, v.TangentU)).ToList());
            ret._indices.AddRange(mesh.Indices.Select(i => (short)i));

            ret.Materials.Add(new Material { Ambient = Color.Gray, Diffuse = Color.White, Specular = new Color4(16, 1, 1, 1) });
            ret.DiffuseMapSRV.Add(null);
            ret.NormalMapSRV.Add(null);

            ret._modelMesh.SetSubsetTable(ret._subsets);
            ret._modelMesh.SetVertices(device, ret._vertices);
            ret._modelMesh.SetIndices(device, ret._indices);

            return ret;
        }
        private void CreateMesh()
        {
            Vec3 size = new Vec3(.97f, .97f, .1f);

            Vec3[] positions;
            Vec3[] normals;
            int[]  indices;
            GeometryGenerator.GenerateBox(size, out positions, out normals, out indices);

            string meshName = MeshManager.Instance.GetUniqueName(
                string.Format("JigsawPuzzlePiece[{0},{1}]", index.X, index.Y));

            mesh = MeshManager.Instance.CreateManual(meshName);

            //create submesh
            SubMesh subMesh = mesh.CreateSubMesh();

            subMesh.UseSharedVertices = false;

            //init VertexData
            VertexDeclaration declaration = subMesh.VertexData.VertexDeclaration;

            declaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position);
            declaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal);
            declaration.AddElement(0, 24, VertexElementType.Float2,
                                   VertexElementSemantic.TextureCoordinates, 0);

            VertexBufferBinding  bufferBinding = subMesh.VertexData.VertexBufferBinding;
            HardwareVertexBuffer vertexBuffer  = HardwareBufferManager.Instance.CreateVertexBuffer(
                32, positions.Length, HardwareBuffer.Usage.StaticWriteOnly);

            bufferBinding.SetBinding(0, vertexBuffer, true);

            subMesh.VertexData.VertexCount = positions.Length;

            unsafe
            {
                Vertex *buffer = (Vertex *)vertexBuffer.Lock(HardwareBuffer.LockOptions.Normal);

                for (int n = 0; n < positions.Length; n++)
                {
                    Vertex vertex = new Vertex();
                    vertex.position = positions[n];
                    vertex.normal   = normals[n];

                    if (JigsawPuzzleManager.Instance != null)
                    {
                        Vec2I pieceCount = JigsawPuzzleManager.Instance.PieceCount;

                        Vec2I i = index;
                        if (vertex.position.X > 0)
                        {
                            i.X++;
                        }
                        if (vertex.position.Y > 0)
                        {
                            i.Y++;
                        }

                        vertex.texCoord = new Vec2(
                            (float)i.X / (float)pieceCount.X,
                            1.0f - (float)i.Y / (float)pieceCount.Y);
                    }

                    *buffer = vertex;
                    buffer++;
                }

                vertexBuffer.Unlock();
            }

            //calculate mesh bounds
            Bounds bounds = Bounds.Cleared;
            float  radius = 0;

            foreach (Vec3 position in positions)
            {
                bounds.Add(position);
                float r = position.Length();
                if (r > radius)
                {
                    radius = r;
                }
            }
            mesh.SetBoundsAndRadius(bounds, radius);

            //init IndexData
            subMesh.IndexData = IndexData.CreateFromArray(indices, 0, indices.Length, false);

            //init material
            subMesh.MaterialName = "JigsawPuzzleImage";
        }
Exemple #31
0
    // Start is called before the first frame update
    void Start()
    {
        difficulty = StateController.option;
        //fill in the layout array
        generateLevel(LEVEL_DURATION);
        bool empty = true;

        //populate the blocks array with the appropriate block type
        for (int i = 0; i < levelLayout.Count; i++)
        {
            if (levelLayout[i].Equals("r"))
            {
                levelBlocks.Add(generateRhythmBlock(0, "r"));
            }
            else if (levelLayout[i].Equals("hr") && constraints[4] == 1)
            {
                if (i != 0 && i != levelLayout.Count - 1)
                {
                    empty = false;
                    levelBlocks.Add(generateRhythmBlock(1, "hr"));
                    levelBlocks.Add(generateRhythmBlock(0, "hr"));
                }
                else
                {
                    levelBlocks.Add(generateRhythmBlock(0, "r"));
                }

                //levelBlocks.Add(generatePuzzleBlock());
            }
            else if (constraints[4] == 1)
            {
                if (i != 0 && i != levelLayout.Count - 1)
                {
                    empty = false;
                    if (constraints[0] == 1)
                    {
                        levelBlocks.Add(generateRhythmBlock(1, "hr"));
                    }
                    else
                    {
                        levelBlocks.Add(generateRhythmBlock(-1, "hr"));
                    }
                    levelBlocks.Add(generateRhythmBlock(0, "hr"));
                }
                else
                {
                    levelBlocks.Add(generateRhythmBlock(0, "r"));
                }
            }
            if (i == levelLayout.Count - 1 && empty && constraints[4] == 1)
            {
                levelBlocks.Add(generateRhythmBlock(1, "hr"));
                levelBlocks.Add(generateRhythmBlock(0, "hr"));
            }
        }

        //place geometry based on the blocks generated
        gen = new GeometryGenerator(levelBlocks, startX, startY, texGround, texEnemy, texSpike, texCoin, texGnd, texSlope, texSlope2, texGoal, texPipe, texUnderGnd, texMoveGnd, texEnemy2, texEnemy3, texEnemy4);
        gen.generateGeometry();
        gen.cleanUpEnemies();
        gen.cleanUpStomps();

        if (constraints[0] == 1)
        {
            gen.jumpTerrain();
        }
        if (constraints[3] == 1 && constraints[0] != 1)
        {
            gen.cleanUpSpikes();
        }
        if (constraints[3] == 1)
        {
            gen.placeSuperEnemies();
        }

        gen.cosmetics();
        //Debug.Log("LVL COUNT: " + GeometryGenerator.lvl.Count);
        //Debug.Log("UPPERLVL COUNT: " + GeometryGenerator.upperLvl.Count);
        //Debug.Log("LOWERLVL COUNT: " + GeometryGenerator.lowerLvl.Count);
        //mySprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height),
        //                         new Vector2(0.5f, 0.5f), 100.0f);
        //sr.sprite = mySprite;
    }
Exemple #32
0
        private void BuildGeometryBuffers()
        {
            var box      = GeometryGenerator.CreateBox(1.0f, 1.0f, 1.0f);
            var grid     = GeometryGenerator.CreateGrid(20.0f, 30.0f, 60, 40);
            var sphere   = GeometryGenerator.CreateSphere(0.5f, 20, 20);
            var cylinder = GeometryGenerator.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20);

            _boxVertexOffset      = 0;
            _gridVertexOffset     = box.Vertices.Count;
            _sphereVertexOffset   = _gridVertexOffset + grid.Vertices.Count;
            _cylinderVertexOffset = _sphereVertexOffset + sphere.Vertices.Count;

            _boxIndexCount      = box.Indices.Count;
            _gridIndexCount     = grid.Indices.Count;
            _sphereIndexCount   = sphere.Indices.Count;
            _cylinderIndexCount = cylinder.Indices.Count;

            _boxIndexOffset      = 0;
            _gridIndexOffset     = _boxIndexCount;
            _sphereIndexOffset   = _gridIndexOffset + _gridIndexCount;
            _cylinderIndexOffset = _sphereIndexOffset + _sphereIndexCount;

            var totalVertexCount = box.Vertices.Count + grid.Vertices.Count + sphere.Vertices.Count + cylinder.Vertices.Count;
            var totalIndexCount  = _boxIndexCount + _gridIndexCount + _sphereIndexCount + _cylinderIndexCount;

            var vs = new List <VertexPC>();

            foreach (var vertex in box.Vertices)
            {
                vs.Add(new VertexPC(vertex.Position, Color.Red));
            }
            foreach (var v in grid.Vertices)
            {
                vs.Add(new VertexPC(v.Position, Color.Green));
            }
            foreach (var v in sphere.Vertices)
            {
                vs.Add(new VertexPC(v.Position, Color.Blue));
            }
            foreach (var v in cylinder.Vertices)
            {
                vs.Add(new VertexPC(v.Position, Color.Yellow));
            }
            var vbd = new BufferDescription(VertexPC.Stride * totalVertexCount,
                                            ResourceUsage.Immutable, BindFlags.VertexBuffer,
                                            CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _vb = new Buffer(Device, new DataStream(vs.ToArray(), false, false), vbd);

            var indices = new List <int>();

            indices.AddRange(box.Indices);
            indices.AddRange(grid.Indices);
            indices.AddRange(sphere.Indices);
            indices.AddRange(cylinder.Indices);

            var ibd = new BufferDescription(sizeof(int) * totalIndexCount, ResourceUsage.Immutable,
                                            BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _ib = new Buffer(Device, new DataStream(indices.ToArray(), false, false), ibd);
        }
Exemple #33
0
 public LevelGenerator(GeometryGenerator geometryGenerator)
 {
     this.geometryGenerator = geometryGenerator;
 }