示例#1
0
文件: Mesh.cs 项目: zulis/Sandbox
        public Mesh(ICore core, ProgramSettings settings, string fileName)
            : base(core)
        {
            this.core     = core;
            this.settings = settings;

            mass            = 0f;
            staticFriction  = 0.9f;
            kineticFriction = 0.5f;
            softness        = 0.1f;
            bounciness      = 0.1f;
            materialIdx     = -1;
            SetMaterialToCustom();

            FileName      = fileName;
            customTexture = string.Empty;
            //Name = fileName.Split(new[] { '\\' }).Last();
            PhysicsId = -1;

            enableLightning = true;

            Name = core.GetName <Mesh>();
            string ending = fileName.Split(new[] { '\\' }).Last().ToUpper();

            mesh = core.Scene.CreateMeshBuilder();

            if (ending.EndsWith(Helpers.GetFileExtension(Helpers.FileFormat.TVM)))
            {
                mesh.LoadTVM(fileName, true, false);
            }
            else if (ending.EndsWith(Helpers.GetFileExtension(Helpers.FileFormat.X)))
            {
                mesh.LoadXFile(fileName, true, false);
            }
            else if (ending.EndsWith(Helpers.GetFileExtension(Helpers.FileFormat.TVA)))
            {
                TVActor actor = core.Scene.CreateActor();
                actor.Load(fileName, true, false);
                mesh = actor.GetDeformedMesh();
                core.Scene.DestroyAllActors();
                IsAnimated = true;
            }
            else
            {
                return;
            }

            mesh.EnableFrustumCulling(true, true);
            mesh.ComputeNormals();
            mesh.ComputeBoundings();
            mesh.ComputeOctree();
            mesh.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
            mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ALPHA);
            mesh.SetAlphaTest(true);
            mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
            mesh.SetShadowCast(true, true);
            lightmapIdx = mesh.GetTextureEx((int)CONST_TV_LAYER.TV_LAYER_LIGHTMAP);

            textureScale = new UV(1.0f, 1.0f);

            LoadTextures();

            UniqueId = mesh.GetMeshName();
        }