コード例 #1
0
        public override GameObject CreateEntity(Vector3f translation, Vector3f slope)
        {
            int numThingsInCluster = rand.Next(1, 4);
            Node clusterNode = new Node();
            for (int i = 0; i < numThingsInCluster; i++)
            {
                Vector3f clusterLoc;
                clusterLoc = new Vector3f((float)RandomDouble(-3f, 3f), 0, (float)RandomDouble(-3f, 3f));

                Geometry m = (Geometry)model.Clone();

                Vector3f pieceLoc;

                if (i > 0)
                    pieceLoc = clusterLoc.Add(translation);
                else
                    pieceLoc = translation;

            //    pieceLoc.y = this.GetHeight(pieceLoc.x, pieceLoc.z);

                m.SetLocalTranslation(pieceLoc);

                m.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, (float)RandomDouble(0, 359)));
                m.SetLocalScale(new Vector3f((float)this.RandomDouble(1.0, 1.9)));
                clusterNode.AddChild(m);
            }

            return clusterNode;
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: ajmd17/apexengine-sharp
 public override GameObject Clone()
 {
     Node res = new Node(this.name);
     res.SetLocalTranslation(this.GetLocalTranslation());
     res.SetLocalScale(this.GetLocalScale());
     res.SetLocalRotation(this.GetLocalRotation());
     for (int i = 0; i< children.Count; i++)
     {
         res.AddChild(children[i].Clone());
     }
     for (int i = 0; i < controls.Count; i++)
     {
         res.AddController(controls[i]);
     }
     return res;
 }
コード例 #3
0
ファイル: Populator.cs プロジェクト: ajmd17/apexengine-sharp
        public Node CreateEntityNode(Vector3f translation, GameObject parentNode, float chunkSize, int entityPerChunk)
        {
            Node n = new Node();
            float mult = chunkSize / (float)entityPerChunk;
            parentNode.UpdateTransform();

            for (int x = 0; x < entityPerChunk; x++)
            {
                for (int z = 0; z < entityPerChunk; z++)
                {
                    float xLoc = (float)RandomDouble(0, chunkSize);
                    float yLoc = 3;
                    float zLoc = (float)RandomDouble(0, chunkSize);

                    yLoc = GetHeight(parentNode.GetWorldTranslation().x + translation.x + xLoc, parentNode.GetWorldTranslation().z + translation.z + zLoc);
                    //	Vec3f norm = getNormal(parentNode, translation.x + x * 4, translation.z + z * 4);
                    if (yLoc != float.NaN)
                    {
                        GameObject entity = CreateEntity(new Vector3f(xLoc, yLoc, zLoc), Vector3f.Zero);
                       // entity.SetLocalScale(new Vector3f((float)RandomDouble(0.1f, 0.5f)));
                        entity.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, (float)RandomDouble(0, 359)));
                        //  n.AddChild(CreateEntity(new Vector3f(x * mult, y, z * mult), Vector3f.ZERO));
                        n.AddChild(entity);
                    }
                }
            }
            if (batchGeometry)
            {
                Node merged = new Node();
                merged.AddChild(new Geometry(MeshUtil.MergeMeshes(n)));
                merged.SetLocalTranslation(translation);
                merged.GetChildGeom(0).SetShader(GetShaderType());
                for (int i = 0; i < n.Children.Count; i++)
                {
                    n.Children[i] = null;
                }
                n = null;
                return merged;
            }
            n.SetLocalTranslation(translation);
            return n;
        }
