9 ALNode::ALNode(aiNode* asNode,
SNode* pNode,
ALScene* alscene, std::vector<aiCamera*> camerasNames, std::vector<aiLight*> lightsNames)
11 mCameras = camerasNames;
12 mLights = lightsNames;
18 aiAnimation** anims = alscene->
getAiScene()->mAnimations;
19 for(
unsigned int n=0; n<alscene->
getAiScene()->mNumAnimations; ++n)
22 for(
unsigned int i=0; i<anims[n]->mNumChannels; ++i)
24 if(anims[n]->mChannels[i]->mNodeName == mOrigin->mName)
26 ALConverterNodeAnim nodeAnim(mScene, anims[n], anims[n]->mChannels[i], mOrigin, anims[n]->mTicksPerSecond);
27 mNodeAnim.push_back(nodeAnim);
36 mCameras = camerasNames;
37 mLights = lightsNames;
41 mParentNodeXml = xmlParent;
44 aiAnimation** anims = alscene->
getAiScene()->mAnimations;
45 for(
unsigned int n=0; n<alscene->
getAiScene()->mNumAnimations; ++n)
47 for(
unsigned int i=0; i<anims[n]->mNumChannels; ++i)
49 if(anims[n]->mChannels[i]->mNodeName == mOrigin->mName)
51 ALConverterNodeAnim nodeAnim(mScene, anims[n], anims[n]->mChannels[i], mOrigin, anims[n]->mTicksPerSecond);
52 mNodeAnim.push_back(nodeAnim);
65 float ALNode::processRange(aiLight* light)
71 light->mAttenuationConstant = 1.0f;
74 light->mAttenuationQuadratic = 0.000001f;
76 float range = (sqrt(4 * light->mAttenuationConstant * light->mAttenuationQuadratic + light->mAttenuationLinear + 4 * light->mAttenuationQuadratic) - light->mAttenuationLinear) / (2 * light->mAttenuationQuadratic);
82 float coef = (scale.x + scale.y + scale.z) / 3.0f;
97 std::string basename((mOrigin->mName).C_Str());
100 basename = boost::filesystem::path(basename).stem().generic_string();
103 if (basename.find(
"Ifc") != std::string::npos)
104 basename = basename.substr(0, basename.length() - 22);
118 for(
unsigned int n=0; n<mNodeAnim.size(); ++n)
120 if(mNodeAnim[n].isAffected(mOrigin->mName))
121 mNodeAnim[n].convert(xmlNode, (n == 0) ?
true :
false);
124 Ogre::Vector3 direction(Ogre::Vector3::UNIT_Z);
127 convertMesh(expPath, xmlNode);
132 for(
unsigned int n=0; n<mLights.size(); ++n)
134 if(mOrigin->mName == mLights[n]->mName)
142 throw "No light associated to this node.";
145 direction = Ogre::Vector3(cLight->mDirection.x, cLight->mDirection.y, cLight->mDirection.z);
148 if(cLight->mType == aiLightSource_POINT)
150 else if(cLight->mType == aiLightSource_SPOT)
155 xmlight->
SetAttribute(
"castShadows", (cLight->mType == aiLightSource_DIRECTIONAL) ?
true :
false);
176 if(cLight->mType == aiLightSource_SPOT)
190 for(
unsigned int n=0; n<mCameras.size(); ++n)
192 if(mOrigin->mName == mCameras[n]->mName)
194 cCamera = mCameras[n];
201 float fovY = cCamera->mHorizontalFOV * cCamera->mAspect;
202 Ogre::Radian gfovY(fovY);
205 gfovY = Ogre::Radian(3.14f / 4.0f);
220 aiMatrix4x4 transformation = mOrigin->mTransformation;
223 aiQuaternion rotation;
224 transformation.Decompose(scale, rotation, pos);
232 Ogre::Quaternion oRot(rotation.w, rotation.x, rotation.y, rotation.z);
234 oRot = oRot * Ogre::Quaternion(sqrt(0.5f), -sqrt(0.5f), 0.0f, 0.0f);
238 Ogre::Vector3 xaxis = Ogre::Vector3::UNIT_X * direction.x;
239 Ogre::Vector3 yaxis = Ogre::Vector3::UNIT_Y * direction.y;
240 Ogre::Vector3 zaxis = Ogre::Vector3::UNIT_Z * direction.z;
241 Ogre::Quaternion dirRotation(xaxis, yaxis, zaxis);
243 oRot = oRot * dirRotation;
273 std::string basename((mOrigin->mName).C_Str());
276 if (basename.find(
"Ifc") != std::string::npos)
277 basename = basename.substr(0, basename.length() - 22);
285 Ogre::Vector3 direction;
292 gudNode =
static_cast<SNode*
>(entity);
296 SLight* nlight = makeLight(mOrigin, direction);
297 gudNode =
static_cast<SNode*
>(nlight);
299 else if (!
isBone(mOrigin))
309 aiMatrix4x4 transformation = mOrigin->mTransformation;
312 aiQuaternion rotation;
314 transformation.Decompose(scale, rotation, pos);
315 Ogre::Vector3 oScale(scale.x, scale.y, scale.z);
316 Ogre::Vector3 oPos(pos.x, pos.y, pos.z);
318 Ogre::Quaternion oRot(rotation.w, rotation.x, rotation.y, rotation.z);
320 oRot = oRot * Ogre::Quaternion(sqrt(0.5f), -sqrt(0.5f), 0.0f, 0.0f);
327 for(
unsigned int n=0; n<mNodeAnim.size(); ++n)
329 if(mNodeAnim[n].isAffected(mOrigin->mName))
330 mNodeAnim[n].load(gudNode);
334 catch(Ogre::Exception&)
344 ALMesh meshConverter(mOrigin, mScene);
345 meshConverter.convert(expPath, nParent);
348 SEntity* ALNode::loadMesh()
350 ALMesh meshConverter(mOrigin, mScene);
351 SEntity* convertedMesh = meshConverter.load();
353 return convertedMesh;
358 return (node->mNumMeshes > 0) ? true :
false;
363 for(
unsigned int n=0; n<mCameras.size(); ++n)
365 if(node->mName == mCameras[n]->mName)
374 for(
unsigned int n=0; n<mLights.size(); ++n)
376 if(node->mName == mLights[n]->mName)
385 return mScene->
isBone(node);
393 SCamera* ALNode::makeCamera(aiNode* node)
396 for(
unsigned int n=0; n<mCameras.size(); ++n)
398 if(node->mName == mCameras[n]->mName)
400 cCamera = mCameras[n];
405 float fovY = cCamera->mHorizontalFOV * cCamera->mAspect;
406 Ogre::Radian gfovY(fovY);
409 gfovY = Ogre::Radian(3.14f / 4.0f);
413 scolCam->SetFarClipDistance(cCamera->mClipPlaneFar);
414 scolCam->SetNearClipDistance(cCamera->mClipPlaneNear);
415 scolCam->SetFOVy(gfovY.valueRadians());
416 scolCam->LookAt(Ogre::Vector3(cCamera->mLookAt.x, cCamera->mLookAt.y, cCamera->mLookAt.z),
SNode::SO3_WORLD_TS);
421 SLight* ALNode::makeLight(aiNode* node, Ogre::Vector3& direction)
424 for(
unsigned int n=0; n<mLights.size(); ++n)
426 if(node->mName == mLights[n]->mName)
434 throw "No light associated to this node.";
440 scolLight->SetDiffuseColour(Ogre::ColourValue(cLight->mColorDiffuse.r, cLight->mColorDiffuse.g, cLight->mColorDiffuse.b, 1.f));
441 scolLight->SetSpecularColour(Ogre::ColourValue(cLight->mColorSpecular.r, cLight->mColorSpecular.g, cLight->mColorSpecular.b, 1.f));
443 scolLight->SetDirection(Ogre::Vector3(cLight->mDirection.x, cLight->mDirection.y, cLight->mDirection.z));
445 if(cLight->mType == aiLightSource_SPOT)
447 else if(cLight->mType == aiLightSource_POINT)
449 else if(cLight->mType == aiLightSource_AREA)
454 scolLight->SetSourceSize(cLight->mSize.x, cLight->mSize.y);
455 scolLight->SetSpotlightInnerAngle(cLight->mAngleInnerCone);
456 scolLight->SetSpotlightOuterAngle(cLight->mAngleOuterCone);
static std::string curentUID()
return the current UID WITHOUT incrementing the UID.
static std::string cleanString(std::string str, bool toLower=true, bool clASCII=true, bool clSpaces=true, bool bUID=true)
Clean a string.
bool isMesh(aiNode *node)
Check if a node is a mesh.
ALNode(aiNode *asNode, SNode *pNode, ALScene *alscene, std::vector< aiCamera * > camerasNames, std::vector< aiLight * > lightsNames)
bool isSceneDependent(aiNode *node)
bool isCamera(aiNode *node)
Check if a node is a camera.
bool isBone(aiNode *node)
Check if a node is a bone.
bool isLight(aiNode *node)
Check if a node is a light.
tinyxml2::XMLElement * convert(boost::filesystem::path expPath)
aiMatrix4x4 getFullTransform(aiNode *toThis)
ALSceneLoader * GetSceneLoader()
bool isSceneDependent(aiNode *node)
const aiScene * getAiScene()
std::string getSceneName()
bool isBone(aiNode *node)
Check if a node is a bone.
std::string getRessourcePath()
void SetAutoAspectRatio(bool state)
void SetAttenuation(const float &range, const float &constant, const float &linear, const float &quadratic)
virtual void SetScale(const Ogre::Vector3 &scale)
virtual void SetOrientation(const Ogre::Quaternion &quat)
virtual void SetPosition(const Ogre::Vector3 &pos)
void AttachToParent(SNode *newParentNode)
SNode * CreateNodeWithUniqueName(const std::string &basename)
SLight * CreateLight(const std::string &newLightName)
SCamera * CreateCamera(const std::string &newCameraName)
XMLElement * NewElement(const char *name)
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
XMLNode * InsertFirstChild(XMLNode *addThis)
XMLNode * InsertEndChild(XMLNode *addThis)