示例#1
0
        float findSize(Bob.ModelChunk bmc)
        {
            Vector3 min = new Vector3(float.MaxValue);
            Vector3 max = new Vector3(float.MinValue);

            foreach (Vector3 v in bmc.verts)
            {
                if (v.X < min.X)
                {
                    min.X = v.X;
                }
                if (v.X > max.X)
                {
                    max.X = v.X;
                }
                if (v.Y < min.Y)
                {
                    min.Y = v.Y;
                }
                if (v.Y > max.Y)
                {
                    max.Y = v.Y;
                }
                if (v.Z < min.Z)
                {
                    min.Z = v.Z;
                }
                if (v.Z > max.Z)
                {
                    max.Z = v.Z;
                }
            }

            return((max - min).Length / 2.0f);
        }
示例#2
0
 void loadIndexes(Model m, Bob.ModelChunk bmc)
 {
     if (bmc.indexType == Bob.ModelChunk.IndexFormat.USHORT)
     {
         m.myIbo.setData(bmc.indexShort);
     }
     else if (bmc.indexType == Bob.ModelChunk.IndexFormat.UINT)
     {
         m.myIbo.setData(bmc.indexInt);
     }
 }
示例#3
0
        void loadMaterials(Model m, Bob.ModelChunk bmc)
        {
            foreach (Bob.Material bm in bmc.myMaterials)
            {
                Material mat = new Material(bm.name);
                mat.myFeatures |= Material.Feature.Lighting;
                mat.ambient     = bm.ambient;
                mat.diffuse     = bm.diffuse;
                mat.spec        = bm.spec;
                mat.emission    = bm.emission;
                mat.shininess   = bm.shininess;
                mat.alpha       = bm.alpha;
                if (bm.diffuseTexture != null)
                {
                    Texture t = getTexture(bm.diffuseTexture);
                    if (t != null)
                    {
                        mat.addAttribute(new TextureAttribute("diffuseMap", t));
                        mat.myFeatures     |= Material.Feature.DiffuseMap;
                        mat.hasTransparency = t.hasAlpha;
                    }
                }
                if (bm.specularTexture != null)
                {
                    Texture t = getTexture(bm.specularTexture);
                    if (t != null)
                    {
                        mat.addAttribute(new TextureAttribute("specularMap", t));
                        mat.myFeatures |= Material.Feature.SpecMap;
                    }
                }
                if (bm.emissionTexture != null)
                {
                    Texture t = getTexture(bm.emissionTexture);
                    if (t != null)
                    {
                        mat.addAttribute(new TextureAttribute("emissionMap", t));
                        mat.myFeatures |= Material.Feature.EmmissiveMap;
                    }
                }
                if (bm.normalTexture != null)
                {
                    Texture t = getTexture(bm.normalTexture);
                    if (t != null)
                    {
                        mat.addAttribute(new TextureAttribute("normalMap", t));
                        mat.myFeatures |= Material.Feature.NormalMap;
                    }
                }

                mat.upload();
                myMaterials.Add(mat);
            }
        }
示例#4
0
 void loadMeshes(Model m, Bob.ModelChunk bmc)
 {
     foreach (Bob.Mesh bm in bmc.myMeshes)
     {
         Mesh mesh = new Mesh();
         mesh.primativeType = bmc.primativeType;
         mesh.indexBase     = (int)bm.indexOffset;
         mesh.indexCount    = (int)bm.indexCount;
         mesh.material      = findMaterial(bm.material);
         m.myMeshes.Add(mesh);
     }
 }
示例#5
0
        Model loadModel(Bob.ModelChunk mc)
        {
            Model model = null;

            if (mc.animated == true)
            {
                model = new SkinnedModel();
            }
            else
            {
                model = new Model();
            }

            loadMaterials(model, mc);
            loadVerts(model, mc);
            loadIndexes(model, mc);
            loadMeshes(model, mc);
            model.size = findSize(mc);

            return(model);
        }
示例#6
0
        void loadVerts(Model m, Bob.ModelChunk bmc)
        {
            VertexBufferObject vbo = new VertexBufferObject(BufferUsageHint.StaticDraw);

            if (bmc.animated == false)
            {
                List <V3N3T2> verts = new List <V3N3T2>();
                for (int i = 0; i < bmc.vertexCount; i++)
                {
                    V3N3T2 v = new V3N3T2();
                    v.Position = bmc.verts[i];
                    v.Normal   = bmc.normals[i];
                    v.TexCoord = bmc.uvs[i];
                    verts.Add(v);
                }

                m.myBindings = V3N3T2.bindings();
                vbo.setData(verts);
            }
            else
            {
                List <V3N3T2B4W4> verts = new List <V3N3T2B4W4>();
                for (int i = 0; i < bmc.vertexCount; i++)
                {
                    V3N3T2B4W4 v = new V3N3T2B4W4();
                    v.Position   = bmc.verts[i];
                    v.Normal     = bmc.normals[i];
                    v.TexCoord   = bmc.uvs[i];
                    v.BoneId     = bmc.boneIdx[i];
                    v.BoneWeight = bmc.boneWeights[i];
                    verts.Add(v);
                }

                m.myBindings = V3N3T2B4W4.bindings();
                vbo.setData(verts);
            }

            m.myVbos.Add(vbo);
        }