Ejemplo n.º 1
0
        private void bImport_Click(object sender, EventArgs e)
        {
            GameData.Item          file;
            OgreSceneImporter.Node tag;
            GameData gameDatum = this.nav.ou.gameData;

            foreach (TreeNode node in this.tree.Nodes)
            {
                if (!node.Checked)
                {
                    continue;
                }
                if (((OgreSceneImporter.Node)node.Tag).target == null)
                {
                    switch (this.getNodeType((OgreSceneImporter.Node)node.Tag))
                    {
                    case OgreSceneImporter.NodeType.PART:
                    {
                        OgreSceneImporter.Entity entity = node.Tag as OgreSceneImporter.Entity;
                        file = gameDatum.createItem(itemType.BUILDING_PART);
                        file["phs or mesh"] = new GameData.File(string.Concat(this.Path, entity.mesh));
                        int?nullable  = null;
                        int?nullable1 = nullable;
                        nullable = null;
                        int?nullable2 = nullable;
                        nullable = null;
                        this.Item.addReference("parts", file, nullable1, nullable2, nullable);
                        break;
                    }

                    case OgreSceneImporter.NodeType.LIGHT:
                    {
                        OgreSceneImporter.Light light = node.Tag as OgreSceneImporter.Light;
                        file               = gameDatum.createItem(itemType.LIGHT);
                        file["diffuse"]    = light.diffuse;
                        file["specular"]   = light.specular;
                        file["radius"]     = light.radius;
                        file["brightness"] = light.power;
                        file["inner"]      = (float)Math.Round((double)(light.inner * 180f) / 3.14159265358979, 2);
                        file["outer"]      = (float)Math.Round((double)(light.outer * 180f) / 3.14159265358979, 2);
                        file["falloff"]    = light.falloff;
                        file["type"]       = light.mode;
                        file["landscape"]  = light.shadows;
                        file["buildings"]  = light.shadows;
                        file["characters"] = light.shadows;
                        this.Item.addInstance(light.name, file, light.x, light.y, light.z, light.qx, light.qy, light.qz, light.qw);
                        break;
                    }

                    case OgreSceneImporter.NodeType.EFFECT:
                    {
                        tag  = node.Tag as OgreSceneImporter.Node;
                        file = gameDatum.createItem(itemType.EFFECT);
                        this.Item.addInstance(tag.name, file.stringID, tag.x, tag.y, tag.z, tag.qx, tag.qy, tag.qz, tag.qw);
                        break;
                    }

                    case OgreSceneImporter.NodeType.NODE:
                    {
                        tag = node.Tag as OgreSceneImporter.Node;
                        this.Item.addInstance(tag.name, "", tag.x, tag.y, tag.z, tag.qx, tag.qy, tag.qz, tag.qw);
                        break;
                    }
                    }
                }
                else
                {
                    tag = node.Tag as OgreSceneImporter.Node;
                    this.Item.addInstance(tag.name, tag.target, tag.x, tag.y, tag.z, tag.qx, tag.qy, tag.qz, tag.qw);
                }
                this.nav.HasChanges = true;
            }
            base.Close();
        }
Ejemplo n.º 2
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);
        }