예제 #1
0
        private void bTarget_Click(object sender, EventArgs e)
        {
            ItemDialog itemDialog;

            OgreSceneImporter.NodeType nodeType = OgreSceneImporter.NodeType.PART;
            foreach (TreeNode node in this.tree.Nodes)
            {
                if (!node.Checked)
                {
                    continue;
                }
                nodeType = this.getNodeType(node.Tag as OgreSceneImporter.Node);
                goto Label0;
            }
Label0:
            switch (nodeType)
            {
            case OgreSceneImporter.NodeType.PART:
            {
                itemDialog = new ItemDialog("Parts", this.nav.ou.gameData, itemType.BUILDING_PART, false, "", itemType.NULL_ITEM);
                break;
            }

            case OgreSceneImporter.NodeType.LIGHT:
            {
                itemDialog = new ItemDialog("Lights", this.nav.ou.gameData, itemType.LIGHT, false, "", itemType.NULL_ITEM);
                break;
            }

            case OgreSceneImporter.NodeType.EFFECT:
            {
                itemDialog = new ItemDialog("Effects", this.nav.ou.gameData, itemType.EFFECT, false, "", itemType.NULL_ITEM);
                break;
            }

            case OgreSceneImporter.NodeType.NODE:
            {
                itemDialog = new ItemDialog("Nodes", this.nav.ou.gameData, itemType.BUILDING, false, "is node=true", itemType.NULL_ITEM);
                break;
            }

            default:
            {
                return;
            }
            }
            if (itemDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach (TreeNode str in this.tree.Nodes)
                {
                    if (!str.Checked || (!(str.Tag is OgreSceneImporter.Light) || nodeType != OgreSceneImporter.NodeType.LIGHT) && (!(str.Tag is OgreSceneImporter.Entity) || nodeType != OgreSceneImporter.NodeType.PART) && (!(str.Tag is OgreSceneImporter.Node) || nodeType != OgreSceneImporter.NodeType.EFFECT && nodeType != OgreSceneImporter.NodeType.NODE))
                    {
                        continue;
                    }
                    OgreSceneImporter.Node tag = (OgreSceneImporter.Node)str.Tag;
                    tag.target = itemDialog.Items[0];
                    str.Text   = tag.ToString();
                }
            }
        }
예제 #2
0
        private void multiplyQuaternion(OgreSceneImporter.Node q, float x, float y, float z, float w)
        {
            float single  = q.qw * w - q.qx * x - q.qy * y - q.qz * z;
            float single1 = q.qw * x + q.qx * w + q.qy * z - q.qz * y;
            float single2 = q.qw * y + q.qy * w + q.qz * x - q.qx * z;
            float single3 = q.qw * z + q.qz * w + q.qx * y - q.qy * x;

            q.qw = single;
            q.qx = single1;
            q.qy = single2;
            q.qz = single3;
        }
예제 #3
0
 private OgreSceneImporter.NodeType getNodeType(OgreSceneImporter.Node n)
 {
     if (n is OgreSceneImporter.Light)
     {
         return(OgreSceneImporter.NodeType.LIGHT);
     }
     if (n is OgreSceneImporter.Entity)
     {
         return(OgreSceneImporter.NodeType.PART);
     }
     if (n != null && n.name.ToLower().Contains("particle"))
     {
         return(OgreSceneImporter.NodeType.EFFECT);
     }
     return(OgreSceneImporter.NodeType.NODE);
 }
예제 #4
0
        private void tree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            ItemDialog itemDialog;

            OgreSceneImporter.Node tag = (OgreSceneImporter.Node)e.Node.Tag;
            switch (this.getNodeType(tag))
            {
            case OgreSceneImporter.NodeType.PART:
            {
                itemDialog = new ItemDialog("Parts", this.nav.ou.gameData, itemType.BUILDING_PART, false, "", itemType.NULL_ITEM);
                break;
            }

            case OgreSceneImporter.NodeType.LIGHT:
            {
                itemDialog = new ItemDialog("Lights", this.nav.ou.gameData, itemType.LIGHT, false, "", itemType.NULL_ITEM);
                break;
            }

            case OgreSceneImporter.NodeType.EFFECT:
            {
                itemDialog = new ItemDialog("Effects", this.nav.ou.gameData, itemType.EFFECT, false, "", itemType.NULL_ITEM);
                break;
            }

            case OgreSceneImporter.NodeType.NODE:
            {
                itemDialog = new ItemDialog("Nodes", this.nav.ou.gameData, itemType.BUILDING, false, "is node=true", itemType.NULL_ITEM);
                break;
            }

            default:
            {
                return;
            }
            }
            if (itemDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                tag.target  = itemDialog.Items[0];
                e.Node.Text = tag.ToString();
            }
        }
