// metallic box with marble on stone floor private void SetupScene4() { TextureMaterial woodMaterial = new TextureMaterial(woodTexture, 0.0, 0.0, 2, .5); TextureMaterial marbleMaterial = new TextureMaterial(marbleTexture, 0.3, 0.0, 2, .5); TextureMaterial wallMaterial = new TextureMaterial(wallTexture, 0.0, 0.0, 2, .4); scene = new Scene(); scene.Background = new Background(new RGBA_Doubles(.3, .8, .8), 0.8); Vector campos = new Vector(14, 2, -6); scene.Camera = new Camera(campos, campos / -2.5, new Vector(-0, 1, 0.1).Normalize()); // marble scene.Shapes.Add(new SphereShape(new Vector(-3, 1, 5), 2, marbleMaterial)); // box scene.Shapes.Add(new BoxShape(new Vector(0, 1, -1), new Vector(1, 0, 0), woodMaterial)); //floor scene.Shapes.Add(new PlaneShape(new Vector(0, 1, 0).Normalize(), 0, wallMaterial)); //wall //scene.Shapes.Add(new PlaneShape(new Vector(0, 0, 1).Normalize(), 0, wallMaterial)); scene.Lights.Add(new Light(new Vector(25, 20, -20), new RGBA_Doubles(0.5, 0.5, 0.5))); scene.Lights.Add(new Light(new Vector(-23, 25, -15), new RGBA_Doubles(0.5, 0.5, 0.5))); }
private void SetupScene1() { TextureMaterial woodMaterial = new TextureMaterial(woodTexture, 0.2, 0.0, 2, .5); TextureMaterial marbleMaterial = new TextureMaterial(marbleTexture, 0.0, 0.0, 2, .5); TextureMaterial wallMaterial = new TextureMaterial(wallTexture, 0.0, 0.0, 2, .4); scene = new Scene(); scene.Background = new Background(new RGBA_Doubles(.8, .8, .8), 0.8); Vector campos = new Vector(5, 1.8, -15); scene.Camera = new Camera(campos, campos / -3, new Vector(0, 1, 0).Normalize()); // marble scene.Shapes.Add(new SphereShape(new Vector(1, 1, -5), 1, marbleMaterial)); //floor scene.Shapes.Add(new PlaneShape(new Vector(0, 1, 0).Normalize(), 0, woodMaterial)); //wall scene.Shapes.Add(new PlaneShape(new Vector(0, 0, 1).Normalize(), 0, wallMaterial)); scene.Lights.Add(new Light(new Vector(25, 20, -20), new RGBA_Doubles(0.5, 0.5, 0.5))); scene.Lights.Add(new Light(new Vector(-3, 5, -15), new RGBA_Doubles(0.5, 0.5, 0.5))); }
// marble balls scene public static Scene MarbleBallsScene(string contentRoot) { var marbleTexture = Texture.FromFile(Path.Combine(contentRoot, "textures/marble.png")); var texture = new TextureMaterial(marbleTexture, 0.0, 0.0, 1, .5); var scene = new Scene() { Camera = new Camera(new Vector(0, 0, -15), new Vector(-.2, 0, 5), new Vector(0, 1, 0)) }; // setup a solid reflecting sphere scene.Shapes.Add(new SphereShape(new Vector(-1.5, 0.5, 0), .5, new SolidMaterial(new Vector(0, .5, .5), 0.2, 0.0, 2.0))); // setup sphere with a marble texture from an image scene.Shapes.Add(new SphereShape(new Vector(0, 0, 0), 1, texture)); // scene.Shapes1.Add(new SphereShape(new Vector(0, 0, 0), 1, new SolidMaterial(new Vector(0.3, 0.0, 0.0), 0.7, 0.0, 3.0))); // setup the chessboard floor scene.Shapes.Add(new PlaneShape(new Vector(0.1, 0.9, -0.5).Normalize(), 1.2, new ChessboardMaterial(new Vector(0.5, 0.5, 0.5), new Vector(0, 0, 0), 0.2, 0, 1, 0.7))); // add two lights for better lighting effects scene.Lights.Add(new Light(new Vector(5, 10, -1), new Vector(0.8, 0.8, 0.8))); scene.Lights.Add(new Light(new Vector(-3, 5, -15), new Vector(0.8, 0.8, 0.8))); return(scene); }
private void CopyToScreen(DrawingContext context, IList <IDrawableObject> drawables) { if (textureMaterial == null) { textureMaterial = new TextureMaterial(context.graphics) { SamplerState = SamplerState.PointClamp } } ; Material = textureMaterial; base.Draw(context, drawables); Material = adoptionMaterial; } }
public WavefrontModel(string name, string filename, string textureFilename, string normalsFilename) { Name = name; TintColor = new Vector4(1, 1, 0, 0); // alpha is intensity // load model if (WavefrontLoader.Load(this, filename)) { Log.WriteLine(Log.LOG_INFO, "WavefrontModel '" + name + "' loaded " + vertices.Length + " vertices, " + normals.Length + " normals, " + texCoords.Length + " texture coords, " + indices.Length + " indices, " + "using " + PolygonType.ToString() + " -> " + (indices.Length / (PolygonType == PrimitiveType.Quads ? 4 : 3)) + " polygons"); } else { Log.WriteLine(Log.LOG_ERROR, "WavefrontModel '" + name + "' failed loading '" + filename + "' - might be incompatible"); return; } // load material material = new TextureMaterial(textureFilename, normalsFilename, normals.Length > 0, true); if (!material.Ready) { Log.WriteLine(Log.LOG_ERROR, "failed to load WavefrontModel material"); return; } // sanity check for normal information /* * if (!material.UseNormalMap && normals.Length == 0) * { * Log.WriteLine(Log.LOG_ERROR, "WavefrontModel '" + name + "' is not using a normal map and does not have vertex normals"); * return; * }*/ // create GL objects createVBOs(); createVAOs(); ready = true; }
private static Dictionary <string, BaseMaterial> LoadMtl(string file) { Dictionary <string, BaseMaterial> materials = new Dictionary <string, BaseMaterial>(); string currentName = ""; BaseMaterial currentMat = new SolidMaterial(); foreach (var s in File.ReadAllLines(file)) { if (String.IsNullOrEmpty(s)) { continue; } var lines = Regex.Split(s, @"\s").Where(l => !String.IsNullOrEmpty(l)).ToList(); string flag = lines[0]; if (flag == "newmtl") { materials.Add(currentName, currentMat); currentName = Regex.Replace(s, @"\s*newmtl\s*(.*\S)\s*$", "$1"); currentMat = new SolidMaterial(); } else if (flag == "map_Kd") { var imageName = Regex.Replace(s, @"\s*map_Kd\s*(.*\S)\s*$", "$1"); var img = new CSharpImageLibrary.ImageEngineImage(imageName); currentMat = new TextureMaterial(img); } else if (flag == "Kd") { currentMat = new SolidMaterial(Color.FromArgb(0, (int)(double.Parse(lines[1]) * 255), (int)(double.Parse(lines[2]) * 255), (int)(double.Parse(lines[3]) * 255))); } } materials.Add(currentName, currentMat); return(materials); }
public void AddObject(Obj o) { var texmats = new List <Material>(); foreach (var face in o.Faces) { var tex = texmats.Find(a => a.Name == face.material); if (tex == null) { if (face.material != null) { tex = TextureMaterial.Load(face.material); } else { tex = ColorMaterials.White; } texmats.Add(tex); } AddTriangle(o.Points[face.v1], o.Points[face.v2], o.Points[face.v3], o.UV[face.uv1], o.UV[face.uv2], o.UV[face.uv3], tex); } }
// marble balls scene private void SetupScene0() { TextureMaterial texture = new TextureMaterial(marbleTexture, 0.0, 0.0, 2, .5); scene = new Scene(); scene.Camera = new Camera(new Vector3(0, 0, -15), new Vector3(-.2, 0, 5), new Vector3(0, 1, 0)); // setup a solid reflecting sphere scene.Shapes.Add(new SphereShape(new Vector(-1.5, 0.5, 0), .5, new SolidMaterial(new RGBA_Doubles(0, .5, .5), 0.2, 0.0, 2.0))); // setup sphere with a marble texture from an image scene.Shapes.Add(new SphereShape(new Vector(0, 0, 0), 1, texture)); scene.Shapes.Add(new BoxShape(new Vector(0, 0, -15), new Vector(.5, .5, .5), new SolidMaterial(new RGBA_Doubles(0, 0, 1), .1, 0, .2))); // setup the chessboard floor scene.Shapes.Add(new PlaneShape(new Vector(0.1, 0.9, -0.5).Normalize(), 1.2, new ChessboardMaterial(new RGBA_Doubles(1, 1, 1), new RGBA_Doubles(0, 0, 0), 0.2, 0, 1, 0.7))); //add two lights for better lighting effects scene.Lights.Add(new Light(new Vector(5, 10, -1), new RGBA_Doubles(0.8, 0.8, 0.8))); scene.Lights.Add(new Light(new Vector(-3, 5, -15), new RGBA_Doubles(0.8, 0.8, 0.8))); }
private void SetItem(IInventoryItem item) { if (item == null) { this.MakeEmpty(); return; } this._myDisplayItem = item; if (!item.datablock.IsSplittable()) { this._stackLabel.color = Color.yellow; this._stackLabel.text = (item.datablock._maxUses <= item.datablock.GetMinUsesForDisplay() ? string.Empty : item.uses.ToString()); } else { this._stackLabel.color = Color.white; if (item.uses <= 1) { this._stackLabel.text = string.Empty; } else { UILabel uILabel = this._stackLabel; int num = item.uses; uILabel.text = string.Concat("x", num.ToString()); } } if (this._amountBackground) { if (this._stackLabel.text != string.Empty) { Vector2 vector2 = this._stackLabel.font.CalculatePrintedSize(this._stackLabel.text, true, UIFont.SymbolStyle.None); this._amountBackground.enabled = true; Transform vector3 = this._amountBackground.transform; float single = vector2.x; Vector3 vector31 = this._stackLabel.transform.localScale; vector3.localScale = new Vector3(single * vector31.x + 12f, 16f, 1f); } else { this._amountBackground.enabled = false; } } if (ItemDataBlock.LoadIconOrUnknown <Texture>(item.datablock.icon, ref item.datablock.iconTex)) { Material material = TextureMaterial.GetMaterial(RPOSInventoryCell._myMaterial, item.datablock.iconTex); this._icon.material = (UIMaterial)material; this._icon.enabled = true; } IHeldItem heldItem = item as IHeldItem; IHeldItem heldItem1 = heldItem; int num1 = (heldItem != null ? heldItem1.totalModSlots : 0); int num2 = (num1 != 0 ? heldItem1.usedModSlots : 0); for (int i = 0; i < (int)this.modSprites.Length; i++) { if (i >= num1) { this.modSprites[i].enabled = false; } else { this.modSprites[i].enabled = true; this.modSprites[i].sprite = (i >= num2 ? this.mod_empty : this.mod_full); this.modSprites[i].spriteName = this.modSprites[i].sprite.name; } } if (item.IsBroken()) { this._icon.color = Color.red; } else if (item.condition / item.maxcondition > 0.4f) { this._icon.color = Color.white; } else { this._icon.color = Color.yellow; } }
private void SetItem(IInventoryItem item) { if (item == null) { this.MakeEmpty(); } else { IHeldItem item2; this._myDisplayItem = item; if (item.datablock.IsSplittable()) { this._stackLabel.color = Color.white; if (item.uses > 1) { this._stackLabel.text = "x" + item.uses.ToString(); } else { this._stackLabel.text = string.Empty; } } else { this._stackLabel.color = Color.yellow; this._stackLabel.text = (item.datablock._maxUses <= item.datablock.GetMinUsesForDisplay()) ? string.Empty : item.uses.ToString(); } if (this._amountBackground != null) { if (this._stackLabel.text == string.Empty) { this._amountBackground.enabled = false; } else { Vector2 vector = this._stackLabel.font.CalculatePrintedSize(this._stackLabel.text, true, UIFont.SymbolStyle.None); this._amountBackground.enabled = true; this._amountBackground.transform.localScale = new Vector3((vector.x * this._stackLabel.transform.localScale.x) + 12f, 16f, 1f); } } if (ItemDataBlock.LoadIconOrUnknown <Texture>(item.datablock.icon, ref item.datablock.iconTex)) { Material material = TextureMaterial.GetMaterial(_myMaterial, item.datablock.iconTex); this._icon.material = (UIMaterial)material; this._icon.enabled = true; } int num = ((item2 = item as IHeldItem) != null) ? item2.totalModSlots : 0; int num2 = (num != 0) ? item2.usedModSlots : 0; for (int i = 0; i < this.modSprites.Length; i++) { if (i < num) { this.modSprites[i].enabled = true; this.modSprites[i].sprite = (i >= num2) ? this.mod_empty : this.mod_full; this.modSprites[i].spriteName = this.modSprites[i].sprite.name; } else { this.modSprites[i].enabled = false; } } if (item.IsBroken()) { this._icon.color = Color.red; } else if ((item.condition / item.maxcondition) <= 0.4f) { this._icon.color = Color.yellow; } else { this._icon.color = Color.white; } } }
private static Material loadMaterial(string name, ResourceCollector.Pack packs) { ResourceCollector.Content.Material mat = ResourceCollector.PackList.Instance.GetObject(name) as ResourceCollector.Content.Material; if (mat.Enginereadedobject.Count == 0) { XNAevents.Add("creating material " + name); TextureMaterial.Lod[] lods = new TextureMaterial.Lod[mat.lodMats.Count]; for (int i = 0; i < mat.lodMats.Count; i++) { TextureMaterial.SubsetMaterial[] mats = new TextureMaterial.SubsetMaterial[mat.lodMats[i].mats.Count]; for (int j = 0; j < mat.lodMats[i].mats.Count; j++) { mats[j] = new TextureMaterial.SubsetMaterial(); Content.EngineTexture texture; ResourceCollector.ImageContent inage = ResourceCollector.PackList.Instance.GetObject(mat.lodMats[i].mats[j].DiffuseTextureName) as ResourceCollector.ImageContent; if (inage.Enginereadedobject.Count == 0) { texture = new Content.EngineTexture(); XNAevents.Add("creating texture " + mat.lodMats[i].mats[j].DiffuseTextureName); texture.loadbody(inage.data); inage.usercount++; } else { texture = inage.Enginereadedobject[0] as Content.EngineTexture; } inage.Enginereadedobject.Add(texture); mats[j].diffuseTexture = texture.texture; } lods[i] = new TextureMaterial.Lod(mats); } TextureMaterial tm = new TextureMaterial(lods); mat.Enginereadedobject.Add(tm); return tm; } else { TextureMaterial result = mat.Enginereadedobject[0] as TextureMaterial; mat.Enginereadedobject.Add(result); for (int i = 0; i < mat.lodMats.Count; i++) { for (int j = 0; j < mat.lodMats[i].mats.Count; j++) { ResourceCollector.ImageContent inage = ResourceCollector.PackList.Instance.GetObject(mat.lodMats[i].mats[j].DiffuseTextureName) as ResourceCollector.ImageContent; inage.Enginereadedobject.Add(inage.Enginereadedobject[0]); } } return result; } }