private void Start() { System.Collections.Generic.List <ScaledObject> objList = new System.Collections.Generic.List <ScaledObject>(); foundObjects = GameDatabase.Instance.GetConfigs("INSTANTIATOR"); //Grab all INSTANTIATOR nodes //If we found no objects, we quit. if (foundObjects.Length < 1) { Debug.LogWarning("[INSTANTIATOR}: No config files found. Shutting down."); return; } //Process all INSTANTIATOR nodes foreach (UrlDir.UrlConfig config in foundObjects) { //In each INSTANTIATOR node, index all SCALED_OBJECT nodes foreach (ConfigNode ObjNode in config.config.GetNodes("SCALED_OBJECT")) { //Make a new entry objList.Add(new ScaledObject(ObjNode.GetValue("Name"), ObjNode.GetValue("Body"), ObjNode.GetValue("Scale"), ObjNode.GetValue("Shader"), ObjNode.GetValue("Rotation"), ObjNode.GetValue("InvertNormals"), ObjNode.GetValue("Texture"), ObjNode.GetValue("Type"), ObjNode.GetValue("IgnoreLight"))); } } //Now, we execute foreach (ScaledObject o in objList) { o.Build(); } }
private static void PraseNote(string str, string bindingOnPrefabUiScript, ref List <ObjNode> objList, ref List <TransformNode> transList, ref List <ScriptNode> scriptNodeList) { string[] strs = str.Split('\n'); if (strs.Length > 2) { string type = strs[1]; if (type.Equals("GameObject:")) { ObjNode node = PraseStrToObjNode(strs); if (null != node) { objList.Add(node); } } else if (type.Equals("Transform:") || type.Equals("RectTransform:")) { TransformNode node = PraseStrToTransformNode(strs); if (null != node) { transList.Add(node); } } else if (type.Equals("MonoBehaviour:")) { ScriptNode node = PraseStrToScriptNode(strs, bindingOnPrefabUiScript); if (null != node) { scriptNodeList.Add(node); } } } }
/** * Copy * * @param original */ public void Copy(OctNode original) { int i; for (i = 0; i < 6; i++) { Adjacent [i] = original.GetAdjacent(i); OctFaces [i] = original.GetFace(i); } for (i = 0; i < 8; i++) { Child [i] = original.GetChild(i); } ObjList = original.GetList(); NumObj = original.GetNumObj(); }
public override bool Equals(Object other) { ObjNode on = (ObjNode)other; // due to bug in cursor throwing try { if (on._obj.Equals(_obj)) { return(true); } } catch { return(false); } return(false); }
/** * Initialize */ private void Initialize() { int i; Adjacent = new OctNode[6]; OctFaces = new Face[6]; Child = new OctNode[8]; for (i = 0; i < 6; i++) { Adjacent [i] = null; } for (i = 0; i < 8; i++) { Child [i] = null; } ObjList = null; NumObj = 0; }
/** * Initialize */ private void Initialize() { int i; Adjacent = new OctNode[6]; OctFaces = new Face[6]; Child = new OctNode[8]; for(i = 0; i < 6; i++) { Adjacent[i] = null; } for(i = 0; i < 8; i++) { Child[i] = null; } ObjList = null; NumObj = 0; }
/** * ReadSphere * * @param infile * @param ObjID * @return int */ private int ReadSphere(int ObjID) { String temp; double[] input = new double[3]; int i; double radius; Point max = new Point(MaxX, MaxY, MaxZ); Point min = new Point(MinX, MinY, MinZ); temp = readString(); temp = readString(); Material theMaterial = ReadMaterial(); temp = readString(); temp = temp.Substring(9); for (i = 0; i < 2; i++) { input[i] = (double)Double.Parse(temp.Substring(0, temp.IndexOf(' '))); temp = temp.Substring(temp.IndexOf(' ') + 1); } input[2] = (double)Double.Parse(temp); Point origin = new Point(input[0], input[1], input[2]); temp = readString(); temp = temp.Substring(9); radius = (double)Double.Parse(temp); for (i = 0; i < 7; i++) { temp = readString(); } SphereObj newsphere = new SphereObj(theMaterial, ++ObjID, origin, radius, max, min); ObjNode newnode = new ObjNode(newsphere, objects); objects = newnode; MaxX = max.GetX(); MaxY = max.GetY(); MaxZ = max.GetZ(); MinX = min.GetX(); MinY = min.GetY(); MinZ = min.GetZ(); return(1); }
/** * LoadSceneOrig * * @param filename * @return int */ private int LoadSceneOrig(String filename) { sceneLines = File.ReadAllLines(filename); scenePos = 0; int numObj = 0, ObjID = 0; camera = null; lights = null; objects = null; materials = null; MaxX = MinX = MaxY = MinY = MaxZ = MinZ = 0.0f; String input; input = readString(); while (input != null) { if (input.Equals("camera {")) { ReadCamera(); } else if (input.Equals("point_light {")) { ReadLight(); } else if (input.Equals("sphere {")) { numObj += ReadSphere(ObjID); } else if (input.Equals("poly_set {")) { numObj += ReadPoly(ObjID); } else { ; } input = readString(); } return(numObj); }
/** * FindLightBlock * * @param tree * @param ray * @param maxt * @return boolean */ private bool FindLightBlock(OctNode tree, Ray ray, double maxt) { OctNode current = tree.FindTreeNode(ray.GetOrigin()); IntersectPt test = new IntersectPt(); Point testpt = new Point(); while (current != null) { ObjNode currentnode = current.GetList(); while (currentnode != null) { bool found = false; if (currentnode.GetObj().GetCachePt().GetID() == ray.GetID()) { found = true; } if (!found) { test.SetOrigID(0); if (currentnode.GetObj().Intersect(ray, test)) { if (test.GetT() < maxt) { return(true); } } } currentnode = currentnode.Next(); } OctNode adjacent = current.Intersect(ray, testpt, test.GetThreshold()); if (adjacent == null) { current = null; } else { current = adjacent.FindTreeNode(testpt); } } return(false); }
/** * CreateTree * * @param objects * @param numObjects */ private void CreateTree(ObjNode objects, int numObjects) { if (objects != null) { if (numObjects > MaxObj) { CreateChildren(objects, 1); } else { ObjNode currentObj = objects; while (currentObj != null) { ObjNode newnode = new ObjNode(currentObj.GetObj(), ObjList); ObjList = newnode; currentObj = currentObj.Next(); } NumObj = numObjects; } } }
private static List <UINode> GetUINode(List <ObjNode> objList, List <TransformNode> transList) { if (transList.Count > 0 && objList.Count > 0 && transList.Count == objList.Count) { //将objNode和对应的transformNode 组合成uinode List <UINode> nodeList = new List <UINode>(); for (int i = 0; i < objList.Count; i++) { ObjNode objNode = objList[i]; string transformGuid = objNode.TransformGuid; TransformNode transNode = transList.Find(p => { return(p.Guid.Equals(transformGuid)); }); if (null != transNode) { nodeList.Add(new UINode() { ObjNode = objNode, TransNode = transNode, ParentNode = null }); } } //设置每个uinode的父级节点 for (int i = 0; i < nodeList.Count; i++) { UINode node = nodeList[i]; string parentGuid = node.TransNode.ParentGuid; if (!string.IsNullOrEmpty(parentGuid)) { UINode parentNode = nodeList.Find(p => { return(p.ObjNode.TransformGuid.Equals(parentGuid)); }); if (null != parentNode) { node.ParentNode = parentNode; } } } return(nodeList); } return(null); }
/// <summary> /// 解析GameObject yaml /// </summary> /// <param name="str"></param> private static ObjNode PraseStrToObjNode(string[] prefabStrs) { if (null == prefabStrs || prefabStrs.Length < 2) { return(null); } ObjNode node = new ObjNode(); node.Guid = ParaseGuid(prefabStrs[0]); List <string> componetList = new List <string>(); string nodeName = string.Empty; for (int i = 2; i < prefabStrs.Length; i++) { string pstr = prefabStrs[i]; if (pstr.IndexOf("- component") >= 0) { string[] comStrs = pstr.Split(':'); if (comStrs.Length >= 3) { string guid = comStrs[2].Replace("}", "").Trim(); componetList.Add(guid); } } else if (pstr.IndexOf("m_Name") >= 0) { string[] nameStrs = pstr.Split(':'); nodeName = nameStrs[1].Trim(); } } node.Name = nodeName; node.ComponetsGuid = componetList; if (componetList.Count > 0) { node.TransformGuid = componetList[0]; } return(node); }
/** * ReadPoly * * @param infile * @param ObjID * @return int */ private int ReadPoly (int ObjID) { String temp; double[] input = new double[3]; int i, j, k; int numpolys = 0; int numverts; bool trimesh, vertnormal; Point max = new Point (MaxX, MaxY, MaxZ); Point min = new Point (MinX, MinY, MinZ); temp = readString (); temp = readString (); Material theMaterial = ReadMaterial (); temp = readString (); if (temp.Substring (7).Equals ("POLYSET_TRI_MESH")) { trimesh = true; } else { trimesh = false; } temp = readString (); if (temp.Substring (11).Equals ("PER_VERTEX_NORMAL")) { vertnormal = true; } else { vertnormal = false; } for (i = 0; i < 4; i++) { temp = readString (); } temp = temp.Substring (11); numpolys = Int32.Parse (temp); ObjID++; for (i = 0; i < numpolys; i++) { temp = readString (); temp = readString (); temp = temp.Substring (16); numverts = Int32.Parse (temp); Point[] vertices = new Point[numverts]; for (j = 0; j < numverts; j++) { temp = readString (); temp = temp.Substring (8); for (k = 0; k < 2; k++) { input [k] = (double)Double.Parse (temp.Substring (0, temp.IndexOf (' '))); temp = temp.Substring (temp.IndexOf (' ') + 1); } input [2] = (double)Double.Parse (temp); vertices [j] = new Point (input [0], input [1], input [2]); if (vertnormal) { temp = readString (); } } temp = readString (); TriangleObj newtriangle; PolygonObj newpoly; ObjNode newnode; if (trimesh) { newtriangle = new TriangleObj (theMaterial, ObjID, numverts, vertices, max, min); newnode = new ObjNode (newtriangle, objects); } else { newpoly = new PolygonObj (theMaterial, ObjID, numverts, vertices, max, min); newnode = new ObjNode (newpoly, objects); } objects = newnode; } temp = readString (); MaxX = max.GetX (); MaxY = max.GetY (); MaxZ = max.GetZ (); MinX = min.GetX (); MinY = min.GetY (); MinZ = min.GetZ (); return (numpolys); }
/** * ReadSphere * * @param infile * @param ObjID * @return int */ private int ReadSphere (int ObjID) { String temp; double[] input = new double[3]; int i; double radius; Point max = new Point (MaxX, MaxY, MaxZ); Point min = new Point (MinX, MinY, MinZ); temp = readString (); temp = readString (); Material theMaterial = ReadMaterial (); temp = readString (); temp = temp.Substring (9); for (i = 0; i < 2; i++) { input [i] = (double)Double.Parse (temp.Substring (0, temp.IndexOf (' '))); temp = temp.Substring (temp.IndexOf (' ') + 1); } input [2] = (double)Double.Parse (temp); Point origin = new Point (input [0], input [1], input [2]); temp = readString (); temp = temp.Substring (9); radius = (double)Double.Parse (temp); for (i = 0; i < 7; i++) { temp = readString (); } SphereObj newsphere = new SphereObj (theMaterial, ++ObjID, origin, radius, max, min); ObjNode newnode = new ObjNode (newsphere, objects); objects = newnode; MaxX = max.GetX (); MaxY = max.GetY (); MaxZ = max.GetZ (); MinX = min.GetX (); MinY = min.GetY (); MinZ = min.GetZ (); return (1); }
// Sets the value of the current object control protected void SetObjectValue() { ArrayList nodes = ObjectTreeNode.GetNodesOfType(_type); ComboBox cb = (ComboBox)_valueControl; // Get rid of the nodes that refer to duplicate or null // objects; for duplicates, choose the node with the // shortest path ArrayList objects = new ArrayList(); for (int i = 0; i < nodes.Count; ) { ObjectTreeNode node = (ObjectTreeNode)nodes[i]; Object obj = node.ObjectInfo.Obj; if (obj == null) { // The remaining nodes move up, so we // don't increment the index nodes.Remove(node); continue; } ObjNode objNode = new ObjNode(obj, node); ObjNode objNodeFound = (ObjNode)Utils.FindHack(objects, objNode); if (objNodeFound == null) { objects.Add(objNode); i++; } else { // See if this node is better than the one // previously found, nodes move up in both // cases so don't increment index if (objNode._pathCount < objNodeFound._pathCount) { nodes.Remove(objNodeFound._node); objects.Remove(objNodeFound); objects.Add(objNode); } else { nodes.Remove(node); } } } // Now measure all of the remaining nodes to figure // out how big to make the combo box Graphics g = cb.CreateGraphics(); int maxWidth = 0; foreach (TreeNode node in nodes) { TraceUtil.WriteLineVerbose(null, "SetObjectValue looking node: " + ((BrowserTreeNode)node).GetName()); int width = (int)g.MeasureString(node.ToString(), cb.Font).Width; if (width > maxWidth) maxWidth = width; } g.Dispose(); // The first value is "null" to allow the object to // be set to null // Second is Missing.Value to allow it to be optional _values.Clear(); _values.Add(null); _values.Add(Missing.Value); _values.AddRange(nodes); if (maxWidth > cb.Width) cb.DropDownWidth = maxWidth; cb.Items.Clear(); cb.Items.Add("null"); cb.Items.Add("Missing.Value"); cb.Items.AddRange(nodes.ToArray()); if (_valueControl2 != null) ((TextBox)_valueControl2).Text = ""; // Select the object if it exists if (_value != null) { bool found = false; foreach (ObjectTreeNode node in nodes) { if (_value == node.ObjectInfo.Obj) { cb.SelectedItem = node; found = true; // Enable the combo box cb.Enabled = true; if (_valueControl2 != null) _valueControl2.Enabled = false; break; } } // Just set the text box to be the string value of whatever // this is if (!found) { if (_valueControl2 != null) { cb.Enabled = false; _valueControl2.Enabled = true; ((TextBox)_valueControl2).Text = _value.ToString(); } } } else { // Make the default for optional parameters missing // so nothing has to be done to specify them if (_optional) { cb.Enabled = true; if (_valueControl2 != null) _valueControl2.Enabled = false; cb.SelectedIndex = OBJECT_MISSING; } else { if (_valueControl2 != null) { // Enable text cb.Enabled = false; _valueControl2.Enabled = true; } cb.SelectedIndex = OBJECT_NULL; } } }
/** * ReadPoly * * @param infile * @param ObjID * @return int */ private int ReadPoly(int ObjID) { String temp; double[] input = new double[3]; int i, j, k; int numpolys = 0; int numverts; bool trimesh, vertnormal; Point max = new Point(MaxX, MaxY, MaxZ); Point min = new Point(MinX, MinY, MinZ); temp = readString(); temp = readString(); Material theMaterial = ReadMaterial(); temp = readString(); if (temp.Substring(7).Equals("POLYSET_TRI_MESH")) { trimesh = true; } else { trimesh = false; } temp = readString(); if (temp.Substring(11).Equals("PER_VERTEX_NORMAL")) { vertnormal = true; } else { vertnormal = false; } for (i = 0; i < 4; i++) { temp = readString(); } temp = temp.Substring(11); numpolys = Int32.Parse(temp); ObjID++; for (i = 0; i < numpolys; i++) { temp = readString(); temp = readString(); temp = temp.Substring(16); numverts = Int32.Parse(temp); Point[] vertices = new Point[numverts]; for (j = 0; j < numverts; j++) { temp = readString(); temp = temp.Substring(8); for (k = 0; k < 2; k++) { input[k] = (double)Double.Parse(temp.Substring(0, temp.IndexOf(' '))); temp = temp.Substring(temp.IndexOf(' ') + 1); } input[2] = (double)Double.Parse(temp); vertices[j] = new Point(input[0], input[1], input[2]); if (vertnormal) { temp = readString(); } } temp = readString(); TriangleObj newtriangle; PolygonObj newpoly; ObjNode newnode; if (trimesh) { newtriangle = new TriangleObj(theMaterial, ObjID, numverts, vertices, max, min); newnode = new ObjNode(newtriangle, objects); } else { newpoly = new PolygonObj(theMaterial, ObjID, numverts, vertices, max, min); newnode = new ObjNode(newpoly, objects); } objects = newnode; } temp = readString(); MaxX = max.GetX(); MaxY = max.GetY(); MaxZ = max.GetZ(); MinX = min.GetX(); MinY = min.GetY(); MinZ = min.GetZ(); return(numpolys); }
/** * SetList * * @param newlist */ public void SetList(ObjNode newlist) { ObjList = newlist; }
/** * CreateTree * * @param objects * @param numObjects */ private void CreateTree(ObjNode objects, int numObjects) { if(objects != null) { if(numObjects > MaxObj) { CreateChildren(objects, 1); } else { ObjNode currentObj = objects; while(currentObj != null) { ObjNode newnode = new ObjNode(currentObj.GetObj(), ObjList); ObjList = newnode; currentObj = currentObj.Next(); } NumObj = numObjects; } } }
/** * CreateChildren * * @param objects * @param depth */ private void CreateChildren(ObjNode objects, int depth) { double maxX = OctFaces[MAXX].GetVert(0).GetX(); double minX = OctFaces[MINX].GetVert(0).GetX(); double maxY = OctFaces[MAXY].GetVert(0).GetY(); double minY = OctFaces[MINY].GetVert(0).GetY(); double maxZ = OctFaces[MAXZ].GetVert(0).GetZ(); double minZ = OctFaces[MINZ].GetVert(0).GetZ(); Point midpt = new Point((maxX + minX) / 2.0f, (maxY + minY) / 2.0f, (maxZ + minZ) / 2.0f); Point max = new Point(); Point min = new Point(); ObjNode currentnode; int i; max.Set(maxX, maxY, maxZ); min.Set(midpt.GetX(), midpt.GetY(), midpt.GetZ()); Child[0] = new OctNode(max, min); max.Set(maxX, midpt.GetY(), maxZ); min.Set(midpt.GetX(), minY, midpt.GetZ()); Child[1] = new OctNode(max, min); max.Set(maxX, midpt.GetY(), midpt.GetZ()); min.Set(midpt.GetX(), minY, minZ); Child[2] = new OctNode(max, min); max.Set(maxX, maxY, midpt.GetZ()); min.Set(midpt.GetX(), midpt.GetY(), minZ); Child[3] = new OctNode(max, min); max.Set(midpt.GetX(), maxY, maxZ); min.Set(minX, midpt.GetY(), midpt.GetZ()); Child[4] = new OctNode(max, min); max.Set(midpt.GetX(), midpt.GetY(), maxZ); min.Set(minX, minY, midpt.GetZ()); Child[5] = new OctNode(max, min); max.Set(midpt.GetX(), midpt.GetY(), midpt.GetZ()); min.Set(minX, minY, minZ); Child[6] = new OctNode(max, min); max.Set(midpt.GetX(), maxY, midpt.GetZ()); min.Set(minX, midpt.GetY(), minZ); Child[7] = new OctNode(max, min); OctNode[] adj = this.Adjacent; OctNode[] chld = this.Child; OctNode adj0 = adj[0]; OctNode adj1 = adj[1]; OctNode adj2 = adj[2]; OctNode adj3 = adj[3]; OctNode adj4 = adj[4]; OctNode adj5 = adj[5]; OctNode chld0 = chld[0]; OctNode chld1 = chld[1]; OctNode chld2 = chld[2]; OctNode chld3 = chld[3]; OctNode chld4 = chld[4]; OctNode chld5 = chld[5]; OctNode chld6 = chld[6]; OctNode chld7 = chld[7]; Child[0].FormAdjacent(adj0, adj1, adj2, chld4, chld1, chld3); Child[1].FormAdjacent(adj0, chld0, adj2, chld5, adj4, chld2); Child[2].FormAdjacent(adj0, chld3, chld1, chld6, adj4, adj5); Child[3].FormAdjacent(adj0, adj1, chld0, chld7, chld2, adj5); Child[4].FormAdjacent(chld0, adj1, adj2, adj3, chld5, chld7); Child[5].FormAdjacent(chld1, chld4, adj2, adj3, adj4, chld6); Child[6].FormAdjacent(chld2, chld7, chld5, adj3, adj4, adj5); Child[7].FormAdjacent(chld3, adj1, chld4, adj3, chld6, adj5); if(objects != null) { currentnode = objects; } else { currentnode = ObjList; } while(currentnode != null) { ObjectType currentobj = currentnode.GetObj(); for(i = 0; i < 8; i++) { OctNode cc = chld[i]; max = cc.GetFace(0).GetVert(0); min = cc.GetFace(5).GetVert(3); if(!((currentobj.GetMin().GetX() > max.GetX()) || (currentobj.GetMax().GetX() < min.GetX()))) { if(!((currentobj.GetMin().GetY() > max.GetY()) || (currentobj.GetMax().GetY() < min.GetY()))) { if(!((currentobj.GetMin().GetZ() > max.GetZ()) || (currentobj.GetMax().GetZ() < min.GetZ()))) { ObjNode newnode = new ObjNode(currentobj, Child[i].GetList()); cc.SetList(newnode); cc.IncNumObj(); } } } } currentnode = currentnode.Next(); } if(objects == null) { NumObj = 0; ObjList = null; } if(depth < MaxDepth) { for(i = 0; i < 8; i++) { if(Child[i].GetNumObj() > MaxObj) { Child[i].CreateChildren(null, depth + 1); } } } }
/** * Copy * * @param original */ public void Copy(OctNode original) { int i; for(i = 0; i < 6; i++) { Adjacent[i] = original.GetAdjacent(i); OctFaces[i] = original.GetFace(i); } for(i = 0; i < 8; i++) { Child[i] = original.GetChild(i); } ObjList = original.GetList(); NumObj = original.GetNumObj(); }
/** * LoadSceneOrig * * @param filename * @return int */ private int LoadSceneOrig () { String instr = Constants.INPUT; char[] spt = new char[1]; spt [0] = '\n'; sceneLines = instr.Split (spt); MainCL.logger.InfoFormat ("number of lines: {0}", sceneLines.Length); scenePos = 0; int numObj = 0, ObjID = 0; camera = null; lights = null; objects = null; materials = null; MaxX = MinX = MaxY = MinY = MaxZ = MinZ = 0.0f; String input; input = readString (); while (input != null) { if (input.Equals ("camera {")) { ReadCamera (); } else if (input.Equals ("point_light {")) { ReadLight (); } else if (input.Equals ("sphere {")) { numObj += ReadSphere (ObjID); } else if (input.Equals ("poly_set {")) { numObj += ReadPoly (ObjID); } else { ; } input = readString (); } return (numObj); }
/** * SetList * * @param newlist */ public void SetList(ObjNode newlist) { ObjList = newlist; }
public ObjectManager(GraphicsDevice GraphDev, TextureAtlas TileAtlas, string strXMLFile, string strXMLRoot = "/objects") { XmlDocument ObjXML; XmlNodeList ObjList, VertList; sObjectInfo_t NewDef; Vector2 vNewVert; //Prepare all class variables cObjDefsList = new Dictionary <string, sObjectInfo_t>(); cObjGroups = new Dictionary <int, List <PhysicalObject> >(); cGraphDev = GraphDev; cImageAtlas = TileAtlas; //Load object definitions from XML file try { ObjXML = new XmlDocument(); ObjXML.Load(strXMLFile); } catch (Exception ExErr) { throw new Exception(String.Format("Failed to load XML File {1}{0}Exception {2}{0}Message {3}", Environment.NewLine, strXMLFile, ExErr.GetType().ToString(), ExErr.Message)); } ObjList = ObjXML.DocumentElement.SelectNodes(strXMLRoot + "/object"); foreach (XmlNode ObjNode in ObjList) { NewDef = new sObjectInfo_t(); NewDef.avVertexes = new List <Vector2>(); //Read all attribute values if (ObjNode.Attributes["name"] != null) { NewDef.strObjName = ObjNode.Attributes["name"].InnerText; } else { throw new Exception("Found object tag with no name attribute in file " + strXMLFile); } if (ObjNode.Attributes["subtexturename"] != null) { NewDef.strTextureName = ObjNode.Attributes["subtexturename"].InnerText; } else { throw new Exception(String.Format("Found object tag named '{0}' with no subtexturename attribute in file {1}", NewDef.strObjName, strXMLFile)); } if (ObjNode.Attributes["texturerotation"] != null) { if (float.TryParse(ObjNode.Attributes["texturerotation"].InnerText, out NewDef.nTextureRotate) == false) { throw new Exception(String.Format("Inside object tag named {0} attribute 'texturerotation' had invalid format: {1}{2}In file {3}", NewDef.strObjName, ObjNode.Attributes["texturerotation"].InnerText, Environment.NewLine, strXMLFile)); } if (Math.Abs(NewDef.nTextureRotate) > 2 * Math.PI) //Angle is kinda big, user probably entered degrees { NewDef.nTextureRotate *= (float)(Math.PI / 180); } } if (ObjNode.Attributes["width"] != null) { if (Int32.TryParse(ObjNode.Attributes["width"].InnerText, out NewDef.nWidth) == false) { throw new Exception(String.Format("Inside object tag named {0} attribute 'width' had invalid format: {1}{2}In file {3}", NewDef.strObjName, ObjNode.Attributes["width"].InnerText, Environment.NewLine, strXMLFile)); } } if (ObjNode.Attributes["height"] != null) { if (Int32.TryParse(ObjNode.Attributes["height"].InnerText, out NewDef.nHeight) == false) { throw new Exception(String.Format("Inside object tag named {0} attribute 'height' had invalid format: {1}{2}In file {3}", NewDef.strObjName, ObjNode.Attributes["height"].InnerText, Environment.NewLine, strXMLFile)); } } //Read all child node values VertList = ObjNode.SelectNodes("vertex"); foreach (XmlNode VertNode in VertList) { vNewVert = new Vector2(0, 0); if (VertNode.Attributes["x"] != null) { if (float.TryParse(VertNode.Attributes["x"].InnerText, out vNewVert.X) == false) { throw new Exception(String.Format("Inside object tag named {0} vertex tag attribute 'x' had invalid format: {1}{2}In file {3}", NewDef.strObjName, VertNode.Attributes["x"].InnerText, Environment.NewLine, strXMLFile)); } } if (VertNode.Attributes["y"] != null) { if (float.TryParse(VertNode.Attributes["y"].InnerText, out vNewVert.Y) == false) { throw new Exception(String.Format("Inside object tag named {0} vertex tag attribute 'y' had invalid format: {1}{2}In file {3}", NewDef.strObjName, VertNode.Attributes["y"].InnerText, Environment.NewLine, strXMLFile)); } } NewDef.avVertexes.Add(vNewVert); } //Object definition loaded, add it to the list cObjDefsList.Add(NewDef.strObjName, NewDef); } return; }
/** * CreateChildren * * @param objects * @param depth */ private void CreateChildren(ObjNode objects, int depth) { double maxX = OctFaces [MAXX].GetVert(0).GetX(); double minX = OctFaces [MINX].GetVert(0).GetX(); double maxY = OctFaces [MAXY].GetVert(0).GetY(); double minY = OctFaces [MINY].GetVert(0).GetY(); double maxZ = OctFaces [MAXZ].GetVert(0).GetZ(); double minZ = OctFaces [MINZ].GetVert(0).GetZ(); Point midpt = new Point((maxX + minX) / 2.0f, (maxY + minY) / 2.0f, (maxZ + minZ) / 2.0f); Point max = new Point(); Point min = new Point(); ObjNode currentnode; int i; max.Set(maxX, maxY, maxZ); min.Set(midpt.GetX(), midpt.GetY(), midpt.GetZ()); Child [0] = new OctNode(max, min); max.Set(maxX, midpt.GetY(), maxZ); min.Set(midpt.GetX(), minY, midpt.GetZ()); Child [1] = new OctNode(max, min); max.Set(maxX, midpt.GetY(), midpt.GetZ()); min.Set(midpt.GetX(), minY, minZ); Child [2] = new OctNode(max, min); max.Set(maxX, maxY, midpt.GetZ()); min.Set(midpt.GetX(), midpt.GetY(), minZ); Child [3] = new OctNode(max, min); max.Set(midpt.GetX(), maxY, maxZ); min.Set(minX, midpt.GetY(), midpt.GetZ()); Child [4] = new OctNode(max, min); max.Set(midpt.GetX(), midpt.GetY(), maxZ); min.Set(minX, minY, midpt.GetZ()); Child [5] = new OctNode(max, min); max.Set(midpt.GetX(), midpt.GetY(), midpt.GetZ()); min.Set(minX, minY, minZ); Child [6] = new OctNode(max, min); max.Set(midpt.GetX(), maxY, midpt.GetZ()); min.Set(minX, midpt.GetY(), minZ); Child [7] = new OctNode(max, min); OctNode[] adj = this.Adjacent; OctNode[] chld = this.Child; OctNode adj0 = adj [0]; OctNode adj1 = adj [1]; OctNode adj2 = adj [2]; OctNode adj3 = adj [3]; OctNode adj4 = adj [4]; OctNode adj5 = adj [5]; OctNode chld0 = chld [0]; OctNode chld1 = chld [1]; OctNode chld2 = chld [2]; OctNode chld3 = chld [3]; OctNode chld4 = chld [4]; OctNode chld5 = chld [5]; OctNode chld6 = chld [6]; OctNode chld7 = chld [7]; Child [0].FormAdjacent(adj0, adj1, adj2, chld4, chld1, chld3); Child [1].FormAdjacent(adj0, chld0, adj2, chld5, adj4, chld2); Child [2].FormAdjacent(adj0, chld3, chld1, chld6, adj4, adj5); Child [3].FormAdjacent(adj0, adj1, chld0, chld7, chld2, adj5); Child [4].FormAdjacent(chld0, adj1, adj2, adj3, chld5, chld7); Child [5].FormAdjacent(chld1, chld4, adj2, adj3, adj4, chld6); Child [6].FormAdjacent(chld2, chld7, chld5, adj3, adj4, adj5); Child [7].FormAdjacent(chld3, adj1, chld4, adj3, chld6, adj5); if (objects != null) { currentnode = objects; } else { currentnode = ObjList; } while (currentnode != null) { ObjectType currentobj = currentnode.GetObj(); for (i = 0; i < 8; i++) { OctNode cc = chld [i]; max = cc.GetFace(0).GetVert(0); min = cc.GetFace(5).GetVert(3); if (!((currentobj.GetMin().GetX() > max.GetX()) || (currentobj.GetMax().GetX() < min.GetX()))) { if (!((currentobj.GetMin().GetY() > max.GetY()) || (currentobj.GetMax().GetY() < min.GetY()))) { if (!((currentobj.GetMin().GetZ() > max.GetZ()) || (currentobj.GetMax().GetZ() < min.GetZ()))) { ObjNode newnode = new ObjNode(currentobj, Child [i].GetList()); cc.SetList(newnode); cc.IncNumObj(); } } } } currentnode = currentnode.Next(); } if (objects == null) { NumObj = 0; ObjList = null; } if (depth < MaxDepth) { for (i = 0; i < 8; i++) { if (Child [i].GetNumObj() > MaxObj) { Child [i].CreateChildren(null, depth + 1); } } } }
// Sets the value of the current object control protected void SetObjectValue() { ArrayList nodes = ObjectTreeNode.GetNodesOfType(_type); ComboBox cb = (ComboBox)_valueControl; // Get rid of the nodes that refer to duplicate or null // objects; for duplicates, choose the node with the // shortest path ArrayList objects = new ArrayList(); for (int i = 0; i < nodes.Count;) { ObjectTreeNode node = (ObjectTreeNode)nodes[i]; Object obj = node.ObjectInfo.Obj; if (obj == null) { // The remaining nodes move up, so we // don't increment the index nodes.Remove(node); continue; } ObjNode objNode = new ObjNode(obj, node); ObjNode objNodeFound = (ObjNode)Utils.FindHack(objects, objNode); if (objNodeFound == null) { objects.Add(objNode); i++; } else { // See if this node is better than the one // previously found, nodes move up in both // cases so don't increment index if (objNode._pathCount < objNodeFound._pathCount) { nodes.Remove(objNodeFound._node); objects.Remove(objNodeFound); objects.Add(objNode); } else { nodes.Remove(node); } } } // Now measure all of the remaining nodes to figure // out how big to make the combo box Graphics g = cb.CreateGraphics(); int maxWidth = 0; foreach (TreeNode node in nodes) { TraceUtil.WriteLineVerbose(null, "SetObjectValue looking node: " + ((BrowserTreeNode)node).GetName()); int width = (int)g.MeasureString(node.ToString(), cb.Font).Width; if (width > maxWidth) { maxWidth = width; } } g.Dispose(); // The first value is "null" to allow the object to // be set to null // Second is Missing.Value to allow it to be optional _values.Clear(); _values.Add(null); _values.Add(Missing.Value); _values.AddRange(nodes); if (maxWidth > cb.Width) { cb.DropDownWidth = maxWidth; } cb.Items.Clear(); cb.Items.Add("null"); cb.Items.Add("Missing.Value"); cb.Items.AddRange(nodes.ToArray()); if (_valueControl2 != null) { ((TextBox)_valueControl2).Text = ""; } // Select the object if it exists if (_value != null) { bool found = false; foreach (ObjectTreeNode node in nodes) { if (_value == node.ObjectInfo.Obj) { cb.SelectedItem = node; found = true; // Enable the combo box cb.Enabled = true; if (_valueControl2 != null) { _valueControl2.Enabled = false; } break; } } // Just set the text box to be the string value of whatever // this is if (!found) { if (_valueControl2 != null) { cb.Enabled = false; _valueControl2.Enabled = true; ((TextBox)_valueControl2).Text = _value.ToString(); } } } else { // Make the default for optional parameters missing // so nothing has to be done to specify them if (_optional) { cb.Enabled = true; if (_valueControl2 != null) { _valueControl2.Enabled = false; } cb.SelectedIndex = OBJECT_MISSING; } else { if (_valueControl2 != null) { // Enable text cb.Enabled = false; _valueControl2.Enabled = true; } cb.SelectedIndex = OBJECT_NULL; } } }
/** * LoadSceneOrig * * @param filename * @return int */ private int LoadSceneOrig(String filename) { sceneLines = File.ReadAllLines(filename); scenePos = 0; int numObj = 0, ObjID = 0; camera = null; lights = null; objects = null; materials = null; MaxX = MinX = MaxY = MinY = MaxZ = MinZ = 0.0f; String input; input = readString(); while(input != null) { if(input.Equals("camera {")) { ReadCamera(); } else if(input.Equals("point_light {")) { ReadLight(); } else if(input.Equals("sphere {")) { numObj += ReadSphere(ObjID); } else if(input.Equals("poly_set {")) { numObj += ReadPoly(ObjID); } else { ;} input = readString(); } return (numObj); }