/// <summary> /// lataa skybox (ei cubemap). skyName on nimen alkuosa eli esim plainsky_ jos tiedostot on plainsky_front.jpg, plainsky_back.jpg jne /// ext on tiedoston pääte eli esim jpg, dds /// </summary> public static Sky Load(string skyName, string ext) { Sky sky = new Sky(); string[] sideStr = { "top", "bottom", "left", "right", "front", "back" }; Node skyNode = new Node(); DotScene ds = DotScene.Load("sky/sky.scene", skyNode); int side = 0; TextureLoaderParameters.WrapModeS = TextureWrapMode.ClampToEdge; TextureLoaderParameters.WrapModeT = TextureWrapMode.ClampToEdge; TextureLoaderParameters.FlipImages = false; skyNode.GetList(true); for (int q = 0; q < ObjList.Count; q++) { OgreMesh m = ObjList[q] as OgreMesh; if (m != null) { sky.skyboxSides[side] = m; m.Boundings = null; m.CastShadow = false; string fileName = skyName + sideStr[side] + "." + ext; m.MaterialName = fileName; m.Material = Material.GetMaterial(fileName + "_material"); m.Material.Textures[Settings.COLOR_TEXUNIT].Tex = Texture.Load(m.MaterialName); side++; } } TextureLoaderParameters.FlipImages = true; TextureLoaderParameters.WrapModeS = TextureWrapMode.Repeat; TextureLoaderParameters.WrapModeT = TextureWrapMode.Repeat; return sky; }
void LoadDotScene(string fileName, Node root) { this.StaticObjects = new List<string>(); this.DynamicObjects = new List<string>(); XmlDocument XMLDoc = null; XmlElement XMLRoot; dir = System.IO.Path.GetDirectoryName(fileName); if (dir.Length > 0) dir += "/"; string fileNameWithoutExtension = fileName.Substring(0, fileName.LastIndexOf('.')); // ensin ladataan .material tiedosto jos löytyy string matFile = Settings.ModelDir + fileNameWithoutExtension + ".material"; if (System.IO.File.Exists(matFile)) { new Material(matFile); } // ladataan userdatat .scene.userdata.xml tiedostosta jos löytyy string userFile = Settings.ModelDir + fileName + ".userdata.xml"; if (System.IO.File.Exists(userFile)) { new UserData(userFile); } try { using (System.IO.StreamReader file = new System.IO.StreamReader(Settings.ModelDir + fileName)) { // tiedosto muistiin string data = file.ReadToEnd(); XMLDoc = new XmlDocument(); XMLDoc.LoadXml(data); } } catch (Exception e) { Log.Error(e.ToString()); } // Validate the File XMLRoot = XMLDoc.DocumentElement; if (XMLRoot.Name != "scene") { Log.Error("Error [" + fileName + "] Invalid .scene File. Missing <scene>"); } // figure out where to attach any nodes we create attachNode = root; // Process the scene processScene(XMLRoot); }
public void Add(Node obj) { Childs.Add(obj); if (obj is Light) { Light.Lights.Add((Light)obj); } else if (obj is Camera) { Camera.cam = (Camera)obj; } Log.WriteLine(obj.Name + " added to " + Name + ".", false); }
void Translate(Node node) { Node obj = node; if (node == null) obj = this; GLExt.Translate(obj.Position.X, obj.Position.Y, obj.Position.Z); GLExt.RotateZ(Rotation.Z); GLExt.RotateY(Rotation.Y); GLExt.RotateX(Rotation.X); GLExt.MultMatrix(ref OrigOrientationMatrix); GLExt.Scale(obj.Scale.X, obj.Scale.Y, obj.Scale.Z); }
public void Remove(Node obj) { if (obj == null) return; if (obj is Light) { Light.Lights.Remove((Light)obj); } else if (obj is Camera) { Camera.cam = new Camera(); // luo uusi kamera niin vanha häviää } Childs.Remove(obj); Log.WriteLine(obj.Name + " removed from " + Name + ".", false); }
public static DotScene Load(string fileName, Node root) { DotScene ds = new DotScene(fileName, root); return ds; }
/* protected void processLightAttenuation(XmlElement XMLNode, Light pLight) { // Process attributes float range = XML.GetAttribReal(XMLNode, "range"); float constant = XML.GetAttribReal(XMLNode, "constant"); float linear = XML.GetAttribReal(XMLNode, "linear"); float quadratic = XML.GetAttribReal(XMLNode, "quadratic"); // Setup the light attenuation pLight.SetAttenuation(range, constant, linear, quadratic); } protected void processLightRange(XmlElement XMLNode, Light pLight) { // Process attributes float inner = XML.GetAttribReal(XMLNode, "inner"); float outer = XML.GetAttribReal(XMLNode, "outer"); float falloff = XML.GetAttribReal(XMLNode, "falloff", 1.0f); // Setup the light range pLight.SetSpotlightRange(new Radian((Degree)inner), new Radian((Degree)outer), falloff); } */ protected void processNode(XmlElement XMLNode, Node pParent) { // Construct the node's name String name = XML.GetAttrib(XMLNode, "name"); // Create the scene node Node pNode = new Node(); Vector3 pos = Vector3.Zero, scale = Vector3.Zero; Quaternion orientation = new Quaternion(); // Process other attributes XmlElement pElement; // Process position pElement = (XmlElement)XMLNode.SelectSingleNode("position"); if (pElement != null) { pos = XML.ParseVector3(pElement); } // Process rotation pElement = (XmlElement)XMLNode.SelectSingleNode("rotation"); if (pElement != null) { orientation = XML.ParseOrientation(pElement); } // Process scale pElement = (XmlElement)XMLNode.SelectSingleNode("scale"); if (pElement != null) { scale = XML.ParseVector3(pElement); } // Process ogremesh pElement = (XmlElement)XMLNode.SelectSingleNode("entity"); if (pElement != null) { pNode = processEntity(pElement); if (pNode == null) return; // jos .scene tiedostossa näkyy että pathin position, rotation tai scale on muuttunut, // silloin path ei toimi oikein koska niitä ei tässä oteta huomioon ollenkaan // (joten path voi ollaki ihan eri kohdassa missä pitäis). // ratkaisu on että pathia EI liikuteta, pyöritetä eikä skaalata 3dsmaxissa! // pivot point pitää olla origossa ja muokkaukset tehdään vain vertex edit moodissa. } // Process light pElement = (XmlElement)XMLNode.SelectSingleNode("light"); if (pElement != null) { pNode = processLight(pElement); pNode.Rotation = QuaternionExt.QuatToEuler(orientation); pElement = (XmlElement)XMLNode.NextSibling; if (pElement != null) { string nname = XML.GetAttrib(pElement, "name"); if (nname.Contains(".Target")) { Vector3 targetPos; pElement = (XmlElement)pElement.SelectSingleNode("position"); if (pElement != null) targetPos = XML.ParseVector3(pElement); else targetPos = Vector3.Zero; pNode.OrigOrientationMatrix = Matrix4.LookAt(pos, targetPos, Vector3.UnitY); } pNode.Name = name; pNode.Position = pos; pNode.Scale = scale; pParent.Add(pNode); return; } } // Process camera pElement = (XmlElement)XMLNode.SelectSingleNode("camera"); if (pElement != null) { pNode = processCamera(pElement); pNode.Rotation = QuaternionExt.QuatToEuler(orientation); } // Process childnodes pElement = (XmlElement)XMLNode.SelectSingleNode("node"); while (pElement != null) { processNode(pElement, pNode); pElement = (XmlElement)pElement.NextSibling; } pNode.Name = name; pNode.Position = pos; pNode.Scale = scale; Matrix4Ext.CreateFromQuaternion(ref orientation, out pNode.OrigOrientationMatrix); pParent.Add(pNode); }
public DotScene(string fileName, Node root) { LoadDotScene(fileName, root); }
/// <summary> /// aseta obj seuraamaan pathia /// </summary> /// <param name="obj"></param> /// <param name="loop"></param> /// <param name="lookAtNextPoint"></param> public void Attach(Node obj, bool loop, bool lookAtNextPoint) { attachedObj = obj; obj.Position = path[0]; this.Looping = loop; this.LookAtNextPoint = lookAtNextPoint; }
void processSubmesh(XmlElement XMLNode, Node pParent, bool path) { XmlElement pElement; if (path == false) { if (MaterialName == "") { MaterialName = XML.GetAttrib(XMLNode, "material"); Material = Material.GetMaterial(MaterialName); } pElement = (XmlElement)XMLNode.SelectSingleNode("faces"); if (pElement != null) { processFaces(pElement); } } pElement = (XmlElement)XMLNode.SelectSingleNode("geometry"); if (pElement != null) { processGeometry(pElement, path); } }