public void MeshBegin(string name) { // Set mesh if (name == null) { devicemesh = new G3DMesh(); } else { devicemesh = ((G3DMesh)meshlist[name]); } }
public void PrimitiveBegin(string name) { // Set primitive if (name == null) { devicemesh = new G3DMesh(); } else { deviceprimitive = ((G3DPrimitive)primitivelist[name]); } }
public override void SetUserDataInMeshContainer(MeshContainer meshcontainer) { G3DMesh g3dmesh = new G3DMesh(); ExtendedMaterial[] materials = meshcontainer.GetMaterials(); if (materials != null) { g3dmesh.Materials = new Material[materials.Length]; g3dmesh.Textures = new Texture[materials.Length]; for (int i = 0; i < materials.Length; i++) { // Load texture from file or resource if (materials[i].TextureFilename != null) { Texture texture; try { texture = TextureLoader.FromFile(meshcontainer.MeshData.Mesh.Device, materials[i].TextureFilename); } catch { try { texture = TextureLoader.FromStream(meshcontainer.MeshData.Mesh.Device, System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(materials[i].TextureFilename)); } catch { texture = null; } } g3dmesh.Textures[i] = texture; } // Load material g3dmesh.Materials[i] = materials[i].Material3D; g3dmesh.Materials[i].Ambient = g3dmesh.Materials[i].Diffuse; } } g3dmesh.Mesh = meshcontainer.MeshData.Mesh; meshcontainer.UserData = g3dmesh; }
public void DrawHierarchyMesh(Frame frame) { // Draw hierarchy mesh Frame oldframe = frame; MatrixStack matrixstack = new MatrixStack(); matrixstack.Push(); matrixstack.LoadMatrix(devicematrix); matrixstack.MultiplyMatrixLocal(frame.TransformationMatrix); if (frame.MeshContainer != null) { device.Transform.World = matrixstack.Top; G3DMesh d3dmesh = (G3DMesh)frame.MeshContainer.UserData; for (int i = 0; i < d3dmesh.Materials.Length; i++) { if (d3dmesh.Textures != null) { device.SetTexture(0, d3dmesh.Textures[i]); } device.Material = d3dmesh.Materials[i]; d3dmesh.Mesh.DrawSubset(i); } } if (frame.FrameFirstChild != null) { DrawHierarchyMesh(frame.FrameFirstChild); } matrixstack.Pop(); frame = oldframe; if (frame.FrameSibling != null) { DrawHierarchyMesh(frame.FrameSibling); } }
public void MeshEnd() { devicemesh = new G3DMesh(); }
public void PrimitiveEnd() { devicemesh = new G3DMesh(); }
public void MakeMesh(string name, string filename, bool computenormals) { G3DMesh g3dmesh = new G3DMesh(); ExtendedMaterial[] meshmaterials = null; // Load Mesh and materials try { g3dmesh.Mesh = Microsoft.DirectX.Direct3D.Mesh.FromFile(filename, MeshFlags.SystemMemory, device, out meshmaterials); } catch { g3dmesh.Mesh = Microsoft.DirectX.Direct3D.Mesh.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(filename), MeshFlags.SystemMemory, device, out meshmaterials); } // Generate normals if (computenormals) { Mesh temp = g3dmesh.Mesh.Clone(MeshFlags.SystemMemory, (VertexFormats)(g3dmesh.Mesh.VertexFormat | VertexFormats.Normal), device); temp.ComputeNormals(); g3dmesh.Mesh.Dispose(); g3dmesh.Mesh = temp; } if (meshmaterials != null) { g3dmesh.Materials = new Material[meshmaterials.Length]; g3dmesh.Textures = new Texture[meshmaterials.Length]; for (int i = 0; i < meshmaterials.Length; i++) { if (meshmaterials[i].TextureFilename != null) { // Load texture from file or resource Texture texture; try { texture = TextureLoader.FromFile(device, meshmaterials[i].TextureFilename); } catch { try { texture = TextureLoader.FromStream(device, System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(meshmaterials[i].TextureFilename)); } catch { texture = null; } } g3dmesh.Textures[i] = texture; } // Load material g3dmesh.Materials[i] = meshmaterials[i].Material3D; g3dmesh.Materials[i].Ambient = g3dmesh.Materials[i].Diffuse; } } // Add to list meshlist.Add(name, g3dmesh); }