Пример #1
0
        private BlendContext pushData()
        {
            BlendContext ctx = new BlendContext();

            ctx.data    = data;
            ctx.datapos = datapos;
            return(ctx);
        }
Пример #2
0
        private void readLayer(long layers, String name)
        {
            if (layers == 0)
            {
                return;
            }
//        Console.WriteLine(name + ".layers=" + Long.toString(layers, 16));
            BlendChunk raw = findChunkByPtr(layers);

            if (raw == null)
            {
                throw new Exception("GL_BLEND:Unable to find " + name + ".layers for Mesh");
            }
            setData(raw.raw);
//        Console.WriteLine("#layers=" + raw.nr);
            for (int a = 0; a < raw.nr; a++)
            {
                BlendCustomDataLayer layer = new BlendCustomDataLayer(this);
                layer.read();
                String layer_name = layer.name;
                if (layer.data == 0)
                {
//                Console.WriteLine("layer.data == null");
                    continue;
                }
                BlendChunk layer_data = findChunkByPtr(layer.data);
                if (layer_data == null)
                {
                    throw new Exception("GL_BLEND:Unable to find " + name + ".layers.data for Mesh");
                }
                BlendContext ctx = pushData();
                setData(layer_data.raw);
//            Console.WriteLine("layer.data=" + Long.toString(layer.data, 16) + ",type==" + layer.type + ",a=" + a);
                switch (layer.type)
                {
                case CD_MTEXPOLY: {    //15
                    //NOTE:There fis a MTexPoly per face, I only read the first
                    BlendMTexPoly tex = new BlendMTexPoly(this);
                    tex.read();
                    BlendChunk imageChunk = findChunkByPtr(tex.tpage);
                    if (imageChunk == null)
                    {
                        throw new Exception("GL_BLEND:No texture found for UVMap:" + a);
                    }
                    setData(imageChunk.raw);
                    BlendImage image = new BlendImage(this);
                    image.read();
                    OpenGLUVMap map;
                    if (a < obj.GetUVMapCount())
                    {
                        map = obj.GetUVMap(a);
                    }
                    else
                    {
                        map = obj.CreateUVMap();
                    }
                    String tn = image.name;
                    //string texture path for now
                    int tnidx = tn.LastIndexOf('/');
                    if (tnidx != -1)
                    {
                        tn = tn.Substring(tnidx + 1);
                    }
                    tnidx = tn.LastIndexOf('\\');
                    if (tnidx != -1)
                    {
                        tn = tn.Substring(tnidx + 1);
                    }
                    int tidx = model.AddTexture(tn);
                    map.SetTextureIndex(tidx);
                    map.SetName(layer_name);
//                    Console.WriteLine("texpoly=" + map.name);
                    break;
                }

                case CD_MLOOPUV: { //16
                    //There fis a UV per face per vertex
                    if (a >= obj.GetUVMapCount())
                    {
                        obj.CreateUVMap();
                    }
//                    Console.WriteLine("loopuv.nr=" + layer_data.nr);
                    for (int b = 0; b < layer_data.nr; b++)
                    {
                        BlendMLoopUV uv = new BlendMLoopUV(this);
                        uv.read();
                        uv.uv[1] = 1.0f - uv.uv[1];    //invert V(y)
                        obj.AddUV(uv.uv, a);
                    }
                    break;
                }
                }
                popData(ctx);
            }
        }
Пример #3
0
 private void popData(BlendContext ctx)
 {
     data    = ctx.data;
     datapos = ctx.datapos;
 }