Exemple #1
0
        public override void Initialize()
        {
            mesh = Scene.CreateMeshBuilder();

            switch (Helpers.GetFileFormat(FileName))
            {
            case Helpers.FileFormat.TVM:
                mesh.LoadTVM(FileName, true, false);
                break;

            case Helpers.FileFormat.X:
                mesh.LoadXFile(FileName, true, false);
                break;
            }

            if (Visible)
            {
                mesh.EnableFrustumCulling(true, true);
                mesh.ComputeNormals();
                mesh.ComputeBoundings();
                mesh.ComputeOctree();
                mesh.SetAlphaTest(true);
                mesh.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
                mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ALPHA);
                mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
                mesh.SetShadowCast(true, true);

                mesh.SetPosition(Position.x, Position.y, Position.z);
                mesh.SetRotation(Rotation.x, Rotation.y, Rotation.z);
                mesh.SetScale(Scale.x, Scale.y, Scale.z);

                // Physics
                SetPhysics();
            }
            else
            {
                // Hide mesh.
                for (var i = 0; i < mesh.GetGroupCount(); i++)
                {
                    mesh.SetGroupEnable(i, false);
                }
            }

            // Register object in Lua.
            ScriptManager.SetGlobal(Name, this);
        }
        //Inicializace a vytvoreni mistnosti
        private void VyvorMistnost()
        {
            //Inicializace mistnosti
            Room = Scene.CreateMeshBuilder("RoomMesh");

            //Nacteni textur
            VytvorTextury();

            //Pridani sten a nastaveni pozice mistnosti
            Room.AddWall3D(Globals.GetTex("Wall"), 150.0f, -350.0f, -350.0f, -350.0f, 350.0f, 5.0f, false, false, -50.0f, 5.0f, 5.0f);
            Room.AddWall3D(Globals.GetTex("Wall"), -350.0f, -350.0f, -350.0f, 150.0f, 350.0f, 5.0f, false, false, -50.0f, 5.0f, 5.0f);
            Room.AddWall3D(Globals.GetTex("Wall"), -350.0f, 150.0f, 150.0f, 150.0f, 350.0f, 5.0f, false, false, -50.0f, 5.0f, 5.0f);
            Room.AddWall3D(Globals.GetTex("Wall"), 150.0f, 150.0f, 150.0f, -350.0f, 350.0f, 5.0f, false, false, -50.0f, 5.0f, 5.0f);
            Room.AddFloor(Globals.GetTex("Floor"), -350.0f, -350f, 150.0f, 150.0f, -50.0f, 20.0f, 20.0f, true);
            Room.AddFloor(Globals.GetTex("Floor"), -350.0f, -350.0f, 150.0f, 150.0f, 300.0f, 10.0f, 10.0f, true);
            Room.SetPosition((float)30.0f, (float)-30.0f, (float)150.0f);

            //Pridani stolku
            Obj1 = new TVMesh();
            Obj1 = Scene.CreateMeshBuilder("Obj1");
            Obj1.LoadXFile("Meshe\\stul.x", true, true);
            Obj1.SetPosition(-57.0f, -80.0f, 38.0f);
            Obj1.SetTexture(Globals.GetTex("Wood"), -1);
            Obj1.SetMeshName("other");

            Obj2 = new TVMesh();
            Obj2 = Scene.CreateMeshBuilder("Obj2");
            Obj2.LoadXFile("Meshe\\okraj.x", true, true);
            Obj2.SetPosition(xc + 17.5f, yc - 1.0f, zc + 17.5f);
            Obj2.SetTexture(Globals.GetTex("Wood2"), -1);
            Obj2.SetMeshName("other");
        }
Exemple #3
0
        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();
        }
