public override void DrawModel(DirectXModel model) { if (model.Mesh == null) { return; } Matrix oldWorldTransform = WorldTransform; ExtendedMaterial[] materials = model.Mesh.GetMaterials(); MultiplyWorldTransform(model.ModifierMatrix); for (int i = 0; i < materials.Length; i++) { Material material = materials[i].MaterialD3D; BaseTexture oldTexture = null; Texture texture; if (model.Textures.TryGetValue(i, out texture) && texture != null) { oldTexture = _device.GetTexture(0); _device.SetTexture(0, texture); } _device.Material = material; model.Mesh.DrawSubset(i); if (texture != null) { _device.SetTexture(0, oldTexture); } } WorldTransform = oldWorldTransform; }
public static DirectXModel CreateBall(Device device, Ball ball) { var drmodel = new DirectXModel { Mesh = Mesh.CreateSphere(device, (float)ball.Radius, Slices, Slices), ModifierMatrix = Matrix.Translation(0, 0, (float)ball.Radius) }; drmodel.Mesh.SetMaterials(new[] {ball.DefaultColor.GetDirectXMaterial()}); return drmodel; }
public static DirectXModel CreateBall(Device device, Ball ball) { var drmodel = new DirectXModel { Mesh = Mesh.CreateSphere(device, (float)ball.Radius, Slices, Slices), ModifierMatrix = Matrix.Translation(0, 0, (float)ball.Radius) }; drmodel.Mesh.SetMaterials(new[] { ball.DefaultColor.GetDirectXMaterial() }); return(drmodel); }
public static DirectXModel CreateCyllinder(Device device, Cylinder cyl) { var drmodel = new DirectXModel { Mesh = DirectXPrimitives.CreateCylinderMesh(device, cyl.RBottom, cyl.RTop, cyl.Height), ModifierMatrix = Matrix.Translation(0, 0, (float)(cyl.Height / 2)) }; var brushes = new[] { cyl.Top, cyl.Bottom, cyl.Side }; drmodel.Mesh.SetMaterials(GetMaterialsFromBrushes(device, cyl.DefaultColor, drmodel, brushes)); return drmodel; }
public static DirectXModel CreateCyllinder(Device device, Cylinder cyl) { var drmodel = new DirectXModel { Mesh = DirectXPrimitives.CreateCylinderMesh(device, cyl.RBottom, cyl.RTop, cyl.Height), ModifierMatrix = Matrix.Translation(0, 0, (float)(cyl.Height / 2)) }; var brushes = new[] { cyl.Top, cyl.Bottom, cyl.Side }; drmodel.Mesh.SetMaterials(GetMaterialsFromBrushes(device, cyl.DefaultColor, drmodel, brushes)); return(drmodel); }
public static DirectXModel FromModel(Device device, byte[] content) { if(device == null) throw new Exception("Must have a Device to create model"); var drmodel = new DirectXModel(); if(content != null) drmodel.Mesh = Mesh.FromMemory(device, content, MeshFlags.Managed); ExtendedMaterial[] materials = drmodel.Mesh.GetMaterials(); for(int i = 0; i < materials.Length; i++) { if(string.IsNullOrEmpty(materials[i].TextureFileName)) continue; var textureImage = GetTextureResourceObject(materials[i].TextureFileName); drmodel.Textures.Add(i, Texture.FromStream(device, textureImage.ToStream(ImageFormat.Jpeg))); } return drmodel; }
public static DirectXModel CreateCustomBoxModel(Device device, Core.Box box) { Color defaultColor = box.DefaultColor; var m = new DirectXModel { Mesh = Mesh.FromMemory(device, CVARC.Engine.KR.Properties.Resources.custombox, MeshFlags.Managed), ModifierMatrix = Matrix.Scaling((float)box.XSize, (float)box.YSize, (float)box.ZSize) * Matrix.Translation(0, 0, (float)box.ZSize / 2) }; var brushesInOrder = new[] { box.Right, box.Left, box.Front, box.Back, box.Top, box.Bottom }; m.Mesh.SetMaterials(GetMaterialsFromBrushes(device, defaultColor, m, brushesInOrder)); return m; }
public static DirectXModel CreateCustomBoxModel(Device device, Core.Box box) { Color defaultColor = box.DefaultColor; var m = new DirectXModel { Mesh = Mesh.FromMemory(device, CVARC.Engine.KR.Properties.Resources.custombox, MeshFlags.Managed), ModifierMatrix = Matrix.Scaling((float)box.XSize, (float)box.YSize, (float)box.ZSize) * Matrix.Translation(0, 0, (float)box.ZSize / 2) }; var brushesInOrder = new[] { box.Right, box.Left, box.Front, box.Back, box.Top, box.Bottom }; m.Mesh.SetMaterials(GetMaterialsFromBrushes(device, defaultColor, m, brushesInOrder)); return(m); }
public override void DrawModel(DirectXModel model) { if(model.Mesh == null) return; Matrix oldWorldTransform = WorldTransform; ExtendedMaterial[] materials = model.Mesh.GetMaterials(); MultiplyWorldTransform(model.ModifierMatrix); for(int i = 0; i < materials.Length; i++) { Material material = materials[i].MaterialD3D; BaseTexture oldTexture = null; Texture texture; if(model.Textures.TryGetValue(i, out texture) && texture != null) { oldTexture = _device.GetTexture(0); _device.SetTexture(0, texture); } _device.Material = material; model.Mesh.DrawSubset(i); if(texture != null) _device.SetTexture(0, oldTexture); } WorldTransform = oldWorldTransform; }
public static DirectXModel FromModel(Device device, byte[] content) { if (device == null) { throw new Exception("Must have a Device to create model"); } var drmodel = new DirectXModel(); if (content != null) { drmodel.Mesh = Mesh.FromMemory(device, content, MeshFlags.Managed); } ExtendedMaterial[] materials = drmodel.Mesh.GetMaterials(); for (int i = 0; i < materials.Length; i++) { if (string.IsNullOrEmpty(materials[i].TextureFileName)) { continue; } var textureImage = GetTextureResourceObject(materials[i].TextureFileName); drmodel.Textures.Add(i, Texture.FromStream(device, textureImage.ToStream(ImageFormat.Jpeg))); } return(drmodel); }
public abstract void DrawModel(DirectXModel model);
private static ExtendedMaterial[] GetMaterialsFromBrushes(Device device, Color defaultColor, DirectXModel m, IPlaneBrush[] brushesInOrder) { var materials = new ExtendedMaterial[brushesInOrder.Length]; var converter = new DirectXBrushConverter(device); for(int i = 0; i < materials.Length; i++) { materials[i] = defaultColor.GetDirectXMaterial(); if(brushesInOrder[i] == null) continue; Texture texture; materials[i] = converter.TryConvert(brushesInOrder[i], out texture); if(texture != null) m.Textures[i] = texture; } return materials; }
private static ExtendedMaterial[] GetMaterialsFromBrushes(Device device, Color defaultColor, DirectXModel m, IPlaneBrush[] brushesInOrder) { var materials = new ExtendedMaterial[brushesInOrder.Length]; var converter = new DirectXBrushConverter(device); for (int i = 0; i < materials.Length; i++) { materials[i] = defaultColor.GetDirectXMaterial(); if (brushesInOrder[i] == null) { continue; } Texture texture; materials[i] = converter.TryConvert(brushesInOrder[i], out texture); if (texture != null) { m.Textures[i] = texture; } } return(materials); }