Exemplo n.º 1
0
        public OpenGLUVMap CreateUVMap()
        {
            OpenGLUVMap map = new OpenGLUVMap(maps.Size());

            maps.Add(map);
            return(map);
        }
Exemplo n.º 2
0
        public void AddVertex(Vertex v)
        {
            vpl.Add(v.x);
            vpl.Add(v.y);
            vpl.Add(v.z);
            OpenGLUVMap map = maps.Get(0);

            map.Add(v.u);
            map.Add(v.v);
        }
Exemplo n.º 3
0
 public OpenGLUVMap GetUVMap(String name)
 {
     for (int a = 0; a < maps.Size(); a++)
     {
         OpenGLUVMap map = maps.Get(a);
         if (map.GetName().Equals(name))
         {
             return(map);
         }
     }
     return(null);
 }
Exemplo n.º 4
0
        /** Release a cloned model @ index.
         */
        public void ReleaseModel(int idx)
        {
            OpenGLModel  mod;
            OpenGLObject obj;

            mod = ml.Get(idx);
            int size = mod.ol.Size();

            for (int a = 0; a < size; a++)
            {
                obj = mod.ol.Get(a);
                for (int m = 0; m < obj.GetUVMapCount(); m++)
                {
                    OpenGLUVMap map = obj.GetUVMap(m);
                    tl.Get(mod.GetTexture(map.GetTextureIndex())).refcnt--;
                }
            }
            ml.RemoveAt(idx);
        }
Exemplo n.º 5
0
//load textures from disk to general-purpose memory
        public bool LoadTextures()
        {
            //scan thru object list and load them all
            bool         ret = true;
            OpenGLObject obj;
            OpenGLModel  mod;
            int          modCnt = ml.Size();

            for (int a = 0; a < modCnt; a++)
            {
                mod = ml.Get(a);
                int objCnt = mod.ol.Size();
                for (int b = 0; b < objCnt; b++)
                {
                    obj = mod.ol.Get(b);
                    int mapCnt = obj.GetUVMapCount();
                    for (int m = 0; m < mapCnt; m++)
                    {
                        OpenGLUVMap map = obj.GetUVMap(m);
                        if (map.IsLoaded())
                        {
                            continue;
                        }
                        if (loadTexture(mod.GetTexture(map.GetTextureIndex()), map.GetMapIndex()))
                        {
                            map.SetLoaded(true);
                        }
                        else
                        {
                            ret = false;
                        }
                    }
                }
            }
            return(ret);
        }
Exemplo n.º 6
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());
        }