Changeset 2388 for GTP/trunk/App/Demos/Illum/Ogre/src/Common
- Timestamp:
- 05/21/07 12:35:33 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Illum/Ogre/src/Common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/src/Common/include/SceneSerializer.h
r2186 r2388 1 1 #include "Ogre.h" 2 3 #ifdef NXOGRE 4 #include "NXOgre.h" 5 using namespace NxOgre; 6 #endif 2 7 3 8 using namespace Ogre; … … 22 27 SceneNode* sceneNode; 23 28 std::map<String, String> meshFiles; 24 std::map<String, unsigned int> pathMapResolutions; 29 std::map<String, unsigned int> pathMapResolutions; 30 31 #ifdef NXOGRE 32 std::map<String, String> meshPhysXShapes; 33 std::map<String, String> meshPhysXShapeParams; 34 //float physXMass; 35 //float physXDensity; 36 //bool physXKinematic; 37 //bool physXStatic; 38 Scene* scene; 39 World* world; 40 Body* physXBody; 41 #endif 25 42 }; 26 43 … … 54 71 void parseEntryPoints(String filename); 55 72 73 #ifdef NXOGRE 74 public: 75 void setScene(Scene* scene){mScriptContext.scene = scene;} 76 void setWorld(World* world){mScriptContext.world = world;} 77 78 #endif 79 56 80 }; -
GTP/trunk/App/Demos/Illum/Ogre/src/Common/src/SceneSerializer.cpp
r2367 r2388 1 #include "OgreIlluminationManager.h" 1 2 #include "SceneSerializer.h" 2 #include "OgreIlluminationManager.h"3 3 4 4 void logParseError(const String& error, const SceneScriptContext& context) … … 20 20 } 21 21 22 #ifdef NXOGRE 23 ShapeDescription* createShape(String params) 24 { 25 std::vector<String> parameters = StringUtil::split(params); 26 27 ShapeDescription* s = 0; 28 if(parameters[0] == "cube") 29 s = new CubeShape(StringConverter::parseReal(parameters[1]),//width 30 StringConverter::parseReal(parameters[2]),//height 31 StringConverter::parseReal(parameters[3]));//depth 32 else if(parameters[0] == "sphere") 33 s = new SphereShape(StringConverter::parseReal(parameters[1]));//radius 34 else if(parameters[0] == "capsule") 35 s = new CapsuleShape(StringConverter::parseReal(parameters[1]),//radius 36 StringConverter::parseReal(parameters[2]));//height 37 else if(parameters[0] == "convex_mesh") 38 s = new ConvexShape(parameters[1]);//mesh name 39 else if(parameters[0] == "free_mesh") 40 s = new MeshShape(parameters[1]);//mesh name 41 42 return s; 43 } 44 #endif 45 22 46 bool parseMeshName(String& params, SceneScriptContext& context) 23 47 { … … 27 51 //create the Entity with the given mesh, attach to a scene node 28 52 StringUtil::trim(params); 29 String meshfilename = context.meshFiles[params]; 53 String meshfilename = ""; 54 if(context.meshFiles.count(params) != 0) 55 meshfilename = context.meshFiles[params]; 30 56 context.meshName = params; 57 58 #ifdef NXOGRE 59 if(context.meshPhysXShapes.count(context.meshName) != 0) 60 { 61 ShapeDescription *newShape = createShape(context.meshPhysXShapes[context.meshName]); 62 //LogManager::getSingleton().logMessage("meshname: " + meshfilename); 63 context.physXBody = context.scene->createBody(context.entityName, meshfilename, newShape, Vector3(0,0,0), context.meshPhysXShapeParams[context.meshName]); 64 context.entity = context.physXBody->getEntity(); 65 context.sceneNode = context.physXBody->getNode(); 66 } 67 else 68 { 69 context.entity = context.sceneManager->createEntity(context.entityName, meshfilename); 70 SceneNode* root = context.sceneManager->getRootSceneNode(); 71 context.sceneNode = root->createChildSceneNode(context.entityName); 72 context.sceneNode->attachObject(context.entity); 73 } 74 #else 31 75 context.entity = context.sceneManager->createEntity(context.entityName, meshfilename); 32 76 SceneNode* root = context.sceneManager->getRootSceneNode(); 33 77 context.sceneNode = root->createChildSceneNode(context.entityName); 34 context.sceneNode->attachObject(context.entity); 35 context.entity->setCastShadows(true); 78 context.sceneNode->attachObject(context.entity); 79 #endif 36 80 return false; 37 81 } … … 42 86 logParseError("No clusters given!", context); 43 87 44 //create the Entity with the given mesh, attach to a scene node45 88 std::vector<String> parameters = StringUtil::split(params); 46 89 String subentityname = context.entityName + "_SE_" + parameters[0]; … … 57 100 } 58 101 102 bool parseCastShadows(String& params, SceneScriptContext& context) 103 { 104 context.entity->setCastShadows(StringConverter::parseBool(params)); 105 106 return false; 107 } 108 109 #ifdef NXOGRE 110 bool parsePhysXShape(String& params, SceneScriptContext& context) 111 { 112 context.meshPhysXShapes[context.meshName] = params; 113 114 return false; 115 } 116 117 bool parsePhysXMass(String& params, SceneScriptContext& context) 118 { 119 if(context.meshPhysXShapeParams.count(context.meshName) == 0) 120 context.meshPhysXShapeParams[context.meshName] = ""; 121 122 context.meshPhysXShapeParams[context.meshName] += "mass: " + params + ","; 123 124 return false; 125 } 126 127 bool parsePhysXDensity(String& params, SceneScriptContext& context) 128 { 129 if(context.meshPhysXShapeParams.count(context.meshName) == 0) 130 context.meshPhysXShapeParams[context.meshName] = ""; 131 132 context.meshPhysXShapeParams[context.meshName] += "density: " + params + ","; 133 134 return false; 135 } 136 137 bool parsePhysXKinematic(String& params, SceneScriptContext& context) 138 { 139 if(context.meshPhysXShapeParams.count(context.meshName) == 0) 140 context.meshPhysXShapeParams[context.meshName] = ""; 141 142 context.meshPhysXShapeParams[context.meshName] += "kinematic: " + params + ","; 143 144 return false; 145 } 146 147 bool parsePhysXStatic(String& params, SceneScriptContext& context) 148 { 149 if(context.meshPhysXShapeParams.count(context.meshName) == 0) 150 context.meshPhysXShapeParams[context.meshName] = ""; 151 152 context.meshPhysXShapeParams[context.meshName] += "static: " + params + ","; 153 154 return false; 155 } 156 157 #endif 158 59 159 bool parseTransform(String& params, SceneScriptContext& context) 60 160 { 61 161 Matrix4 transformMatrix = StringConverter::parseMatrix4(params); 62 context.sceneNode->setOrientation(transformMatrix.extractQuaternion());63 162 64 163 Vector4 x(1,0,0,0); … … 68 167 Vector4 z(0,0,1,0); 69 168 z = transformMatrix * z; 169 170 #ifdef NXOGRE 171 if(context.meshPhysXShapes.count(context.meshName) != 0) 172 { 173 context.sceneNode->scale((Vector3(x.x,x.y,x.z)).length(), 174 (Vector3(y.x,y.y,y.z)).length(), 175 (Vector3(z.x,z.y,z.z)).length()); 176 context.physXBody->setGlobalOrientation(transformMatrix.extractQuaternion()); 177 context.physXBody->setGlobalPosition(transformMatrix.getTrans()); 178 } 179 else 180 { 181 context.sceneNode->setOrientation(transformMatrix.extractQuaternion()); 182 context.sceneNode->scale((Vector3(x.x,x.y,x.z)).length(), 183 (Vector3(y.x,y.y,y.z)).length(), 184 (Vector3(z.x,z.y,z.z)).length()); 185 context.sceneNode->translate(transformMatrix.getTrans()); 186 } 187 #else 188 context.sceneNode->setOrientation(transformMatrix.extractQuaternion()); 70 189 context.sceneNode->scale((Vector3(x.x,x.y,x.z)).length(), 71 190 (Vector3(y.x,y.y,y.z)).length(), 72 191 (Vector3(z.x,z.y,z.z)).length()); 73 192 context.sceneNode->translate(transformMatrix.getTrans()); 193 #endif 74 194 75 195 return false; … … 125 245 mEntityAttribParsers.insert(AttribParserList::value_type("subentity", (SCENE_ATTRIBUTE_PARSER)parseClusters)); 126 246 mEntityAttribParsers.insert(AttribParserList::value_type("pathmapfile", (SCENE_ATTRIBUTE_PARSER)parsePRMMapName)); 127 247 mEntityAttribParsers.insert(AttribParserList::value_type("castShadows", (SCENE_ATTRIBUTE_PARSER)parseCastShadows)); 248 249 #ifdef NXOGRE 250 mMeshAttribParsers.insert(AttribParserList::value_type("physXShape", (SCENE_ATTRIBUTE_PARSER)parsePhysXShape)); 251 mMeshAttribParsers.insert(AttribParserList::value_type("physXMass", (SCENE_ATTRIBUTE_PARSER)parsePhysXMass)); 252 mMeshAttribParsers.insert(AttribParserList::value_type("physXDensity", (SCENE_ATTRIBUTE_PARSER)parsePhysXDensity)); 253 mMeshAttribParsers.insert(AttribParserList::value_type("physXKinematic", (SCENE_ATTRIBUTE_PARSER)parsePhysXKinematic)); 254 mMeshAttribParsers.insert(AttribParserList::value_type("physXStatic", (SCENE_ATTRIBUTE_PARSER)parsePhysXStatic)); 255 #endif 128 256 } 129 257
Note: See TracChangeset
for help on using the changeset viewer.