private void InitModel() { ComputeTangentFrame(); vertexDeclaration = new VertexDeclaration( game.Graphics.Device, VertexPositionNormalBinormalTangentTexture.VertexElements); vertexBuffer = new VertexBuffer(game.Graphics.Device, VertexPositionNormalBinormalTangentTexture.SizeInBytes * (vertexArray.Length), BufferUsage.None); vertexBuffer.SetData(vertexArray); indexBuffer = new IndexBuffer( game.Graphics.Device, sizeof(short) * index.Length, BufferUsage.None, IndexElementSize.SixteenBits ); // Set the data in the index buffer to our array indexBuffer.SetData( index); myMesh[0] = new VbIbAdapterMesh(game, vertexBuffer, indexBuffer, vertexDeclaration, indexCount, vertexCount, "CanyonSegment"); IMaterial[] tmp = new IMaterial[1]; tmp[0] = material; Model = new Model(game, myMesh, tmp, "CanyonModel"); CreateAllSegmentBoxes(); /* * if (globalIndex == 4) * { * //Vector3 forward = new Vector3(1, 1, -3); * //Vector3 up = Vector3.Cross(forward, new Vector3(0,0,-1)); * * //createBoxFromVectorsAndPostion(forward, up, 30, Vector3.Zero); * createCanyonBoxes(new Vector3(0, 0, 400), new Vector3(0, 0, 200), new Vector3(50, 0, 0), new Vector3(0, 50, 0), 4); * } */ /* * XnaDevRu.Physics.BoxShapeData = new BoxShapeData(); * * * Model.CollisionShapes.Add(b); * AddShape(b);*/ }
protected override void LoadContent() { base.LoadContent(); // vertex declaration VertexElement[] vertexElements = new VertexElement[] { // vertex position new VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0), // texture coordinates new VertexElement(0, 12, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0), }; VertexDeclaration vdecl = new VertexDeclaration(game.Graphics.Device, vertexElements); // vertices VertexPositionTexture[] verts = new VertexPositionTexture[7]; verts[0] = new VertexPositionTexture(new Vector3(-0.5f, 0, 1), new Vector2(1, 1)); verts[1] = new VertexPositionTexture(new Vector3(0, 0, 1), new Vector2(1, 0.5f)); verts[2] = new VertexPositionTexture(new Vector3(0.5f, 0, 1), new Vector2(1, 0)); verts[3] = new VertexPositionTexture(new Vector3(0.5f, 0, 0), new Vector2(0, 0)); verts[4] = new VertexPositionTexture(new Vector3(0.1f, 0.5f, 0), new Vector2(0, 0.4f)); verts[5] = new VertexPositionTexture(new Vector3(-0.1f, 0.5f, 0), new Vector2(0, 0.6f)); verts[6] = new VertexPositionTexture(new Vector3(-0.5f, 0, 0), new Vector2(0, 1)); // vertexBuffer VertexBuffer vertexBuffer = new VertexBuffer(game.Graphics.Device, VertexPositionTexture.SizeInBytes * verts.Length, BufferUsage.WriteOnly | BufferUsage.None); vertexBuffer.SetData(verts); // indices short[] indices = new short[15]; indices[0] = 0; indices[1] = 6; indices[2] = 1; indices[3] = 1; indices[4] = 3; indices[5] = 2; indices[6] = 6; indices[7] = 5; indices[8] = 1; indices[9] = 5; indices[10] = 4; indices[11] = 1; indices[12] = 4; indices[13] = 3; indices[14] = 1; // indexBuffer IndexBuffer ib = new IndexBuffer( game.Graphics.Device, sizeof(short) * indices.Length, BufferUsage.None, IndexElementSize.SixteenBits ); ib.SetData(indices); IMaterial[] materials = new IMaterial[1]; materials[0] = Material.Create(game, "AfterBurner", InstancingType.None); IMesh[] meshes = new IMesh[1]; meshes[0] = new VbIbAdapterMesh(game, vertexBuffer, ib, vdecl, 5, 7, "AfterBurner"); Model = new Engine.Graphics.Models.Model(game, meshes, materials, "AfterBurner"); maxSize = LocalScale; rotation = LocalRotation; }
protected override void LoadContent() { base.LoadContent(); IMesh[] meshes = new IMesh[1]; // vertex declaration VertexElement[] vertexElements = new VertexElement[] { // vertex data // vertex position new VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0), // texture coordinates new VertexElement(0, 12, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 1), // instance data // instance transform matrix 3x4 new VertexElement(1, 0, VertexElementFormat.Single, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0) }; VertexDeclaration vdecl = new VertexDeclaration(Game.Graphics.Device, vertexElements); // vertices VertexPositionTexture[] verts = new VertexPositionTexture[4]; verts[0] = new VertexPositionTexture(new Vector3(-8f, 0, -4), new Vector2(0, 0)); verts[1] = new VertexPositionTexture(new Vector3(-8f, 0, 0), new Vector2(0, 1)); verts[2] = new VertexPositionTexture(new Vector3(8f, 0, -4), new Vector2(1, 0)); verts[3] = new VertexPositionTexture(new Vector3(8f, 0, 0), new Vector2(1, 1)); // vertexBuffer VertexBuffer vertexBuffer = new VertexBuffer(Game.Graphics.Device, VertexPositionTexture.SizeInBytes * verts.Length, BufferUsage.WriteOnly | BufferUsage.None); vertexBuffer.SetData <VertexPositionTexture>(verts); // instances instanceVertices = new InstanceVertex[instanceCount]; for (int i = 0; i < instanceCount; ++i) { instanceVertices[i] = new InstanceVertex(i); } // instanceBuffer instanceBuffer = new VertexBuffer(Game.Graphics.Device, typeof(InstanceVertex), instanceCount, BufferUsage.WriteOnly); instanceBuffer.SetData <InstanceVertex>(instanceVertices); // indices short[] indices = new short[6]; indices[0] = 0; indices[1] = 2; indices[2] = 3; indices[3] = 3; indices[4] = 1; indices[5] = 0; // ib IndexBuffer ib = new IndexBuffer( Game.Graphics.Device, sizeof(short) * indices.Length, BufferUsage.None, IndexElementSize.SixteenBits ); ib.SetData <short>(indices); meshes[0] = new VbIbAdapterMesh(Game, vertexBuffer, instanceBuffer, ib, vdecl, 2, 4, instanceCount, "UltraPhaserProjectile"); IMaterial[] materials = new IMaterial[1]; materials[0] = Material.Create(Game, "PhaserTex", InstancingType.Constants); projectileInstances = new DynamicInstancingModel(Game, meshes, materials, "Phaser"); foreach (EffectParameter parameter in projectileInstances.Materials[0].Effect.Parameters) { if (parameter.Semantic == "INSTANCE_DATA") { instanceParameter = parameter; } } }
/// <summary> /// Called when graphics resources need to be loaded. Override this method to load any component-specific graphics resources. /// </summary> protected override void LoadContent() { base.LoadContent(); IMesh[] meshes = new IMesh[1]; // vertex declaration VertexElement[] velements = new VertexElement[1]; velements[0] = new VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0); VertexDeclaration vdecl = new VertexDeclaration(game.Graphics.Device, velements); // vertices Vector3[] verts = new Vector3[8]; verts[0] = new Vector3(-10, -10, -10); verts[1] = new Vector3(-10, -10, 10); verts[2] = new Vector3(-10, 10, -10); verts[3] = new Vector3(-10, 10, 10); verts[4] = new Vector3(10, -10, -10); verts[5] = new Vector3(10, -10, 10); verts[6] = new Vector3(10, 10, -10); verts[7] = new Vector3(10, 10, 10); // vb VertexBuffer vb = new VertexBuffer(game.Graphics.Device, vdecl.GetVertexStrideSize(0) * verts.Length, BufferUsage.None); vb.SetData <Vector3>(verts); // indices short[] indices = new short[36]; indices[0] = 0; indices[1] = 2; indices[2] = 6; indices[3] = 6; indices[4] = 4; indices[5] = 0; indices[6] = 0; indices[7] = 1; indices[8] = 2; indices[9] = 2; indices[10] = 1; indices[11] = 3; indices[12] = 3; indices[13] = 1; indices[14] = 5; indices[15] = 5; indices[16] = 7; indices[17] = 3; indices[18] = 7; indices[19] = 5; indices[20] = 6; indices[21] = 6; indices[22] = 5; indices[23] = 4; indices[24] = 4; indices[25] = 5; indices[26] = 1; indices[27] = 1; indices[28] = 0; indices[29] = 4; indices[30] = 2; indices[31] = 3; indices[32] = 6; indices[33] = 6; indices[34] = 3; indices[35] = 7; // ib IndexBuffer ib = new IndexBuffer( game.Graphics.Device, sizeof(short) * indices.Length, BufferUsage.None, IndexElementSize.SixteenBits ); ib.SetData <short>(indices); meshes[0] = mesh = new VbIbAdapterMesh(game, vb, ib, vdecl, 12, 8, "Sky"); IMaterial[] materials = new IMaterial[1]; materials[0] = material = Material.Create(game, name, InstancingType.None); model = new Model(game, meshes, materials, "Sky"); }