// // Zusammenfassung: // Called when the component needs to load graphics resources. Override this // method to load any component-specific graphics resources. // // Parameter: // loadAllContent: // true if all graphics resources need to be loaded; false if only manual resources // need to be loaded. protected override void LoadContent() { if (modelName != "") { if (Model != null) { Model.Parent = null; } Model = new Model(game, modelName); } }
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);*/ }
/// <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"); }