コード例 #4
0
        static TreePopulator()
        {
            /*  tree = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\tree\\pine\\LoblollyPine.obj");

            tree.GetChildGeom(1).Material.SetValue("tree_height", tree.GetLocalBoundingBox().Max.y);
            tree.GetChildGeom(1).SetShader(typeof(BarkShader));

            tree.GetChildGeom(1).DepthShader = ShaderManager.GetShader(typeof(BarkShader), new ShaderProperties()
                .SetProperty("DEPTH", true)
                .SetProperty(Material.TEXTURE_DIFFUSE, true));

            tree.GetChildGeom(2).Material.SetValue("tree_height", tree.GetLocalBoundingBox().Max.y);
            tree.GetChildGeom(2).Material.SetValue(Material.MATERIAL_BLENDMODE, 1);
            tree.GetChildGeom(2).Material.SetValue(Material.MATERIAL_CULLENABLED, false);
            tree.GetChildGeom(2).Material.SetValue(Material.MATERIAL_ALPHADISCARD, 0.7f);
            tree.GetChildGeom(2).Material.Bucket = Rendering.RenderManager.Bucket.Transparent;
            tree.GetChildGeom(2).SetShader(typeof(LeafShader));

            tree.GetChildGeom(2).DepthShader = ShaderManager.GetShader(typeof(LeafShader), new ShaderProperties()
                .SetProperty("DEPTH", true)
                .SetProperty(Material.TEXTURE_DIFFUSE, true));*/

            tree = new Node();

            Geometry g = new Geometry(MeshFactory.CreateQuad());
            g.SetLocalScale(new Vector3f(15));
            g.SetLocalTranslation(new Vector3f(0, 10, 0));
            g.Material.SetValue(Material.MATERIAL_CASTSHADOWS, 0);
            g.Material.SetValue(Material.MATERIAL_BLENDMODE, 1);
            g.Material.SetValue(Material.TEXTURE_DIFFUSE, AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\models\\tree\\pine\\billboard.png"));
            g.Material.SetValue(Material.SHININESS, 0.0f);
            g.Material.SetValue(Material.MATERIAL_ALPHADISCARD, 0.5f);
            g.Material.Bucket = RenderManager.Bucket.Transparent;
            g.SetShader(typeof(GrassShader));
            g.Material.SetValue("fade_start", 250.0f);
            g.Material.SetValue("fade_end", 260.0f);
            tree.AddChild(g);
        }
コード例 #5
0
ファイル: TestGame.cs プロジェクト: ajmd17/apexengine-sharp
        public void OnChunkAdd(Terrain.TerrainChunkNode chunk, EventArgs e)
        {
            if (!chunk.HasController(typeof(GrassPopulator)))
            {
                GrassPopulator grass;
                chunk.AddController(grass = new GrassPopulator(PhysicsWorld, cam));
                grass.GenPatches(chunk, 5, 12);
            }
            if (!chunk.HasController(typeof(RockPopulator)))
            {
                RockPopulator rock;
                chunk.AddController(rock = new RockPopulator(PhysicsWorld, cam));
                rock.GenPatches(chunk, 3, 3);
            }
            if (!chunk.HasController(typeof(TreePopulator)))
            {
                TreePopulator tree;
                chunk.AddController(tree = new TreePopulator(PhysicsWorld, cam));
                tree.GenPatches(chunk, 2, 2);
            }

            /*
            for (int i = 0; i < chunk.hm.heights.Length; i++)
            {
                chunk.hm.heights[i] = 0f;
            }
            chunk.hm.RebuildTerrainMesh();*/
        }
コード例 #6
0
        public Mesh QuadFromLine(Line line)
        {
            float width = 2f;

            float scale = 2f;

            Vector3f quadSize = line.To.Subtract(line.From);
            float texCoordScale = ((float)System.Math.Abs(quadSize.x) + (float)System.Math.Abs(quadSize.z)) / 4;
            quadSize.NormalizeStore();

            Node rNode = new Node();

              Mesh mesh = new Mesh();
              List<Vertex> vertices = new List<Vertex>();

              vertices.Add(new Vertex(new Vector3f(line.From.x - quadSize.z, line.From.y, line.From.z + quadSize.x), new Vector2f(0, 0), new Vector3f(0, 1, 0)));
              vertices.Add(new Vertex(new Vector3f(line.From.x + quadSize.z, line.From.y, line.From.z - quadSize.x), new Vector2f(0, 1), new Vector3f(0, 1, 0)));
              vertices.Add(new Vertex(new Vector3f(line.To.x + quadSize.z, line.To.y, line.To.z - quadSize.x), new Vector2f(texCoordScale, 1), new Vector3f(0, 1, 0)));

              vertices.Add(new Vertex(new Vector3f(line.To.x + quadSize.z, line.To.y, line.To.z - quadSize.x), new Vector2f(texCoordScale, 1), new Vector3f(0, 1, 0)));
              vertices.Add(new Vertex(new Vector3f(line.To.x - quadSize.z, line.To.y, line.To.z + quadSize.x), new Vector2f(texCoordScale, 0), new Vector3f(0, 1, 0)));
              vertices.Add(new Vertex(new Vector3f(line.From.x - quadSize.z, line.From.y, line.From.z + quadSize.x), new Vector2f(0, 0), new Vector3f(0, 1, 0)));

              mesh.SetVertices(vertices);

            rNode.AddChild(new Geometry(mesh));

            return mesh;
        }
コード例 #7
0
ファイル: RenderUtil.cs プロジェクト: ajmd17/apexengine-sharp
 private static void GatherMeshes(Node node, List<Mesh> meshes, List<Material> materials, List<Matrix4f> worldTransforms)
 {
     foreach (GameObject child in node.Children)
     {
         if (child is Node)
         {
             GatherMeshes((Node)child, meshes, materials, worldTransforms);
         }
         else if (child is Geometry)
         {
             meshes.Add(((Geometry)child).Mesh);
             materials.Add(((Geometry)child).Material);
             Transform ttransform = new Transform();
             ttransform.SetTranslation(child.GetUpdatedWorldTranslation());
             ttransform.SetRotation(child.GetUpdatedWorldRotation());
             ttransform.SetScale(child.GetUpdatedWorldScale());
             Matrix4f matrix = ttransform.GetMatrix();
             worldTransforms.Add(matrix);
         }
     }
 }
コード例 #8
0
ファイル: RenderUtil.cs プロジェクト: ajmd17/apexengine-sharp
 private static void GatherObjects(Node node, List<GameObject> objs)
 {
     foreach (GameObject child in node.Children)
     {
         if (child is Node)
         {
             objs.Add(child);
             GatherObjects((Node)child, objs);
         }
         else if (child is Geometry)
         {
             objs.Add(child);
         }
     }
 }
コード例 #9
0
ファイル: RenderUtil.cs プロジェクト: ajmd17/apexengine-sharp
 private static void GatherGeometry(Node node, List<Geometry> geoms)
 {
     foreach (GameObject child in node.Children)
     {
         if (child is Node)
         {
             GatherGeometry((Node)child, geoms);
         }
         else if (child is Geometry)
         {
             geoms.Add((Geometry)child);
         }
     }
 }
コード例 #10
0
ファイル: RenderUtil.cs プロジェクト: ajmd17/apexengine-sharp
 private static void GatherMeshes(Node node, List<Mesh> meshes)
 {
     foreach (GameObject child in node.Children)
     {
         if (child is Node)
         {
             GatherMeshes((Node)child, meshes);
         }
         else if (child is Geometry)
         {
             meshes.Add(((Geometry)child).Mesh);
         }
     }
 }
コード例 #11
0
ファイル: Paging.cs プロジェクト: ajmd17/apexengine-sharp
 public Patch(Node parentNode, GridTile tile)
 {
     this.tile = tile;
     this.parentNode = parentNode;
 }
コード例 #12
0
ファイル: Bone.cs プロジェクト: ajmd17/apexengine-sharp
 public override void SetParent(Node par)
 {
     base.SetParent(par);
     if (par is Bone)
         this.parentBone = (Bone)par;
 }
コード例 #13
0
        public override object Load(LoadedAsset asset)
        {
            XmlReader xmlReader = XmlReader.Create(asset.Data);
            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.Element)
                {
                    if (xmlReader.Name == "position")
                    {
                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));
                        Vector3f vec = new Vector3f(x, y, z);
                        positions.Add(vec);
                    }
                    else if (xmlReader.Name == "normal")
                    {
                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));
                        Vector3f vec = new Vector3f(x, y, z);
                        normals.Add(vec);
                    }
                    else if (xmlReader.Name == "texcoord")
                    {
                        float x = float.Parse(xmlReader.GetAttribute(0));
                        float y = float.Parse(xmlReader.GetAttribute(1));
                        Vector2f tc = new Vector2f(x, -y);
                        texCoords.Add(tc);
                    }
                    else if (xmlReader.Name == "face")
                    {
                        if (!useSubmeshes)
                        {
                            faces.Add(int.Parse(xmlReader.GetAttribute(0)));
                            faces.Add(int.Parse(xmlReader.GetAttribute(1)));
                            faces.Add(int.Parse(xmlReader.GetAttribute(2)));
                        }
                        else if (useSubmeshes)
                        {
                            CurrentSubmesh().faces.Add(int.Parse(xmlReader.GetAttribute(0)));
                            CurrentSubmesh().faces.Add(int.Parse(xmlReader.GetAttribute(1)));
                            CurrentSubmesh().faces.Add(int.Parse(xmlReader.GetAttribute(2)));
                        }
                    }
                    else if (xmlReader.Name == "skeletonlink")
                    {
                        string parentPath = System.IO.Directory.GetParent(asset.FilePath).ToString();
                        string skeletonPath = parentPath + "\\" + xmlReader.GetAttribute(0) + ".xml";
                        skeleton = (Skeleton)AssetManager.Load(skeletonPath, OgreXmlSkeletonLoader.GetInstance());
                    }
                    else if (xmlReader.Name == "vertexboneassignment" || xmlReader.Name == "boneassignment")
                    {
                        int vidx = int.Parse(xmlReader.GetAttribute("vertexindex"));
                        float boneWeight = float.Parse(xmlReader.GetAttribute("weight"));
                        int boneIndex = int.Parse(xmlReader.GetAttribute("boneindex"));
                        AddToBoneAssigns(vidx, new BoneAssign(vidx, boneWeight, boneIndex));
                    }
                    else if (xmlReader.Name == "submesh")
                    {
                        useSubmeshes = true;
                        if (xmlReader.GetAttribute("operationtype") != null)
                        {
                            // material
                            Submesh sm = new Submesh();
                            subMeshes.Add(sm);
                        }
                    }
                }
            }
            xmlReader.Close();
            List<Vertex> vertices = new List<Vertex>();
            if (!useSubmeshes)
            {
                LoopThrough(faces, ref vertices);
            }
            else
            {
                for (int i = subMeshes.Count - 1; i > -1; i--)
                {
                    Submesh s = subMeshes[i];
                    if (s.faces.Count > 0)
                        LoopThrough(s.faces, ref s.vertices);
                    else
                        subMeshes.Remove(s);
                }
            }

            if (skeleton.GetNumBones() > 0)
            {
                for (int i = 0; i < skeleton.GetNumBones(); i++)
                    skeleton.GetBone(i).SetToBindingPose();
                skeleton.GetBone(0).CalculateBindingRotation();
                skeleton.GetBone(0).CalculateBindingTranslation();
                for (int i = 0; i < skeleton.GetNumBones(); i++)
                {
                    skeleton.GetBone(i).StoreBindingPose();
                    skeleton.GetBone(i).ClearPose();
                }
                skeleton.GetBone(0).UpdateTransform();
            }
            bool hasAnimations = skeleton.GetAnimations().Count > 0;
            AnimationController animControl = new AnimationController(skeleton);
            Node res = new Node();
            if (!useSubmeshes)
            {
                Mesh mesh = new Mesh();
                mesh.SetSkeleton(skeleton);
                mesh.SetVertices(vertices);
                Geometry geom = new Geometry();
                geom.Mesh = mesh;
                res.AddChild(geom);
            }
            else
            {
                for (int i = 0; i < subMeshes.Count; i++)
                {
                    Submesh sm = subMeshes[i];

                    Mesh mesh = new Mesh();
                    mesh.SetSkeleton(skeleton);
                    mesh.SetVertices(sm.vertices);
                    Geometry geom = new Geometry();
                    geom.Mesh = mesh;
                    res.AddChild(geom);
                }
            }
            if (hasAnimations)
            {
                res.AddController(animControl);
            }
            ResetLoader();
            return res;
        }
