예제 #1
0
        private void saveJF3D(OpenGLModel model, IOStream os)
        {
            baos = new ByteArrayStream();
            tmp  = new byte[8];
            int size;

            writeuint32(MAGIC);
            writeuint32(VERSION);
            writeuint32(ID_MODEL);
            size = 0;
            int tcnt = model.textures.Size();

            for (int a = 0; a < tcnt; a++)
            {
                size += model.textures.Get(a).Length + 1;
            }
            writeuint32(size);
            writeuint32(tcnt);
            for (int a = 0; a < tcnt; a++)
            {
                writeString(model.textures.Get(a));
            }
            for (int o = 0; o < model.ol.Size(); o++)
            {
                OpenGLObject obj = model.ol.Get(o);
                writeuint32(ID_OBJECT);
                int vcnt = obj.GetVertexCount() * 3;
                int pcnt = obj.GetPolyCount();
                size = obj.GetName().Length + 1 + 4 + (4 * 3) + (4 + (vcnt * 4)) + (4 + (pcnt * 4));
                writeuint32(size);
                writeString(obj.GetName());
                writeuint32(obj.GetType());
                writefloat(obj.GetOrigin().x);
                writefloat(obj.GetOrigin().y);
                writefloat(obj.GetOrigin().z);
                writeuint32(vcnt / 3);
                float[] xyz = obj.GetVertexBuffer();
                for (int a = 0; a < vcnt; a++)
                {
                    writefloat(xyz[a]);
                }
                switch (obj.GetType())
                {
                case GL_TRIANGLES:
                    writeuint32(pcnt / 3);
                    break;

                case GL_QUADS:
                    writeuint32(pcnt / 4);
                    break;
                }
                int[] pts = obj.GetPolyBuffer();
                for (int a = 0; a < pcnt; a++)
                {
                    writeuint32(pts[a]);
                }
                int maps = obj.GetUVMaps().Size();
                if (maps == 0)
                {
                    Console.WriteLine("GL_JF3D:Warning:No UVMaps found for object:" + obj.GetName());
                }
                for (int m = 0; m < maps; m++)
                {
                    OpenGLUVMap map = obj.GetUVMaps().Get(m);
                    writeuint32(ID_UVMAP);
                    int uvcnt = map.GetUVCount() * 2;
                    size = map.GetName().Length + 1 + 4 + (4 + (uvcnt * 4));
                    writeuint32(size);
                    writeString(map.GetName());
                    writeuint32(map.GetTextureIndex());
                    writeuint32(uvcnt / 2);
                    float[] uv = map.GetBuffer();
                    for (int a = 0; a < uvcnt; a++)
                    {
                        writefloat(uv[a]);
                    }
                }
            }
            os.Write(baos.GetData().ToArray());
        }