public float getFocus() { RaycastCallback raycast = new RaycastCallback(RaycastCallback); RigidBody body; JVector normal; float frac; bool result = Scene.world.CollisionSystem.Raycast(GenericMethods.FromOpenTKVector(Position), GenericMethods.FromOpenTKVector(PointingDirection), raycast, out body, out normal, out frac); if (result) { return(frac); } else { return(zFar); } }
public void loadMaterialXml(Material target) { XmlTextReader reader = new XmlTextReader(target.pointer); //target.envMapAlphaBaseTexture = false; gameWindow.log("parsing material: " + target.name); while (reader.Read()) { // parsing data in material tag if (reader.Name == "material" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "shader") { target.shader = gameWindow.shaderLoader.getShader(reader.Value); } else if (reader.Name == "ssnshader") { target.ssnshader = gameWindow.shaderLoader.getShader(reader.Value); } else if (reader.Name == "selection") { target.selectionshader = gameWindow.shaderLoader.getShader(reader.Value); } else if (reader.Name == "shadow") { target.shadowshader = gameWindow.shaderLoader.getShader(reader.Value); } else if (reader.Name == "definfo") { target.definfoshader = gameWindow.shaderLoader.getShader(reader.Value); } } gameWindow.log("shader: " + target.shader.name); reader.MoveToElement(); } // parsing textures if (reader.Name == "textures" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { Texture tmpTex = gameWindow.textureLoader.getTexture(reader.Value); if (reader.Name == "base") { target.setTexture(Material.TexType.baseTexture, tmpTex); } else if (reader.Name == "base2") { target.setTexture(Material.TexType.base2Texture, tmpTex); } else if (reader.Name == "base3") { target.setTexture(Material.TexType.base3Texture, tmpTex); } else if (reader.Name == "normal") { target.setTexture(Material.TexType.normalTexture, tmpTex); } else if (reader.Name == "reflection") { target.setTexture(Material.TexType.reflectionTexture, tmpTex); } else if (reader.Name == "definfo") { target.setTexture(Material.TexType.definfoTexture, tmpTex); } else if (reader.Name == "emit") { target.setTexture(Material.TexType.emitTexture, tmpTex); } } gameWindow.log("base: " + target.getTextureName(Material.TexType.baseTexture)); gameWindow.log("normal: " + target.getTextureName(Material.TexType.normalTexture)); reader.MoveToElement(); } // parsing envmap data if (reader.Name == "envmap") { target.propertys.useEnv = true; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "source") { if (reader.Value == "normalalpha") { target.propertys.envMapAlphaNormalTexture = true; } else if (reader.Value == "basealpha") { target.propertys.envMapAlphaBaseTexture = true; } else { target.setTexture(Material.TexType.envMapTexture, gameWindow.textureLoader.getTexture(reader.Value)); } } else if (reader.Name == "tint") { target.propertys.envMapTint = GenericMethods.VectorFromString(reader.Value); } } reader.MoveToElement(); } } /* -- moved to textures * // parsing specular data * if (reader.Name == "specmap") * { * target.propertys.useSpec = true; * if (reader.HasAttributes) * { * while (reader.MoveToNextAttribute()) * { * if (reader.Name == "source") * { * if (reader.Value == "normalalpha") * target.propertys.specMapAlphaNormalTexture = true; * * else if (reader.Value == "basealpha") * target.propertys.specMapAlphaBaseTexture = true; * * else * target.setTexture(Material.TexType.specMapTexture, gameWindow.textureLoader.getTexture(reader.Value)); * * } * else if (reader.Name == "tint") * { * target.propertys.specMapTint = GenericMethods.VectorFromString(reader.Value); * } * else if (reader.Name == "exp") * { * target.propertys.specExp = GenericMethods.FloatFromString(reader.Value); * } * } * reader.MoveToElement(); * } * } */ // parsing emit data if (reader.Name == "emit") { target.propertys.useEmit = true; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "source") { if (reader.Value == "normalalpha") { target.propertys.emitMapAlphaNormalTexture = true; } else if (reader.Value == "basealpha") { target.propertys.emitMapAlphaBaseTexture = true; } else { target.setTexture(Material.TexType.emitMapTexture, gameWindow.textureLoader.getTexture(reader.Value)); } } else if (reader.Name == "tint") { target.propertys.emitMapTint = GenericMethods.VectorFromString(reader.Value); } } reader.MoveToElement(); } } // parsing transparency data if (reader.Name == "transparency") { target.propertys.useAlpha = true; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "refraction") { target.propertys.refStrength = GenericMethods.FloatFromString(reader.Value); } if (reader.Name == "blur") { target.propertys.blurStrength = GenericMethods.FloatFromString(reader.Value); } if (reader.Name == "fresnel") { target.propertys.fresnelStrength = GenericMethods.FloatFromString(reader.Value); } } reader.MoveToElement(); } } // parsing lighting data if (reader.Name == "lighted") { target.propertys.useLight = true; } // parsing nucull if (reader.Name == "nocull") { target.propertys.noCull = true; } // parsing nucull if (reader.Name == "nodepthmask") { target.propertys.noDepthMask = true; } // parsing additive if (reader.Name == "additive") { target.propertys.additive = true; } // parsing fresnel data if (reader.Name == "fresnel" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "exp") { target.propertys.fresnelExp = GenericMethods.FloatFromString(reader.Value); } else if (reader.Name == "strength") { target.propertys.fresnelStr = GenericMethods.FloatFromString(reader.Value); } } reader.MoveToElement(); } target.loaded = true; materials[target.identifier] = target; } }
private void loadTemplate(Template target) { XmlTextReader reader = new XmlTextReader(target.pointer); target.meshes = new List <string> { }; target.pmeshes = new List <string> { }; target.materials = new List <string> { }; target.isStatic = false; target.useType = Template.UseType.Model; while (reader.Read()) { // parsing data in template tag if (reader.Name == "template") { while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { target.name = reader.Value; } if (reader.Name == "type") { switch (reader.Value) { case "animated": target.useType = Template.UseType.Animated; break; case "meta": target.useType = Template.UseType.Meta; break; default: target.useType = Template.UseType.Model; break; } } } gameWindow.log("parsing template: " + target.name); reader.MoveToElement(); while (reader.Read()) { if (reader.Name == "template") { break; } if (reader.Name == "static") { target.isStatic = true; } if (reader.Name == "material" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "source") { target.materials.Add(reader.Value); gameWindow.log("material: " + reader.Value); } } } if (reader.Name == "mesh" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "source") { target.meshes.Add(reader.Value); gameWindow.log("mesh: " + reader.Value); } } } if (reader.Name == "pmesh" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "source") { target.pmeshes.Add(reader.Value); gameWindow.log("phys mesh: " + reader.Value); } } } if (reader.Name == "position" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "offset") { target.positionOffset = GenericMethods.FloatFromString(reader.Value); gameWindow.log("offset: " + reader.Value); } } } if (reader.Name == "volume" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "radius") { target.volumeRadius = GenericMethods.FloatFromString(reader.Value); gameWindow.log("radius: " + reader.Value); } } } if (reader.Name == "light" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { target.hasLight = true; if (reader.Name == "color") { target.lightColor = GenericMethods.VectorFromString(reader.Value); } } } if (reader.Name == "normal") { target.normal = true; } target.loaded = true; templates[target.identifier] = target; } } } }
protected void genericLoad(ref XmlTextReader reader, string type) { if (reader.Name == PhysModel.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { childname = reader.Value; } } GameObject child = new PhysModel(this); child.Name = childname; child.load(ref reader, "pmodel"); } if (reader.Name == AnimatedModel.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { childname = reader.Value; } } GameObject child = new AnimatedModel(this); child.Name = childname; child.load(ref reader, "animodel"); } if (reader.Name == MetaModel.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { childname = reader.Value; } } GameObject child = new MetaModel(this); child.Name = childname; child.load(ref reader, "metamodel"); } if (reader.Name == LightSpot.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { childname = reader.Value; } } GameObject child = new LightSpot(this); child.Name = childname; child.load(ref reader, "lamp"); } if (reader.Name == "position" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); Position = GenericMethods.VectorFromString(reader.Value); } if (reader.Name == "direction" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); PointingDirection = GenericMethods.VectorFromString(reader.Value); } if (reader.Name == "color" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); Color = new Vector4(GenericMethods.VectorFromString(reader.Value), 1); } if (reader.Name == "rotation" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); Orientation = GenericMethods.ToOpenTKMatrix(GenericMethods.JMatrixFromString(reader.Value)); } }
internal Mesh fromXml(string pointer) { string name = pointer.Replace(gameWindow.modelFolder, ""); if (!meshesNames.ContainsKey(name)) { Mesh curMesh = new Mesh(); curMesh.type = Mesh.Type.colladaManaged; //curMesh.pointer = pointer; curMesh.identifier = meshes.Count; curMesh.name = name; curMesh.animationData = new List <AnimationData> { }; XmlTextReader reader = new XmlTextReader(pointer); while (reader.Read()) { if (reader.Name == "mesh") { while (reader.MoveToNextAttribute()) { if (reader.Name == "source") { curMesh.pointer = reader.Value; } } } if (reader.Name == "animation") { while (reader.MoveToNextAttribute()) { if (reader.Name == "source") { AnimationData tmpAni = new AnimationData(); tmpAni.pointer = gameWindow.modelFolder + reader.Value; tmpAni.name = reader.Value; curMesh.animationData.Add(tmpAni); } } } if (reader.Name == "fps" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); curMesh.animationFps = GenericMethods.FloatFromString(reader.Value); } } meshesNames.Add(curMesh.name, curMesh.identifier); meshes.Add(curMesh); return(curMesh); } else { return(getMesh(name)); } }
public void readCacheFile() { string filename = Settings.Instance.game.modelCacheFile; FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); List <Mesh> tmpMeshes; using (fileStream) { // Read the source file into a byte array. byte[] bytes = new byte[fileStream.Length]; int numBytesToRead = (int)fileStream.Length; int numBytesRead = 0; while (numBytesToRead > 0) { // Read may return anything from 0 to numBytesToRead. int n = fileStream.Read(bytes, numBytesRead, numBytesToRead); // Break when the end of the file is reached. if (n == 0) { break; } numBytesRead += n; numBytesToRead -= n; } tmpMeshes = (List <Mesh>)GenericMethods.ByteArrayToObject(bytes); fileStream.Close(); } int meshCount = tmpMeshes.Count; for (int i = 0; i < meshCount; i++) { Mesh curMesh = tmpMeshes[i]; string name = curMesh.name; if (!meshesNames.ContainsKey(name)) { if (curMesh.indicesVboData != null) { curMesh.type = Mesh.Type.fromCache; } else { curMesh.type = Mesh.Type.empty; curMesh.loaded = true; } int identifier = meshes.Count; curMesh.identifier = identifier; if (curMesh.animationData != null) { curMesh.curAnimationData = curMesh.animationData[0]; } meshesNames.Add(name, identifier); meshes.Add(curMesh); } } gameWindow.log("loaded " + meshCount + " meshes from cache"); }