Exemplo n.º 1
0
        private void loadModelData(BlenderFile file)
        {
            models            = new List <BlenderModel>();
            transparentModels = new List <BlenderModel>();
            currentLayer      = 1;

            Structure curscene = file.GetStructuresOfType("FileGlobal")[0]["curscene"].Dereference()[0];
            ulong     next     = curscene["base.first"].Value;

            while (next != 0)
            {
                Structure objBase   = file.GetStructuresByAddress(next)[0];
                Structure obj       = objBase["object"].Dereference()[0];
                IField    data      = obj["data"];
                int       SDNAIndex = file.GetBlockByAddress((data as Field <ulong>).Value).SDNAIndex;
                while (file.StructureDNA.StructureList[SDNAIndex].StructureTypeName != "Mesh")
                {
                    ulong nextPointer = (objBase["next"] as Field <ulong>).Value;
                    if (nextPointer == 0)
                    {
                        return; // we've run out of objects in the list, and haven't found any meshes
                    }
                    objBase   = file.GetStructuresByAddress(nextPointer)[0];
                    obj       = objBase["object"].Dereference()[0];
                    data      = obj["data"];
                    SDNAIndex = file.GetBlockByAddress((data as Field <ulong>).Value).SDNAIndex;
                }

                Structure    mesh  = data.Dereference()[0];
                BlenderModel model = new BlenderModel(mesh, obj, GraphicsDevice, file);
                if (model.TextureHasTransparency)
                {
                    transparentModels.Add(model);
                }
                else
                {
                    models.Add(model);
                }

                next = (objBase["next"] as Field <ulong>).Value;
            }
        }
Exemplo n.º 2
0
 private void drawModel(BlenderModel model, bool transparent = false)
 {
     effect.View       = camera.View;
     effect.Projection = camera.Projection;
     effect.World      = camera.World * Matrix.CreateScale(model.Scale) * Matrix.CreateFromQuaternion(model.Rotation) * Matrix.CreateTranslation(model.Position);
     GraphicsDevice.RasterizerState  = RasterizerState.CullNone;
     GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
     if (transparent)
     {
         GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
         GraphicsDevice.BlendState        = BlendState.AlphaBlend;
     }
     else
     {
         GraphicsDevice.BlendState        = BlendState.Opaque;
         GraphicsDevice.DepthStencilState = DepthStencilState.Default;
     }
     effect.LightingEnabled             = model.LightingEnabled;
     effect.DirectionalLight0.Direction = -Vector3.UnitZ;
     effect.DirectionalLight1.Enabled   = true;
     effect.DirectionalLight1.Direction = Vector3.UnitZ;
     effect.TextureEnabled         = true;
     effect.PreferPerPixelLighting = true;
     effect.VertexColorEnabled     = false;
     effect.Texture = model.Texture;
     GraphicsDevice.SetVertexBuffer(model.VertexBuffer);
     foreach (EffectPass pass in effect.CurrentTechnique.Passes)
     {
         pass.Apply();
         GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, model.Vertices, 0, model.Vertices.Length / 3);
     }
     effect.TextureEnabled     = false;
     effect.LightingEnabled    = false;
     effect.VertexColorEnabled = true;
     GraphicsDevice.SetVertexBuffer(model.NormalBuffer);
     foreach (EffectPass pass in effect.CurrentTechnique.Passes)
     {
         pass.Apply();
         GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, model.NormalVerts, 0, model.NormalVerts.Length / 2);
     }
 }