示例#1
0
        protected override void OnCreateScene(Mesh[] meshes, MeshObject[] meshObjects,
                                              Light[] lights, ColorValue shadowColor, bool calculateShadows)
        {
            //create separated physics scene
            physicsScene = PhysicsWorld.Instance.CreateScene("Static Lighting");

            //initialize contact group
            physicsScene.SpecialContactGroupsEnabled = true;
            physicsScene.SetupSpecialContactGroups(1, 1, true);

            Dictionary <Mesh, string> meshPhysicsMeshNames = new Dictionary <Mesh, string>();

            //register physics custom mesh names
            foreach (Mesh mesh in meshes)
            {
                string customMeshName = PhysicsWorld.Instance.AddCustomMeshGeometry(
                    mesh.Positions, mesh.Indices, null, MeshShape.MeshTypes.TriangleMesh, 0, 0, false);

                meshPhysicsMeshNames.Add(mesh, customMeshName);
            }

            //create bodies
            foreach (MeshObject meshObject in meshObjects)
            {
                Body body = physicsScene.CreateBody();
                body.Static   = true;
                body.Position = meshObject.Position;
                body.Rotation = meshObject.Rotation;
                body.UserData = meshObject;

                MeshShape shape = body.CreateMeshShape();
                shape.ContactGroup = contactGroup;
                shape.MeshName     = meshPhysicsMeshNames[meshObject.Mesh];
                shape.MeshScale    = meshObject.Scale;

                body.PushedToWorld = true;
            }

            //lights
            {
                this.lights = new MyLight[lights.Length];
                for (int n = 0; n < lights.Length; n++)
                {
                    Light light = lights[n];

                    MyLight myLight = null;

                    PointLight pointLight = light as PointLight;
                    if (pointLight != null)
                    {
                        myLight = new MyPointLight(pointLight);
                    }

                    SpotLight spotLight = light as SpotLight;
                    if (spotLight != null)
                    {
                        myLight = new MySpotLight(spotLight);
                    }

                    DirectionalLight directionalLight = light as DirectionalLight;
                    if (directionalLight != null)
                    {
                        myLight = new MyDirectionalLight(directionalLight);
                    }

                    if (myLight == null)
                    {
                        Log.Fatal("SimpleStaticLightingCalculationWorld.OnCreateScene: not implemented light type.");
                    }

                    this.lights[n] = myLight;
                    this.lights[n].Initialize();
                }
            }

            this.shadowColor      = shadowColor;
            this.calculateShadows = calculateShadows;
        }
        protected override void OnCreateScene( Mesh[] meshes, MeshObject[] meshObjects,
			Light[] lights, ColorValue shadowColor, bool calculateShadows )
        {
            //create separated physics scene
            physicsScene = PhysicsWorld.Instance.CreateScene( "Static Lighting" );

            //initialize contact group
            physicsScene.SpecialContactGroupsEnabled = true;
            physicsScene.SetupSpecialContactGroups( 1, 1, true );

            Dictionary<Mesh, string> meshPhysicsMeshNames = new Dictionary<Mesh, string>();

            //register physics custom mesh names
            foreach( Mesh mesh in meshes )
            {
                string customMeshName = PhysicsWorld.Instance.AddCustomMeshGeometry(
                    mesh.Positions, mesh.Indices, null, MeshShape.MeshTypes.TriangleMesh, 0, 0 );

                meshPhysicsMeshNames.Add( mesh, customMeshName );
            }

            //create bodies
            foreach( MeshObject meshObject in meshObjects )
            {
                Body body = physicsScene.CreateBody();
                body.Static = true;
                body.Position = meshObject.Position;
                body.Rotation = meshObject.Rotation;
                body.UserData = meshObject;

                MeshShape shape = body.CreateMeshShape();
                shape.ContactGroup = contactGroup;
                shape.MeshName = meshPhysicsMeshNames[ meshObject.Mesh ];
                shape.MeshScale = meshObject.Scale;

                body.PushedToWorld = true;
            }

            //lights
            {
                this.lights = new MyLight[ lights.Length ];
                for( int n = 0; n < lights.Length; n++ )
                {
                    Light light = lights[ n ];

                    MyLight myLight = null;

                    PointLight pointLight = light as PointLight;
                    if( pointLight != null )
                        myLight = new MyPointLight( pointLight );

                    SpotLight spotLight = light as SpotLight;
                    if( spotLight != null )
                        myLight = new MySpotLight( spotLight );

                    DirectionalLight directionalLight = light as DirectionalLight;
                    if( directionalLight != null )
                        myLight = new MyDirectionalLight( directionalLight );

                    if( myLight == null )
                        Log.Fatal( "SimpleStaticLightingCalculationWorld.OnCreateScene: not implemented light type." );

                    this.lights[ n ] = myLight;
                    this.lights[ n ].Initialize();
                }
            }

            this.shadowColor = shadowColor;
            this.calculateShadows = calculateShadows;
        }