예제 #1
0
        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;
        }
예제 #2
0
		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;
		}
예제 #3
0
        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);
        }
예제 #4
0
		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;
		}
예제 #5
0
        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);
        }
예제 #6
0
		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;
		}
예제 #7
0
		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;
		}
예제 #8
0
        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);
        }
예제 #9
0
		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;
		}
예제 #10
0
        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);
        }
예제 #11
0
 public abstract void DrawModel(DirectXModel model);
예제 #12
0
파일: Effect.cs 프로젝트: DmitryZyr/CVARC
		public abstract void DrawModel(DirectXModel model);
예제 #13
0
		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;
		}
예제 #14
0
        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);
        }