コード例 #14
0
        public override object Load(LoadedAsset asset)
        {
            XmlReader xmlReader = XmlReader.Create(asset.Data);
            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.Element)
                {
                    if (xmlReader.Name == ApxExporter.TOKEN_NODE)
                    {
                        node = true;
                        geom = false;
                        string name = xmlReader.GetAttribute(ApxExporter.TOKEN_NAME);
                        Node n = new Node(name);
                        if (lastNode != null)
                            lastNode.AddChild(n);
                        lastNode = n;
                        nodes.Add(n);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_GEOMETRY)
                    {
                        node = false;
                        geom = true;
                        string name = xmlReader.GetAttribute(ApxExporter.TOKEN_NAME);
                        Geometry g = new Geometry();
                        g.Name = name;
                        if (lastNode != null)
                            lastNode.AddChild(g);
                        geoms.Add(g);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_MATERIAL)
                    {
                        Material mat = new Material();
                        mats.Add(mat);
                        string bucketStr = xmlReader.GetAttribute(ApxExporter.TOKEN_MATERIAL_BUCKET);
                        RenderManager.Bucket bucket;
                        if (bucketStr != null)
                            Enum.TryParse<RenderManager.Bucket>(bucketStr, out bucket);
                        else
                            bucket = RenderManager.Bucket.Opaque;
                        Console.WriteLine("Bucket: " + bucket.ToString());
                        mat.Bucket = bucket;
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_MATERIAL_PROPERTY)
                    {
                        Material lastMaterial = mats[mats.Count - 1];

                        string name = xmlReader.GetAttribute(ApxExporter.TOKEN_NAME);
                        string type = xmlReader.GetAttribute(ApxExporter.TOKEN_TYPE);
                        string val = xmlReader.GetAttribute(ApxExporter.TOKEN_VALUE);

                        object value = null;
                        if (type == ApxExporter.TOKEN_TYPE_STRING)
                            value = val;
                        else if (type == ApxExporter.TOKEN_TYPE_INT)
                            value = int.Parse(val);
                        else if (type == ApxExporter.TOKEN_TYPE_BOOLEAN)
                            value = bool.Parse(val);
                        else if (type == ApxExporter.TOKEN_TYPE_FLOAT)
                            value = float.Parse(val);
                        else if (type == ApxExporter.TOKEN_TYPE_VECTOR2)
                            value = ParseVector2(val);
                        else if (type == ApxExporter.TOKEN_TYPE_VECTOR3)
                            value = ParseVector3(val);
                        else if (type == ApxExporter.TOKEN_TYPE_VECTOR4)
                            value = ParseVector4(val);
                        else if (type == ApxExporter.TOKEN_TYPE_TEXTURE)
                        {
                            string texPath = val;
                            string parentPath = System.IO.Directory.GetParent(asset.FilePath).ToString();
                            string finalTexPath = parentPath + "\\" + texPath;
                            if (System.IO.File.Exists(finalTexPath))
                            {
                                value = AssetManager.LoadTexture(finalTexPath);
                            }
                            else if (System.IO.File.Exists(texPath)) // absolute path
                            {
                                value = AssetManager.LoadTexture(texPath);
                            }
                            else
                                value = null;
                        }

                        lastMaterial.SetValue(name, value);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_TRANSLATION)
                    {
                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));

                        Vector3f vec = new Vector3f(x, y, z);
                        GameObject go = null;
                        if (node)
                            go = nodes[nodes.Count - 1];
                        else if (geom)
                            go = geoms[geoms.Count - 1];
                        go.SetLocalTranslation(vec);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_ROTATION)
                    {
                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));
                        float w = float.Parse(xmlReader.GetAttribute("w"));

                        Quaternion quat = new Quaternion(x, y, z, w);
                        GameObject go = null;
                        if (node)
                            go = nodes[nodes.Count - 1];
                        else if (geom)
                            go = geoms[geoms.Count - 1];
                        go.SetLocalRotation(quat);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_SCALE)
                    {
                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));

                        Vector3f vec = new Vector3f(x, y, z);
                        GameObject go = null;
                        if (node)
                            go = nodes[nodes.Count - 1];
                        else if (geom)
                            go = geoms[geoms.Count - 1];
                        go.SetLocalScale(vec);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_MESH)
                    {
                        meshes.Add(new Mesh());
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_VERTICES)
                    {
                        List<Vertex> newVList = new List<Vertex>();
                        vertices.Add(newVList);

                        List<Vector3f> newPList = new List<Vector3f>();
                        positions.Add(newPList);

                        List<Vector3f> newNList = new List<Vector3f>();
                        normals.Add(newNList);

                        List<Vector2f> newT0List = new List<Vector2f>();
                        texcoords0.Add(newT0List);

                        List<Vector2f> newT1List = new List<Vector2f>();
                        texcoords1.Add(newT1List);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_POSITION)
                    {
                        List<Vector3f> pos = positions[positions.Count - 1];

                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));

                        Vector3f position = new Vector3f(x, y, z);
                        pos.Add(position);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_NORMAL)
                    {
                        List<Vector3f> nor = normals[normals.Count - 1];

                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));

                        Vector3f normal = new Vector3f(x, y, z);
                        nor.Add(normal);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_TEXCOORD0)
                    {
                        List<Vector2f> tc0 = texcoords0[texcoords0.Count - 1];

                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));

                        Vector2f tc = new Vector2f(x, y);
                        tc0.Add(tc);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_TEXCOORD1)
                    {
                        List<Vector2f> tc1 = texcoords1[texcoords1.Count - 1];

                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));

                        Vector2f tc = new Vector2f(x, y);
                        tc1.Add(tc);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_FACES)
                    {
                        faces.Add(new List<int>());
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_FACE)
                    {
                        List<int> fList = faces[faces.Count - 1];
                        for (int i = 0; i < 3; i++)
                        {
                            string val = xmlReader.GetAttribute("i" + i.ToString());
                            if (val != "")
                            {
                                string[] tokens = val.Split('/');
                                for (int j = 0; j < tokens.Length; j++)
                                {
                                    fList.Add(int.Parse(tokens[j]));
                                }
                            }
                        }
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_SKELETON)
                    {
                        skeletons.Add(new Skeleton());
                        bones.Add(new List<Bone>());
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_SKELETON_ASSIGN)
                    {
                        string assign = xmlReader.GetAttribute(ApxExporter.TOKEN_ID);
                        skeletonAssigns.Add(int.Parse(assign));
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_BONE)
                    {
                        string name = xmlReader.GetAttribute(ApxExporter.TOKEN_NAME);
                        string parent = xmlReader.GetAttribute(ApxExporter.TOKEN_PARENT);
                        Bone bone = new Bone(name);
                        List<Bone> lastBL = bones[bones.Count - 1];
                        if (!string.IsNullOrEmpty(parent))
                        {
                            foreach (Bone b in lastBL)
                            {
                                if (b.Name == parent)
                                {
                                    b.AddChild(bone);
                                }
                            }
                        }
                        List<Bone> skel = bones[bones.Count - 1];
                        skel.Add(bone);
                        Skeleton lastSkeleton = skeletons[skeletons.Count - 1];
                        lastSkeleton.AddBone(bone);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_BONE_BINDPOSITION)
                    {
                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));

                        Vector3f vec = new Vector3f(x, y, z);
                        List<Bone> skel = bones[bones.Count - 1];
                        if (skel.Count > 0)
                        {
                            Bone lastBone = skel[skel.Count - 1];
                            lastBone.SetBindTranslation(vec);
                        }
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_BONE_BINDROTATION)
                    {
                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));
                        float w = float.Parse(xmlReader.GetAttribute("w"));

                        List<Bone> skel = bones[bones.Count - 1];
                        if (skel.Count > 0)
                        {
                            Bone lastBone = skel[skel.Count - 1];
                            //   lastBone.SetBindAxisAngle(new Vector3f(x, y, z), w);
                            lastBone.SetBindRotation(new Quaternion(x, y, z, w));
                        }
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_BONE_ASSIGNS)
                    {
                        boneAssigns.Add(new List<BoneAssign>());
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_BONE_ASSIGN)
                    {
                        int vertIdx = int.Parse(xmlReader.GetAttribute(ApxExporter.TOKEN_VERTEXINDEX));
                        int boneIdx = int.Parse(xmlReader.GetAttribute(ApxExporter.TOKEN_BONEINDEX));
                        float boneWeight = float.Parse(xmlReader.GetAttribute(ApxExporter.TOKEN_BONEWEIGHT));
                        List<BoneAssign> ba = boneAssigns[boneAssigns.Count - 1];
                        ba.Add(new BoneAssign(vertIdx, boneWeight, boneIdx));
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_ANIMATIONS)
                    {
                        hasAnimations = true;
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_ANIMATION)
                    {
                        string name = xmlReader.GetAttribute(ApxExporter.TOKEN_NAME);
                        Animation anim = new Animation(name);
                        animations.Add(anim);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_ANIMATION_TRACK)
                    {
                        string bone = xmlReader.GetAttribute(ApxExporter.TOKEN_BONE);
                        Bone b = skeletons[skeletons.Count - 1].GetBone(bone);
                        if (b != null)
                        {
                            AnimationTrack track = new AnimationTrack(b);
                            animations[animations.Count - 1].AddTrack(track);
                        }
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_KEYFRAME)
                    {
                        float time = float.Parse(xmlReader.GetAttribute(ApxExporter.TOKEN_TIME));

                        Keyframe frame = new Keyframe(time, null, null);
                        Animation canim = animations[animations.Count - 1];
                        AnimationTrack ctrack = canim.GetTrack(canim.GetTracks().Count - 1);
                        ctrack.AddKeyframe(frame);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_KEYFRAME_TRANSLATION)
                    {
                        Animation canim = animations[animations.Count - 1];
                        AnimationTrack ctrack = canim.GetTrack(canim.GetTracks().Count - 1);
                        Keyframe lastFrame = ctrack.frames[ctrack.frames.Count - 1];

                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));

                        Vector3f vec = new Vector3f(x, y, z);
                        lastFrame.SetTranslation(vec);
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_KEYFRAME_ROTATION)
                    {
                        Animation canim = animations[animations.Count - 1];
                        AnimationTrack ctrack = canim.GetTrack(canim.GetTracks().Count - 1);
                        Keyframe lastFrame = ctrack.frames[ctrack.frames.Count - 1];

                        float x = float.Parse(xmlReader.GetAttribute("x"));
                        float y = float.Parse(xmlReader.GetAttribute("y"));
                        float z = float.Parse(xmlReader.GetAttribute("z"));
                        float w = float.Parse(xmlReader.GetAttribute("w"));

                        Quaternion rot = new Quaternion(x, y, z, w);
                        lastFrame.SetRotation(rot);
                    }
                } // start element
                else if (xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    if (xmlReader.Name == ApxExporter.TOKEN_NODE)
                    {
                        if (lastNode != null)
                        {
                            if (lastNode.GetParent() != null)
                            {
                                lastNode = lastNode.GetParent();
                            }
                            else
                            {
                                lastNode = null;
                            }
                        }
                        node = false;
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_GEOMETRY)
                    {
                        geom = false;
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_MATERIAL)
                    {
                        if (geoms.Count > 0)
                        {
                            int lastGeomIndex = geoms.Count - 1;
                            Geometry parent = geoms[lastGeomIndex];
                            int lastMatIndex = mats.Count - 1;
                            Material m = mats[lastMatIndex];
                            geomMats.Add(parent, m);
                        }
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_SKELETON)
                    {
                    }
                    else if (xmlReader.Name == ApxExporter.TOKEN_MODEL)
                    {
                        // end of model, load in meshes
                        EndModel();
                    }
                } // end element
            }
            xmlReader.Close();
            Node finalNode = new Node();
            foreach (Node n in nodes)
                if (n.GetParent() == null)
                    finalNode.AddChild(n);
            this.ResetLoader();
            return finalNode;
        }
