Example #1
0
        BlitzObject readObject(BlitzObject parent)
        {
            BlitzObject obj = null;

            string name = readString();

            float[] pos, scl, rot;
            pos = readFloatArray(3);
            scl = readFloatArray(3);
            rot = readFloatArray(4);

            Animation keys = new Animation();
            int       anim_len = 0;
            MeshModel mesh = null;
            int       mesh_flags, mesh_brush;

            while (chunkSize() > 0)
            {
                switch (readChunk())
                {
                case "MESH":
                    obj        = mesh = MeshLoader.CreateMesh();
                    mesh_brush = readInt();
                    //mesh_flags=readMesh();
                    break;

                case "BONE":
                    obj = readBone();
                    break;

                case "KEYS":
                    readKeys(ref keys);
                    break;

                case "ANIM":
                    readInt();
                    anim_len = readInt();
                    readFloat();
                    break;

                case "NODE":
                    if (obj == null)
                    {
                        obj = new MeshModel();
                    }
                    readObject(obj);
                    break;
                }
                exitChunk();
            }

            if (obj == null)
            {
                obj = new MeshModel();
            }

            obj.Name          = name;
            obj.LocalPosition = (new Vector(pos[0], pos[1], pos[2]));
            obj.LocalScale    = (new Vector(scl[0], scl[1], scl[2]));
            obj.LocalRotation = (new Quat(rot[0], new Vector(rot[1], rot[2], rot[3])));
            obj.setAnimation(keys);

            if (mesh != null)
            {
                //MeshLoader::endMesh(mesh);
                //if (!(mesh_flags & 1)) mesh->updateNormals();
                //if (mesh_brush != -1) mesh->setBrush(brushes[mesh_brush]);
            }

            if (mesh != null && mesh.Bones.Any())
            {
                mesh.Bones.Insert(0, mesh);
                mesh.setAnimator(new Animator(mesh.Bones, anim_len));
            }
            else if (anim_len > 0)
            {
                obj.setAnimator(new Animator(obj, anim_len));
            }
            if (parent != null)
            {
                obj.Parent = (parent);
            }
            LoadedObjects.Add(obj);
            return(obj);
        }