Просмотр исходного кода

Modified character sample to test support for non-flat terrain in PhysicsCharacter.

Ken Whatmough 12 лет назад
Родитель
Сommit
94ae6f9ede

+ 27 - 2
samples/character/res/common/sample.scene

@@ -124,7 +124,7 @@ scene
     node wallnorth
     {
         material = res/common/sample.material#wallnorth
-        collisionObject = res/common/sample.physics#staticBox
+        collisionObject = res/common/sample.physics#staticMesh
     }
 
     node wallsouth
@@ -153,7 +153,7 @@ scene
     node doorframe
     {
         material = res/common/sample.material#doorframe
-        collisionObject = res/common/sample.physics#staticBox
+        collisionObject = res/common/sample.physics#staticMesh
     }
 
     node bookshelf
@@ -200,6 +200,31 @@ scene
         collisionObject = res/common/sample.physics#staticBox
     }
 
+	node terrain
+	{
+		terrain = res/common/terrain/sample.terrain
+
+        translate = -2500,-430,2500
+
+		collisionObject
+		{
+			type = RIGID_BODY
+			shape = HEIGHTFIELD
+			mass = 0
+			kinematic = true
+		}
+	}
+
+    node sky
+    {
+        url = res/common/terrain/sky.gpb#sphere
+
+        material = res/common/terrain/sky.material
+
+        scale = 30000,30000,30000
+        translate = 0,25000,0
+    }
+
     physics
     {
         // TODO: Fixme Gravity is set to 3x normal gravity to compenate for larger scale of scene. Bug

BIN
samples/character/res/common/terrain/dirt.dds


+ 19 - 0
samples/character/res/common/terrain/encode.bat

@@ -0,0 +1,19 @@
+@echo off
+
+set encoder="..\..\..\..\bin\windows\gameplay-encoder.exe"
+
+REM ====================================================================
+REM Generate sky model
+REM ====================================================================
+%encoder% sky.fbx
+
+REM ====================================================================
+REM Generate normal map for terrain.
+REM NOTE: Encoder currently expects a .raw format, so temporarily rename
+REM .r16 to .raw for normal map generation.
+REM ====================================================================
+copy /Y heightmap.r16 heightmap.raw
+%encoder% -n -w 10000,4000,10000 -s 256,256 heightmap.raw normalmap.png
+del /Q heightmap.raw
+
+pause

BIN
samples/character/res/common/terrain/grass.dds


BIN
samples/character/res/common/terrain/heightmap.r16


BIN
samples/character/res/common/terrain/normalmap.dds


BIN
samples/character/res/common/terrain/rock.dds


+ 66 - 0
samples/character/res/common/terrain/sample.scene

@@ -0,0 +1,66 @@
+scene terrainSampleScene
+{
+	node terrain
+	{
+		terrain = res/common/terrain/sample.terrain
+
+		collisionObject
+		{
+			type = RIGID_BODY
+			shape = HEIGHTFIELD
+			mass = 0
+			kinematic = true
+		}
+	}
+
+    node sky
+    {
+        url = res/common/terrain/sky.gpb#sphere
+
+        material = res/common/terrain/sky.material
+
+        scale = 30000,30000,30000
+        translate = 0,25000,0
+    }
+
+    node directionalLight
+    {
+        light
+        {
+            type = DIRECTIONAL
+            color = 1,1,1
+        }
+
+        rotate = 1,0,0, -45
+    }
+
+	node camera
+	{
+		camera
+		{
+			type = PERSPECTIVE
+			nearPlane = 1.0
+			farPlane = 100000
+		}
+
+        // Starting position on ground
+		translate = 3095, 369, -4393
+		rotate = 0,1,0, 148
+
+        // Screenshot position in air (screenshots)
+        //translate = 3824, 1466, -3622
+        //rotate = 0, 1.0, 0, 142
+	}
+
+	// Basic scene lighting properties
+	ambientColor = 0.2, 0.2, 0.2
+
+	// Set active camera
+	activeCamera = camera
+
+    physics
+    {
+        // Bump up gravity force for this sample since our units are larger than normal
+        gravity = 0, -90, 0
+    }
+}

+ 56 - 0
samples/character/res/common/terrain/sample.terrain

@@ -0,0 +1,56 @@
+terrain
+{
+    material = res/common/terrain/terrain.material
+
+	heightmap
+	{
+		path = res/common/terrain/heightmap.r16
+		size = 256, 256
+	}
+
+	size = 10000, 4000, 10000
+	patchSize = 32
+	detailLevels = 3
+	skirtScale = 0.1
+
+    normalMap = res/common/terrain/normalmap.dds
+
+	layer rock
+	{
+		texture
+		{
+			path = res/common/terrain/rock.dds
+			repeat = 30,30
+		}
+	}
+
+    layer dirt
+    {
+		texture
+		{
+			path = res/common/terrain/dirt.dds
+			repeat = 750,750
+		}
+
+		blend
+		{
+            path = res/common/terrain/dirt.dds
+            channel = 3
+		}
+    }
+
+    layer grass
+	{
+		texture
+		{
+			path = res/common/terrain/grass.dds
+			repeat = 500,500
+		}
+
+		blend
+		{
+            path = res/common/terrain/grass.dds
+            channel = 3
+		}
+	}
+}

+ 50 - 0
samples/character/res/common/terrain/shapes.material

@@ -0,0 +1,50 @@
+material textured
+{
+    u_worldViewProjectionMatrix = WORLD_VIEW_PROJECTION_MATRIX
+    u_inverseTransposeWorldViewMatrix = INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX
+
+    u_ambientColor = SCENE_AMBIENT_COLOR
+    u_directionalLightDirection[0] = LIGHT_DIRECTION_0
+    u_directionalLightColor[0] = LIGHT_COLOR_0
+
+    sampler u_diffuseTexture
+    {
+        mipmap = true
+        wrapS = CLAMP
+        wrapT = CLAMP
+        minFilter = LINEAR_MIPMAP_LINEAR
+        magFilter = LINEAR
+    }
+
+    renderState
+    {
+        cullFace = true
+        depthTest = true
+    }
+
+    technique
+    {
+        pass
+        {
+            vertexShader = res/shaders/textured.vert
+            fragmentShader = res/shaders/textured.frag
+            defines = DIRECTIONAL_LIGHT_COUNT 1
+        }
+    }
+}
+
+material sphere : textured
+{
+    sampler u_diffuseTexture
+    {
+        path = res/png/dirt.png
+    }
+}
+
+material box : textured
+{
+    sampler u_diffuseTexture
+    {
+        path = res/png/crate.png
+    }
+}

BIN
samples/character/res/common/terrain/sky.dds


Разница между файлами не показана из-за своего большого размера
+ 286 - 0
samples/character/res/common/terrain/sky.fbx


BIN
samples/character/res/common/terrain/sky.gpb


+ 29 - 0
samples/character/res/common/terrain/sky.material

@@ -0,0 +1,29 @@
+material sky
+{
+    u_worldViewProjectionMatrix = WORLD_VIEW_PROJECTION_MATRIX
+
+    sampler u_diffuseTexture
+    {
+        path = res/common/terrain/sky.dds
+        mipmap = true
+        wrapS = REPEAT
+        wrapT = REPEAT
+        minFilter = LINEAR_MIPMAP_LINEAR
+        magFilter = LINEAR
+    }
+
+    renderState
+    {
+        cullFace = true
+        depthTest = true
+    }
+
+    technique
+    {
+        pass
+        {
+            vertexShader = res/shaders/textured.vert
+            fragmentShader = res/shaders/textured.frag
+        }
+    }
+}

+ 154 - 0
samples/character/res/common/terrain/terrain.form

@@ -0,0 +1,154 @@
+form terrainForm
+{
+    theme = res/common/default.theme
+
+    style = Container
+    autoWidth = true
+    autoHeight = true
+    consumeInputEvents = false
+
+    padding
+    {
+        left = 5
+        top = 5
+        right = 50
+        bottom = 5
+    }
+
+    container main
+    {
+        style = Form
+        width = 230
+        height = 395
+        consumeInputEvents = false
+
+        padding
+        {
+            top = -5
+            left = -5
+        }
+
+        button plusButton
+        {
+            style = plus
+            width = 40
+            height = 40
+            visible = false
+        }
+
+        button minusButton
+        {
+            style = minus
+            width = 40
+            height = 40
+        }
+
+        container settings
+        {
+            autoWidth = true
+            autoHeight = true
+            consumeInputEvents = false
+
+            checkbox wireframe
+		    {
+			    imageSize = 35, 35
+			    size = 200, 40
+                position = 10, 50
+			    text = Wireframe (1)
+                textAlignment = ALIGN_VCENTER_LEFT
+                fontSize = 16
+                checked = false
+		    }
+
+            checkbox patches : wireframe
+		    {
+                position = 10, 90
+			    text = Debug Patches (2)
+                checked = false
+		    }
+
+            checkbox physics : wireframe
+            {
+                position = 10, 130
+			    text = Debug Physics (3)
+                checked = false
+            }
+
+            checkbox lod : wireframe
+		    {
+                position = 10, 170
+			    text = Level of Detail (4)
+                checked = true
+		    }
+
+            checkbox culling : wireframe
+		    {
+                position = 10, 210
+			    text = Frustum Culling (5)
+                checked = true
+		    }
+
+            checkbox snapToGround : wireframe
+		    {
+                position = 10, 250
+			    text = Snap To Ground (6)
+                checked = true
+		    }
+        }
+    }
+
+    container physicsSettings
+    {
+        style = Form
+        position = 0, 395
+        width = 230
+        height = 165
+        layout = LAYOUT_VERTICAL
+        consumeInputEvents = false
+
+        padding
+        {
+            top = 5
+            left = 5
+            right = 5
+            bottom = 5
+        }
+
+        button dropSphere
+        {
+            autoWidth = true
+            text = Drop Sphere
+            height = 45
+        }
+
+        button dropBox : dropSphere
+        {
+            text = Drop Box
+        }
+
+        button clearAll : dropSphere
+        {
+            text = Remove All
+        }
+    }
+
+    container messageBox
+    {
+        style = Form
+        alignment = ALIGN_VCENTER_HCENTER
+        width = 500
+        height = 50
+        consumeInputEvents = false
+        visible = false
+
+        label message
+        {
+            consumeInputEvents = false
+            autoWidth = true
+            autoHeight = true
+            font = res/ui/arial.gpb
+            fontSize = 24
+            textAlignment = ALIGN_VCENTER_HCENTER
+        }
+    }
+}

+ 29 - 0
samples/character/res/common/terrain/terrain.material

@@ -0,0 +1,29 @@
+
+material terrain
+{
+    u_worldViewProjectionMatrix = WORLD_VIEW_PROJECTION_MATRIX
+
+    u_normalMatrix = INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX
+    u_normalMap = TERRAIN_NORMAL_MAP
+    u_surfaceLayerMaps = TERRAIN_LAYER_MAPS
+
+    u_ambientColor = SCENE_AMBIENT_COLOR
+    u_directionalLightDirection[0] = LIGHT_DIRECTION_0
+    u_directionalLightColor[0] = LIGHT_COLOR_0
+
+    renderState
+    {
+        cullFace = true
+        depthTest = true
+    }
+
+    technique
+    {
+        pass
+        {
+            vertexShader = res/shaders/terrain.vert
+            fragmentShader = res/shaders/terrain.frag
+            defines = DIRECTIONAL_LIGHT_COUNT 1
+        }
+    }
+}

+ 10 - 4
samples/character/src/CharacterGame.cpp

@@ -58,6 +58,8 @@ void CharacterGame::initialize()
     rbParams.angularDamping = 0.16f;
     ceiling->setCollisionObject(PhysicsCollisionObject::RIGID_BODY, PhysicsCollisionShape::box(Vector3(49.5f, 1.0f, 49.5f)), &rbParams);
 
+    _scene->removeNode(_scene->findNode("door"));
+
     // Initialize scene.
     _scene->visit(this, &CharacterGame::initializeScene);
 
@@ -96,6 +98,7 @@ void CharacterGame::initializeCharacter()
     
     // Store the physics character object.
     _character = static_cast<PhysicsCharacter*>(node->getCollisionObject());
+    _character->setMaxSlopeAngle(20.0f);
     
     // Store character nodes.
     _characterNode = node->findNode("boyScale");
@@ -146,7 +149,14 @@ void CharacterGame::drawSplash(void* param)
 bool CharacterGame::drawScene(Node* node, bool transparent)
 {
     if (node->getModel() && (transparent == node->hasTag("transparent")))
+    {
         node->getModel()->draw(_wireframe);
+    }
+    else if (node->getTerrain())
+    {
+        Terrain* terrain = node->getTerrain();
+        terrain->draw(_wireframe);
+    }
 
     return true;
 }
@@ -636,8 +646,6 @@ void CharacterGame::grabBall()
     Node* boy = _character->getNode();
     boy->setCollisionObject(PhysicsCollisionObject::CHARACTER, PhysicsCollisionShape::capsule(2.9f, 6.0f, Vector3(0.0f, 3.0f, 0.0f), true), &rbParams);
     _character = static_cast<PhysicsCharacter*>(boy->getCollisionObject());
-    _character->setMaxSlopeAngle(0.0f);
-    _character->setMaxStepHeight(0.0f);
     _character->setVelocity(currentVelocity);
 }
 
@@ -651,8 +659,6 @@ void CharacterGame::releaseBall()
     boy->setCollisionObject(PhysicsCollisionObject::CHARACTER, PhysicsCollisionShape::capsule(1.2f, 6.0f, Vector3(0.0f, 3.0f, 0.0f), true), &rbParams);
     _character = static_cast<PhysicsCharacter*>(boy->getCollisionObject());
     _character->setVelocity(velocity);
-    _character->setMaxSlopeAngle(0.0f);
-    _character->setMaxStepHeight(0.0f);
     
     PhysicsRigidBody* basketball = (PhysicsRigidBody*) _basketballNode->getCollisionObject();
     basketball->setEnabled(true);

Некоторые файлы не были показаны из-за большого количества измененных файлов