コード例 #15
0
 public override void ResetLoader()
 {
     nodes.Clear();
     geoms.Clear();
     meshes.Clear();
     skeletonAssigns.Clear();
     skeletons.Clear();
     bones.Clear();
     boneAssigns.Clear();
     animations.Clear();
     hasAnimations = false;
     positions.Clear();
     normals.Clear();
     texcoords0.Clear();
     texcoords1.Clear();
     vertices.Clear();
     faces.Clear();
     geomMats.Clear();
     mats.Clear();
     node = false;
     geom = false;
     lastNode = null;
 }
コード例 #16
0
 private static void SaveNode(Node node, XmlWriter writer)
 {
     writer.WriteStartElement(TOKEN_NODE);
     if (node.Name != "root")
         writer.WriteAttributeString(TOKEN_NAME, node.Name);
     else
         writer.WriteAttributeString(TOKEN_NAME, "root_model");
     writer.WriteStartElement(TOKEN_TRANSLATION);
     writer.WriteAttributeString("x", node.GetLocalTranslation().x.ToString());
     writer.WriteAttributeString("y", node.GetLocalTranslation().y.ToString());
     writer.WriteAttributeString("z", node.GetLocalTranslation().z.ToString());
     writer.WriteEndElement();
     writer.WriteStartElement(TOKEN_SCALE);
     writer.WriteAttributeString("x", node.GetLocalScale().x.ToString());
     writer.WriteAttributeString("y", node.GetLocalScale().y.ToString());
     writer.WriteAttributeString("z", node.GetLocalScale().z.ToString());
     writer.WriteEndElement();
     writer.WriteStartElement(TOKEN_ROTATION);
     writer.WriteAttributeString("x", node.GetLocalRotation().x.ToString());
     writer.WriteAttributeString("y", node.GetLocalRotation().y.ToString());
     writer.WriteAttributeString("z", node.GetLocalRotation().z.ToString());
     writer.WriteAttributeString("w", node.GetLocalRotation().w.ToString());
     writer.WriteEndElement();
     for (int i = 0; i < node.Children.Count; i++)
     {
         SaveObject(node.GetChild(i), writer);
     }
     writer.WriteEndElement();
 }
コード例 #17
0
ファイル: TestGame.cs プロジェクト: ajmd17/apexengine-sharp
        public void OnChunkRemove(Terrain.TerrainChunkNode chunk, EventArgs e)
        {
            if (chunk.HasController(typeof(GrassPopulator)))
            {
                GrassPopulator grass = (GrassPopulator)chunk.GetController(typeof(GrassPopulator));
                grass.Destroy();
                grass = null;
            }
            if (chunk.HasController(typeof(RockPopulator)))
            {
                RockPopulator rock = (RockPopulator)chunk.GetController(typeof(RockPopulator));
                rock.Destroy();
                rock = null;
            }

            if (chunk.HasController(typeof(TreePopulator)))
            {
                TreePopulator tree = (TreePopulator)chunk.GetController(typeof(TreePopulator));
                tree.Destroy();
                tree = null;
            }
        }