Exemple #4
0
        public override void Initialize()
        {
            mesh = Scene.CreateMeshBuilder();

            switch (Helpers.GetFileFormat(FileName))
            {
                case Helpers.FileFormat.TVM:
                    mesh.LoadTVM(FileName, true, false);
                    break;
                case Helpers.FileFormat.X:
                    mesh.LoadXFile(FileName, true, false);
                    break;
            }

            if (Visible)
            {
                mesh.EnableFrustumCulling(true, true);
                mesh.ComputeNormals();
                mesh.ComputeBoundings();
                mesh.ComputeOctree();
                mesh.SetAlphaTest(true);
                mesh.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
                mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ALPHA);
                mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
                mesh.SetShadowCast(true, true);

                mesh.SetPosition(Position.x, Position.y, Position.z);
                mesh.SetRotation(Rotation.x, Rotation.y, Rotation.z);
                mesh.SetScale(Scale.x, Scale.y, Scale.z);

                // Physics
                SetPhysics();
            }
            else
            {
                // Hide mesh.
                for (var i = 0; i < mesh.GetGroupCount(); i++)
                    mesh.SetGroupEnable(i, false);
            }

            // Register object in Lua.
            ScriptManager.SetGlobal(Name, this);
        }
        //*** Render Method
        private void SetupScene(IntPtr hWnd)
        {
            TV_3DVECTOR Min = new TV_3DVECTOR();
            TV_3DVECTOR Max = new TV_3DVECTOR();
            TV_3DVECTOR Offset = new TV_3DVECTOR();
            TV_3DVECTOR SphereCenter = new TV_3DVECTOR();
            TV_3DVECTOR posVector = new TV_3DVECTOR();

            TV = new TVEngine();
            Scene = new TVScene();
            Cam = new TVCamera();
            TF = new TVTextureFactory();
            Mats = new TVMaterialFactory();
            Lights = new TVLightEngine();
            Maths = new TVMathLibrary();

            //Initialize the TV engine
            TV.SetDebugFile(Application.StartupPath + "\\debug.txt");
            TV.Init3DWindowed(hWnd, true);
            TV.SetSearchDirectory(Application.StartupPath);
            TV.SetAngleSystem(CONST_TV_ANGLE.TV_ANGLE_DEGREE);  // use degree system

            Scene.SetBackgroundColor(0.6f, 0.6f, 0.6f);

            //Load the texture into the integer ID holder
            FloorTex = TF.LoadTexture("smallGrid.bmp", "Grid", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            WallTex = TF.LoadTexture("smallGridWall.bmp", "Wall", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);

            Room = Scene.CreateMeshBuilder("Room");
            Room.AddFloor(FloorTex, -300.0f, -300.0f, 300.0f, 300.0f, 0, 15.0f, 15.0f, true);
            Room.AddWall(WallTex, -300.0f, 300.0f, 300.0f, 300.0f, 400.0f, 0, 15.0f, 15.0f, true);
            Room.AddWall(WallTex, 300.0f, -300.0f, -300.0f, -300.0f, 400.0f, 0, 15.0f, 15.0f, true);
            Room.AddWall(WallTex, 300.0f, 300.0f, 300.0f, -300.0f, 400.0f, 0, 15.0f, 15.0f, true);
            Room.AddWall(WallTex, -300.0f, -300.0f, -300.0f, 300.0f, 400.0f, 0, 15.0f, 15.0f, true);
            //ShowVector("RoomLocal", Room.GetPosition());
            //ShowVector("RoomWorld", Room.GetWorldPosition(Room.GetPosition()));

            SensorNode = Scene.CreateMeshBuilder("SensorNode");
            SensorNode.LoadXFile("N70.X", true, true);
            SensorNode.SetParent(CONST_TV_NODETYPE.TV_NODETYPE_MESH, Room.GetIndex(), 1);
            SensorNode.SetPosition(0.0f, 150.0f, 0.0f);
            TV_3DVECTOR oriScale = SensorNode.GetScale();
            SensorNode.SetScale(oriScale.x, oriScale.y, oriScale.z * 1.5f);
            SensorNode.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_NORMAL, 0, 1);
            SensorNode.SetRotation(90.0f, 0.0f, 0.0f);
            //SensorNode.GetBoundingBox(ref Min, ref Max, true);
            //SensorNode.ShowBoundingBox(true);
            //ShowVector("MoteLocal", SensorNode.GetPosition());
            //ShowVector("MoteWorld", Room.GetWorldPosition(SensorNode.GetPosition()));

            //WiimoteMesh = Scene.CreateMeshBuilder("Wiimote");
            //WiimoteMesh.LoadXFile("Wiimote.X", true, true);
            //TV_3DVECTOR oriScale = WiimoteMesh.GetScale();
            //WiimoteMesh.SetScale(oriScale.x * 0.15f, oriScale.y * 0.15f, oriScale.z * 0.15f);
            //WiimoteMesh.SetPosition(0.0f, 70.0f, 0.0f);
            //WiimoteMesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_NORMAL, 0, 1);//Tell TV we want normal, per-vertex, lighting with 1 point light.

            Cam.SetParent(CONST_TV_NODETYPE.TV_NODETYPE_MESH, Room.GetIndex(), 0);
            Cam.SetPosition(0.0f, 250.0f, 200.0f);
            Cam.LookAtMesh(SensorNode);
            //ShowVector("CamLocal", Cam.GetPosition());
            //ShowVector("CamWorld", Room.GetWorldPosition(Cam.GetPosition()));

            //Create a point light. Again, these can be more complex.
            IDLight = Lights.CreatePointLight(new TV_3DVECTOR(0.0f, 250.0f, 200.0f), 0.9f, 0.9f, 0.9f, 250.0f);
            IDBackLight = Lights.CreatePointLight(new TV_3DVECTOR(0.0f, 250.0f, -200.0f), 0.1f, 0.1f, 0.1f, 250.0f);
            Lights.SetSpecularLighting(false);
        }
Exemple #6
0
        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();
        }