예제 #5
0
 private void parseNode(OgreSceneImporter.Node n, XmlElement e)
 {
     n.name = e.GetAttribute("name");
     foreach (XmlElement childNode in e.ChildNodes)
     {
         if (childNode.Name != "position")
         {
             if (childNode.Name != "rotation")
             {
                 continue;
             }
             float.TryParse(childNode.GetAttribute("qx"), out n.qx);
             float.TryParse(childNode.GetAttribute("qy"), out n.qy);
             float.TryParse(childNode.GetAttribute("qz"), out n.qz);
             float.TryParse(childNode.GetAttribute("qw"), out n.qw);
         }
         else
         {
             float.TryParse(childNode.GetAttribute("x"), out n.x);
             float.TryParse(childNode.GetAttribute("y"), out n.y);
             float.TryParse(childNode.GetAttribute("z"), out n.z);
         }
     }
 }
예제 #6
0
        public bool loadScene(string filename)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(filename);
            XmlElement documentElement = xmlDocument.DocumentElement;

            this.tree.Nodes.Clear();
            XmlElement xmlElement = null;

            foreach (XmlElement childNode in documentElement.ChildNodes)
            {
                if (childNode.Name != "nodes")
                {
                    continue;
                }
                xmlElement = childNode;
                goto Label0;
            }
Label0:
            if (xmlElement == null)
            {
                MessageBox.Show("场景为空", "Ogre场景导入器", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(true);
            }
            foreach (XmlElement xmlElement1 in xmlElement)
            {
                if (xmlElement1.Name != "node")
                {
                    continue;
                }
                XmlNodeList elementsByTagName = xmlElement1.GetElementsByTagName("entity");
                XmlNodeList xmlNodeLists      = xmlElement1.GetElementsByTagName("light");
                foreach (XmlElement xmlElement2 in elementsByTagName)
                {
                    OgreSceneImporter.Entity entity = new OgreSceneImporter.Entity();
                    this.parseNode(entity, xmlElement1);
                    entity.mesh = xmlElement2.GetAttribute("meshFile");
                    this.tree.Nodes.Add(string.Concat(new string[] { "ENTITY ", entity.name, " [", entity.mesh, "]" })).Tag = entity;
                }
                foreach (XmlElement xmlElement3 in xmlNodeLists)
                {
                    OgreSceneImporter.Light light = new OgreSceneImporter.Light();
                    this.parseNode(light, xmlElement1);
                    if (xmlElement3.GetAttribute("type") != "spot")
                    {
                        light.mode = head.LightType.POINT;
                    }
                    else
                    {
                        light.mode = head.LightType.SPOT;
                    }
                    light.shadows = xmlElement3.GetAttribute("castShadows") == "true";
                    float.TryParse(xmlElement3.GetAttribute("power"), out light.power);
                    foreach (XmlElement childNode1 in xmlElement3.ChildNodes)
                    {
                        if (childNode1.Name == "colourDiffuse")
                        {
                            light.diffuse = this.parseColour(childNode1);
                        }
                        else if (childNode1.Name == "colourSpecular")
                        {
                            light.specular = this.parseColour(childNode1);
                        }
                        else if (childNode1.Name != "lightAttenuation")
                        {
                            if (childNode1.Name != "lightRange")
                            {
                                continue;
                            }
                            float.TryParse(childNode1.GetAttribute("inner"), out light.inner);
                            float.TryParse(childNode1.GetAttribute("outer"), out light.outer);
                            float.TryParse(childNode1.GetAttribute("falloff"), out light.falloff);
                            if (light.falloff > 0f)
                            {
                                continue;
                            }
                            light.falloff = 1f;
                        }
                        else
                        {
                            float.TryParse(childNode1.GetAttribute("range"), out light.radius);
                        }
                    }
                    this.tree.Nodes.Add(string.Concat(light.mode.ToString(), "LIGHT ", light.name)).Tag = light;
                }
                if (elementsByTagName.Count != 0 || xmlNodeLists.Count != 0)
                {
                    continue;
                }
                OgreSceneImporter.Node node = new OgreSceneImporter.Node();
                this.parseNode(node, xmlElement1);
                this.multiplyQuaternion(node, 0f, -0.707107f, 0f, 0.707107f);
                string str = (this.getNodeType(node) == OgreSceneImporter.NodeType.EFFECT ? "EFFECT" : "NODE");
                this.tree.Nodes.Add(string.Concat(str, " ", node.name)).Tag = node;
            }
            foreach (object obj in this.tree.Nodes)
            {
                ((TreeNode)obj).Checked = true;
            }
            return(true);
        }