Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.hpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.hpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.hpp (revision 24247) @@ -1,93 +1,93 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -// -// FCDEffectParameterT -// - -template -FCDEffectParameterT::~FCDEffectParameterT() -{ -} - -template -bool FCDEffectParameterT::IsValueEqual(FCDEffectParameter* parameter) -{ - if (!FCDEffectParameter::IsValueEqual(parameter)) return false; - FCDEffectParameterT* param = (FCDEffectParameterT*) parameter; - return IsEquivalent(value, param->GetValue()); -} - -template -FCDEffectParameter* FCDEffectParameterT::Clone(FCDEffectParameter* _clone) const -{ - FCDEffectParameterT* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDEffectParameterT(const_cast(GetDocument())); - else if (_clone->HasType(FCDEffectParameterT::GetClassType())) clone = (FCDEffectParameterT*) _clone; - - if (_clone != NULL) FCDEffectParameter::Clone(_clone); - if (clone != NULL) clone->value = *value; - return _clone; -} - -template -void FCDEffectParameterT::Overwrite(FCDEffectParameter* target) -{ - if (target->GetType() == GetType()) - { - FCDEffectParameterT* s = (FCDEffectParameterT*) target; - s->value = value; - SetDirtyFlag(); - } -} - -// -// FCDEffectParameterAnimatableT -// - -template -FCDEffectParameterAnimatableT::~FCDEffectParameterAnimatableT() -{ -} - -template -bool FCDEffectParameterAnimatableT::IsValueEqual(FCDEffectParameter* parameter) -{ - if (!FCDEffectParameter::IsValueEqual(parameter)) return false; - FCDEffectParameterAnimatableT* param = (FCDEffectParameterAnimatableT*) parameter; - - if (floatType != param->GetFloatType()) return false; - return IsEquivalent(value, param->GetValue()); -} - -template -FCDEffectParameter* FCDEffectParameterAnimatableT::Clone(FCDEffectParameter* _clone) const -{ - FCDEffectParameterAnimatableT* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDEffectParameterAnimatableT(const_cast(GetDocument())); - else if (_clone->HasType(FCDEffectParameterAnimatableT::GetClassType())) clone = (FCDEffectParameterAnimatableT*) _clone; - - if (_clone != NULL) FCDEffectParameter::Clone(_clone); - if (clone != NULL) - { - clone->floatType = floatType; - clone->value = *value; - } - return _clone; -} - -template -void FCDEffectParameterAnimatableT::Overwrite(FCDEffectParameter* target) -{ - if (target->GetType() == GetType()) - { - FCDEffectParameterAnimatableT* s = (FCDEffectParameterAnimatableT*) target; - s->value = *value; - SetDirtyFlag(); - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +// +// FCDEffectParameterT +// + +template +FCDEffectParameterT::~FCDEffectParameterT() +{ +} + +template +bool FCDEffectParameterT::IsValueEqual(FCDEffectParameter* parameter) +{ + if (!FCDEffectParameter::IsValueEqual(parameter)) return false; + FCDEffectParameterT* param = (FCDEffectParameterT*) parameter; + return IsEquivalent(value, param->GetValue()); +} + +template +FCDEffectParameter* FCDEffectParameterT::Clone(FCDEffectParameter* _clone) const +{ + FCDEffectParameterT* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDEffectParameterT(const_cast(GetDocument())); + else if (_clone->HasType(FCDEffectParameterT::GetClassType())) clone = (FCDEffectParameterT*) _clone; + + if (_clone != NULL) FCDEffectParameter::Clone(_clone); + if (clone != NULL) clone->value = *value; + return _clone; +} + +template +void FCDEffectParameterT::Overwrite(FCDEffectParameter* target) +{ + if (target->GetType() == GetType()) + { + FCDEffectParameterT* s = (FCDEffectParameterT*) target; + s->value = value; + SetDirtyFlag(); + } +} + +// +// FCDEffectParameterAnimatableT +// + +template +FCDEffectParameterAnimatableT::~FCDEffectParameterAnimatableT() +{ +} + +template +bool FCDEffectParameterAnimatableT::IsValueEqual(FCDEffectParameter* parameter) +{ + if (!FCDEffectParameter::IsValueEqual(parameter)) return false; + FCDEffectParameterAnimatableT* param = (FCDEffectParameterAnimatableT*) parameter; + + if (floatType != param->GetFloatType()) return false; + return IsEquivalent(value, param->GetValue()); +} + +template +FCDEffectParameter* FCDEffectParameterAnimatableT::Clone(FCDEffectParameter* _clone) const +{ + FCDEffectParameterAnimatableT* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDEffectParameterAnimatableT(const_cast(GetDocument())); + else if (_clone->HasType(FCDEffectParameterAnimatableT::GetClassType())) clone = (FCDEffectParameterAnimatableT*) _clone; + + if (_clone != NULL) FCDEffectParameter::Clone(_clone); + if (clone != NULL) + { + clone->floatType = floatType; + clone->value = *value; + } + return _clone; +} + +template +void FCDEffectParameterAnimatableT::Overwrite(FCDEffectParameter* target) +{ + if (target->GetType() == GetType()) + { + FCDEffectParameterAnimatableT* s = (FCDEffectParameterAnimatableT*) target; + s->value = *value; + SetDirtyFlag(); + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.hpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSampler.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSampler.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSampler.cpp (revision 24247) @@ -1,93 +1,93 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffectPass.h" -#include "FCDocument/FCDEffectProfile.h" -#include "FCDocument/FCDEffectTechnique.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterSurface.h" -#include "FCDocument/FCDEffectParameterSampler.h" -#include "FCDocument/FCDImage.h" - -// -// FCDEffectParameterSampler -// - -ImplementObjectType(FCDEffectParameterSampler); -ImplementParameterObjectNoCtr(FCDEffectParameterSampler, FCDEffectParameterSurface, surface); - -FCDEffectParameterSampler::FCDEffectParameterSampler(FCDocument* document) -: FCDEffectParameter(document) -, InitializeParameter(samplerType, SAMPLER2D) -, InitializeParameterNoArg(surface) -, InitializeParameter(wrap_s, FUDaeTextureWrapMode::DEFAULT) -, InitializeParameter(wrap_t, FUDaeTextureWrapMode::DEFAULT) -, InitializeParameter(wrap_p, FUDaeTextureWrapMode::DEFAULT) -, InitializeParameter(minFilter, FUDaeTextureFilterFunction::DEFAULT) -, InitializeParameter(magFilter, FUDaeTextureFilterFunction::DEFAULT) -, InitializeParameter(mipFilter, FUDaeTextureFilterFunction::DEFAULT) -{ -} - -FCDEffectParameterSampler::~FCDEffectParameterSampler() -{ -} - -// Sets the surface parameter for the surface to sample. -void FCDEffectParameterSampler::SetSurface(FCDEffectParameterSurface* _surface) -{ - surface = _surface; - SetNewChildFlag(); -} - -// compare value -bool FCDEffectParameterSampler::IsValueEqual(FCDEffectParameter* parameter) -{ - if (!FCDEffectParameter::IsValueEqual(parameter)) return false; - if (parameter->GetObjectType() != FCDEffectParameterSampler::GetClassType()) return false; - FCDEffectParameterSampler *param = (FCDEffectParameterSampler*)parameter; - - if (GetSamplerType() != param->GetSamplerType()) return false; - if (param->GetSurface() == NULL && surface == NULL) {} - else if (param->GetSurface() == NULL || surface == NULL) return false; - else if (!IsEquivalent(param->GetSurface()->GetReference(), surface->GetReference())) return false; - - return true; -} - -// Clone -FCDEffectParameter* FCDEffectParameterSampler::Clone(FCDEffectParameter* _clone) const -{ - FCDEffectParameterSampler* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDEffectParameterSampler(const_cast(GetDocument())); - else if (_clone->GetObjectType() == FCDEffectParameterSampler::GetClassType()) clone = (FCDEffectParameterSampler*) _clone; - - if (_clone != NULL) FCDEffectParameter::Clone(_clone); - if (clone != NULL) - { - clone->surface = const_cast((const FCDEffectParameterSurface*)(surface)); - clone->samplerType = samplerType; - } - return _clone; -} - -// Flattening: overwrite the target parameter with this parameter -void FCDEffectParameterSampler::Overwrite(FCDEffectParameter* target) -{ - if (target->GetType() == SAMPLER) - { - FCDEffectParameterSampler* s = (FCDEffectParameterSampler*) target; - if (samplerType == s->samplerType) - { - s->surface = surface; - SetNewChildFlag(); - } - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffectPass.h" +#include "FCDocument/FCDEffectProfile.h" +#include "FCDocument/FCDEffectTechnique.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterSurface.h" +#include "FCDocument/FCDEffectParameterSampler.h" +#include "FCDocument/FCDImage.h" + +// +// FCDEffectParameterSampler +// + +ImplementObjectType(FCDEffectParameterSampler); +ImplementParameterObjectNoCtr(FCDEffectParameterSampler, FCDEffectParameterSurface, surface); + +FCDEffectParameterSampler::FCDEffectParameterSampler(FCDocument* document) +: FCDEffectParameter(document) +, InitializeParameter(samplerType, SAMPLER2D) +, InitializeParameterNoArg(surface) +, InitializeParameter(wrap_s, FUDaeTextureWrapMode::DEFAULT) +, InitializeParameter(wrap_t, FUDaeTextureWrapMode::DEFAULT) +, InitializeParameter(wrap_p, FUDaeTextureWrapMode::DEFAULT) +, InitializeParameter(minFilter, FUDaeTextureFilterFunction::DEFAULT) +, InitializeParameter(magFilter, FUDaeTextureFilterFunction::DEFAULT) +, InitializeParameter(mipFilter, FUDaeTextureFilterFunction::DEFAULT) +{ +} + +FCDEffectParameterSampler::~FCDEffectParameterSampler() +{ +} + +// Sets the surface parameter for the surface to sample. +void FCDEffectParameterSampler::SetSurface(FCDEffectParameterSurface* _surface) +{ + surface = _surface; + SetNewChildFlag(); +} + +// compare value +bool FCDEffectParameterSampler::IsValueEqual(FCDEffectParameter* parameter) +{ + if (!FCDEffectParameter::IsValueEqual(parameter)) return false; + if (parameter->GetObjectType() != FCDEffectParameterSampler::GetClassType()) return false; + FCDEffectParameterSampler *param = (FCDEffectParameterSampler*)parameter; + + if (GetSamplerType() != param->GetSamplerType()) return false; + if (param->GetSurface() == NULL && surface == NULL) {} + else if (param->GetSurface() == NULL || surface == NULL) return false; + else if (!IsEquivalent(param->GetSurface()->GetReference(), surface->GetReference())) return false; + + return true; +} + +// Clone +FCDEffectParameter* FCDEffectParameterSampler::Clone(FCDEffectParameter* _clone) const +{ + FCDEffectParameterSampler* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDEffectParameterSampler(const_cast(GetDocument())); + else if (_clone->GetObjectType() == FCDEffectParameterSampler::GetClassType()) clone = (FCDEffectParameterSampler*) _clone; + + if (_clone != NULL) FCDEffectParameter::Clone(_clone); + if (clone != NULL) + { + clone->surface = const_cast((const FCDEffectParameterSurface*)(surface)); + clone->samplerType = samplerType; + } + return _clone; +} + +// Flattening: overwrite the target parameter with this parameter +void FCDEffectParameterSampler::Overwrite(FCDEffectParameter* target) +{ + if (target->GetType() == SAMPLER) + { + FCDEffectParameterSampler* s = (FCDEffectParameterSampler*) target; + if (samplerType == s->samplerType) + { + s->surface = surface; + SetNewChildFlag(); + } + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSampler.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerInstance.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerInstance.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerInstance.h (revision 24247) @@ -1,142 +1,142 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDControllerInstance.h - This file contains the FCDControllerInstance class. -*/ - -#ifndef _FCD_CONTROLLER_INSTANCE_H_ -#define _FCD_CONTROLLER_INSTANCE_H_ - -#ifndef _FCD_GEOMETRY_ENTITY_H_ -#include "FCDocument/FCDGeometryInstance.h" -#endif // _FCD_GEOMETRY_ENTITY_H_ - -#ifndef _FU_URI_H_ -#include "FUtils/FUUri.h" -#endif // _FU_URI_H_ - -class FCDSkinController; -class FCDSceneNode; -typedef fm::pvector FCDSceneNodeList; /**< A dynamically-sized array of visual scene nodes. */ -typedef FUTrackedList FCDSceneNodeTrackList; /**< A dynamically-sized array of tracked visual scene nodes. */ - -/** - A COLLADA controller instance. - - When a COLLADA controller is instantiated, all its target(s) - are instantiated in order to use them for the rendering or - the logic. As such, all the information necessary to - instantiate a geometry is also necessary to instantiate a - controller. - - Each COLLADA skin controller should instantiate its own skeleton, - for this reason, the skeleton root(s) are defined at instantiation. - - A controller instance should define the skeleton root joint. Previously - a FCDSkinController directly linked to its joints. We now read the skeletonRoot - here, and call which means that the FCDSkinController should never try and know about - its own nodes. It should all be linked through here. -*/ -class FCOLLADA_EXPORT FCDControllerInstance : public FCDGeometryInstance -{ -private: - DeclareObjectType(FCDGeometryInstance); - - friend class FCDEntityInstanceFactory; - - FUUriList skeletonRoots; - DeclareParameterTrackList(FCDSceneNode, joints, FC("Skeleton Joints")); - -protected: - /** Constructor: do not use directly. - Instead, use the FCDSceneNode::AddInstance function. - @param document The COLLADA document that owns the controller instance. - @param parent The parent visual scene node. - @param entityType The type of the entity instantiate. - Unless the class is overwritten, FCDEntity::CONTROLLER should be given. */ - FCDControllerInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType = FCDEntity::CONTROLLER); - -public: - /** Destructor. */ - virtual ~FCDControllerInstance(); - - /** Retrieves the entity instance class type. - This is used to determine the up-class for the entity instance object. - @deprecated Instead use: FCDEntityInstance::HasType(FCDController::GetClassType()) - @return The class type: CONTROLLER. */ - virtual Type GetType() const { return CONTROLLER; } - - /** Clones the controller instance. - @param clone The controller instance to become the clone. - If this pointer is NULL, a new controller instance will be created - and you will need to release the returned pointer. - @return The clone. */ - virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; - - /** Retrieves a list of all the root joint ids for the controller. - @return List of parent Ids */ - const FUUriList& GetSkeletonRoots() const { return skeletonRoots; } - FUUriList& GetSkeletonRoots() { return skeletonRoots; } - - /** Retrieves a list of all the root scene nodes for the controller. - This list is generated with a call to this method. - @param skeletonNodes The list of parent Ids to fill in. - This list is not cleared first. */ - void FindSkeletonNodes(FCDSceneNodeList& skeletonNodes) const; - - /** Calculate our skeleton roots, based on the node list we have */ - void CalculateRootIds(); - - /** Retrieves the number of joints used by this controller. - Joints only make sense when used with skin controllers. - Defining the skeleton root affects the actual joints, but not the joint sids. - @return The number of joints used by this controller. */ - size_t GetJointCount() const { return joints.size(); } - - /** Reset the joint lists. */ - void ResetJoints() { joints.clear(); skeletonRoots.clear(); } - - /** Retrieves a specific joint. - @param index The index of the joint. - @return The joint. This pointer will be NULL, if the index is out-of-bounds. */ - inline FCDSceneNode* GetJoint(size_t index) { FUAssert(index < GetJointCount(), return NULL); return joints.at(index); } - inline const FCDSceneNode* GetJoint(size_t index) const { FUAssert(index < GetJointCount(), return NULL); return joints.at(index); } /**< See above. */ - - /** Adds an existing joint to the list of controller joints. - @param j A joint-typed scene node. */ - bool AddJoint(FCDSceneNode* j); - - /** Find a given joint in this skin instance. - @param joint The joint. - @return true if the node is present, false if not. */ - bool FindJoint(const FCDSceneNode* joint) const; /**< See above. */ - - /** Find the index of the given joint in this skin instance - @param joint The joint. - @return The joints index, else "(size_t) ~0" if not present. */ - size_t FindJointIndex(const FCDSceneNode* joint) const; - - /** Removes a joint from the skin instance. - @param index The index of the joint to remove. */ - inline void RemoveJoint(size_t index) { joints.erase(index); } - - /** Removes a joint from the skin instance. - @param joint The joint to remove. */ - inline void RemoveJoint(FCDSceneNode* joint) { joints.erase(joint); } - -private: - void AppendJoint(FCDSceneNode* j); - - const FCDSkinController* FindSkin(const FCDEntity* entity) const; - inline FCDSkinController* FindSkin(FCDEntity* entity) { return const_cast(const_cast(this)->FindSkin(entity)); } -}; - -#endif // _FCD_CONTROLLER_INSTANCE_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDControllerInstance.h + This file contains the FCDControllerInstance class. +*/ + +#ifndef _FCD_CONTROLLER_INSTANCE_H_ +#define _FCD_CONTROLLER_INSTANCE_H_ + +#ifndef _FCD_GEOMETRY_ENTITY_H_ +#include "FCDocument/FCDGeometryInstance.h" +#endif // _FCD_GEOMETRY_ENTITY_H_ + +#ifndef _FU_URI_H_ +#include "FUtils/FUUri.h" +#endif // _FU_URI_H_ + +class FCDSkinController; +class FCDSceneNode; +typedef fm::pvector FCDSceneNodeList; /**< A dynamically-sized array of visual scene nodes. */ +typedef FUTrackedList FCDSceneNodeTrackList; /**< A dynamically-sized array of tracked visual scene nodes. */ + +/** + A COLLADA controller instance. + + When a COLLADA controller is instantiated, all its target(s) + are instantiated in order to use them for the rendering or + the logic. As such, all the information necessary to + instantiate a geometry is also necessary to instantiate a + controller. + + Each COLLADA skin controller should instantiate its own skeleton, + for this reason, the skeleton root(s) are defined at instantiation. + + A controller instance should define the skeleton root joint. Previously + a FCDSkinController directly linked to its joints. We now read the skeletonRoot + here, and call which means that the FCDSkinController should never try and know about + its own nodes. It should all be linked through here. +*/ +class FCOLLADA_EXPORT FCDControllerInstance : public FCDGeometryInstance +{ +private: + DeclareObjectType(FCDGeometryInstance); + + friend class FCDEntityInstanceFactory; + + FUUriList skeletonRoots; + DeclareParameterTrackList(FCDSceneNode, joints, FC("Skeleton Joints")); + +protected: + /** Constructor: do not use directly. + Instead, use the FCDSceneNode::AddInstance function. + @param document The COLLADA document that owns the controller instance. + @param parent The parent visual scene node. + @param entityType The type of the entity instantiate. + Unless the class is overwritten, FCDEntity::CONTROLLER should be given. */ + FCDControllerInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType = FCDEntity::CONTROLLER); + +public: + /** Destructor. */ + virtual ~FCDControllerInstance(); + + /** Retrieves the entity instance class type. + This is used to determine the up-class for the entity instance object. + @deprecated Instead use: FCDEntityInstance::HasType(FCDController::GetClassType()) + @return The class type: CONTROLLER. */ + virtual Type GetType() const { return CONTROLLER; } + + /** Clones the controller instance. + @param clone The controller instance to become the clone. + If this pointer is NULL, a new controller instance will be created + and you will need to release the returned pointer. + @return The clone. */ + virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; + + /** Retrieves a list of all the root joint ids for the controller. + @return List of parent Ids */ + const FUUriList& GetSkeletonRoots() const { return skeletonRoots; } + FUUriList& GetSkeletonRoots() { return skeletonRoots; } + + /** Retrieves a list of all the root scene nodes for the controller. + This list is generated with a call to this method. + @param skeletonNodes The list of parent Ids to fill in. + This list is not cleared first. */ + void FindSkeletonNodes(FCDSceneNodeList& skeletonNodes) const; + + /** Calculate our skeleton roots, based on the node list we have */ + void CalculateRootIds(); + + /** Retrieves the number of joints used by this controller. + Joints only make sense when used with skin controllers. + Defining the skeleton root affects the actual joints, but not the joint sids. + @return The number of joints used by this controller. */ + size_t GetJointCount() const { return joints.size(); } + + /** Reset the joint lists. */ + void ResetJoints() { joints.clear(); skeletonRoots.clear(); } + + /** Retrieves a specific joint. + @param index The index of the joint. + @return The joint. This pointer will be NULL, if the index is out-of-bounds. */ + inline FCDSceneNode* GetJoint(size_t index) { FUAssert(index < GetJointCount(), return NULL); return joints.at(index); } + inline const FCDSceneNode* GetJoint(size_t index) const { FUAssert(index < GetJointCount(), return NULL); return joints.at(index); } /**< See above. */ + + /** Adds an existing joint to the list of controller joints. + @param j A joint-typed scene node. */ + bool AddJoint(FCDSceneNode* j); + + /** Find a given joint in this skin instance. + @param joint The joint. + @return true if the node is present, false if not. */ + bool FindJoint(const FCDSceneNode* joint) const; /**< See above. */ + + /** Find the index of the given joint in this skin instance + @param joint The joint. + @return The joints index, else "(size_t) ~0" if not present. */ + size_t FindJointIndex(const FCDSceneNode* joint) const; + + /** Removes a joint from the skin instance. + @param index The index of the joint to remove. */ + inline void RemoveJoint(size_t index) { joints.erase(index); } + + /** Removes a joint from the skin instance. + @param joint The joint to remove. */ + inline void RemoveJoint(FCDSceneNode* joint) { joints.erase(joint); } + +private: + void AppendJoint(FCDSceneNode* j); + + const FCDSkinController* FindSkin(const FCDEntity* entity) const; + inline FCDSkinController* FindSkin(FCDEntity* entity) { return const_cast(const_cast(this)->FindSkin(entity)); } +}; + +#endif // _FCD_CONTROLLER_INSTANCE_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerInstance.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerTools.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerTools.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerTools.h (revision 24247) @@ -1,42 +1,42 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDControllerTools.h - This file defines the FCDControllerTools namespace. -*/ - -#ifndef _FCD_CONTROLLER_TOOLS_H_ -#define _FCD_CONTROLLER_TOOLS_H_ - -#include "FCDocument/FCDocument.h" - -class FCDSkinController; -class FCDSkinControllerVertex; - -/** A translation map between old vertex position indices and the new indices. - It is generated in the FCDGeometryPolygonsTools::GenerateUniqueIndices function. */ -typedef fm::map FCDGeometryIndexTranslationMap; - -/** Holds commonly-used transformation functions for skin controllers. */ -namespace FCDControllerTools -{ - /** Applies a translation map obtained from - FCDGeometryPolygonsTools::GenerateUniqueIndices to a given - FCDSkinController to synchronize with the updated indices. This is - useful for older engines and the applications that only support one - index per face-vertex pair. - @param controller The skin controller to process. - @param translationMap The map that translates old vertex position - indices into new indices. This map is recieved from - FCDGeometryPolygonsTools::GenerateUniqueIndices. */ - void FCOLLADA_EXPORT ApplyTranslationMap(const FCDSkinController* controller, const FCDGeometryIndexTranslationMap& translationMap, - const UInt16List& packingMap, fm::pvector& skinInfluences); -} - -#endif // _FCD_CONTROLLER_TOOLS_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDControllerTools.h + This file defines the FCDControllerTools namespace. +*/ + +#ifndef _FCD_CONTROLLER_TOOLS_H_ +#define _FCD_CONTROLLER_TOOLS_H_ + +#include "FCDocument/FCDocument.h" + +class FCDSkinController; +class FCDSkinControllerVertex; + +/** A translation map between old vertex position indices and the new indices. + It is generated in the FCDGeometryPolygonsTools::GenerateUniqueIndices function. */ +typedef fm::map FCDGeometryIndexTranslationMap; + +/** Holds commonly-used transformation functions for skin controllers. */ +namespace FCDControllerTools +{ + /** Applies a translation map obtained from + FCDGeometryPolygonsTools::GenerateUniqueIndices to a given + FCDSkinController to synchronize with the updated indices. This is + useful for older engines and the applications that only support one + index per face-vertex pair. + @param controller The skin controller to process. + @param translationMap The map that translates old vertex position + indices into new indices. This map is recieved from + FCDGeometryPolygonsTools::GenerateUniqueIndices. */ + void FCOLLADA_EXPORT ApplyTranslationMap(const FCDSkinController* controller, const FCDGeometryIndexTranslationMap& translationMap, + const UInt16List& packingMap, fm::pvector& skinInfluences); +} + +#endif // _FCD_CONTROLLER_TOOLS_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerTools.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffect.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffect.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffect.h (revision 24247) @@ -1,149 +1,149 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffect.h - This file contains the FCDEffect class. -*/ - -#ifndef _FCD_EFFECT_H_ -#define _FCD_EFFECT_H_ - -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDocument; -class FCDEffectStandard; -class FCDEffectParameter; -class FCDEffectProfile; - -/** - @defgroup FCDEffect COLLADA Effect Classes [ColladaFX] -*/ - -/** - A COLLADA effect. - - A COLLADA effect is one of many abstraction level that defines how - to render mesh polygon sets. It contains one or more rendering profile - that the application can choose to support. In theory, all the rendering - profiles should reach the same render output, using different - rendering technologies. - - An effect may also declare new general purpose parameters that are common - to all the profiles. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffect : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - DeclareParameterContainer(FCDEffectProfile, profiles, FC("Profiles")); - DeclareParameterContainer(FCDEffectParameter, parameters, FC("Parameters")); - -public: - /** Constructor: do not use directly. - Instead use the FCDLibrary::AddEntity function. - @param document The COLLADA document that owns this effect. */ - FCDEffect(FCDocument* document); - - /** Destructor. */ - virtual ~FCDEffect(); - - /** Retrieves the type for this entity class. - This function is a part of the FCDEntity interface. - @return The entity type: EFFECT. */ - virtual Type GetType() const { return FCDEntity::EFFECT; } - - /** Retrieves the number of profiles contained within the effect. - @return The number of profiles within the effect. */ - size_t GetProfileCount() const { return profiles.size(); } - - /** Retrieves a profile contained within the effect. - @param index The index of the profile. - @return The profile. This pointer will be NULL, if the given index is out-of-bounds. */ - FCDEffectProfile* GetProfile(size_t index) { FUAssert(index < GetProfileCount(), return NULL); return profiles.at(index); } - const FCDEffectProfile* GetProfile(size_t index) const { FUAssert(index < GetProfileCount(), return NULL); return profiles.at(index); } /**< See above. */ - - /** Retrieves the list of the profiles contained within the effect. - @return The list of effect profiles. */ - DEPRECATED(3.05A, GetProfileCount and GetProfile(index)) void GetProfiles() const {} - - /** Retrieves the first profile for a specific profile type. - There should only be one profile of each type within an effect. This - function allows you to retrieve the profile for a given type. - @param type The profile type. - @return The first profile of this type. This pointer will be NULL if the effect - does not have any profile of this type. */ - const FCDEffectProfile* FindProfile(FUDaeProfileType::Type type) const; - inline FCDEffectProfile* FindProfile(FUDaeProfileType::Type type) { return const_cast(const_cast(this)->FindProfile(type)); } /**< See above. */ - - /** Retrieves the profile for a specific profile type and platform. - There should only be one profile of each type within an effect. This - function allows you to retrieve the profile for a given type. - @param type The profile type. - @param platform The profile platform. - @return The profile of this type. This pointer will be NULL if the effect - does not have any profile of this type. */ - inline FCDEffectProfile* FindProfileByTypeAndPlatform(FUDaeProfileType::Type type, const fm::string& platform) { return const_cast(const_cast(this)->FindProfileByTypeAndPlatform(type, platform)); } - const FCDEffectProfile* FindProfileByTypeAndPlatform(FUDaeProfileType::Type type, const fm::string& platform) const; /**< See above. */ - - /** Retrieves whether the effect contains a profile of the given type. - @param type The profile type. - @return Whether the effect has a profile of this type. */ - inline bool HasProfile(FUDaeProfileType::Type type) const { return FindProfile(type) != NULL; } - - /** Creates a profile of the given type. - If a profile of this type already exists, it will be released, as - a COLLADA effect should only contain one profile of each type. - @param type The profile type. - @return The new effect profile. */ - FCDEffectProfile* AddProfile(FUDaeProfileType::Type type); - - /** Retrieves the number of local effect parameters - @return The number of local effect parameters. */ - inline size_t GetEffectParameterCount() const { return parameters.size(); } - - /** Retrieves a given local effect parameter. - @param index An index. - @return The local effect parameter at the given index. */ - inline FCDEffectParameter* GetEffectParameter(size_t index) { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } - inline const FCDEffectParameter* GetEffectParameter(size_t index) const { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } - - /** Adds a local effect parameter to the local list. - @see FCDEffectParameter::Type - @param type The value type of the effect parameter to create. - @return The new local effect parameter. */ - FCDEffectParameter* AddEffectParameter(uint32 type); - - /** Clones the effect object. - @param clone The clone object into which to copy the effect information. - If this pointer is NULL, a new effect will be created and your will - need to release the returned pointer. - @param cloneChildren Whether to recursively clone this entity's children. - @return The cloned effect object. You will must delete this pointer. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - - /** [INTERNAL] Flattens the effect, pushing all the common effect parameters - into to the effect technique level of abstraction. To correctly flatten a - material, use the FCDMaterialInstance::FlattenMaterial function. */ - DEPRECATED(3.05A, not recommended) void Flatten(); -}; - -#endif // _FCD_MATERIAL_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffect.h + This file contains the FCDEffect class. +*/ + +#ifndef _FCD_EFFECT_H_ +#define _FCD_EFFECT_H_ + +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDocument; +class FCDEffectStandard; +class FCDEffectParameter; +class FCDEffectProfile; + +/** + @defgroup FCDEffect COLLADA Effect Classes [ColladaFX] +*/ + +/** + A COLLADA effect. + + A COLLADA effect is one of many abstraction level that defines how + to render mesh polygon sets. It contains one or more rendering profile + that the application can choose to support. In theory, all the rendering + profiles should reach the same render output, using different + rendering technologies. + + An effect may also declare new general purpose parameters that are common + to all the profiles. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffect : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + DeclareParameterContainer(FCDEffectProfile, profiles, FC("Profiles")); + DeclareParameterContainer(FCDEffectParameter, parameters, FC("Parameters")); + +public: + /** Constructor: do not use directly. + Instead use the FCDLibrary::AddEntity function. + @param document The COLLADA document that owns this effect. */ + FCDEffect(FCDocument* document); + + /** Destructor. */ + virtual ~FCDEffect(); + + /** Retrieves the type for this entity class. + This function is a part of the FCDEntity interface. + @return The entity type: EFFECT. */ + virtual Type GetType() const { return FCDEntity::EFFECT; } + + /** Retrieves the number of profiles contained within the effect. + @return The number of profiles within the effect. */ + size_t GetProfileCount() const { return profiles.size(); } + + /** Retrieves a profile contained within the effect. + @param index The index of the profile. + @return The profile. This pointer will be NULL, if the given index is out-of-bounds. */ + FCDEffectProfile* GetProfile(size_t index) { FUAssert(index < GetProfileCount(), return NULL); return profiles.at(index); } + const FCDEffectProfile* GetProfile(size_t index) const { FUAssert(index < GetProfileCount(), return NULL); return profiles.at(index); } /**< See above. */ + + /** Retrieves the list of the profiles contained within the effect. + @return The list of effect profiles. */ + DEPRECATED(3.05A, GetProfileCount and GetProfile(index)) void GetProfiles() const {} + + /** Retrieves the first profile for a specific profile type. + There should only be one profile of each type within an effect. This + function allows you to retrieve the profile for a given type. + @param type The profile type. + @return The first profile of this type. This pointer will be NULL if the effect + does not have any profile of this type. */ + const FCDEffectProfile* FindProfile(FUDaeProfileType::Type type) const; + inline FCDEffectProfile* FindProfile(FUDaeProfileType::Type type) { return const_cast(const_cast(this)->FindProfile(type)); } /**< See above. */ + + /** Retrieves the profile for a specific profile type and platform. + There should only be one profile of each type within an effect. This + function allows you to retrieve the profile for a given type. + @param type The profile type. + @param platform The profile platform. + @return The profile of this type. This pointer will be NULL if the effect + does not have any profile of this type. */ + inline FCDEffectProfile* FindProfileByTypeAndPlatform(FUDaeProfileType::Type type, const fm::string& platform) { return const_cast(const_cast(this)->FindProfileByTypeAndPlatform(type, platform)); } + const FCDEffectProfile* FindProfileByTypeAndPlatform(FUDaeProfileType::Type type, const fm::string& platform) const; /**< See above. */ + + /** Retrieves whether the effect contains a profile of the given type. + @param type The profile type. + @return Whether the effect has a profile of this type. */ + inline bool HasProfile(FUDaeProfileType::Type type) const { return FindProfile(type) != NULL; } + + /** Creates a profile of the given type. + If a profile of this type already exists, it will be released, as + a COLLADA effect should only contain one profile of each type. + @param type The profile type. + @return The new effect profile. */ + FCDEffectProfile* AddProfile(FUDaeProfileType::Type type); + + /** Retrieves the number of local effect parameters + @return The number of local effect parameters. */ + inline size_t GetEffectParameterCount() const { return parameters.size(); } + + /** Retrieves a given local effect parameter. + @param index An index. + @return The local effect parameter at the given index. */ + inline FCDEffectParameter* GetEffectParameter(size_t index) { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } + inline const FCDEffectParameter* GetEffectParameter(size_t index) const { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } + + /** Adds a local effect parameter to the local list. + @see FCDEffectParameter::Type + @param type The value type of the effect parameter to create. + @return The new local effect parameter. */ + FCDEffectParameter* AddEffectParameter(uint32 type); + + /** Clones the effect object. + @param clone The clone object into which to copy the effect information. + If this pointer is NULL, a new effect will be created and your will + need to release the returned pointer. + @param cloneChildren Whether to recursively clone this entity's children. + @return The cloned effect object. You will must delete this pointer. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + + /** [INTERNAL] Flattens the effect, pushing all the common effect parameters + into to the effect technique level of abstraction. To correctly flatten a + material, use the FCDMaterialInstance::FlattenMaterial function. */ + DEPRECATED(3.05A, not recommended) void Flatten(); +}; + +#endif // _FCD_MATERIAL_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffect.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectCode.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectCode.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectCode.h (revision 24247) @@ -1,114 +1,114 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectCode.h - This file contains the FCDEffectCode class. -*/ - -#ifndef _FCD_EFFECT_CODE_H_ -#define _FCD_EFFECT_CODE_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ - -class FCDocument; - -/** - A COLLADA code inclusion. - - Code inclusions come in two forms: file includes and inline code. - For file includes, you will want to grab the filename of the file - using the GetFilename function and for inline code, you can get - the code directly through the GetCode function. - - Code inclusions are referenced through sub-ids by the effect pass - shaders. Regardless of the extension of the filename of file - includes, the code inclusions' language is solely determined by - the effect profile they belong to. -*/ -class FCOLLADA_EXPORT FCDEffectCode : public FCDObject -{ -public: - /** The list of support code inclusion types. */ - enum Type - { - INCLUDE, /** A file include. @see GetFilename */ - CODE /** Inlined code. @see GetCode */ - }; - -private: - DeclareObjectType(FCDObject); - - Type type; - fm::string sid; - fstring code; - fstring filename; - -public: - /** Constructor: do not use directly. - Instead, use the FCDEffectProfile::AddCode - or the FCDEffectTechnique::AddCode functions. - @param document The COLLADA document that owns this code inclusion. */ - FCDEffectCode(FCDocument* document); - - /** Destructor. */ - virtual ~FCDEffectCode(); - - /** Retrieves the form of the code inclusion. - @return The form. */ - inline Type GetType() const { return type; } - - /** Sets the form of the code inclusion. - Changing the form of the code inclusion will not - remove the inline code or the filename. - @param _type The form. */ - inline void SetType(Type _type) { type = _type; SetDirtyFlag(); } - - /** Retrieves the sub-id of the code inclusion. - Used to match the code inclusion within the effect pass shaders. - @return The sub-id. */ - inline const fm::string& GetSubId() const { return sid; } - - /** Sets the sub-id of the code inclusion. - This value may change on export, as the sub-id must be unique within its scope. - @param _sid The sub-id. */ - void SetSubId(const fm::string& _sid); - - /** Retrieves the inlined code. - First verify that this code inclusion contains inlined code - using the GetType function. - @return The inlined code. */ - inline const fstring& GetCode() const { return code; } - - /** Sets the inlined code. - As a side-effect, calling this function forces the type of the code inclusion. - @param _code The inlined code. */ - inline void SetCode(const fstring& _code) { code = _code; type = CODE; SetDirtyFlag(); } - - /** Retrieves the filename of the code file to open. - First verify that this code inclusion contains a filename - using the GetType function. - @return The code filename. */ - inline const fstring& GetFilename() const { return filename; } - - /** Sets the filename of the code file. - As a side-effect, calling this function forces the type of the code inclusion. - @param _filename The code filename. */ - void SetFilename(const fstring& _filename); - - /** Clones the code inclusion. - @param clone The cloned code inclusion. - If this pointer is NULL, a new code inclusion is created and - you will need to release this new code inclusion. - @return The cloned effect object. This pointer will never be NULL. */ - FCDEffectCode* Clone(FCDEffectCode* clone = NULL) const; -}; - -#endif // _FCD_EFFECT_CODE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectCode.h + This file contains the FCDEffectCode class. +*/ + +#ifndef _FCD_EFFECT_CODE_H_ +#define _FCD_EFFECT_CODE_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ + +class FCDocument; + +/** + A COLLADA code inclusion. + + Code inclusions come in two forms: file includes and inline code. + For file includes, you will want to grab the filename of the file + using the GetFilename function and for inline code, you can get + the code directly through the GetCode function. + + Code inclusions are referenced through sub-ids by the effect pass + shaders. Regardless of the extension of the filename of file + includes, the code inclusions' language is solely determined by + the effect profile they belong to. +*/ +class FCOLLADA_EXPORT FCDEffectCode : public FCDObject +{ +public: + /** The list of support code inclusion types. */ + enum Type + { + INCLUDE, /** A file include. @see GetFilename */ + CODE /** Inlined code. @see GetCode */ + }; + +private: + DeclareObjectType(FCDObject); + + Type type; + fm::string sid; + fstring code; + fstring filename; + +public: + /** Constructor: do not use directly. + Instead, use the FCDEffectProfile::AddCode + or the FCDEffectTechnique::AddCode functions. + @param document The COLLADA document that owns this code inclusion. */ + FCDEffectCode(FCDocument* document); + + /** Destructor. */ + virtual ~FCDEffectCode(); + + /** Retrieves the form of the code inclusion. + @return The form. */ + inline Type GetType() const { return type; } + + /** Sets the form of the code inclusion. + Changing the form of the code inclusion will not + remove the inline code or the filename. + @param _type The form. */ + inline void SetType(Type _type) { type = _type; SetDirtyFlag(); } + + /** Retrieves the sub-id of the code inclusion. + Used to match the code inclusion within the effect pass shaders. + @return The sub-id. */ + inline const fm::string& GetSubId() const { return sid; } + + /** Sets the sub-id of the code inclusion. + This value may change on export, as the sub-id must be unique within its scope. + @param _sid The sub-id. */ + void SetSubId(const fm::string& _sid); + + /** Retrieves the inlined code. + First verify that this code inclusion contains inlined code + using the GetType function. + @return The inlined code. */ + inline const fstring& GetCode() const { return code; } + + /** Sets the inlined code. + As a side-effect, calling this function forces the type of the code inclusion. + @param _code The inlined code. */ + inline void SetCode(const fstring& _code) { code = _code; type = CODE; SetDirtyFlag(); } + + /** Retrieves the filename of the code file to open. + First verify that this code inclusion contains a filename + using the GetType function. + @return The code filename. */ + inline const fstring& GetFilename() const { return filename; } + + /** Sets the filename of the code file. + As a side-effect, calling this function forces the type of the code inclusion. + @param _filename The code filename. */ + void SetFilename(const fstring& _filename); + + /** Clones the code inclusion. + @param clone The cloned code inclusion. + If this pointer is NULL, a new code inclusion is created and + you will need to release this new code inclusion. + @return The cloned effect object. This pointer will never be NULL. */ + FCDEffectCode* Clone(FCDEffectCode* clone = NULL) const; +}; + +#endif // _FCD_EFFECT_CODE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectCode.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.h (revision 24247) @@ -1,377 +1,377 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectParameter.h - This file contains the FCDEffectParameter interface and the simpler of its derivate classes: - FCDEffectParameterString, FCDEffectParameterFloat, FCDEffectParameterVector... -*/ - -#ifndef _FCD_EFFECT_PARAMETER_H_ -#define _FCD_EFFECT_PARAMETER_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -class FCDocument; -class FCDEffectParameterAnnotation; - -/** - A COLLADA effect parameter. - - This interface class is used to define all the valid - ColladaFX parameter types. There are many types of - parameters: integers, booleans, floating-point - values, 2D, 3D and 4D vectors of floating-point values, - matrices, strings, surfaces and their samplers. - - A COLLADA effect parameter may generate a new - effect parameter, in which case it will declare a semantic - and a reference: to represent it within the COLLADA document. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectParameter : public FCDObject -{ -public: - /** The value type of the effect parameter. */ - enum Type - { - SAMPLER, /**< A sampler effect parameter. Points towards a surface parameter and adds extra texturing parameters. */ - INTEGER, /**< A single integer effect parameter. */ - BOOLEAN, /**< A single boolean effect parameter. */ - FLOAT, /**< A single floating-pointer value effect parameter. */ - FLOAT2, /**< A 2D vector of floating-pointer values. */ - FLOAT3, /**< A 3D vector of floating-pointer values. */ - VECTOR, /**< A 4D vector of floating-pointer values. */ - MATRIX, /**< A 4x4 matrix. */ - STRING, /**< A string effect parameter. */ - SURFACE /**< A surface effect parameter. Contains a COLLADA image pointer. */ - }; - - /** The usage type of the effect parameter. */ - enum ParamType - { - GENERATOR, /**< This should be the type used for a 'newparam' element. - Valid only at the levels of effect, profile common or technique common.*/ - MODIFIER, /**< This should be the type used for a 'setparam' element. - Valid only at the instance effect level. */ - ANIMATOR, /**< This should be the type used for a 'param' element that is to be animated. - Valid only at the bind_material level.*/ - REFERENCER, /**< This should be the type used for a 'param' element used in any of the common techniques. - The 'param' needs to have a reference that is the same as the generator used above.*/ - CONSTANT /**< This should be the type used for a parameter that is either a color or a float in - any of the common techniques. This type isn't linked to any parameter elsewhere.*/ - }; - -private: - DeclareObjectType(FCDObject); - - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, paramType, FC("Parameter Type")); // ParamType - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, reference, FC("Identifier")); - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, semantic, FC("Semantic")); // this is a COLLADA Semantic, not a Cg semantic - DeclareParameterContainer(FCDEffectParameterAnnotation, annotations, FC("Annotations")); - -public: - /** Constructor: do not use directly. - Instead, use the appropriate AddEffectParameter function. - @param document The COLLADA document that owns the effect parameter. */ - FCDEffectParameter(FCDocument* document); - - /** Destructor. */ - virtual ~FCDEffectParameter(); - - /** Retrieves the type of effect parameter class. - @return The type of the effect parameter class.*/ - virtual Type GetType() const = 0; - - /** Retrieves the type of parameter. - The parameter can be a generator (newparam), a modifier (setparam) - or an animated param (animator). - @return The type of the parameter. */ - inline ParamType GetParamType() const { return (ParamType) *paramType; } - - /** Retrieves the reference for this effect parameter. - In the case of generators, the reference string contains the sub-id. - @return The reference. */ - inline const fm::string& GetReference() const { return reference; } - - /** Sets the reference for the effect parameter. - In the case of generators, the reference string contains the sub-id. - @param _reference The reference. */ - void SetReference(const char* _reference); - - /** Retrieves the semantic for this effect parameter. - @return The semantic. */ - inline const fm::string& GetSemantic() const { return semantic; } - - /** Sets the semantic for this effect parameter. - @param _semantic The semantic. */ - void SetSemantic(const char* _semantic) { semantic = _semantic; SetDirtyFlag(); } - - /** Retrieves whether this effect parameter is a parameter generator. - A ColladaFX parameter must be generated to be modified or bound at - higher abstraction levels. - @return Whether this is a generator. */ - inline bool IsGenerator() const { return paramType == GENERATOR; } - - /** Sets this effect parameter as a generator. */ - inline void SetGenerator() { paramType = GENERATOR; SetDirtyFlag(); } - - /** Retrieves whether this effect parameter is a parameter modifier. - A ColladaFX parameter must be generated to be modified or bound at - higher abstraction levels. - @return Whether this is a modifier. */ - inline bool IsModifier() const { return paramType == MODIFIER; } - - /** Sets this effect parameter as a modified. */ - inline void SetModifier() { paramType = MODIFIER; SetDirtyFlag(); } - - /** Retrieves whether this effect is an animated parameter. - A ColladaFX parameter must be generated to be modified or bound at - higher abstraction levels. - @return Whether this is an animator. */ - inline bool IsAnimator() const { return paramType == ANIMATOR; } - - /** Sets this effect parameter as animated. */ - inline void SetAnimator() { paramType = ANIMATOR; SetDirtyFlag(); } - - /** Retrieves whether this effect is a referenced parameter. - This type of parameter must have a valid reference equal - to that of the generator paramater in order to be properly linked. - @return Whether this is a referencer. */ - inline bool IsReferencer() const { return paramType == REFERENCER; } - - /** Sets this effect parameter as referencer. */ - inline void SetReferencer() { paramType = REFERENCER; SetDirtyFlag(); } - - /** Retrieves whether this effect is a constant parameter. - This type of parameter belongs to the technique and isn't - referenced anywhere. It should have an empty reference. - @return Whether this is a constant parameter. */ - inline bool IsConstant() const { return paramType == CONSTANT; } - - /** Sets this effect parameter as constant. */ - inline void SetConstant() { paramType = CONSTANT; SetDirtyFlag(); } - - /** Retrieves the list of annotations for this parameter. - @return The list of annotations. */ - inline const FCDEffectParameterAnnotation** GetAnnotations() const { return annotations.begin(); } /**< See above. */ - - /** Retrieves the number of annotations for this parameter. - @return The number of annotations. */ - inline size_t GetAnnotationCount() const { return annotations.size(); } - - /** Retrieves an annotation of this parameter. - @param index The index of the annotation. - @return The annotation for the given index. This pointer will be NULL - if the index is out-of-bounds. */ - inline FCDEffectParameterAnnotation* GetAnnotation(size_t index) { FUAssert(index < GetAnnotationCount(), return NULL); return annotations.at(index); } - inline const FCDEffectParameterAnnotation* GetAnnotation(size_t index) const { FUAssert(index < GetAnnotationCount(), return NULL); return annotations.at(index); } /**< See above. */ - - /** Adds a blank annotation to this parameter. - @return The blank annotation. */ - FCDEffectParameterAnnotation* AddAnnotation(); - - /** Adds an annotation to this parameter. - @param name The name of the annotation. - @param type The type of the annotation. - @param value The value of the annotation. */ - void AddAnnotation(const fchar* name, FCDEffectParameter::Type type, const fchar* value); - inline void AddAnnotation(const fstring& name, FCDEffectParameter::Type type, const fchar* value) { AddAnnotation(name.c_str(), type, value); } /**< See above. */ - inline void AddAnnotation(const fchar* name, FCDEffectParameter::Type type, const fstring& value) { AddAnnotation(name, type, value.c_str()); } /**< See above. */ - inline void AddAnnotation(const fstring& name, FCDEffectParameter::Type type, const fstring& value) { AddAnnotation(name.c_str(), type, value.c_str()); } /**< See above. */ - template inline void AddAnnotation(const fchar* name, FCDEffectParameter::Type type, const T& value) { FUStringBuilder builder; builder.set(value); AddAnnotation(name, type, builder.ToCharPtr()); } /**< See above. */ - template inline void AddAnnotation(const fstring& name, FCDEffectParameter::Type type, const T& value) { FUStringBuilder builder; builder.set(value); AddAnnotation(name.c_str(), type, builder.ToCharPtr()); } /**< See above. */ - - /** Releases an annotation of this parameter. - @param annotation The annotation to release. */ - DEPRECATED(3.05A, annotation->Release) inline void ReleaseAnnotation(FCDEffectParameterAnnotation* annotation) { ((FCDObject*) annotation)->Release(); } - - /** Compares this parameter's value with another - @param parameter The given parameter to compare with. - @return true if the values are equal */ - virtual bool IsValueEqual(FCDEffectParameter *parameter) = 0; - - /** Creates a full copy of the effect parameter. - @param clone The cloned effect parameter. If this pointer is NULL, - a new effect parameter will be created and you - will need to delete this pointer. - @return The cloned effect parameter. */ - virtual FCDEffectParameter* Clone(FCDEffectParameter* clone = NULL) const; - - /** [INTERNAL] Overwrites the target parameter with this parameter. - This function is used during the flattening of materials. - @param target The target parameter to overwrite. */ - virtual void Overwrite(FCDEffectParameter* target); -}; - -/** - A COLLADA non-animatable effect parameter template. - @ingroup FCDEffect -*/ -template -class FCOLLADA_EXPORT FCDEffectParameterT : public FCDEffectParameter -{ -private: - DeclareObjectType(FCDEffectParameter); - DeclareParameter(PrimitiveType, FUParameterQualifiers::SIMPLE, value, FC("Value")); - -public: - /** Constructor: do not use directly. - Instead, use the appropriate AddEffectParameter function. - @param document The COLLADA document that owns the effect parameter. */ - FCDEffectParameterT(FCDocument* document); - - /** Destructor. */ - virtual ~FCDEffectParameterT(); - - /** Retrieves the type of effect parameter class. - @return The parameter class type. */ - virtual Type GetType() const; - - /** Retrieves the value of the effect parameter. - @return The integer value. */ - inline const PrimitiveType& GetValue() const { return *value; } - - /** Sets the integer value of the effect parameter. - @param _value The integer value. */ - inline void SetValue(const PrimitiveType& _value) { value = _value; SetDirtyFlag(); } - - /** Compares this parameter's value with another - @param parameter The given parameter to compare with. - @return true if the values are equal */ - virtual bool IsValueEqual(FCDEffectParameter *parameter); - - /** Creates a full copy of the effect parameter. - @param clone The cloned effect parameter. If this pointer is NULL, - a new effect parameter will be created and you - will need to delete this pointer. - @return The cloned effect parameter. */ - virtual FCDEffectParameter* Clone(FCDEffectParameter* clone = NULL) const; - - /** [INTERNAL] Overwrites the target parameter with this parameter. - This function is used during the flattening of materials. - @param target The target parameter to overwrite. */ - virtual void Overwrite(FCDEffectParameter* target); -}; - -typedef FCDEffectParameterT FCDEffectParameterInt; /**< An integer effect parameter. */ -typedef FCDEffectParameterT FCDEffectParameterBool; /**< A boolean effect parameter. */ -typedef FCDEffectParameterT FCDEffectParameterString; /**< A string effect parameter. */ - -/** - A COLLADA non-animatable effect parameter template. - @ingroup FCDEffect -*/ -template -class FCOLLADA_EXPORT FCDEffectParameterAnimatableT : public FCDEffectParameter -{ -public: - /** The supported types of float-point values. */ - enum FloatType - { - FLOAT, /** A full-fledged floating-point value. This is the default. */ - HALF /** Probably implies a 16-bit floating-point value. */ - }; - -private: - DeclareObjectType(FCDEffectParameter); - FloatType floatType; - DeclareParameterAnimatable(PrimitiveType, Qualifiers, value, FC("Value")); - -public: - /** Constructor: do not use directly. - Instead, use the appropriate AddEffectParameter function. - @param document The COLLADA document that owns the effect parameter. */ - FCDEffectParameterAnimatableT(FCDocument* document); - - /** Destructor. */ - virtual ~FCDEffectParameterAnimatableT(); - - /** Retrieves the type of effect parameter class. - @return The parameter class type. */ - virtual Type GetType() const; - - /** Retrieves the type of floating-point value held by this effect parameter. - @return The type of floating-point value. */ - inline FloatType GetFloatType() const { return floatType; } - - /** Sets the type of floating-point value held by this effect parameter. - @param type The type of floating-point value. */ - inline void SetFloatType(FloatType type) { floatType = type; SetDirtyFlag(); } - - /** Retrieves the value of the effect parameter. - @return The integer value. */ - inline FCDParameterAnimatableT& GetValue() { return value; } - inline const FCDParameterAnimatableT& GetValue() const { return value; } /**< See above. */ - - /** Sets the integer value of the effect parameter. - @param _value The integer value. */ - inline void SetValue(const PrimitiveType& _value) { value = _value; SetDirtyFlag(); } - - /** Compares this parameter's value with another - @param parameter The given parameter to compare with. - @return true if the values are equal */ - virtual bool IsValueEqual(FCDEffectParameter *parameter); - - /** Creates a full copy of the effect parameter. - @param clone The cloned effect parameter. If this pointer is NULL, - a new effect parameter will be created and you - will need to delete this pointer. - @return The cloned effect parameter. */ - virtual FCDEffectParameter* Clone(FCDEffectParameter* clone = NULL) const; - - /** [INTERNAL] Overwrites the target parameter with this parameter. - This function is used during the flattening of materials. - @param target The target parameter to overwrite. */ - virtual void Overwrite(FCDEffectParameter* target); -}; - -typedef FCDEffectParameterAnimatableT FCDEffectParameterFloat; /**< An effect parameter containing one floating point value. */ -typedef FCDEffectParameterAnimatableT FCDEffectParameterFloat2; /**< An effect parameter containing a 2D floating point vector. */ -typedef FCDEffectParameterAnimatableT FCDEffectParameterFloat3; /**< An effect parameter containing a 3D floating point vector. */ -typedef FCDEffectParameterAnimatableT FCDEffectParameterColor3; /**< An effect parameter containing a 3D color value. */ -typedef FCDEffectParameterAnimatableT FCDEffectParameterVector; /**< An effect parameter containing a 4D floating point vector. */ -typedef FCDEffectParameterAnimatableT FCDEffectParameterColor4; /**< An effect parameter containing a 4D color value. */ -typedef FCDEffectParameterAnimatableT FCDEffectParameterMatrix; /**< An effect parameter containing a 4x4 matrix. */ - -/** - A ColladaFX annotation. - - ColladaFX annotations are used mainly to describe the user - interface necessary to modify a parameter. Common annotations - are "UIMin", "UIMax" and "UIWidget". -*/ -class FCOLLADA_EXPORT FCDEffectParameterAnnotation : public FUParameterizable -{ -private: - DeclareObjectType(FUParameterizable); - -public: - /** Constructor. Do not use directly. - Instead, use FCDEffectParameter::AddAnnotation. */ - FCDEffectParameterAnnotation(); - /** Destructor. */ - virtual ~FCDEffectParameterAnnotation(); - - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name")); /**< The annotation name. */ - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, type, FC("Value Type")); /**< The annotation value type (FCDEffectParameter::Type). */ - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, value, FC("Value")); /**< The annotation value. */ -}; - -#if defined(__APPLE__) || defined(LINUX) -#include -#endif - -#endif // _FCD_EFFECT_PARAMETER_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectParameter.h + This file contains the FCDEffectParameter interface and the simpler of its derivate classes: + FCDEffectParameterString, FCDEffectParameterFloat, FCDEffectParameterVector... +*/ + +#ifndef _FCD_EFFECT_PARAMETER_H_ +#define _FCD_EFFECT_PARAMETER_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +class FCDocument; +class FCDEffectParameterAnnotation; + +/** + A COLLADA effect parameter. + + This interface class is used to define all the valid + ColladaFX parameter types. There are many types of + parameters: integers, booleans, floating-point + values, 2D, 3D and 4D vectors of floating-point values, + matrices, strings, surfaces and their samplers. + + A COLLADA effect parameter may generate a new + effect parameter, in which case it will declare a semantic + and a reference: to represent it within the COLLADA document. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectParameter : public FCDObject +{ +public: + /** The value type of the effect parameter. */ + enum Type + { + SAMPLER, /**< A sampler effect parameter. Points towards a surface parameter and adds extra texturing parameters. */ + INTEGER, /**< A single integer effect parameter. */ + BOOLEAN, /**< A single boolean effect parameter. */ + FLOAT, /**< A single floating-pointer value effect parameter. */ + FLOAT2, /**< A 2D vector of floating-pointer values. */ + FLOAT3, /**< A 3D vector of floating-pointer values. */ + VECTOR, /**< A 4D vector of floating-pointer values. */ + MATRIX, /**< A 4x4 matrix. */ + STRING, /**< A string effect parameter. */ + SURFACE /**< A surface effect parameter. Contains a COLLADA image pointer. */ + }; + + /** The usage type of the effect parameter. */ + enum ParamType + { + GENERATOR, /**< This should be the type used for a 'newparam' element. + Valid only at the levels of effect, profile common or technique common.*/ + MODIFIER, /**< This should be the type used for a 'setparam' element. + Valid only at the instance effect level. */ + ANIMATOR, /**< This should be the type used for a 'param' element that is to be animated. + Valid only at the bind_material level.*/ + REFERENCER, /**< This should be the type used for a 'param' element used in any of the common techniques. + The 'param' needs to have a reference that is the same as the generator used above.*/ + CONSTANT /**< This should be the type used for a parameter that is either a color or a float in + any of the common techniques. This type isn't linked to any parameter elsewhere.*/ + }; + +private: + DeclareObjectType(FCDObject); + + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, paramType, FC("Parameter Type")); // ParamType + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, reference, FC("Identifier")); + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, semantic, FC("Semantic")); // this is a COLLADA Semantic, not a Cg semantic + DeclareParameterContainer(FCDEffectParameterAnnotation, annotations, FC("Annotations")); + +public: + /** Constructor: do not use directly. + Instead, use the appropriate AddEffectParameter function. + @param document The COLLADA document that owns the effect parameter. */ + FCDEffectParameter(FCDocument* document); + + /** Destructor. */ + virtual ~FCDEffectParameter(); + + /** Retrieves the type of effect parameter class. + @return The type of the effect parameter class.*/ + virtual Type GetType() const = 0; + + /** Retrieves the type of parameter. + The parameter can be a generator (newparam), a modifier (setparam) + or an animated param (animator). + @return The type of the parameter. */ + inline ParamType GetParamType() const { return (ParamType) *paramType; } + + /** Retrieves the reference for this effect parameter. + In the case of generators, the reference string contains the sub-id. + @return The reference. */ + inline const fm::string& GetReference() const { return reference; } + + /** Sets the reference for the effect parameter. + In the case of generators, the reference string contains the sub-id. + @param _reference The reference. */ + void SetReference(const char* _reference); + + /** Retrieves the semantic for this effect parameter. + @return The semantic. */ + inline const fm::string& GetSemantic() const { return semantic; } + + /** Sets the semantic for this effect parameter. + @param _semantic The semantic. */ + void SetSemantic(const char* _semantic) { semantic = _semantic; SetDirtyFlag(); } + + /** Retrieves whether this effect parameter is a parameter generator. + A ColladaFX parameter must be generated to be modified or bound at + higher abstraction levels. + @return Whether this is a generator. */ + inline bool IsGenerator() const { return paramType == GENERATOR; } + + /** Sets this effect parameter as a generator. */ + inline void SetGenerator() { paramType = GENERATOR; SetDirtyFlag(); } + + /** Retrieves whether this effect parameter is a parameter modifier. + A ColladaFX parameter must be generated to be modified or bound at + higher abstraction levels. + @return Whether this is a modifier. */ + inline bool IsModifier() const { return paramType == MODIFIER; } + + /** Sets this effect parameter as a modified. */ + inline void SetModifier() { paramType = MODIFIER; SetDirtyFlag(); } + + /** Retrieves whether this effect is an animated parameter. + A ColladaFX parameter must be generated to be modified or bound at + higher abstraction levels. + @return Whether this is an animator. */ + inline bool IsAnimator() const { return paramType == ANIMATOR; } + + /** Sets this effect parameter as animated. */ + inline void SetAnimator() { paramType = ANIMATOR; SetDirtyFlag(); } + + /** Retrieves whether this effect is a referenced parameter. + This type of parameter must have a valid reference equal + to that of the generator paramater in order to be properly linked. + @return Whether this is a referencer. */ + inline bool IsReferencer() const { return paramType == REFERENCER; } + + /** Sets this effect parameter as referencer. */ + inline void SetReferencer() { paramType = REFERENCER; SetDirtyFlag(); } + + /** Retrieves whether this effect is a constant parameter. + This type of parameter belongs to the technique and isn't + referenced anywhere. It should have an empty reference. + @return Whether this is a constant parameter. */ + inline bool IsConstant() const { return paramType == CONSTANT; } + + /** Sets this effect parameter as constant. */ + inline void SetConstant() { paramType = CONSTANT; SetDirtyFlag(); } + + /** Retrieves the list of annotations for this parameter. + @return The list of annotations. */ + inline const FCDEffectParameterAnnotation** GetAnnotations() const { return annotations.begin(); } /**< See above. */ + + /** Retrieves the number of annotations for this parameter. + @return The number of annotations. */ + inline size_t GetAnnotationCount() const { return annotations.size(); } + + /** Retrieves an annotation of this parameter. + @param index The index of the annotation. + @return The annotation for the given index. This pointer will be NULL + if the index is out-of-bounds. */ + inline FCDEffectParameterAnnotation* GetAnnotation(size_t index) { FUAssert(index < GetAnnotationCount(), return NULL); return annotations.at(index); } + inline const FCDEffectParameterAnnotation* GetAnnotation(size_t index) const { FUAssert(index < GetAnnotationCount(), return NULL); return annotations.at(index); } /**< See above. */ + + /** Adds a blank annotation to this parameter. + @return The blank annotation. */ + FCDEffectParameterAnnotation* AddAnnotation(); + + /** Adds an annotation to this parameter. + @param name The name of the annotation. + @param type The type of the annotation. + @param value The value of the annotation. */ + void AddAnnotation(const fchar* name, FCDEffectParameter::Type type, const fchar* value); + inline void AddAnnotation(const fstring& name, FCDEffectParameter::Type type, const fchar* value) { AddAnnotation(name.c_str(), type, value); } /**< See above. */ + inline void AddAnnotation(const fchar* name, FCDEffectParameter::Type type, const fstring& value) { AddAnnotation(name, type, value.c_str()); } /**< See above. */ + inline void AddAnnotation(const fstring& name, FCDEffectParameter::Type type, const fstring& value) { AddAnnotation(name.c_str(), type, value.c_str()); } /**< See above. */ + template inline void AddAnnotation(const fchar* name, FCDEffectParameter::Type type, const T& value) { FUStringBuilder builder; builder.set(value); AddAnnotation(name, type, builder.ToCharPtr()); } /**< See above. */ + template inline void AddAnnotation(const fstring& name, FCDEffectParameter::Type type, const T& value) { FUStringBuilder builder; builder.set(value); AddAnnotation(name.c_str(), type, builder.ToCharPtr()); } /**< See above. */ + + /** Releases an annotation of this parameter. + @param annotation The annotation to release. */ + DEPRECATED(3.05A, annotation->Release) inline void ReleaseAnnotation(FCDEffectParameterAnnotation* annotation) { ((FCDObject*) annotation)->Release(); } + + /** Compares this parameter's value with another + @param parameter The given parameter to compare with. + @return true if the values are equal */ + virtual bool IsValueEqual(FCDEffectParameter *parameter) = 0; + + /** Creates a full copy of the effect parameter. + @param clone The cloned effect parameter. If this pointer is NULL, + a new effect parameter will be created and you + will need to delete this pointer. + @return The cloned effect parameter. */ + virtual FCDEffectParameter* Clone(FCDEffectParameter* clone = NULL) const; + + /** [INTERNAL] Overwrites the target parameter with this parameter. + This function is used during the flattening of materials. + @param target The target parameter to overwrite. */ + virtual void Overwrite(FCDEffectParameter* target); +}; + +/** + A COLLADA non-animatable effect parameter template. + @ingroup FCDEffect +*/ +template +class FCOLLADA_EXPORT FCDEffectParameterT : public FCDEffectParameter +{ +private: + DeclareObjectType(FCDEffectParameter); + DeclareParameter(PrimitiveType, FUParameterQualifiers::SIMPLE, value, FC("Value")); + +public: + /** Constructor: do not use directly. + Instead, use the appropriate AddEffectParameter function. + @param document The COLLADA document that owns the effect parameter. */ + FCDEffectParameterT(FCDocument* document); + + /** Destructor. */ + virtual ~FCDEffectParameterT(); + + /** Retrieves the type of effect parameter class. + @return The parameter class type. */ + virtual Type GetType() const; + + /** Retrieves the value of the effect parameter. + @return The integer value. */ + inline const PrimitiveType& GetValue() const { return *value; } + + /** Sets the integer value of the effect parameter. + @param _value The integer value. */ + inline void SetValue(const PrimitiveType& _value) { value = _value; SetDirtyFlag(); } + + /** Compares this parameter's value with another + @param parameter The given parameter to compare with. + @return true if the values are equal */ + virtual bool IsValueEqual(FCDEffectParameter *parameter); + + /** Creates a full copy of the effect parameter. + @param clone The cloned effect parameter. If this pointer is NULL, + a new effect parameter will be created and you + will need to delete this pointer. + @return The cloned effect parameter. */ + virtual FCDEffectParameter* Clone(FCDEffectParameter* clone = NULL) const; + + /** [INTERNAL] Overwrites the target parameter with this parameter. + This function is used during the flattening of materials. + @param target The target parameter to overwrite. */ + virtual void Overwrite(FCDEffectParameter* target); +}; + +typedef FCDEffectParameterT FCDEffectParameterInt; /**< An integer effect parameter. */ +typedef FCDEffectParameterT FCDEffectParameterBool; /**< A boolean effect parameter. */ +typedef FCDEffectParameterT FCDEffectParameterString; /**< A string effect parameter. */ + +/** + A COLLADA non-animatable effect parameter template. + @ingroup FCDEffect +*/ +template +class FCOLLADA_EXPORT FCDEffectParameterAnimatableT : public FCDEffectParameter +{ +public: + /** The supported types of float-point values. */ + enum FloatType + { + FLOAT, /** A full-fledged floating-point value. This is the default. */ + HALF /** Probably implies a 16-bit floating-point value. */ + }; + +private: + DeclareObjectType(FCDEffectParameter); + FloatType floatType; + DeclareParameterAnimatable(PrimitiveType, Qualifiers, value, FC("Value")); + +public: + /** Constructor: do not use directly. + Instead, use the appropriate AddEffectParameter function. + @param document The COLLADA document that owns the effect parameter. */ + FCDEffectParameterAnimatableT(FCDocument* document); + + /** Destructor. */ + virtual ~FCDEffectParameterAnimatableT(); + + /** Retrieves the type of effect parameter class. + @return The parameter class type. */ + virtual Type GetType() const; + + /** Retrieves the type of floating-point value held by this effect parameter. + @return The type of floating-point value. */ + inline FloatType GetFloatType() const { return floatType; } + + /** Sets the type of floating-point value held by this effect parameter. + @param type The type of floating-point value. */ + inline void SetFloatType(FloatType type) { floatType = type; SetDirtyFlag(); } + + /** Retrieves the value of the effect parameter. + @return The integer value. */ + inline FCDParameterAnimatableT& GetValue() { return value; } + inline const FCDParameterAnimatableT& GetValue() const { return value; } /**< See above. */ + + /** Sets the integer value of the effect parameter. + @param _value The integer value. */ + inline void SetValue(const PrimitiveType& _value) { value = _value; SetDirtyFlag(); } + + /** Compares this parameter's value with another + @param parameter The given parameter to compare with. + @return true if the values are equal */ + virtual bool IsValueEqual(FCDEffectParameter *parameter); + + /** Creates a full copy of the effect parameter. + @param clone The cloned effect parameter. If this pointer is NULL, + a new effect parameter will be created and you + will need to delete this pointer. + @return The cloned effect parameter. */ + virtual FCDEffectParameter* Clone(FCDEffectParameter* clone = NULL) const; + + /** [INTERNAL] Overwrites the target parameter with this parameter. + This function is used during the flattening of materials. + @param target The target parameter to overwrite. */ + virtual void Overwrite(FCDEffectParameter* target); +}; + +typedef FCDEffectParameterAnimatableT FCDEffectParameterFloat; /**< An effect parameter containing one floating point value. */ +typedef FCDEffectParameterAnimatableT FCDEffectParameterFloat2; /**< An effect parameter containing a 2D floating point vector. */ +typedef FCDEffectParameterAnimatableT FCDEffectParameterFloat3; /**< An effect parameter containing a 3D floating point vector. */ +typedef FCDEffectParameterAnimatableT FCDEffectParameterColor3; /**< An effect parameter containing a 3D color value. */ +typedef FCDEffectParameterAnimatableT FCDEffectParameterVector; /**< An effect parameter containing a 4D floating point vector. */ +typedef FCDEffectParameterAnimatableT FCDEffectParameterColor4; /**< An effect parameter containing a 4D color value. */ +typedef FCDEffectParameterAnimatableT FCDEffectParameterMatrix; /**< An effect parameter containing a 4x4 matrix. */ + +/** + A ColladaFX annotation. + + ColladaFX annotations are used mainly to describe the user + interface necessary to modify a parameter. Common annotations + are "UIMin", "UIMax" and "UIWidget". +*/ +class FCOLLADA_EXPORT FCDEffectParameterAnnotation : public FUParameterizable +{ +private: + DeclareObjectType(FUParameterizable); + +public: + /** Constructor. Do not use directly. + Instead, use FCDEffectParameter::AddAnnotation. */ + FCDEffectParameterAnnotation(); + /** Destructor. */ + virtual ~FCDEffectParameterAnnotation(); + + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name")); /**< The annotation name. */ + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, type, FC("Value Type")); /**< The annotation value type (FCDEffectParameter::Type). */ + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, value, FC("Value")); /**< The annotation value. */ +}; + +#if defined(__APPLE__) || defined(LINUX) +#include +#endif + +#endif // _FCD_EFFECT_PARAMETER_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterFactory.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterFactory.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterFactory.h (revision 24247) @@ -1,43 +1,43 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectParameterFactory.h - This file contains the FCDEffectParameterFactory class. -*/ - -#ifndef _FCD_EFFECT_PARAMETER_FACTORY_H_ -#define _FCD_EFFECT_PARAMETER_FACTORY_H_ - -class FCDocument; -class FCDEffectParameter; - -/** - [INTERNAL] The factory for COLLADA effect parameters. - - Takes in a COLLADA XML tree and returns a new - parameter that represent it, if one is possible. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectParameterFactory -{ -private: - // Never instantiate: this is a static class - FCDEffectParameterFactory() {} - -public: - /** [INTERNAL] Creates a new effect parameter, given a type. - To create new effect parameters, use the appropriate AddEffectParameter function. - @param document The COLLADA document that will own the effect parameter. - @param type The type of effect to create. - This value should reflect the FCDEffectParameter::Type enum. */ - static FCDEffectParameter* Create(FCDocument* document, uint32 type); -}; - -#endif // _FCD_EFFECT_PARAMETER_FACTORY_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectParameterFactory.h + This file contains the FCDEffectParameterFactory class. +*/ + +#ifndef _FCD_EFFECT_PARAMETER_FACTORY_H_ +#define _FCD_EFFECT_PARAMETER_FACTORY_H_ + +class FCDocument; +class FCDEffectParameter; + +/** + [INTERNAL] The factory for COLLADA effect parameters. + + Takes in a COLLADA XML tree and returns a new + parameter that represent it, if one is possible. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectParameterFactory +{ +private: + // Never instantiate: this is a static class + FCDEffectParameterFactory() {} + +public: + /** [INTERNAL] Creates a new effect parameter, given a type. + To create new effect parameters, use the appropriate AddEffectParameter function. + @param document The COLLADA document that will own the effect parameter. + @param type The type of effect to create. + This value should reflect the FCDEffectParameter::Type enum. */ + static FCDEffectParameter* Create(FCDocument* document, uint32 type); +}; + +#endif // _FCD_EFFECT_PARAMETER_FACTORY_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterFactory.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSurface.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSurface.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSurface.cpp (revision 24247) @@ -1,360 +1,360 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffectPass.h" -#include "FCDocument/FCDEffectProfile.h" -#include "FCDocument/FCDEffectTechnique.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterSurface.h" -#include "FCDocument/FCDImage.h" - -// -// FCDEffectParameterSurface -// - -ImplementObjectType(FCDEffectParameterSurface); -ImplementParameterObjectNoCtr(FCDEffectParameterSurface, FCDImage, images); - -// surface type parameter -FCDEffectParameterSurface::FCDEffectParameterSurface(FCDocument* document) -: FCDEffectParameter(document) -, InitializeParameterNoArg(images) -, initMethod(NULL) -, format("A8R8G8B8") -, formatHint(NULL) -, size(FMVector3::Zero) -, viewportRatio(1.0f) -, mipLevelCount(0) -, generateMipmaps(false) -, type("2D") -{ -} - -FCDEffectParameterSurface::~FCDEffectParameterSurface() -{ - SAFE_DELETE(initMethod); - SAFE_DELETE(formatHint); - names.clear(); -} - -void FCDEffectParameterSurface::SetInitMethod(FCDEffectParameterSurfaceInit* method) -{ - SAFE_DELETE(initMethod); - initMethod = method; - SetNewChildFlag(); -} - -// Retrieves the index that matches the given image. -size_t FCDEffectParameterSurface::FindImage(const FCDImage* image) const -{ - const FCDImage** it = images.find(image); - if (it != images.end()) return it - images.begin(); - else return (size_t) ~0; -} - -// Adds an image to the list. -size_t FCDEffectParameterSurface::AddImage(FCDImage* image, size_t index) -{ - size_t exists = FindImage(image); - if (exists == (size_t) ~0) - { - if (index == (size_t) ~0) - { - index = images.size(); - images.push_back(image); - } - else - { - FUAssert(index > images.size(), return (size_t) ~0); - images.insert(index, image); - } - SetNewChildFlag(); - } - return index; -} - -// Removes an image from the list. -void FCDEffectParameterSurface::RemoveImage(FCDImage* image) -{ - size_t index = FindImage(image); - if (index != (size_t) ~0) - { - images.erase(index); - - if (initMethod != NULL && initMethod->GetInitType() == FCDEffectParameterSurfaceInitFactory::CUBE) - { - // Shift down all the indexes found within the cube map initialization. - FCDEffectParameterSurfaceInitCube* cube = (FCDEffectParameterSurfaceInitCube*) initMethod; - for (UInt16List::iterator itI = cube->order.begin(); itI != cube->order.end(); ++itI) - { - if ((*itI) == index) (*itI) = 0; - else if ((*itI) > index) --(*itI); - } - } - - SetNewChildFlag(); - } -} - -// compare value -bool FCDEffectParameterSurface::IsValueEqual(FCDEffectParameter *parameter) -{ - if (!FCDEffectParameter::IsValueEqual(parameter)) return false; - FCDEffectParameterSurface *param = (FCDEffectParameterSurface*)parameter; - - // compage images - size_t imgCount = this->GetImageCount(); - if (imgCount != param->GetImageCount()) return false; - - for (size_t i = 0; i < imgCount; i++) - { - if (this->GetImage(i) != param->GetImage(i)) return false; - } - - // compare initialisation methods - if (initMethod != NULL && param->GetInitMethod() != NULL) - { - if (initMethod->GetInitType() != param->GetInitMethod()->GetInitType()) return false; - } - else - { - if (initMethod != param->GetInitMethod()) return false; - } - - if (size != param->GetSize()) return false; - if (mipLevelCount != param->GetMipLevelCount()) return false; - if (generateMipmaps != param->IsGenerateMipMaps()) return false; - if (viewportRatio != param->GetViewportRatio()) return false; - - // if you want to add more tests, feel free! - - return true; -} - -// Clone -FCDEffectParameter* FCDEffectParameterSurface::Clone(FCDEffectParameter* _clone) const -{ - FCDEffectParameterSurface* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDEffectParameterSurface(const_cast(GetDocument())); - else if (_clone->GetObjectType() == FCDEffectParameterSurface::GetClassType()) clone = (FCDEffectParameterSurface*) _clone; - - if (_clone != NULL) FCDEffectParameter::Clone(_clone); - if (clone != NULL) - { - clone->images.reserve(images.size()); - for (const FCDImage** itI = images.begin(); itI != images.end(); ++itI) - { - clone->AddImage(const_cast(*itI)); - } - - if (initMethod != NULL) - { - clone->initMethod = FCDEffectParameterSurfaceInitFactory::Create(initMethod->GetInitType()); - initMethod->Clone(clone->initMethod); - } - - clone->size = size; - clone->viewportRatio = viewportRatio; - clone->mipLevelCount = mipLevelCount; - clone->generateMipmaps = generateMipmaps; - - clone->format = format; - if (formatHint != NULL) - { - FCDFormatHint* cloneHint = clone->AddFormatHint(); - cloneHint->channels = formatHint->channels; - cloneHint->range = formatHint->range; - cloneHint->precision = formatHint->precision; - cloneHint->options = formatHint->options; - } - } - return _clone; -} - -// Flattening: overwrite the target parameter with this parameter -void FCDEffectParameterSurface::Overwrite(FCDEffectParameter* target) -{ - if (target->GetType() == SURFACE) - { - FCDEffectParameterSurface* s = (FCDEffectParameterSurface*) target; - s->images.clear(); - for (uint32 i=0; iimages.push_back(images[i]); - -// s->initMethod->initType = initMethod->GetInitType(); - s->size = size; - s->viewportRatio = viewportRatio; - s->mipLevelCount = mipLevelCount; - s->generateMipmaps = generateMipmaps; - SetDirtyFlag(); - } -} - -FCDFormatHint* FCDEffectParameterSurface::AddFormatHint() -{ - if (formatHint == NULL) formatHint = new FCDFormatHint(); - return formatHint; -} - -FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInit::Clone(FCDEffectParameterSurfaceInit* clone) const -{ - if (clone == NULL) - { - clone = FCDEffectParameterSurfaceInitFactory::Create(GetInitType()); - return clone != NULL ? Clone(clone) : NULL; - } - else - { - //no member variables to copy in this class, but leave this for future use. - return clone; - } -} - -// -// FCDEffectParameterSurfaceInitCube -// - -FCDEffectParameterSurfaceInitCube::FCDEffectParameterSurfaceInitCube() -{ - cubeType = ALL; -} - -FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitCube::Clone(FCDEffectParameterSurfaceInit* _clone) const -{ - FCDEffectParameterSurfaceInitCube* clone = NULL; - if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitCube(); - else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitCube*) _clone; - - if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); - if (clone != NULL) - { - clone->cubeType = cubeType; - } - return clone; -} - -// -// FCDEffectParameterSurfaceInitFrom -// - -FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitFrom::Clone(FCDEffectParameterSurfaceInit* _clone) const -{ - FCDEffectParameterSurfaceInitFrom* clone = NULL; - if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitFrom(); - else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitFrom*) _clone; - - if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); - if (clone != NULL) - { - clone->face = face; - clone->mip = mip; - clone->slice = slice; - } - return clone; -} - -// -// FCDEffectParameterSurfaceInitVolume -// - -FCDEffectParameterSurfaceInitVolume::FCDEffectParameterSurfaceInitVolume() -{ - volumeType = ALL; -} - -FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitVolume::Clone(FCDEffectParameterSurfaceInit* _clone) const -{ - FCDEffectParameterSurfaceInitVolume* clone = NULL; - if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitVolume(); - else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitVolume*) _clone; - - if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); - if (clone != NULL) - { - clone->volumeType = volumeType; - } - return clone; -} - -// -// FCDEffectParameterSurfaceInitAsNull -// - -FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitAsNull::Clone(FCDEffectParameterSurfaceInit* _clone) const -{ - FCDEffectParameterSurfaceInitAsNull* clone = NULL; - if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitAsNull(); - else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitAsNull*) _clone; - - if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); - if (clone != NULL) - { - // Nothing to clone. - } - return clone; -} - -// -// FCDEffectParameterSurfaceInitAsTarget -// - -FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitAsTarget::Clone(FCDEffectParameterSurfaceInit* _clone) const -{ - FCDEffectParameterSurfaceInitAsTarget* clone = NULL; - if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitAsTarget(); - else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitAsTarget*) _clone; - - if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); - if (clone != NULL) - { - // Nothing to clone. - } - return clone; -} - -// -// FCDEffectParameterSurfaceInitPlanar -// - -FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitPlanar::Clone(FCDEffectParameterSurfaceInit* _clone) const -{ - FCDEffectParameterSurfaceInitPlanar* clone = NULL; - if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitPlanar(); - else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitPlanar*) _clone; - - if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); - if (clone != NULL) - { - // Nothing to clone. - } - return clone; -} - -// -// FCDEffectParameterSurfaceInitFactory -// - -FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitFactory::Create(InitType type) -{ - FCDEffectParameterSurfaceInit* parameter = NULL; - - switch (type) - { - case FCDEffectParameterSurfaceInitFactory::AS_NULL: parameter = new FCDEffectParameterSurfaceInitAsNull(); break; - case FCDEffectParameterSurfaceInitFactory::AS_TARGET: parameter = new FCDEffectParameterSurfaceInitAsTarget(); break; - case FCDEffectParameterSurfaceInitFactory::CUBE: parameter = new FCDEffectParameterSurfaceInitCube(); break; - case FCDEffectParameterSurfaceInitFactory::FROM: parameter = new FCDEffectParameterSurfaceInitFrom(); break; - case FCDEffectParameterSurfaceInitFactory::PLANAR: parameter = new FCDEffectParameterSurfaceInitPlanar(); break; - case FCDEffectParameterSurfaceInitFactory::VOLUME: parameter = new FCDEffectParameterSurfaceInitVolume(); break; - default: break; - } - - return parameter; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffectPass.h" +#include "FCDocument/FCDEffectProfile.h" +#include "FCDocument/FCDEffectTechnique.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterSurface.h" +#include "FCDocument/FCDImage.h" + +// +// FCDEffectParameterSurface +// + +ImplementObjectType(FCDEffectParameterSurface); +ImplementParameterObjectNoCtr(FCDEffectParameterSurface, FCDImage, images); + +// surface type parameter +FCDEffectParameterSurface::FCDEffectParameterSurface(FCDocument* document) +: FCDEffectParameter(document) +, InitializeParameterNoArg(images) +, initMethod(NULL) +, format("A8R8G8B8") +, formatHint(NULL) +, size(FMVector3::Zero) +, viewportRatio(1.0f) +, mipLevelCount(0) +, generateMipmaps(false) +, type("2D") +{ +} + +FCDEffectParameterSurface::~FCDEffectParameterSurface() +{ + SAFE_DELETE(initMethod); + SAFE_DELETE(formatHint); + names.clear(); +} + +void FCDEffectParameterSurface::SetInitMethod(FCDEffectParameterSurfaceInit* method) +{ + SAFE_DELETE(initMethod); + initMethod = method; + SetNewChildFlag(); +} + +// Retrieves the index that matches the given image. +size_t FCDEffectParameterSurface::FindImage(const FCDImage* image) const +{ + const FCDImage** it = images.find(image); + if (it != images.end()) return it - images.begin(); + else return (size_t) ~0; +} + +// Adds an image to the list. +size_t FCDEffectParameterSurface::AddImage(FCDImage* image, size_t index) +{ + size_t exists = FindImage(image); + if (exists == (size_t) ~0) + { + if (index == (size_t) ~0) + { + index = images.size(); + images.push_back(image); + } + else + { + FUAssert(index > images.size(), return (size_t) ~0); + images.insert(index, image); + } + SetNewChildFlag(); + } + return index; +} + +// Removes an image from the list. +void FCDEffectParameterSurface::RemoveImage(FCDImage* image) +{ + size_t index = FindImage(image); + if (index != (size_t) ~0) + { + images.erase(index); + + if (initMethod != NULL && initMethod->GetInitType() == FCDEffectParameterSurfaceInitFactory::CUBE) + { + // Shift down all the indexes found within the cube map initialization. + FCDEffectParameterSurfaceInitCube* cube = (FCDEffectParameterSurfaceInitCube*) initMethod; + for (UInt16List::iterator itI = cube->order.begin(); itI != cube->order.end(); ++itI) + { + if ((*itI) == index) (*itI) = 0; + else if ((*itI) > index) --(*itI); + } + } + + SetNewChildFlag(); + } +} + +// compare value +bool FCDEffectParameterSurface::IsValueEqual(FCDEffectParameter *parameter) +{ + if (!FCDEffectParameter::IsValueEqual(parameter)) return false; + FCDEffectParameterSurface *param = (FCDEffectParameterSurface*)parameter; + + // compage images + size_t imgCount = this->GetImageCount(); + if (imgCount != param->GetImageCount()) return false; + + for (size_t i = 0; i < imgCount; i++) + { + if (this->GetImage(i) != param->GetImage(i)) return false; + } + + // compare initialisation methods + if (initMethod != NULL && param->GetInitMethod() != NULL) + { + if (initMethod->GetInitType() != param->GetInitMethod()->GetInitType()) return false; + } + else + { + if (initMethod != param->GetInitMethod()) return false; + } + + if (size != param->GetSize()) return false; + if (mipLevelCount != param->GetMipLevelCount()) return false; + if (generateMipmaps != param->IsGenerateMipMaps()) return false; + if (viewportRatio != param->GetViewportRatio()) return false; + + // if you want to add more tests, feel free! + + return true; +} + +// Clone +FCDEffectParameter* FCDEffectParameterSurface::Clone(FCDEffectParameter* _clone) const +{ + FCDEffectParameterSurface* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDEffectParameterSurface(const_cast(GetDocument())); + else if (_clone->GetObjectType() == FCDEffectParameterSurface::GetClassType()) clone = (FCDEffectParameterSurface*) _clone; + + if (_clone != NULL) FCDEffectParameter::Clone(_clone); + if (clone != NULL) + { + clone->images.reserve(images.size()); + for (const FCDImage** itI = images.begin(); itI != images.end(); ++itI) + { + clone->AddImage(const_cast(*itI)); + } + + if (initMethod != NULL) + { + clone->initMethod = FCDEffectParameterSurfaceInitFactory::Create(initMethod->GetInitType()); + initMethod->Clone(clone->initMethod); + } + + clone->size = size; + clone->viewportRatio = viewportRatio; + clone->mipLevelCount = mipLevelCount; + clone->generateMipmaps = generateMipmaps; + + clone->format = format; + if (formatHint != NULL) + { + FCDFormatHint* cloneHint = clone->AddFormatHint(); + cloneHint->channels = formatHint->channels; + cloneHint->range = formatHint->range; + cloneHint->precision = formatHint->precision; + cloneHint->options = formatHint->options; + } + } + return _clone; +} + +// Flattening: overwrite the target parameter with this parameter +void FCDEffectParameterSurface::Overwrite(FCDEffectParameter* target) +{ + if (target->GetType() == SURFACE) + { + FCDEffectParameterSurface* s = (FCDEffectParameterSurface*) target; + s->images.clear(); + for (uint32 i=0; iimages.push_back(images[i]); + +// s->initMethod->initType = initMethod->GetInitType(); + s->size = size; + s->viewportRatio = viewportRatio; + s->mipLevelCount = mipLevelCount; + s->generateMipmaps = generateMipmaps; + SetDirtyFlag(); + } +} + +FCDFormatHint* FCDEffectParameterSurface::AddFormatHint() +{ + if (formatHint == NULL) formatHint = new FCDFormatHint(); + return formatHint; +} + +FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInit::Clone(FCDEffectParameterSurfaceInit* clone) const +{ + if (clone == NULL) + { + clone = FCDEffectParameterSurfaceInitFactory::Create(GetInitType()); + return clone != NULL ? Clone(clone) : NULL; + } + else + { + //no member variables to copy in this class, but leave this for future use. + return clone; + } +} + +// +// FCDEffectParameterSurfaceInitCube +// + +FCDEffectParameterSurfaceInitCube::FCDEffectParameterSurfaceInitCube() +{ + cubeType = ALL; +} + +FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitCube::Clone(FCDEffectParameterSurfaceInit* _clone) const +{ + FCDEffectParameterSurfaceInitCube* clone = NULL; + if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitCube(); + else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitCube*) _clone; + + if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); + if (clone != NULL) + { + clone->cubeType = cubeType; + } + return clone; +} + +// +// FCDEffectParameterSurfaceInitFrom +// + +FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitFrom::Clone(FCDEffectParameterSurfaceInit* _clone) const +{ + FCDEffectParameterSurfaceInitFrom* clone = NULL; + if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitFrom(); + else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitFrom*) _clone; + + if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); + if (clone != NULL) + { + clone->face = face; + clone->mip = mip; + clone->slice = slice; + } + return clone; +} + +// +// FCDEffectParameterSurfaceInitVolume +// + +FCDEffectParameterSurfaceInitVolume::FCDEffectParameterSurfaceInitVolume() +{ + volumeType = ALL; +} + +FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitVolume::Clone(FCDEffectParameterSurfaceInit* _clone) const +{ + FCDEffectParameterSurfaceInitVolume* clone = NULL; + if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitVolume(); + else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitVolume*) _clone; + + if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); + if (clone != NULL) + { + clone->volumeType = volumeType; + } + return clone; +} + +// +// FCDEffectParameterSurfaceInitAsNull +// + +FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitAsNull::Clone(FCDEffectParameterSurfaceInit* _clone) const +{ + FCDEffectParameterSurfaceInitAsNull* clone = NULL; + if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitAsNull(); + else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitAsNull*) _clone; + + if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); + if (clone != NULL) + { + // Nothing to clone. + } + return clone; +} + +// +// FCDEffectParameterSurfaceInitAsTarget +// + +FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitAsTarget::Clone(FCDEffectParameterSurfaceInit* _clone) const +{ + FCDEffectParameterSurfaceInitAsTarget* clone = NULL; + if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitAsTarget(); + else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitAsTarget*) _clone; + + if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); + if (clone != NULL) + { + // Nothing to clone. + } + return clone; +} + +// +// FCDEffectParameterSurfaceInitPlanar +// + +FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitPlanar::Clone(FCDEffectParameterSurfaceInit* _clone) const +{ + FCDEffectParameterSurfaceInitPlanar* clone = NULL; + if (_clone == NULL) clone = new FCDEffectParameterSurfaceInitPlanar(); + else if (_clone->GetInitType() == GetInitType()) clone = (FCDEffectParameterSurfaceInitPlanar*) _clone; + + if (_clone != NULL) FCDEffectParameterSurfaceInit::Clone(_clone); + if (clone != NULL) + { + // Nothing to clone. + } + return clone; +} + +// +// FCDEffectParameterSurfaceInitFactory +// + +FCDEffectParameterSurfaceInit* FCDEffectParameterSurfaceInitFactory::Create(InitType type) +{ + FCDEffectParameterSurfaceInit* parameter = NULL; + + switch (type) + { + case FCDEffectParameterSurfaceInitFactory::AS_NULL: parameter = new FCDEffectParameterSurfaceInitAsNull(); break; + case FCDEffectParameterSurfaceInitFactory::AS_TARGET: parameter = new FCDEffectParameterSurfaceInitAsTarget(); break; + case FCDEffectParameterSurfaceInitFactory::CUBE: parameter = new FCDEffectParameterSurfaceInitCube(); break; + case FCDEffectParameterSurfaceInitFactory::FROM: parameter = new FCDEffectParameterSurfaceInitFrom(); break; + case FCDEffectParameterSurfaceInitFactory::PLANAR: parameter = new FCDEffectParameterSurfaceInitPlanar(); break; + case FCDEffectParameterSurfaceInitFactory::VOLUME: parameter = new FCDEffectParameterSurfaceInitVolume(); break; + default: break; + } + + return parameter; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSurface.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimated.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimated.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimated.cpp (revision 24247) @@ -1,364 +1,364 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimationChannel.h" -#include "FCDocument/FCDAnimationCurve.h" -#include "FCDocument/FCDAnimationCurveTools.h" -#include "FCDocument/FCDAnimated.h" - - -// -// FCDAnimated -// - -ImplementObjectType(FCDAnimated); - -FCDAnimated::FCDAnimated(FCDocument* document, size_t valueCount, const char** _qualifiers, float** _values) -: FCDObject(document) -, target(NULL) -{ - arrayElement = -1; - - // Allocate the values/qualifiers/curves arrays - values.resize(valueCount); - qualifiers.resize(valueCount); - curves.resize(valueCount); - - for (size_t i = 0; i < valueCount; ++i) - { - values[i] = _values[i]; - qualifiers[i] = _qualifiers[i]; - } - - ResetRelativeAnimationFlag(); -} - -FCDAnimated::FCDAnimated(FCDObject* object, size_t valueCount, const char** _qualifiers, float** _values) -: FCDObject(object->GetDocument()) -{ - arrayElement = -1; - - // Allocate the values/qualifiers/curves arrays - values.resize(valueCount); - qualifiers.resize(valueCount); - curves.resize(valueCount); - - for (size_t i = 0; i < valueCount; ++i) - { - values[i] = _values[i]; - qualifiers[i] = _qualifiers[i]; - } - - // Register this animated value with the document - GetDocument()->RegisterAnimatedValue(this); - - target = object; - TrackObject(target); -} - -FCDAnimated::~FCDAnimated() -{ - GetDocument()->UnregisterAnimatedValue(this); - - values.clear(); - qualifiers.clear(); - curves.clear(); - - UntrackObject(target); -} - -// Assigns a curve to a value of the animated element. -bool FCDAnimated::AddCurve(size_t index, FCDAnimationCurve* curve) -{ - FUAssert(index < GetValueCount(), return false); - curves.at(index).push_back(curve); - SetNewChildFlag(); - return true; -} - -bool FCDAnimated::AddCurve(size_t index, FCDAnimationCurveList& curve) -{ - FUAssert(index < GetValueCount() && !curve.empty(), return false); - curves.at(index).insert(curves.at(index).end(), curve.begin(), curve.end()); - SetNewChildFlag(); - return true; -} - -// Removes the curves affecting a value of the animated element. -bool FCDAnimated::RemoveCurve(size_t index) -{ - FUAssert(index < GetValueCount(), return false); - bool hasCurve = !curves[index].empty(); - curves[index].clear(); - SetNewChildFlag(); - return hasCurve; -} - -const fm::string& FCDAnimated::GetQualifier(size_t index) const -{ - FUAssert(index < GetValueCount(), return emptyString); - return qualifiers.at(index); -} - -// Retrieves an animated value, given a valid qualifier -float* FCDAnimated::FindValue(const fm::string& qualifier) -{ - for (size_t i = 0; i < qualifiers.size(); ++i) - { - if (qualifiers[i] == qualifier) return values[i]; - } - return NULL; -} -const float* FCDAnimated::FindValue(const fm::string& qualifier) const -{ - for (size_t i = 0; i < qualifiers.size(); ++i) - { - if (qualifiers[i] == qualifier) return values[i]; - } - return NULL; -} - -// Retrieve the index of a given qualifier -size_t FCDAnimated::FindQualifier(const char* qualifier) const -{ - for (size_t i = 0; i < qualifiers.size(); ++i) - { - if (qualifiers[i] == qualifier) return i; - } - - // Otherwise, check for a matrix element - int32 matrixElement = FUStringConversion::ParseQualifier(qualifier); - if (matrixElement >= 0 && matrixElement < (int32) qualifiers.size()) return matrixElement; - return size_t(-1); -} - -// Retrieve the index of a given value pointer -size_t FCDAnimated::FindValue(const float* value) const -{ - for (size_t i = 0; i < values.size(); ++i) - { - if (values[i] == value) return i; - } - return size_t(-1); -} - -// Return the update target of this animations -void FCDAnimated::SetTargetObject(FCDObject* _target) -{ - UntrackObject(target); - target = _target; - TrackObject(target); -} - -// Returns whether any of the contained curves are non-NULL -bool FCDAnimated::HasCurve() const -{ - FCDAnimationCurveListList::const_iterator cit; - for (cit = curves.begin(); cit != curves.end() && (*cit).empty(); ++cit) {} - return cit != curves.end(); -} - -// Create one multi-curve out of this animated value's single curves -FCDAnimationMultiCurve* FCDAnimated::CreateMultiCurve() const -{ - FloatList defaultValues; - size_t count = values.size(); - defaultValues.resize(count); - for (size_t i = 0; i < count; ++i) defaultValues[i] = (*values[i]); - - fm::pvector toMerge; - toMerge.resize(count); - for (size_t i = 0; i < count; ++i) toMerge[i] = (!curves[i].empty()) ? curves[i][0] : NULL; - return FCDAnimationCurveTools::MergeCurves(toMerge, defaultValues); -} - -// Create one multi-curve out of the single curves from many FCDAnimated objects -FCDAnimationMultiCurve* FCDAnimated::CreateMultiCurve(const FCDAnimatedList& toMerge) -{ - // Calculate the total dimension of the curve to create - size_t count = 0; - for (FCDAnimatedList::const_iterator cit = toMerge.begin(); cit != toMerge.end(); ++cit) - { - count += (*cit)->GetValueCount(); - } - - // Generate the list of default values and the list of curves - FloatList defaultValues(count, 0.0f); - FCDAnimationCurveConstList curves(count); - size_t offset = 0; - for (FCDAnimatedList::const_iterator cit = toMerge.begin(); cit != toMerge.end(); ++cit) - { - size_t localCount = (*cit)->GetValueCount(); - for (size_t i = 0; i < localCount; ++i) - { - defaultValues[offset + i] = *(*cit)->GetValue(i); - curves[offset + i] = (*cit)->GetCurve(i); - } - offset += localCount; - } - - return FCDAnimationCurveTools::MergeCurves(curves, defaultValues); -} - -// Sample the animated values for a given time -void FCDAnimated::Evaluate(float time) -{ - size_t valueCount = values.size(); - size_t curveCount = curves.size(); - size_t count = min(curveCount, valueCount); - for (size_t i = 0; i < count; ++i) - { - if (!curves[i].empty()) - { - // Retrieve the curve and the corresponding value - FCDAnimationCurve* curve = curves[i][0]; - if (curve == NULL) continue; - float* value = values[i]; - if (value == NULL) continue; - - // Evaluate the curve at this time - (*value) = curve->Evaluate(time); - if (target != NULL) target->SetValueChange(); - } - } -} - -FCDAnimated* FCDAnimated::Clone(FCDocument* document) const -{ - // Generate the constant arrays for the qualifiers and the value pointers. - size_t valueCount = GetValueCount(); - typedef const char* ccharptr; - typedef float* floatptr; - ccharptr* cloneQualifiers = new ccharptr[valueCount]; - floatptr* cloneValues = new floatptr[valueCount]; - for (size_t i = 0; i < valueCount; ++i) - { - cloneQualifiers[i] = qualifiers[i].c_str(); - cloneValues[i] = const_cast(values[i]); - } - - // Clone this animated. - FCDAnimated* clone = new FCDAnimated(document, GetValueCount(), cloneQualifiers, cloneValues); - clone->arrayElement = arrayElement; - for (size_t i = 0; i < curves.size(); ++i) - { - for (size_t j = 0; j < curves[i].size(); ++j) - { - FCDAnimationCurve* clonedCurve = const_cast(curves[i][j])->GetParent()->AddCurve(); - curves[i][j]->Clone(clonedCurve); - clone->AddCurve(i, clonedCurve); - } - } - - SAFE_DELETE_ARRAY(cloneQualifiers); - SAFE_DELETE_ARRAY(cloneValues); - return clone; -} - -FCDAnimated* FCDAnimated::Clone(FCDAnimated* clone) const -{ - if (clone != NULL) - { - // Clone the miscellaneous parameters. - clone->arrayElement = arrayElement; - - // Clone the qualifiers and the curve lists for each value. - size_t valueCount = min(GetValueCount(), clone->GetValueCount()); - for (size_t i = 0; i < valueCount; ++i) - { - clone->qualifiers[i] = qualifiers[i]; - clone->curves[i] = curves[i]; - } - } - return clone; -} - -void FCDAnimated::OnObjectReleased(FUTrackable* object) -{ - FUAssert(object == target, return); - target = NULL; - - // Delete ourselves. We have no job left, if something - // wants us they can reconstruct from FCDAnimationChannel - Release(); -} - -// -// FCDAnimatedCustom -// - -ImplementObjectType(FCDAnimatedCustom); - -static const char* customAnimatedTemporaryQualifier = ""; -static float* customAnimatedTemporaryValue = NULL; - -FCDAnimatedCustom::FCDAnimatedCustom(FCDObject* object) -: FCDAnimated(object, 1, &customAnimatedTemporaryQualifier, &customAnimatedTemporaryValue) -, dummy(0.0f) -{ - values[0] = &dummy; - - // Register this animated value with the document - GetDocument()->RegisterAnimatedValue(this); -} - -void FCDAnimatedCustom::Copy(const FCDAnimated* copy) -{ - if (copy != NULL) - { - Resize(copy->GetValueCount(), NULL, false); - copy->Clone(this); - } -} - -void FCDAnimatedCustom::Resize(size_t count, const char** _qualifiers, bool prependDot) -{ - FUAssert(count >= values.size(), return); // don't loose information, but growing is fine. - values.reserve(count); while (values.size() < count) values.push_back(&dummy); - qualifiers.resize(count); - curves.resize(count); - - for (size_t i = 0; i < count && _qualifiers != NULL && *_qualifiers != 0; ++i) - { - qualifiers[i] = (prependDot ? fm::string(".") : fm::string("")) + *(_qualifiers++); - } -} - -void FCDAnimatedCustom::Resize(const StringList& _qualifiers, bool prependDot) -{ - size_t count = _qualifiers.size(); - FUAssert(count >= values.size(), return); // don't loose information, but growing is fine. - values.reserve(count); while (values.size() < count) values.push_back(&dummy); - qualifiers.resize(count); - curves.resize(count); - - for (size_t i = 0; i < count; ++i) - { - qualifiers[i] = (prependDot ? fm::string(".") : fm::string("")) + _qualifiers[i]; - } -} - -namespace FCDAnimatedStandardQualifiers -{ - FCOLLADA_EXPORT const char* EMPTY[1] = { "" }; - FCOLLADA_EXPORT const char* XYZW[4] = { ".X", ".Y", ".Z", ".W" }; - FCOLLADA_EXPORT const char* RGBA[4] = { ".R", ".G", ".B", ".A" }; - - FCOLLADA_EXPORT const char* ROTATE_AXIS[4] = { ".X", ".Y", ".Z", ".ANGLE" }; - FCOLLADA_EXPORT const char* SKEW[7] = { ".ROTATEX", ".ROTATEY", ".ROTATEZ", ".AROUNDX", ".AROUNDY", ".AROUNDZ", ".ANGLE" }; - FCOLLADA_EXPORT const char* MATRIX[16] = { "(0)(0)", "(1)(0)", "(2)(0)", "(3)(0)", "(0)(1)", "(1)(1)", "(2)(1)", "(3)(1)", "(0)(2)", "(1)(2)", "(2)(2)", "(3)(2)", "(0)(3)", "(1)(3)", "(2)(3)", "(3)(3)" }; - FCOLLADA_EXPORT const char* LOOKAT[9] = { ".POSITIONX", ".POSITIONY", ".POSITIONZ", ".TARGETX", ".TARGETY", ".TARGETZ", ".UPX", ".UPY", ".UPZ" }; -}; +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimationChannel.h" +#include "FCDocument/FCDAnimationCurve.h" +#include "FCDocument/FCDAnimationCurveTools.h" +#include "FCDocument/FCDAnimated.h" + + +// +// FCDAnimated +// + +ImplementObjectType(FCDAnimated); + +FCDAnimated::FCDAnimated(FCDocument* document, size_t valueCount, const char** _qualifiers, float** _values) +: FCDObject(document) +, target(NULL) +{ + arrayElement = -1; + + // Allocate the values/qualifiers/curves arrays + values.resize(valueCount); + qualifiers.resize(valueCount); + curves.resize(valueCount); + + for (size_t i = 0; i < valueCount; ++i) + { + values[i] = _values[i]; + qualifiers[i] = _qualifiers[i]; + } + + ResetRelativeAnimationFlag(); +} + +FCDAnimated::FCDAnimated(FCDObject* object, size_t valueCount, const char** _qualifiers, float** _values) +: FCDObject(object->GetDocument()) +{ + arrayElement = -1; + + // Allocate the values/qualifiers/curves arrays + values.resize(valueCount); + qualifiers.resize(valueCount); + curves.resize(valueCount); + + for (size_t i = 0; i < valueCount; ++i) + { + values[i] = _values[i]; + qualifiers[i] = _qualifiers[i]; + } + + // Register this animated value with the document + GetDocument()->RegisterAnimatedValue(this); + + target = object; + TrackObject(target); +} + +FCDAnimated::~FCDAnimated() +{ + GetDocument()->UnregisterAnimatedValue(this); + + values.clear(); + qualifiers.clear(); + curves.clear(); + + UntrackObject(target); +} + +// Assigns a curve to a value of the animated element. +bool FCDAnimated::AddCurve(size_t index, FCDAnimationCurve* curve) +{ + FUAssert(index < GetValueCount(), return false); + curves.at(index).push_back(curve); + SetNewChildFlag(); + return true; +} + +bool FCDAnimated::AddCurve(size_t index, FCDAnimationCurveList& curve) +{ + FUAssert(index < GetValueCount() && !curve.empty(), return false); + curves.at(index).insert(curves.at(index).end(), curve.begin(), curve.end()); + SetNewChildFlag(); + return true; +} + +// Removes the curves affecting a value of the animated element. +bool FCDAnimated::RemoveCurve(size_t index) +{ + FUAssert(index < GetValueCount(), return false); + bool hasCurve = !curves[index].empty(); + curves[index].clear(); + SetNewChildFlag(); + return hasCurve; +} + +const fm::string& FCDAnimated::GetQualifier(size_t index) const +{ + FUAssert(index < GetValueCount(), return emptyString); + return qualifiers.at(index); +} + +// Retrieves an animated value, given a valid qualifier +float* FCDAnimated::FindValue(const fm::string& qualifier) +{ + for (size_t i = 0; i < qualifiers.size(); ++i) + { + if (qualifiers[i] == qualifier) return values[i]; + } + return NULL; +} +const float* FCDAnimated::FindValue(const fm::string& qualifier) const +{ + for (size_t i = 0; i < qualifiers.size(); ++i) + { + if (qualifiers[i] == qualifier) return values[i]; + } + return NULL; +} + +// Retrieve the index of a given qualifier +size_t FCDAnimated::FindQualifier(const char* qualifier) const +{ + for (size_t i = 0; i < qualifiers.size(); ++i) + { + if (qualifiers[i] == qualifier) return i; + } + + // Otherwise, check for a matrix element + int32 matrixElement = FUStringConversion::ParseQualifier(qualifier); + if (matrixElement >= 0 && matrixElement < (int32) qualifiers.size()) return matrixElement; + return size_t(-1); +} + +// Retrieve the index of a given value pointer +size_t FCDAnimated::FindValue(const float* value) const +{ + for (size_t i = 0; i < values.size(); ++i) + { + if (values[i] == value) return i; + } + return size_t(-1); +} + +// Return the update target of this animations +void FCDAnimated::SetTargetObject(FCDObject* _target) +{ + UntrackObject(target); + target = _target; + TrackObject(target); +} + +// Returns whether any of the contained curves are non-NULL +bool FCDAnimated::HasCurve() const +{ + FCDAnimationCurveListList::const_iterator cit; + for (cit = curves.begin(); cit != curves.end() && (*cit).empty(); ++cit) {} + return cit != curves.end(); +} + +// Create one multi-curve out of this animated value's single curves +FCDAnimationMultiCurve* FCDAnimated::CreateMultiCurve() const +{ + FloatList defaultValues; + size_t count = values.size(); + defaultValues.resize(count); + for (size_t i = 0; i < count; ++i) defaultValues[i] = (*values[i]); + + fm::pvector toMerge; + toMerge.resize(count); + for (size_t i = 0; i < count; ++i) toMerge[i] = (!curves[i].empty()) ? curves[i][0] : NULL; + return FCDAnimationCurveTools::MergeCurves(toMerge, defaultValues); +} + +// Create one multi-curve out of the single curves from many FCDAnimated objects +FCDAnimationMultiCurve* FCDAnimated::CreateMultiCurve(const FCDAnimatedList& toMerge) +{ + // Calculate the total dimension of the curve to create + size_t count = 0; + for (FCDAnimatedList::const_iterator cit = toMerge.begin(); cit != toMerge.end(); ++cit) + { + count += (*cit)->GetValueCount(); + } + + // Generate the list of default values and the list of curves + FloatList defaultValues(count, 0.0f); + FCDAnimationCurveConstList curves(count); + size_t offset = 0; + for (FCDAnimatedList::const_iterator cit = toMerge.begin(); cit != toMerge.end(); ++cit) + { + size_t localCount = (*cit)->GetValueCount(); + for (size_t i = 0; i < localCount; ++i) + { + defaultValues[offset + i] = *(*cit)->GetValue(i); + curves[offset + i] = (*cit)->GetCurve(i); + } + offset += localCount; + } + + return FCDAnimationCurveTools::MergeCurves(curves, defaultValues); +} + +// Sample the animated values for a given time +void FCDAnimated::Evaluate(float time) +{ + size_t valueCount = values.size(); + size_t curveCount = curves.size(); + size_t count = min(curveCount, valueCount); + for (size_t i = 0; i < count; ++i) + { + if (!curves[i].empty()) + { + // Retrieve the curve and the corresponding value + FCDAnimationCurve* curve = curves[i][0]; + if (curve == NULL) continue; + float* value = values[i]; + if (value == NULL) continue; + + // Evaluate the curve at this time + (*value) = curve->Evaluate(time); + if (target != NULL) target->SetValueChange(); + } + } +} + +FCDAnimated* FCDAnimated::Clone(FCDocument* document) const +{ + // Generate the constant arrays for the qualifiers and the value pointers. + size_t valueCount = GetValueCount(); + typedef const char* ccharptr; + typedef float* floatptr; + ccharptr* cloneQualifiers = new ccharptr[valueCount]; + floatptr* cloneValues = new floatptr[valueCount]; + for (size_t i = 0; i < valueCount; ++i) + { + cloneQualifiers[i] = qualifiers[i].c_str(); + cloneValues[i] = const_cast(values[i]); + } + + // Clone this animated. + FCDAnimated* clone = new FCDAnimated(document, GetValueCount(), cloneQualifiers, cloneValues); + clone->arrayElement = arrayElement; + for (size_t i = 0; i < curves.size(); ++i) + { + for (size_t j = 0; j < curves[i].size(); ++j) + { + FCDAnimationCurve* clonedCurve = const_cast(curves[i][j])->GetParent()->AddCurve(); + curves[i][j]->Clone(clonedCurve); + clone->AddCurve(i, clonedCurve); + } + } + + SAFE_DELETE_ARRAY(cloneQualifiers); + SAFE_DELETE_ARRAY(cloneValues); + return clone; +} + +FCDAnimated* FCDAnimated::Clone(FCDAnimated* clone) const +{ + if (clone != NULL) + { + // Clone the miscellaneous parameters. + clone->arrayElement = arrayElement; + + // Clone the qualifiers and the curve lists for each value. + size_t valueCount = min(GetValueCount(), clone->GetValueCount()); + for (size_t i = 0; i < valueCount; ++i) + { + clone->qualifiers[i] = qualifiers[i]; + clone->curves[i] = curves[i]; + } + } + return clone; +} + +void FCDAnimated::OnObjectReleased(FUTrackable* object) +{ + FUAssert(object == target, return); + target = NULL; + + // Delete ourselves. We have no job left, if something + // wants us they can reconstruct from FCDAnimationChannel + Release(); +} + +// +// FCDAnimatedCustom +// + +ImplementObjectType(FCDAnimatedCustom); + +static const char* customAnimatedTemporaryQualifier = ""; +static float* customAnimatedTemporaryValue = NULL; + +FCDAnimatedCustom::FCDAnimatedCustom(FCDObject* object) +: FCDAnimated(object, 1, &customAnimatedTemporaryQualifier, &customAnimatedTemporaryValue) +, dummy(0.0f) +{ + values[0] = &dummy; + + // Register this animated value with the document + GetDocument()->RegisterAnimatedValue(this); +} + +void FCDAnimatedCustom::Copy(const FCDAnimated* copy) +{ + if (copy != NULL) + { + Resize(copy->GetValueCount(), NULL, false); + copy->Clone(this); + } +} + +void FCDAnimatedCustom::Resize(size_t count, const char** _qualifiers, bool prependDot) +{ + FUAssert(count >= values.size(), return); // don't loose information, but growing is fine. + values.reserve(count); while (values.size() < count) values.push_back(&dummy); + qualifiers.resize(count); + curves.resize(count); + + for (size_t i = 0; i < count && _qualifiers != NULL && *_qualifiers != 0; ++i) + { + qualifiers[i] = (prependDot ? fm::string(".") : fm::string("")) + *(_qualifiers++); + } +} + +void FCDAnimatedCustom::Resize(const StringList& _qualifiers, bool prependDot) +{ + size_t count = _qualifiers.size(); + FUAssert(count >= values.size(), return); // don't loose information, but growing is fine. + values.reserve(count); while (values.size() < count) values.push_back(&dummy); + qualifiers.resize(count); + curves.resize(count); + + for (size_t i = 0; i < count; ++i) + { + qualifiers[i] = (prependDot ? fm::string(".") : fm::string("")) + _qualifiers[i]; + } +} + +namespace FCDAnimatedStandardQualifiers +{ + FCOLLADA_EXPORT const char* EMPTY[1] = { "" }; + FCOLLADA_EXPORT const char* XYZW[4] = { ".X", ".Y", ".Z", ".W" }; + FCOLLADA_EXPORT const char* RGBA[4] = { ".R", ".G", ".B", ".A" }; + + FCOLLADA_EXPORT const char* ROTATE_AXIS[4] = { ".X", ".Y", ".Z", ".ANGLE" }; + FCOLLADA_EXPORT const char* SKEW[7] = { ".ROTATEX", ".ROTATEY", ".ROTATEZ", ".AROUNDX", ".AROUNDY", ".AROUNDZ", ".ANGLE" }; + FCOLLADA_EXPORT const char* MATRIX[16] = { "(0)(0)", "(1)(0)", "(2)(0)", "(3)(0)", "(0)(1)", "(1)(1)", "(2)(1)", "(3)(1)", "(0)(2)", "(1)(2)", "(2)(2)", "(3)(2)", "(0)(3)", "(1)(3)", "(2)(3)", "(3)(3)" }; + FCOLLADA_EXPORT const char* LOOKAT[9] = { ".POSITIONX", ".POSITIONY", ".POSITIONZ", ".TARGETX", ".TARGETY", ".TARGETZ", ".UPX", ".UPY", ".UPZ" }; +}; Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimated.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimated.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimated.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimated.h (revision 24247) @@ -1,328 +1,328 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDAnimated.h - This file contains the FCDAnimated class. -*/ - -#ifndef _FCD_ANIMATED_H_ -#define _FCD_ANIMATED_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ - -class FCDocument; -class FCDAnimated; -class FCDAnimationCurve; -class FCDAnimationChannel; -class FCDAnimationMultiCurve; - -typedef fm::pvector FloatPtrList; /**< A dynamically-sized array of floating-point value pointers. */ -typedef fm::pvector FCDAnimationCurveList; /**< A dynamically-sized array of animation curves. */ -typedef FUTrackedList FCDAnimationCurveTrackList; /**< A dynamically-sized array of tracked animation curves. */ -typedef fm::vector FCDAnimationCurveListList; /**< A dynamically-sized array of animation curve lists. */ -typedef fm::pvector FCDAnimationChannelList; /**< A dynamically-sized array of animation channels. */ -typedef fm::pvector FCDAnimatedList; /**< A dynamically-sized array of animated values. */ - -/** - An animated element. - An animated element encapsulates a set of floating-point values that are - marked as animated. - - For this purpose, an animated element holds a list of floating-point values, - their animation curves and their COLLADA qualifiers for the generation of - COLLADA targets. For animated list elements, an animated element holds an array index. - - There are many classes built on top of this class. They represent - the different element types that may be animated, such as 3D points, - colors and matrices. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDAnimated : public FCDObject, FUTracker -{ -private: - DeclareObjectType(FCDObject); - -protected: - /** The list of value pointers. */ - FloatPtrList values; - - /** The list of target qualifiers. - There is always one qualifier for one value pointer. */ - StringList qualifiers; - - /** The list of animation curves. - There is always one curve for one value pointer, although - that curve may be the NULL pointer to indicate a non-animated value. */ - FCDAnimationCurveListList curves; - - /** The target object who contain the float values.*/ - FCDObject* target; - - /** The array index for animated element that belong - to a list of animated elements. This value may be -1 - to indicate that the element does not belong to a list. - Otherwise, the index should always be unsigned. */ - int32 arrayElement; - -public: - DeclareFlag(RelativeAnimation, 0); /**< Flag to indicate that the animation should be applied relative to the default value. */ - DeclareFlagCount(1); /**< The FCDAnimated class declares one flag. */ - -public: - /** Constructor. - @param object The FCollada object that owns this animated element. - @param valueCount The number of values inside the animated element. - @param qualifiers A constant array of UTF8 string defining the qualifier for each value. - You should check out the arrays in FUDaeAccessor for examples. - @param values A constant array containing the value pointers. */ - FCDAnimated(FCDObject* object, size_t valueCount, const char** qualifiers, float** values); - - /** Constructor. - @param document The COLLADA document that owns this animated element. - @param valueCount The number of values inside the animated element. - @param qualifiers A constant array of UTF8 string defining the qualifier for each value. - You should check out the arrays in FUDaeAccessor for examples. - @param values A constant array containing the value pointers. */ - FCDAnimated(FCDocument* document, size_t valueCount, const char** qualifiers, float** values); - - /** Destructor. */ - virtual ~FCDAnimated(); - - /** Retrieves the number of values contained within this animated element. - @return The number of values. */ - inline size_t GetValueCount() const { return values.size(); } - - /** Retrieves the number of animation curves affecting one value of an animated element. - @param index The value index. - @return The number of curves affecting this value. */ - inline size_t GetCurveCount(size_t index) const { FUAssert(index < GetValueCount(), return 0); return curves[index].size(); } - - /** Retrieves the animation curve affecting the value of an animated element. - @param index The value index. - @param curveIndex The index of the curve within the list of curves affecting the - value at the given index. - @return The curve affecting the value at the given index. This pointer will - be NULL if one of the index is out-of-bounds or if the value is not animated. */ - inline FCDAnimationCurve* GetCurve(size_t index, size_t curveIndex = 0) { FUAssert(index < GetValueCount(), return NULL); return curveIndex < curves.at(index).size() ? curves.at(index).at(curveIndex) : NULL; } - inline const FCDAnimationCurve* GetCurve(size_t index, size_t curveIndex = 0) const { FUAssert(index < GetValueCount(), return NULL); return curveIndex < curves.at(index).size() ? curves.at(index).at(curveIndex) : NULL; } /**< See above. */ - - /** Retrieves the list of the curves affecting the values of an animated element. - This list may contain the NULL pointer, where a value is not animated. - @return The list of animation curves. */ - inline FCDAnimationCurveListList& GetCurves() { return curves; } - inline const FCDAnimationCurveListList& GetCurves() const { return curves; } /**< See above. */ - - /** Assigns a curve to a value of the animated element. - The previously assigned curve will be deleted. - @param index The value index. - @param curve The new curve(s) that will affect the value at the given index. - @return Whether the curve was successfully assigned. Will return false if - the index is out-of-bounds. */ - bool AddCurve(size_t index, FCDAnimationCurve* curve); - bool AddCurve(size_t index, FCDAnimationCurveList& curve); /**< See above. */ - - /** Removes the curves affecting a value of the animated element. - @param index The value index. - @return Whether a curve was successfully removed. Will return false - if there was no curve to release or the index is out-of-bounds. */ - bool RemoveCurve(size_t index); - - /** Retrieves the value of an animated element. - @param index The value index. - @return The value at the given index. This pointer will - be NULL if the index is out-of-boudns. */ - inline float* GetValue(size_t index) { FUAssert(index < GetValueCount(), return NULL); return values.at(index); } - inline const float* GetValue(size_t index) const { FUAssert(index < GetValueCount(), return NULL); return values.at(index); } /**< See above. */ - - /** [INTERNAL] Overwrites the value pointer of an animated element. - Used when changing the list size within FCDParameterAnimatableList. - @param index The value index. - @param value The new value pointer for this index. */ - inline void SetValue(size_t index, float* value) { FUAssert(index < GetValueCount(), return); values.at(index) = value; } - - /** Retrieves the qualifier of the value of an animated element. - @param index The value index. - @return The qualifier for the value. The value returned will be an - empty string when the index is out-of-bounds. */ - const fm::string& GetQualifier(size_t index) const; - - /** [INTERNAL] Retrieve the qualifier list directly. - @return The reference to the qualifier list. - */ - StringList& GetQualifiers(){ return qualifiers; } - - /** Retrieves an animated value given a valid qualifier. - @param qualifier A valid qualifier. - @return The animated value for this qualifier. This pointer will be - NULL if the given qualifier is not used within this animated element. */ - float* FindValue(const fm::string& qualifier); - const float* FindValue(const fm::string& qualifier) const; /**< See above. */ - - /** Retrieves an animation curve given a valid qualifier. - @param qualifier A valid qualifier. - @return The animation curve for this qualifier. This pointer will be - NULL if the given qualifier is not used within this animated element - or if the value for the given qualifier is not animated. */ - inline FCDAnimationCurve* FindCurve(const char* qualifier) { size_t index = FindQualifier(qualifier); return index < GetValueCount() ? GetCurve(index) : NULL; } - inline FCDAnimationCurve* FindCurve(const fm::string& qualifier) { return FindCurve(qualifier.c_str()); } /**< See above. */ - inline const FCDAnimationCurve* FindCurve(const char* qualifier) const { size_t index = FindQualifier(qualifier); return index < GetValueCount() ? GetCurve(index) : NULL; } /**< See above. */ - inline const FCDAnimationCurve* FindCurve(const fm::string& qualifier) const { return FindCurve(qualifier.c_str()); } /**< See above. */ - - /** Retrieves an animation curve given a value pointer. - @param value A value pointer contained within the animated element. - @return The animation curve for this qualifier. This pointer will be - NULL if the value pointer is not contained by this animated element - or if the value is not animated. */ - inline FCDAnimationCurve* FindCurve(const float* value) { size_t index = FindValue(value); return index < GetValueCount() ? GetCurve(index) : NULL; } - inline const FCDAnimationCurve* FindCurve(const float* value) const { size_t index = FindValue(value); return index < GetValueCount() ? GetCurve(index) : NULL; } /**< See above. */ - - /** Retrieves the value index for a given qualifier. - @param qualifier A valid qualifier. - @return The value index. This value will be -1 to indicate that the - qualifier does not belong to this animated element. */ - size_t FindQualifier(const char* qualifier) const; - inline size_t FindQualifier(const fm::string& qualifier) const { return FindQualifier(qualifier.c_str()); } /**< See above. */ - - /** Retrieves the value index for a given value pointer. - @param value A value pointer contained within the animated element. - @return The value index. This value will be -1 to indicate that the - value pointer is not contained by this animated element. */ - size_t FindValue(const float* value) const; - - /** Sets the FCDObject this animated value will notify when making changes - @param _target Pointer to the FCDObject we will notify*/ - void SetTargetObject(FCDObject* _target); - - /** Returns the FCDObject this animated value will notify when making changes - @return Pointer to the FCDObject we notify*/ - FCDObject* GetTargetObject() { return target; } - - /** Retrieves the array index for an animated element. - This value is used only for animated elements that belong - to a list of animated elements within the COLLADA document. - @return The array index. This value will be -1 to indicate that - the animated element does not belong to a list. */ - inline int32 GetArrayElement() const { return arrayElement; } - - /** Sets the array index for an animated element. - This value is used only for animated elements that belong - to a list of animated elements within the COLLADA document. - @param index The array index. This value should be -1 to indicate that - the animated element does not belong to a list. */ - inline void SetArrayElement(int32 index) { arrayElement = index; SetDirtyFlag(); } - - /** Retrieves whether this animated element has any animation curves - affecting its values. - @return Whether any curves affect this animated element. */ - bool HasCurve() const; - - /** Creates one multi-dimensional animation curve from this animated element. - This function is useful is your application does not handle animations - per-values, but instead needs one animation per-element. - @return The multi-dimensional animation curve. */ - FCDAnimationMultiCurve* CreateMultiCurve() const; - - /** Creates one multi-dimensional animation curve from a list of animated element. - This function is useful if your application does not handle animations - per-values. For example, we use this function is ColladaMax for animated scale values, - where one scale value is two rotations for the scale rotation pivot and one - 3D point for the scale factors. - @param toMerge The list of animated elements to merge - @return The multi-dimensional animation curve. */ - static FCDAnimationMultiCurve* CreateMultiCurve(const FCDAnimatedList& toMerge); - - /** Evaluates the animated element at a given time. - This function directly and permanently modifies the values - of the animated element according to the curves affecting them. - @param time The evaluation time. */ - void Evaluate(float time); - - /** Clones an animated element. - @param document The COLLADA document that owns the cloned animated element. - @return The cloned animated element. */ - FCDAnimated* Clone(FCDocument* document) const; - - /** Clones an animated element. - @param clone An animated element to be the clone of this element. - @return The clone. */ - FCDAnimated* Clone(FCDAnimated* clone) const; - - /** [INTERNAL] See FUTracker - On object deletion, remove ourselves as we no longer have any values to animate */ - virtual void OnObjectReleased(FUTrackable* object); -}; - -/** A COLLADA custom animated value. - Used for animated extra elements. A single value is used multiple times to hold - as many value pointers are necessary to hold the animation curves. - @ingroup FCDocument */ -class FCOLLADA_EXPORT FCDAnimatedCustom : public FCDAnimated -{ -private: - DeclareObjectType(FCDAnimated); - float dummy; - - bool Link(xmlNode* node); - -public: - /** [INTERNAL] - Don't build directly. - @param object The object that owns this animated value. */ - FCDAnimatedCustom(FCDObject* object); - - /** [INTERNAL] Initialized a custom animated element from - another animated element. The custom animated element will - be resized to copy the given animated element. - @param copy The animated element to copy. */ - void Copy(const FCDAnimated* copy); - - /** Retrieves the floating-point value used for all the value pointers. - @return The dummy floating-point value. */ - float& GetDummy() { return dummy; } - const float& GetDummy() const { return dummy; } /**< See above. */ - - /** Resizes the wanted qualifiers. - Using the FUDaeAccessor types or the FCDAnimatedStandardQualifiers types is recommended. - @param count The new size of the animated element. - @param qualifiers The new qualifiers for the animated element. - @param prependDot Whether to prepend the '.' character for all the qualifiers of the animated element. */ - void Resize(size_t count, const char** qualifiers = NULL, bool prependDot = true); - - /** Resizes the wanted qualifiers. - @param qualifiers The new qualifiers for the animated element. - @param prependDot Whether to prepend the '.' character for all the qualifiers of the animated element. */ - void Resize(const StringList& qualifiers = StringList(), bool prependDot = true); -}; - -/** The common qualifier lists. */ -namespace FCDAnimatedStandardQualifiers -{ - /** Common accessor type string arrays. - These are NULL-terminated and can be used with the AddAccessor function. */ - FCOLLADA_EXPORT extern const char* EMPTY[1]; /**< Used for qualifying single values. */ - FCOLLADA_EXPORT extern const char* XYZW[4]; /**< Used for position and vector values. */ - FCOLLADA_EXPORT extern const char* RGBA[4]; /**< Used for color value. */ - - FCOLLADA_EXPORT extern const char* ROTATE_AXIS[4]; /**< Used for angle-axis rotation transforms. */ - FCOLLADA_EXPORT extern const char* SKEW[7]; /**< Used for the skew transforms. */ - FCOLLADA_EXPORT extern const char* MATRIX[16]; /**< Used for animating matrix values. */ - FCOLLADA_EXPORT extern const char* LOOKAT[9]; /**< Used for the look-at transforms. */ -}; - -#endif // _FCD_ANIMATED_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDAnimated.h + This file contains the FCDAnimated class. +*/ + +#ifndef _FCD_ANIMATED_H_ +#define _FCD_ANIMATED_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ + +class FCDocument; +class FCDAnimated; +class FCDAnimationCurve; +class FCDAnimationChannel; +class FCDAnimationMultiCurve; + +typedef fm::pvector FloatPtrList; /**< A dynamically-sized array of floating-point value pointers. */ +typedef fm::pvector FCDAnimationCurveList; /**< A dynamically-sized array of animation curves. */ +typedef FUTrackedList FCDAnimationCurveTrackList; /**< A dynamically-sized array of tracked animation curves. */ +typedef fm::vector FCDAnimationCurveListList; /**< A dynamically-sized array of animation curve lists. */ +typedef fm::pvector FCDAnimationChannelList; /**< A dynamically-sized array of animation channels. */ +typedef fm::pvector FCDAnimatedList; /**< A dynamically-sized array of animated values. */ + +/** + An animated element. + An animated element encapsulates a set of floating-point values that are + marked as animated. + + For this purpose, an animated element holds a list of floating-point values, + their animation curves and their COLLADA qualifiers for the generation of + COLLADA targets. For animated list elements, an animated element holds an array index. + + There are many classes built on top of this class. They represent + the different element types that may be animated, such as 3D points, + colors and matrices. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDAnimated : public FCDObject, FUTracker +{ +private: + DeclareObjectType(FCDObject); + +protected: + /** The list of value pointers. */ + FloatPtrList values; + + /** The list of target qualifiers. + There is always one qualifier for one value pointer. */ + StringList qualifiers; + + /** The list of animation curves. + There is always one curve for one value pointer, although + that curve may be the NULL pointer to indicate a non-animated value. */ + FCDAnimationCurveListList curves; + + /** The target object who contain the float values.*/ + FCDObject* target; + + /** The array index for animated element that belong + to a list of animated elements. This value may be -1 + to indicate that the element does not belong to a list. + Otherwise, the index should always be unsigned. */ + int32 arrayElement; + +public: + DeclareFlag(RelativeAnimation, 0); /**< Flag to indicate that the animation should be applied relative to the default value. */ + DeclareFlagCount(1); /**< The FCDAnimated class declares one flag. */ + +public: + /** Constructor. + @param object The FCollada object that owns this animated element. + @param valueCount The number of values inside the animated element. + @param qualifiers A constant array of UTF8 string defining the qualifier for each value. + You should check out the arrays in FUDaeAccessor for examples. + @param values A constant array containing the value pointers. */ + FCDAnimated(FCDObject* object, size_t valueCount, const char** qualifiers, float** values); + + /** Constructor. + @param document The COLLADA document that owns this animated element. + @param valueCount The number of values inside the animated element. + @param qualifiers A constant array of UTF8 string defining the qualifier for each value. + You should check out the arrays in FUDaeAccessor for examples. + @param values A constant array containing the value pointers. */ + FCDAnimated(FCDocument* document, size_t valueCount, const char** qualifiers, float** values); + + /** Destructor. */ + virtual ~FCDAnimated(); + + /** Retrieves the number of values contained within this animated element. + @return The number of values. */ + inline size_t GetValueCount() const { return values.size(); } + + /** Retrieves the number of animation curves affecting one value of an animated element. + @param index The value index. + @return The number of curves affecting this value. */ + inline size_t GetCurveCount(size_t index) const { FUAssert(index < GetValueCount(), return 0); return curves[index].size(); } + + /** Retrieves the animation curve affecting the value of an animated element. + @param index The value index. + @param curveIndex The index of the curve within the list of curves affecting the + value at the given index. + @return The curve affecting the value at the given index. This pointer will + be NULL if one of the index is out-of-bounds or if the value is not animated. */ + inline FCDAnimationCurve* GetCurve(size_t index, size_t curveIndex = 0) { FUAssert(index < GetValueCount(), return NULL); return curveIndex < curves.at(index).size() ? curves.at(index).at(curveIndex) : NULL; } + inline const FCDAnimationCurve* GetCurve(size_t index, size_t curveIndex = 0) const { FUAssert(index < GetValueCount(), return NULL); return curveIndex < curves.at(index).size() ? curves.at(index).at(curveIndex) : NULL; } /**< See above. */ + + /** Retrieves the list of the curves affecting the values of an animated element. + This list may contain the NULL pointer, where a value is not animated. + @return The list of animation curves. */ + inline FCDAnimationCurveListList& GetCurves() { return curves; } + inline const FCDAnimationCurveListList& GetCurves() const { return curves; } /**< See above. */ + + /** Assigns a curve to a value of the animated element. + The previously assigned curve will be deleted. + @param index The value index. + @param curve The new curve(s) that will affect the value at the given index. + @return Whether the curve was successfully assigned. Will return false if + the index is out-of-bounds. */ + bool AddCurve(size_t index, FCDAnimationCurve* curve); + bool AddCurve(size_t index, FCDAnimationCurveList& curve); /**< See above. */ + + /** Removes the curves affecting a value of the animated element. + @param index The value index. + @return Whether a curve was successfully removed. Will return false + if there was no curve to release or the index is out-of-bounds. */ + bool RemoveCurve(size_t index); + + /** Retrieves the value of an animated element. + @param index The value index. + @return The value at the given index. This pointer will + be NULL if the index is out-of-boudns. */ + inline float* GetValue(size_t index) { FUAssert(index < GetValueCount(), return NULL); return values.at(index); } + inline const float* GetValue(size_t index) const { FUAssert(index < GetValueCount(), return NULL); return values.at(index); } /**< See above. */ + + /** [INTERNAL] Overwrites the value pointer of an animated element. + Used when changing the list size within FCDParameterAnimatableList. + @param index The value index. + @param value The new value pointer for this index. */ + inline void SetValue(size_t index, float* value) { FUAssert(index < GetValueCount(), return); values.at(index) = value; } + + /** Retrieves the qualifier of the value of an animated element. + @param index The value index. + @return The qualifier for the value. The value returned will be an + empty string when the index is out-of-bounds. */ + const fm::string& GetQualifier(size_t index) const; + + /** [INTERNAL] Retrieve the qualifier list directly. + @return The reference to the qualifier list. + */ + StringList& GetQualifiers(){ return qualifiers; } + + /** Retrieves an animated value given a valid qualifier. + @param qualifier A valid qualifier. + @return The animated value for this qualifier. This pointer will be + NULL if the given qualifier is not used within this animated element. */ + float* FindValue(const fm::string& qualifier); + const float* FindValue(const fm::string& qualifier) const; /**< See above. */ + + /** Retrieves an animation curve given a valid qualifier. + @param qualifier A valid qualifier. + @return The animation curve for this qualifier. This pointer will be + NULL if the given qualifier is not used within this animated element + or if the value for the given qualifier is not animated. */ + inline FCDAnimationCurve* FindCurve(const char* qualifier) { size_t index = FindQualifier(qualifier); return index < GetValueCount() ? GetCurve(index) : NULL; } + inline FCDAnimationCurve* FindCurve(const fm::string& qualifier) { return FindCurve(qualifier.c_str()); } /**< See above. */ + inline const FCDAnimationCurve* FindCurve(const char* qualifier) const { size_t index = FindQualifier(qualifier); return index < GetValueCount() ? GetCurve(index) : NULL; } /**< See above. */ + inline const FCDAnimationCurve* FindCurve(const fm::string& qualifier) const { return FindCurve(qualifier.c_str()); } /**< See above. */ + + /** Retrieves an animation curve given a value pointer. + @param value A value pointer contained within the animated element. + @return The animation curve for this qualifier. This pointer will be + NULL if the value pointer is not contained by this animated element + or if the value is not animated. */ + inline FCDAnimationCurve* FindCurve(const float* value) { size_t index = FindValue(value); return index < GetValueCount() ? GetCurve(index) : NULL; } + inline const FCDAnimationCurve* FindCurve(const float* value) const { size_t index = FindValue(value); return index < GetValueCount() ? GetCurve(index) : NULL; } /**< See above. */ + + /** Retrieves the value index for a given qualifier. + @param qualifier A valid qualifier. + @return The value index. This value will be -1 to indicate that the + qualifier does not belong to this animated element. */ + size_t FindQualifier(const char* qualifier) const; + inline size_t FindQualifier(const fm::string& qualifier) const { return FindQualifier(qualifier.c_str()); } /**< See above. */ + + /** Retrieves the value index for a given value pointer. + @param value A value pointer contained within the animated element. + @return The value index. This value will be -1 to indicate that the + value pointer is not contained by this animated element. */ + size_t FindValue(const float* value) const; + + /** Sets the FCDObject this animated value will notify when making changes + @param _target Pointer to the FCDObject we will notify*/ + void SetTargetObject(FCDObject* _target); + + /** Returns the FCDObject this animated value will notify when making changes + @return Pointer to the FCDObject we notify*/ + FCDObject* GetTargetObject() { return target; } + + /** Retrieves the array index for an animated element. + This value is used only for animated elements that belong + to a list of animated elements within the COLLADA document. + @return The array index. This value will be -1 to indicate that + the animated element does not belong to a list. */ + inline int32 GetArrayElement() const { return arrayElement; } + + /** Sets the array index for an animated element. + This value is used only for animated elements that belong + to a list of animated elements within the COLLADA document. + @param index The array index. This value should be -1 to indicate that + the animated element does not belong to a list. */ + inline void SetArrayElement(int32 index) { arrayElement = index; SetDirtyFlag(); } + + /** Retrieves whether this animated element has any animation curves + affecting its values. + @return Whether any curves affect this animated element. */ + bool HasCurve() const; + + /** Creates one multi-dimensional animation curve from this animated element. + This function is useful is your application does not handle animations + per-values, but instead needs one animation per-element. + @return The multi-dimensional animation curve. */ + FCDAnimationMultiCurve* CreateMultiCurve() const; + + /** Creates one multi-dimensional animation curve from a list of animated element. + This function is useful if your application does not handle animations + per-values. For example, we use this function is ColladaMax for animated scale values, + where one scale value is two rotations for the scale rotation pivot and one + 3D point for the scale factors. + @param toMerge The list of animated elements to merge + @return The multi-dimensional animation curve. */ + static FCDAnimationMultiCurve* CreateMultiCurve(const FCDAnimatedList& toMerge); + + /** Evaluates the animated element at a given time. + This function directly and permanently modifies the values + of the animated element according to the curves affecting them. + @param time The evaluation time. */ + void Evaluate(float time); + + /** Clones an animated element. + @param document The COLLADA document that owns the cloned animated element. + @return The cloned animated element. */ + FCDAnimated* Clone(FCDocument* document) const; + + /** Clones an animated element. + @param clone An animated element to be the clone of this element. + @return The clone. */ + FCDAnimated* Clone(FCDAnimated* clone) const; + + /** [INTERNAL] See FUTracker + On object deletion, remove ourselves as we no longer have any values to animate */ + virtual void OnObjectReleased(FUTrackable* object); +}; + +/** A COLLADA custom animated value. + Used for animated extra elements. A single value is used multiple times to hold + as many value pointers are necessary to hold the animation curves. + @ingroup FCDocument */ +class FCOLLADA_EXPORT FCDAnimatedCustom : public FCDAnimated +{ +private: + DeclareObjectType(FCDAnimated); + float dummy; + + bool Link(xmlNode* node); + +public: + /** [INTERNAL] + Don't build directly. + @param object The object that owns this animated value. */ + FCDAnimatedCustom(FCDObject* object); + + /** [INTERNAL] Initialized a custom animated element from + another animated element. The custom animated element will + be resized to copy the given animated element. + @param copy The animated element to copy. */ + void Copy(const FCDAnimated* copy); + + /** Retrieves the floating-point value used for all the value pointers. + @return The dummy floating-point value. */ + float& GetDummy() { return dummy; } + const float& GetDummy() const { return dummy; } /**< See above. */ + + /** Resizes the wanted qualifiers. + Using the FUDaeAccessor types or the FCDAnimatedStandardQualifiers types is recommended. + @param count The new size of the animated element. + @param qualifiers The new qualifiers for the animated element. + @param prependDot Whether to prepend the '.' character for all the qualifiers of the animated element. */ + void Resize(size_t count, const char** qualifiers = NULL, bool prependDot = true); + + /** Resizes the wanted qualifiers. + @param qualifiers The new qualifiers for the animated element. + @param prependDot Whether to prepend the '.' character for all the qualifiers of the animated element. */ + void Resize(const StringList& qualifiers = StringList(), bool prependDot = true); +}; + +/** The common qualifier lists. */ +namespace FCDAnimatedStandardQualifiers +{ + /** Common accessor type string arrays. + These are NULL-terminated and can be used with the AddAccessor function. */ + FCOLLADA_EXPORT extern const char* EMPTY[1]; /**< Used for qualifying single values. */ + FCOLLADA_EXPORT extern const char* XYZW[4]; /**< Used for position and vector values. */ + FCOLLADA_EXPORT extern const char* RGBA[4]; /**< Used for color value. */ + + FCOLLADA_EXPORT extern const char* ROTATE_AXIS[4]; /**< Used for angle-axis rotation transforms. */ + FCOLLADA_EXPORT extern const char* SKEW[7]; /**< Used for the skew transforms. */ + FCOLLADA_EXPORT extern const char* MATRIX[16]; /**< Used for animating matrix values. */ + FCOLLADA_EXPORT extern const char* LOOKAT[9]; /**< Used for the look-at transforms. */ +}; + +#endif // _FCD_ANIMATED_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimated.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimation.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimation.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimation.cpp (revision 24247) @@ -1,135 +1,135 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimation.h" -#include "FCDocument/FCDAnimationChannel.h" -#include "FCDocument/FCDAsset.h" - -// -// FCDAnimation -// - -ImplementObjectType(FCDAnimation); -ImplementParameterObject(FCDAnimation, FCDAnimation, children, new FCDAnimation(parent->GetDocument(), parent)); -ImplementParameterObject(FCDAnimation, FCDAnimationChannel, channels, new FCDAnimationChannel(parent->GetDocument(), parent)); - -FCDAnimation::FCDAnimation(FCDocument* document, FCDAnimation* _parent) -: FCDEntity(document, "Animation") -, parent(_parent) -, InitializeParameterNoArg(children) -, InitializeParameterNoArg(channels) -{ -} - -FCDAnimation::~FCDAnimation() -{ -// childNodes.clear(); - parent = NULL; -} - -FCDEntity* FCDAnimation::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDAnimation* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDAnimation(const_cast(GetDocument()), NULL); - else if (_clone->HasType(FCDAnimation::GetClassType())) clone = (FCDAnimation*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - // Clone the channels - for (const FCDAnimationChannel** it = channels.begin(); it != channels.end(); ++it) - { - FCDAnimationChannel* clonedChannel = clone->AddChannel(); - (*it)->Clone(clonedChannel); - } - - if (cloneChildren) - { - // Clone the animation tree children - for (const FCDAnimation** it = children.begin(); it != children.end(); ++it) - { - FCDAnimation* clonedChild = clone->AddChild(); - (*it)->Clone(clonedChild, cloneChildren); - } - } - } - - return _clone; -} - -// Creates a new animation entity sub-tree contained within this animation entity tree. -FCDAnimation* FCDAnimation::AddChild() -{ - FCDAnimation* animation = new FCDAnimation(GetDocument(), this); - children.push_back(animation); - SetNewChildFlag(); - return children.back(); -} - -// Adds a new animation channel to this animation entity. -FCDAnimationChannel* FCDAnimation::AddChannel() -{ - FCDAnimationChannel* channel = new FCDAnimationChannel(GetDocument(), this); - channels.push_back(channel); - SetNewChildFlag(); - return channels.back(); -} - -// Look for an animation children with the given COLLADA Id. -const FCDEntity* FCDAnimation::FindDaeId(const fm::string& daeId) const -{ - if (GetDaeId() == daeId) return this; - - for (const FCDAnimation** it = children.begin(); it != children.end(); ++it) - { - const FCDEntity* found = (*it)->FindDaeId(daeId); - if (found != NULL) return found; - } - return NULL; -} - -void FCDAnimation::GetHierarchicalAssets(FCDAssetConstList& assets) const -{ - for (const FCDAnimation* animation = this; animation != NULL; animation = animation->GetParent()) - { - // Retrieve the asset information structure for this node. - const FCDAsset* asset = animation->GetAsset(); - if (asset != NULL) assets.push_back(asset); - } - assets.push_back(GetDocument()->GetAsset()); -} - -// Retrieve all the curves created under this animation element, in the animation tree -void FCDAnimation::GetCurves(FCDAnimationCurveList& curves) -{ - // Retrieve the curves for this animation tree element - for (const FCDAnimationChannel** it = (const FCDAnimationChannel**) channels.begin(); it != channels.end(); ++it) - { - size_t channelCurveCount = (*it)->GetCurveCount(); - for (size_t i = 0; i < channelCurveCount; ++i) - { - curves.push_back((*it)->GetCurve(i)); - } - } - - // Retrieve the curves for the animation nodes under this one in the animation tree - size_t childCount = children.size(); - for (size_t i = 0; i < childCount; ++i) - { - children[i]->GetCurves(curves); - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimation.h" +#include "FCDocument/FCDAnimationChannel.h" +#include "FCDocument/FCDAsset.h" + +// +// FCDAnimation +// + +ImplementObjectType(FCDAnimation); +ImplementParameterObject(FCDAnimation, FCDAnimation, children, new FCDAnimation(parent->GetDocument(), parent)); +ImplementParameterObject(FCDAnimation, FCDAnimationChannel, channels, new FCDAnimationChannel(parent->GetDocument(), parent)); + +FCDAnimation::FCDAnimation(FCDocument* document, FCDAnimation* _parent) +: FCDEntity(document, "Animation") +, parent(_parent) +, InitializeParameterNoArg(children) +, InitializeParameterNoArg(channels) +{ +} + +FCDAnimation::~FCDAnimation() +{ +// childNodes.clear(); + parent = NULL; +} + +FCDEntity* FCDAnimation::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDAnimation* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDAnimation(const_cast(GetDocument()), NULL); + else if (_clone->HasType(FCDAnimation::GetClassType())) clone = (FCDAnimation*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + // Clone the channels + for (const FCDAnimationChannel** it = channels.begin(); it != channels.end(); ++it) + { + FCDAnimationChannel* clonedChannel = clone->AddChannel(); + (*it)->Clone(clonedChannel); + } + + if (cloneChildren) + { + // Clone the animation tree children + for (const FCDAnimation** it = children.begin(); it != children.end(); ++it) + { + FCDAnimation* clonedChild = clone->AddChild(); + (*it)->Clone(clonedChild, cloneChildren); + } + } + } + + return _clone; +} + +// Creates a new animation entity sub-tree contained within this animation entity tree. +FCDAnimation* FCDAnimation::AddChild() +{ + FCDAnimation* animation = new FCDAnimation(GetDocument(), this); + children.push_back(animation); + SetNewChildFlag(); + return children.back(); +} + +// Adds a new animation channel to this animation entity. +FCDAnimationChannel* FCDAnimation::AddChannel() +{ + FCDAnimationChannel* channel = new FCDAnimationChannel(GetDocument(), this); + channels.push_back(channel); + SetNewChildFlag(); + return channels.back(); +} + +// Look for an animation children with the given COLLADA Id. +const FCDEntity* FCDAnimation::FindDaeId(const fm::string& daeId) const +{ + if (GetDaeId() == daeId) return this; + + for (const FCDAnimation** it = children.begin(); it != children.end(); ++it) + { + const FCDEntity* found = (*it)->FindDaeId(daeId); + if (found != NULL) return found; + } + return NULL; +} + +void FCDAnimation::GetHierarchicalAssets(FCDAssetConstList& assets) const +{ + for (const FCDAnimation* animation = this; animation != NULL; animation = animation->GetParent()) + { + // Retrieve the asset information structure for this node. + const FCDAsset* asset = animation->GetAsset(); + if (asset != NULL) assets.push_back(asset); + } + assets.push_back(GetDocument()->GetAsset()); +} + +// Retrieve all the curves created under this animation element, in the animation tree +void FCDAnimation::GetCurves(FCDAnimationCurveList& curves) +{ + // Retrieve the curves for this animation tree element + for (const FCDAnimationChannel** it = (const FCDAnimationChannel**) channels.begin(); it != channels.end(); ++it) + { + size_t channelCurveCount = (*it)->GetCurveCount(); + for (size_t i = 0; i < channelCurveCount; ++i) + { + curves.push_back((*it)->GetCurve(i)); + } + } + + // Retrieve the curves for the animation nodes under this one in the animation tree + size_t childCount = children.size(); + for (size_t i = 0; i < childCount; ++i) + { + children[i]->GetCurves(curves); + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimation.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimation.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimation.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimation.h (revision 24247) @@ -1,158 +1,158 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDAnimation.h - This file contains the FCDAnimation class. -*/ - -#ifndef _FCD_ANIMATION_H_ -#define _FCD_ANIMATION_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDocument; -class FCDAnimated; -class FCDAnimation; -class FCDAnimationChannel; -class FCDAnimationCurve; - -typedef fm::pvector FCDAnimationChannelList; /**< A dynamically-sized array of animation channels. */ -typedef fm::pvector FCDAnimationCurveList; /**< A dynamically-sized array of animation curves. */ - -/** - A COLLADA animation entity. - An animation entity contains a list of child animation entities, - in order to form a tree of animation entities. - It also hold a list of animation channels, which hold the information - to generate animation curves. - - In other words, the animation entity is a structural class - used to group animation channels hierarchically. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDAnimation : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - - // Animation hierarchy - FCDAnimation* parent; - DeclareParameterContainer(FCDAnimation, children, FC("Children")); - - // Animation sources and channels - DeclareParameterContainer(FCDAnimationChannel, channels, FC("Channels")); - -public: - /** Constructor. Do not use directly. - Instead, use the FCDLibrary::AddEntity function - or the AddChild function, depending on the - hierarchical level of the animation entity. - @param document The FCollada document that owns the animation entity. - @param parent The parent animation entity. This pointer will be NULL for root animation entities. */ - FCDAnimation(FCDocument* document, FCDAnimation* parent = NULL); - - /** Destructor .*/ - virtual ~FCDAnimation(); - - /** Retrieves the entity class type. - This function is a part of the FCDEntity interface. - @return The entity class type: ANIMATION. */ - virtual Type GetType() const { return ANIMATION; } - - /** Retrieves the parent of the animation structure. - @return The animation parent. This pointer will be NULL - to indicate a root-level animation structure that is - contained within the animation library. */ - inline FCDAnimation* GetParent() { return parent; } - inline const FCDAnimation* GetParent() const { return parent; } /**< See above. */ - - /** Copies the animation tree into a clone. - The clone may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new animation tree - will be created and you will need to release the returned pointer manually. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - - /** Retrieves the entity with the given COLLADA id. - This function will look through the local sub-tree of animations - for the given COLLADA id. - @param daeId A COLLADA id. - @return The animation entity that matches the COLLADA id. This pointer - will be NULL if there are no animation entities that matches the COLLADA id. */ - virtual FCDEntity* FindDaeId(const fm::string& daeId) { return const_cast(const_cast(this)->FindDaeId(daeId)); } - virtual const FCDEntity* FindDaeId(const fm::string& daeId) const; /**< See above. */ - - /** Retrieves the number of animation entity sub-trees contained - by this animation entity tree. - @return The number of animation entity sub-trees. */ - inline size_t GetChildrenCount() const { return children.size(); } - - /** Retrieves an animation entity sub-tree contained by this - animation entity tree. - @param index The index of the sub-tree. - @return The animation entity sub-tree at the given index. This pointer will - be NULL if the index is out-of-bounds. */ - inline FCDAnimation* GetChild(size_t index) { FUAssert(index < children.size(), return NULL); return children.at(index); } - inline const FCDAnimation* GetChild(size_t index) const { FUAssert(index < children.size(), return NULL); return children.at(index); } /**< See above. */ - - /** Creates a new animation entity sub-tree contained within this animation entity tree. - @return The new animation sub-tree. */ - FCDAnimation* AddChild(); - - /** Retrieves the asset information structures that affect - this entity in its hierarchy. - @param assets A list of asset information structures to fill in. */ - inline void GetHierarchicalAssets(FCDAssetList& assets) { GetHierarchicalAssets(*(FCDAssetConstList*) &assets); } - virtual void GetHierarchicalAssets(FCDAssetConstList& assets) const; /**< See above. */ - - /** Retrieves the animation channels that target the given COLLADA target pointer. - @param pointer A COLLADA target pointer. - @param targetChannels A list of animation channels to fill in. - This list is not cleared. */ - void FindAnimationChannels(const fm::string& pointer, FCDAnimationChannelList& targetChannels); - - /** Retrieves the number of animation channels at this level within the animation tree. - @return The number of animation channels. */ - size_t GetChannelCount() const { return channels.size(); } - - /** Retrieves an animation channel contained by this animation entity. - @param index The index of the channel. - @return The channel at the given index. This pointer will be NULL - if the index is out-of-bounds. */ - FCDAnimationChannel* GetChannel(size_t index) { FUAssert(index < GetChannelCount(), return NULL); return channels.at(index); } - const FCDAnimationChannel* GetChannel(size_t index) const { FUAssert(index < GetChannelCount(), return NULL); return channels.at(index); } /**< See above. */ - - /** [INTERNAL] Retrieves the channels' list - @deprecated - @return The list of channels */ - DEPRECATED(3.05A, GetChannelCount and GetChannel(index)) - void GetChannels() const {} - - /** Adds a new animation channel to this animation entity. - @return The new animation channel. */ - FCDAnimationChannel* AddChannel(); - - /** Retrieves all the curves created in the subtree of this animation element. - @param curves A list of animation curves to fill in. - This list is not cleared. */ - void GetCurves(FCDAnimationCurveList& curves); -}; - -#endif // _FCD_ANIMATION_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDAnimation.h + This file contains the FCDAnimation class. +*/ + +#ifndef _FCD_ANIMATION_H_ +#define _FCD_ANIMATION_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDocument; +class FCDAnimated; +class FCDAnimation; +class FCDAnimationChannel; +class FCDAnimationCurve; + +typedef fm::pvector FCDAnimationChannelList; /**< A dynamically-sized array of animation channels. */ +typedef fm::pvector FCDAnimationCurveList; /**< A dynamically-sized array of animation curves. */ + +/** + A COLLADA animation entity. + An animation entity contains a list of child animation entities, + in order to form a tree of animation entities. + It also hold a list of animation channels, which hold the information + to generate animation curves. + + In other words, the animation entity is a structural class + used to group animation channels hierarchically. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDAnimation : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + + // Animation hierarchy + FCDAnimation* parent; + DeclareParameterContainer(FCDAnimation, children, FC("Children")); + + // Animation sources and channels + DeclareParameterContainer(FCDAnimationChannel, channels, FC("Channels")); + +public: + /** Constructor. Do not use directly. + Instead, use the FCDLibrary::AddEntity function + or the AddChild function, depending on the + hierarchical level of the animation entity. + @param document The FCollada document that owns the animation entity. + @param parent The parent animation entity. This pointer will be NULL for root animation entities. */ + FCDAnimation(FCDocument* document, FCDAnimation* parent = NULL); + + /** Destructor .*/ + virtual ~FCDAnimation(); + + /** Retrieves the entity class type. + This function is a part of the FCDEntity interface. + @return The entity class type: ANIMATION. */ + virtual Type GetType() const { return ANIMATION; } + + /** Retrieves the parent of the animation structure. + @return The animation parent. This pointer will be NULL + to indicate a root-level animation structure that is + contained within the animation library. */ + inline FCDAnimation* GetParent() { return parent; } + inline const FCDAnimation* GetParent() const { return parent; } /**< See above. */ + + /** Copies the animation tree into a clone. + The clone may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new animation tree + will be created and you will need to release the returned pointer manually. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + + /** Retrieves the entity with the given COLLADA id. + This function will look through the local sub-tree of animations + for the given COLLADA id. + @param daeId A COLLADA id. + @return The animation entity that matches the COLLADA id. This pointer + will be NULL if there are no animation entities that matches the COLLADA id. */ + virtual FCDEntity* FindDaeId(const fm::string& daeId) { return const_cast(const_cast(this)->FindDaeId(daeId)); } + virtual const FCDEntity* FindDaeId(const fm::string& daeId) const; /**< See above. */ + + /** Retrieves the number of animation entity sub-trees contained + by this animation entity tree. + @return The number of animation entity sub-trees. */ + inline size_t GetChildrenCount() const { return children.size(); } + + /** Retrieves an animation entity sub-tree contained by this + animation entity tree. + @param index The index of the sub-tree. + @return The animation entity sub-tree at the given index. This pointer will + be NULL if the index is out-of-bounds. */ + inline FCDAnimation* GetChild(size_t index) { FUAssert(index < children.size(), return NULL); return children.at(index); } + inline const FCDAnimation* GetChild(size_t index) const { FUAssert(index < children.size(), return NULL); return children.at(index); } /**< See above. */ + + /** Creates a new animation entity sub-tree contained within this animation entity tree. + @return The new animation sub-tree. */ + FCDAnimation* AddChild(); + + /** Retrieves the asset information structures that affect + this entity in its hierarchy. + @param assets A list of asset information structures to fill in. */ + inline void GetHierarchicalAssets(FCDAssetList& assets) { GetHierarchicalAssets(*(FCDAssetConstList*) &assets); } + virtual void GetHierarchicalAssets(FCDAssetConstList& assets) const; /**< See above. */ + + /** Retrieves the animation channels that target the given COLLADA target pointer. + @param pointer A COLLADA target pointer. + @param targetChannels A list of animation channels to fill in. + This list is not cleared. */ + void FindAnimationChannels(const fm::string& pointer, FCDAnimationChannelList& targetChannels); + + /** Retrieves the number of animation channels at this level within the animation tree. + @return The number of animation channels. */ + size_t GetChannelCount() const { return channels.size(); } + + /** Retrieves an animation channel contained by this animation entity. + @param index The index of the channel. + @return The channel at the given index. This pointer will be NULL + if the index is out-of-bounds. */ + FCDAnimationChannel* GetChannel(size_t index) { FUAssert(index < GetChannelCount(), return NULL); return channels.at(index); } + const FCDAnimationChannel* GetChannel(size_t index) const { FUAssert(index < GetChannelCount(), return NULL); return channels.at(index); } /**< See above. */ + + /** [INTERNAL] Retrieves the channels' list + @deprecated + @return The list of channels */ + DEPRECATED(3.05A, GetChannelCount and GetChannel(index)) + void GetChannels() const {} + + /** Adds a new animation channel to this animation entity. + @return The new animation channel. */ + FCDAnimationChannel* AddChannel(); + + /** Retrieves all the curves created in the subtree of this animation element. + @param curves A list of animation curves to fill in. + This list is not cleared. */ + void GetCurves(FCDAnimationCurveList& curves); +}; + +#endif // _FCD_ANIMATION_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimation.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationChannel.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationChannel.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationChannel.cpp (revision 24247) @@ -1,57 +1,57 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDAnimationChannel.h" -#include "FCDocument/FCDAnimationCurve.h" - -// -// FCDAnimationChannel -// - -ImplementObjectType(FCDAnimationChannel); -ImplementParameterObject(FCDAnimationChannel, FCDAnimationCurve, curves, new FCDAnimationCurve(parent->GetDocument(), parent)); - -FCDAnimationChannel::FCDAnimationChannel(FCDocument* document, FCDAnimation* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(curves) -{ -} - -FCDAnimationChannel::~FCDAnimationChannel() -{ - parent = NULL; -} - -FCDAnimationChannel* FCDAnimationChannel::Clone(FCDAnimationChannel* clone) const -{ - if (clone == NULL) clone = new FCDAnimationChannel(const_cast(GetDocument()), NULL); - - // Clone the curves - for (const FCDAnimationCurve** it = curves.begin(); it != curves.end(); ++it) - { - FCDAnimationCurve* clonedCurve = clone->AddCurve(); - (*it)->Clone(clonedCurve, false); - } - - return clone; -} - -FCDAnimationCurve* FCDAnimationChannel::AddCurve() -{ - FCDAnimationCurve* curve = new FCDAnimationCurve(GetDocument(), this); - curves.push_back(curve); - SetNewChildFlag(); - return curve; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDAnimationChannel.h" +#include "FCDocument/FCDAnimationCurve.h" + +// +// FCDAnimationChannel +// + +ImplementObjectType(FCDAnimationChannel); +ImplementParameterObject(FCDAnimationChannel, FCDAnimationCurve, curves, new FCDAnimationCurve(parent->GetDocument(), parent)); + +FCDAnimationChannel::FCDAnimationChannel(FCDocument* document, FCDAnimation* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(curves) +{ +} + +FCDAnimationChannel::~FCDAnimationChannel() +{ + parent = NULL; +} + +FCDAnimationChannel* FCDAnimationChannel::Clone(FCDAnimationChannel* clone) const +{ + if (clone == NULL) clone = new FCDAnimationChannel(const_cast(GetDocument()), NULL); + + // Clone the curves + for (const FCDAnimationCurve** it = curves.begin(); it != curves.end(); ++it) + { + FCDAnimationCurve* clonedCurve = clone->AddCurve(); + (*it)->Clone(clonedCurve, false); + } + + return clone; +} + +FCDAnimationCurve* FCDAnimationChannel::AddCurve() +{ + FCDAnimationCurve* curve = new FCDAnimationCurve(GetDocument(), this); + curves.push_back(curve); + SetNewChildFlag(); + return curve; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationChannel.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationChannel.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationChannel.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationChannel.h (revision 24247) @@ -1,96 +1,96 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDAnimationChannel.h - This file contains the FCDAnimationChannel class. -*/ - -#ifndef _FCD_ANIMATION_CHANNEL_H_ -#define _FCD_ANIMATION_CHANNEL_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -class FCDAnimated; -class FCDAnimation; -class FCDAnimationCurve; - -typedef fm::pvector FCDAnimationCurveList; /**< A dynamically-sized array of animation curves. */ - -/** - A COLLADA animation channel. - Each animation channel holds the animation curves for one animatable element, - such as a single floating-point value, a 3D vector or a matrix. - - @see FCDAnimated - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDAnimationChannel : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - FCDAnimation* parent; - - DeclareParameterContainer(FCDAnimationCurve, curves, FC("Animation Curves")); - -public: - /** Constructor: do not use directly. - Instead, call the FCDAnimation::AddChannel function. - @param document The COLLADA document that owns the animation channel. - @param parent The animation sub-tree that contains the animation channel. */ - FCDAnimationChannel(FCDocument* document, FCDAnimation* parent); - - /** Destructor. */ - virtual ~FCDAnimationChannel(); - - /** Copies the animation channel into a clone. - The clone may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new animation channel - will be created and you will need to release the returned pointer manually. - @return The clone. */ - FCDAnimationChannel* Clone(FCDAnimationChannel* clone = NULL) const; - - /** Retrieves the animation sub-tree that contains the animation channel. - @return The parent animation sub-tree. */ - FCDAnimation* GetParent() { return parent; } - const FCDAnimation* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the list of animation curves contained within the channel. - @deprecated - @return The list of animation curves. */ - DEPRECATED(3.05A, GetCurveCount and GetCurve(index)) - void GetCurves() const {} - - /** Retrieves the number of animation curves contained within the channel. - @return The number of animation curves. */ - size_t GetCurveCount() const { return curves.size(); } - - /** Retrieves an animation curve contained within the channel. - @param index The index of the animation curve. - @return The animation curve at the given index. This pointer will be NULL - if the index is out-of-bounds. */ - FCDAnimationCurve* GetCurve(size_t index) { FUAssert(index < GetCurveCount(), return NULL); return curves.at(index); } - const FCDAnimationCurve* GetCurve(size_t index) const { FUAssert(index < GetCurveCount(), return NULL); return curves.at(index); } /**< See above. */ - - /** Adds a new animation curve to this animation channel. - @return The new animation curve. */ - FCDAnimationCurve* AddCurve(); -}; - -#endif // _FCD_ANIMATION_CHANNEL_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDAnimationChannel.h + This file contains the FCDAnimationChannel class. +*/ + +#ifndef _FCD_ANIMATION_CHANNEL_H_ +#define _FCD_ANIMATION_CHANNEL_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +class FCDAnimated; +class FCDAnimation; +class FCDAnimationCurve; + +typedef fm::pvector FCDAnimationCurveList; /**< A dynamically-sized array of animation curves. */ + +/** + A COLLADA animation channel. + Each animation channel holds the animation curves for one animatable element, + such as a single floating-point value, a 3D vector or a matrix. + + @see FCDAnimated + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDAnimationChannel : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + FCDAnimation* parent; + + DeclareParameterContainer(FCDAnimationCurve, curves, FC("Animation Curves")); + +public: + /** Constructor: do not use directly. + Instead, call the FCDAnimation::AddChannel function. + @param document The COLLADA document that owns the animation channel. + @param parent The animation sub-tree that contains the animation channel. */ + FCDAnimationChannel(FCDocument* document, FCDAnimation* parent); + + /** Destructor. */ + virtual ~FCDAnimationChannel(); + + /** Copies the animation channel into a clone. + The clone may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new animation channel + will be created and you will need to release the returned pointer manually. + @return The clone. */ + FCDAnimationChannel* Clone(FCDAnimationChannel* clone = NULL) const; + + /** Retrieves the animation sub-tree that contains the animation channel. + @return The parent animation sub-tree. */ + FCDAnimation* GetParent() { return parent; } + const FCDAnimation* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the list of animation curves contained within the channel. + @deprecated + @return The list of animation curves. */ + DEPRECATED(3.05A, GetCurveCount and GetCurve(index)) + void GetCurves() const {} + + /** Retrieves the number of animation curves contained within the channel. + @return The number of animation curves. */ + size_t GetCurveCount() const { return curves.size(); } + + /** Retrieves an animation curve contained within the channel. + @param index The index of the animation curve. + @return The animation curve at the given index. This pointer will be NULL + if the index is out-of-bounds. */ + FCDAnimationCurve* GetCurve(size_t index) { FUAssert(index < GetCurveCount(), return NULL); return curves.at(index); } + const FCDAnimationCurve* GetCurve(size_t index) const { FUAssert(index < GetCurveCount(), return NULL); return curves.at(index); } /**< See above. */ + + /** Adds a new animation curve to this animation channel. + @return The new animation curve. */ + FCDAnimationCurve* AddCurve(); +}; + +#endif // _FCD_ANIMATION_CHANNEL_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationChannel.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClip.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClip.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClip.cpp (revision 24247) @@ -1,85 +1,85 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimation.h" -#include "FCDocument/FCDAnimationChannel.h" -#include "FCDocument/FCDAnimationClip.h" -#include "FCDocument/FCDAnimationCurve.h" -#include "FCDocument/FCDAnimated.h" - -// -// FCDAnimationClip -// - -ImplementObjectType(FCDAnimationClip); -ImplementParameterObjectNoCtr(FCDAnimationClip, FCDEntityInstance, animations); - -FCDAnimationClip::FCDAnimationClip(FCDocument* document) -: FCDEntity(document, "AnimationClip") -, InitializeParameter(start, 0.0f) -, InitializeParameter(end, 0.0f) -, InitializeParameterNoArg(animations) -{ -} - -FCDAnimationClip::~FCDAnimationClip() -{ - curves.clear(); -} - -void FCDAnimationClip::AddClipCurve(FCDAnimationCurve* curve) -{ - curve->RegisterAnimationClip(this); - curves.push_back(curve); - SetNewChildFlag(); -} - -FCDEntity* FCDAnimationClip::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDAnimationClip* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDAnimationClip(const_cast(GetDocument())); - else if (_clone->HasType(FCDAnimationClip::GetClassType())) clone = (FCDAnimationClip*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - // Copy the generic animation clip parameters - clone->start = start; - clone->end = end; - - // If requested, clone the animation curves as well. - for (FCDAnimationCurveTrackList::const_iterator it = curves.begin(); it != curves.end(); ++it) - { - if (cloneChildren) - { - FCDAnimationCurve* clonedCurve = (*it)->Clone(NULL, false); - clonedCurve->AddClip(clone); - clone->AddClipCurve(clonedCurve); - } - } - } - - return _clone; -} - -FCDEntityInstance* FCDAnimationClip::AddInstanceAnimation() -{ - FCDEntityInstance* newInstance = FCDEntityInstanceFactory::CreateInstance(GetDocument(), NULL, FCDEntity::ANIMATION); - animations.push_back(newInstance); - return newInstance; -} - -FCDEntityInstance* FCDAnimationClip::AddInstanceAnimation(FCDAnimation* animation) -{ - FCDEntityInstance* newInstance = FCDEntityInstanceFactory::CreateInstance(GetDocument(), NULL, animation); - animations.push_back(newInstance); - return newInstance; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimation.h" +#include "FCDocument/FCDAnimationChannel.h" +#include "FCDocument/FCDAnimationClip.h" +#include "FCDocument/FCDAnimationCurve.h" +#include "FCDocument/FCDAnimated.h" + +// +// FCDAnimationClip +// + +ImplementObjectType(FCDAnimationClip); +ImplementParameterObjectNoCtr(FCDAnimationClip, FCDEntityInstance, animations); + +FCDAnimationClip::FCDAnimationClip(FCDocument* document) +: FCDEntity(document, "AnimationClip") +, InitializeParameter(start, 0.0f) +, InitializeParameter(end, 0.0f) +, InitializeParameterNoArg(animations) +{ +} + +FCDAnimationClip::~FCDAnimationClip() +{ + curves.clear(); +} + +void FCDAnimationClip::AddClipCurve(FCDAnimationCurve* curve) +{ + curve->RegisterAnimationClip(this); + curves.push_back(curve); + SetNewChildFlag(); +} + +FCDEntity* FCDAnimationClip::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDAnimationClip* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDAnimationClip(const_cast(GetDocument())); + else if (_clone->HasType(FCDAnimationClip::GetClassType())) clone = (FCDAnimationClip*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + // Copy the generic animation clip parameters + clone->start = start; + clone->end = end; + + // If requested, clone the animation curves as well. + for (FCDAnimationCurveTrackList::const_iterator it = curves.begin(); it != curves.end(); ++it) + { + if (cloneChildren) + { + FCDAnimationCurve* clonedCurve = (*it)->Clone(NULL, false); + clonedCurve->AddClip(clone); + clone->AddClipCurve(clonedCurve); + } + } + } + + return _clone; +} + +FCDEntityInstance* FCDAnimationClip::AddInstanceAnimation() +{ + FCDEntityInstance* newInstance = FCDEntityInstanceFactory::CreateInstance(GetDocument(), NULL, FCDEntity::ANIMATION); + animations.push_back(newInstance); + return newInstance; +} + +FCDEntityInstance* FCDAnimationClip::AddInstanceAnimation(FCDAnimation* animation) +{ + FCDEntityInstance* newInstance = FCDEntityInstanceFactory::CreateInstance(GetDocument(), NULL, animation); + animations.push_back(newInstance); + return newInstance; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClip.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClip.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClip.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClip.h (revision 24247) @@ -1,133 +1,133 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDAnimationClip.h - This file contains the FCDAnimationClip class. -*/ - -#ifndef _FCD_ANIMATION_CLIP_H_ -#define _FCD_ANIMATION_CLIP_H_ - -class FCDocument; -class FCDAnimation; -class FCDAnimationCurve; - -class FCDEntityInstance; - -typedef FUTrackedList FCDAnimationCurveTrackList; /**< A dynamically-sized tracking array of animation curves. */ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -#ifndef _FCD_ENTITY_INSTANCE_H_ -#include "FCDocument/FCDEntityInstance.h" -#endif // _FCD_ENTITY__INSTANCE_H_ - -/** - A COLLADA animation clip. - - Animation clips are used to group together animation segments. - Animation clips are typically used to form complex animation sequences - where all the curves should only be used simultaneously. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDAnimationClip : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - FCDAnimationCurveTrackList curves; - - DeclareParameter(float, FUParameterQualifiers::SIMPLE, start, FC("Start Time")); - DeclareParameter(float, FUParameterQualifiers::SIMPLE, end, FC("End Time")); - DeclareParameterContainer(FCDEntityInstance, animations, FC("Animation Instances")); - StringList names; // names are supported on animation_instances - -public: - /** Constructor. - @param document The COLLADA document that holds this animation clip. */ - FCDAnimationClip(FCDocument* document); - - /** Destructor. */ - virtual ~FCDAnimationClip(); - - /** Copies the animation clip entity into a clone. - The clone may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new animation clip - will be created and you will need to release the returned pointer manually. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - - /** Retrieves the entity type for this class. This function is part - of the FCDEntity class interface. - @return The entity type: IMAGE. */ - virtual Type GetType() const { return ANIMATION_CLIP; } - - /** Retrieves the list of curves that are used by this animation clip. - @return The list of curves for the clip. */ - FCDAnimationCurveTrackList& GetClipCurves() { return curves; } - const FCDAnimationCurveTrackList& GetClipCurves() const { return curves; } /**< See above. */ - - /** Inserts an existing curve within this animation clip. - @param curve An animation curve to be used within this clip. */ - void AddClipCurve(FCDAnimationCurve* curve); - - /** Retrieves the start time marker position for this animation clip. - When using the animation clip, all the animation curves will need - to be synchronized in order for the animation to start at the start time. - @return The start time marker position, in seconds. */ - float GetStart() const { return start; } - - /** Sets the start time marker position for this animation clip. - @param _start The new start time marker position. */ - void SetStart(float _start) { start = _start; SetDirtyFlag(); } - - /** Retrieves the end time marker position for this animation clip. - When using the animation clip, all the animation curves will need - to be synchronized in order for the animation to complete at the end time. - @return The end time marker position, in seconds. */ - float GetEnd() const { return end; } - - /** Sets the end time marker position for this animation clip. - @param _end The end time marker position. */ - void SetEnd(float _end) { end = _end; SetDirtyFlag(); } - - /** Retrieves the number of instanced animations within this animation clip. - @return The number of instanced animations. */ - inline size_t GetAnimationCount() const { return animations.size(); } - - /** Retrieves a given animation instanced by this clip. - @param index The index of the animation to retrieve. - @return The animation object at the given index. */ - inline FCDAnimation* GetAnimation(size_t index) const { FUAssert(GetAnimationCount() > index, return NULL); return (FCDAnimation*) animations[index]->GetEntity(); }; - - /** Sets the name of the animation at a given index. - @param name The name to give the animation at the given index. - @param index The index of the animation that will get the new name. */ - inline void SetAnimationName(const fm::string& name, size_t index) { if (names.size() <= index) names.resize(index + 1); names[index] = name; } - - /** Retrieves the name of the animation at a given index. - @param index The index of the animation. - @return The name of the animation. */ - inline fm::string GetAnimationName(size_t index) const { return names[index]; } - - /** [INTERNAL] Adds an animation instance. - @return The empty animation instance. */ - FCDEntityInstance* AddInstanceAnimation(); - - /** [INTERNAL] Adds an animation instance. - @param animation The animation to instance. - @return The animation instance. */ - FCDEntityInstance* AddInstanceAnimation(FCDAnimation* animation); -}; - -#endif // _FCD_ANIMATION_CLIP_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDAnimationClip.h + This file contains the FCDAnimationClip class. +*/ + +#ifndef _FCD_ANIMATION_CLIP_H_ +#define _FCD_ANIMATION_CLIP_H_ + +class FCDocument; +class FCDAnimation; +class FCDAnimationCurve; + +class FCDEntityInstance; + +typedef FUTrackedList FCDAnimationCurveTrackList; /**< A dynamically-sized tracking array of animation curves. */ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +#ifndef _FCD_ENTITY_INSTANCE_H_ +#include "FCDocument/FCDEntityInstance.h" +#endif // _FCD_ENTITY__INSTANCE_H_ + +/** + A COLLADA animation clip. + + Animation clips are used to group together animation segments. + Animation clips are typically used to form complex animation sequences + where all the curves should only be used simultaneously. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDAnimationClip : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + FCDAnimationCurveTrackList curves; + + DeclareParameter(float, FUParameterQualifiers::SIMPLE, start, FC("Start Time")); + DeclareParameter(float, FUParameterQualifiers::SIMPLE, end, FC("End Time")); + DeclareParameterContainer(FCDEntityInstance, animations, FC("Animation Instances")); + StringList names; // names are supported on animation_instances + +public: + /** Constructor. + @param document The COLLADA document that holds this animation clip. */ + FCDAnimationClip(FCDocument* document); + + /** Destructor. */ + virtual ~FCDAnimationClip(); + + /** Copies the animation clip entity into a clone. + The clone may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new animation clip + will be created and you will need to release the returned pointer manually. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + + /** Retrieves the entity type for this class. This function is part + of the FCDEntity class interface. + @return The entity type: IMAGE. */ + virtual Type GetType() const { return ANIMATION_CLIP; } + + /** Retrieves the list of curves that are used by this animation clip. + @return The list of curves for the clip. */ + FCDAnimationCurveTrackList& GetClipCurves() { return curves; } + const FCDAnimationCurveTrackList& GetClipCurves() const { return curves; } /**< See above. */ + + /** Inserts an existing curve within this animation clip. + @param curve An animation curve to be used within this clip. */ + void AddClipCurve(FCDAnimationCurve* curve); + + /** Retrieves the start time marker position for this animation clip. + When using the animation clip, all the animation curves will need + to be synchronized in order for the animation to start at the start time. + @return The start time marker position, in seconds. */ + float GetStart() const { return start; } + + /** Sets the start time marker position for this animation clip. + @param _start The new start time marker position. */ + void SetStart(float _start) { start = _start; SetDirtyFlag(); } + + /** Retrieves the end time marker position for this animation clip. + When using the animation clip, all the animation curves will need + to be synchronized in order for the animation to complete at the end time. + @return The end time marker position, in seconds. */ + float GetEnd() const { return end; } + + /** Sets the end time marker position for this animation clip. + @param _end The end time marker position. */ + void SetEnd(float _end) { end = _end; SetDirtyFlag(); } + + /** Retrieves the number of instanced animations within this animation clip. + @return The number of instanced animations. */ + inline size_t GetAnimationCount() const { return animations.size(); } + + /** Retrieves a given animation instanced by this clip. + @param index The index of the animation to retrieve. + @return The animation object at the given index. */ + inline FCDAnimation* GetAnimation(size_t index) const { FUAssert(GetAnimationCount() > index, return NULL); return (FCDAnimation*) animations[index]->GetEntity(); }; + + /** Sets the name of the animation at a given index. + @param name The name to give the animation at the given index. + @param index The index of the animation that will get the new name. */ + inline void SetAnimationName(const fm::string& name, size_t index) { if (names.size() <= index) names.resize(index + 1); names[index] = name; } + + /** Retrieves the name of the animation at a given index. + @param index The index of the animation. + @return The name of the animation. */ + inline fm::string GetAnimationName(size_t index) const { return names[index]; } + + /** [INTERNAL] Adds an animation instance. + @return The empty animation instance. */ + FCDEntityInstance* AddInstanceAnimation(); + + /** [INTERNAL] Adds an animation instance. + @param animation The animation to instance. + @return The animation instance. */ + FCDEntityInstance* AddInstanceAnimation(FCDAnimation* animation); +}; + +#endif // _FCD_ANIMATION_CLIP_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClip.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClipTools.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClipTools.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClipTools.cpp (revision 24247) @@ -1,36 +1,36 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDAnimationClip.h" -#include "FCDocument/FCDAnimationClipTools.h" -#include "FCDocument/FCDAnimationCurve.h" - -namespace FCDAnimationClipTools -{ - void ResetAnimationClipTimes(FCDocument* document, float startValue) - { - for (size_t i = 0; i < document->GetAnimationClipLibrary()->GetEntityCount(); i++) - { - FCDAnimationClip* clip = document->GetAnimationClipLibrary()->GetEntity(i); - - // Calculate the offset and apply it to the start/end on the clip. - float offset = startValue - clip->GetStart(); - clip->SetStart(startValue); - clip->SetEnd(clip->GetEnd() + offset); - - // Apply the offset on the curve keys. - for (FCDAnimationCurveTrackList::iterator it = clip->GetClipCurves().begin(); it != clip->GetClipCurves().end(); ++it) - { - (*it)->SetClipOffset(offset, clip); - } - } - } -}; +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDAnimationClip.h" +#include "FCDocument/FCDAnimationClipTools.h" +#include "FCDocument/FCDAnimationCurve.h" + +namespace FCDAnimationClipTools +{ + void ResetAnimationClipTimes(FCDocument* document, float startValue) + { + for (size_t i = 0; i < document->GetAnimationClipLibrary()->GetEntityCount(); i++) + { + FCDAnimationClip* clip = document->GetAnimationClipLibrary()->GetEntity(i); + + // Calculate the offset and apply it to the start/end on the clip. + float offset = startValue - clip->GetStart(); + clip->SetStart(startValue); + clip->SetEnd(clip->GetEnd() + offset); + + // Apply the offset on the curve keys. + for (FCDAnimationCurveTrackList::iterator it = clip->GetClipCurves().begin(); it != clip->GetClipCurves().end(); ++it) + { + (*it)->SetClipOffset(offset, clip); + } + } + } +}; Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClipTools.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClipTools.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClipTools.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClipTools.h (revision 24247) @@ -1,26 +1,26 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDAnimationClipTools.h - This file contains the FCDAnimationClipTools namespace. -*/ - -#ifndef _FCD_ANIMATION_CLIP_TOOLS_H_ -#define _FCD_ANIMATION_CLIP_TOOLS_H_ - -class FCDocument; - -namespace FCDAnimationClipTools -{ - /** Resets the times for the animation clips to a given value. - @param document A COLLADA document that contains animation clips. */ - FCOLLADA_EXPORT void ResetAnimationClipTimes(FCDocument* document, float startValue); -}; - -#endif // _FCD_ANIMATION_CLIP_TOOLS_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDAnimationClipTools.h + This file contains the FCDAnimationClipTools namespace. +*/ + +#ifndef _FCD_ANIMATION_CLIP_TOOLS_H_ +#define _FCD_ANIMATION_CLIP_TOOLS_H_ + +class FCDocument; + +namespace FCDAnimationClipTools +{ + /** Resets the times for the animation clips to a given value. + @param document A COLLADA document that contains animation clips. */ + FCOLLADA_EXPORT void ResetAnimationClipTimes(FCDocument* document, float startValue); +}; + +#endif // _FCD_ANIMATION_CLIP_TOOLS_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationClipTools.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurve.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurve.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurve.cpp (revision 24247) @@ -1,597 +1,597 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDAnimationCurve.h" -#include "FCDocument/FCDAnimationClip.h" -#include "FCDocument/FCDAnimationKey.h" -#include "FUtils/FUDaeEnum.h" - -// -// Local Definitions -// - -// Declaring the type of evaluation for curves once. -bool FCDAnimationCurve::is2DEvaluation = true; - -// Uses iterative method to accurately pin-point the 't' of the Bezier -// equation that corresponds to the current time. -float FindT(float cp0x, float cp1x, float cp2x, float cp3x, float input, float initialGuess) -{ - float localTolerance = 0.001f; - float highT = 1.0f; - float lowT = 0.0f; - - //Optimize here, start with a more intuitive value than 0.5 - float midT = 0.5f; - if (initialGuess <= 0.1) midT = 0.1f; //clamp to 10% or 90%, because if miss, the cost is too high. - else if (initialGuess >= 0.9) midT = 0.9f; - else midT = initialGuess; - bool once = true; - while ((highT-lowT) > localTolerance) { - if (once) once = false; - else midT = (highT - lowT) / 2.0f + lowT; - float ti = 1.0f - midT; // (1 - t) - float calculatedTime = cp0x*ti*ti*ti + 3*cp1x*midT*ti*ti + 3*cp2x*midT*midT*ti + cp3x*midT*midT*midT; - if (fabsf(calculatedTime - input) <= localTolerance) break; //If we 'fall' very close, we like it and break. - if (calculatedTime > input) highT = midT; - else lowT = midT; - } - return midT; -} - -static void ComputeTCBTangent(const FCDAnimationKey* previousKey, const FCDAnimationKey* currentKey, const FCDAnimationKey* nextKey, float tens, float cont, float bias, FMVector2& leftTangent, FMVector2& rightTangent) -{ - FUAssert(currentKey != NULL, return;); - - // Calculate the intervals and allow for time differences of both sides. - FMVector2 pCurrentMinusPrevious; - FMVector2 pNextMinusCurrent; - - //If the previous key or the last key is NULL, do make one up... - if (!previousKey) { - if (nextKey) pCurrentMinusPrevious.x = nextKey->input - currentKey->input; - else pCurrentMinusPrevious.x = 0.5f; //Case where there is only one TCB key.. should not happen. - pCurrentMinusPrevious.y = 0.0f; - } - else { - pCurrentMinusPrevious.x = previousKey->input - currentKey->input; - pCurrentMinusPrevious.y = previousKey->output - currentKey->output; - } - if (!nextKey) { - if (previousKey) pNextMinusCurrent.x = currentKey->input - previousKey->input; - else pNextMinusCurrent.x = 0.5f; //Case where there is only one TCB key.. ? - pNextMinusCurrent.y = 0.0f; - } - else { - pNextMinusCurrent.x = nextKey->input - currentKey->input; - pNextMinusCurrent.y = nextKey->output - currentKey->output; - } - - //Calculate the constants applied that contain the continuity, tension, and bias. - float k1 = ((1.0f - tens) * (1.0f - cont) * (1.0f + bias))/2; - float k2 = ((1.0f - tens) * (1.0f + cont) * (1.0f - bias))/2; - float k3 = ((1.0f - tens) * (1.0f + cont) * (1.0f + bias))/2; - float k4 = ((1.0f - tens) * (1.0f - cont) * (1.0f - bias))/2; - - leftTangent.x = k1 * pCurrentMinusPrevious.x + k2 * pNextMinusCurrent.x; - leftTangent.y = k1 * pCurrentMinusPrevious.y + k2 * pNextMinusCurrent.y; - - rightTangent.x = k3 * pCurrentMinusPrevious.x + k4 * pNextMinusCurrent.x; - rightTangent.y = k3 * pCurrentMinusPrevious.y + k4 * pNextMinusCurrent.y; -} - -// -// FCDAnimationCurve -// - -ImplementObjectType(FCDAnimationCurve); - -FCDAnimationCurve::FCDAnimationCurve(FCDocument* document, FCDAnimationChannel* _parent) - : FCDObject(document), parent(_parent), - targetElement(-1), - preInfinity(FUDaeInfinity::CONSTANT), postInfinity(FUDaeInfinity::CONSTANT), - inputDriver(NULL), inputDriverIndex(0) -{ - currentClip = NULL; - currentOffset = 0; -} - -FCDAnimationCurve::~FCDAnimationCurve() -{ - CLEAR_POINTER_VECTOR(keys); - - inputDriver = NULL; - parent = NULL; - clips.clear(); - clipOffsets.clear(); -} - -void FCDAnimationCurve::SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation) -{ - size_t oldCount = GetKeyCount(); - if (oldCount < count) - { - keys.reserve(count); - for (; oldCount < count; ++oldCount) AddKey(interpolation); - } - else if (count < oldCount) - { - for (FCDAnimationKeyList::iterator it = keys.begin() + count; it != keys.end(); ++it) delete (*it); - keys.resize(count); - } - SetDirtyFlag(); -} - -FCDAnimationKey* FCDAnimationCurve::AddKey(FUDaeInterpolation::Interpolation interpolation) -{ - FCDAnimationKey* key; - switch (interpolation) - { - case FUDaeInterpolation::STEP: key = new FCDAnimationKey; break; - case FUDaeInterpolation::LINEAR: key = new FCDAnimationKey; break; - case FUDaeInterpolation::BEZIER: key = new FCDAnimationKeyBezier; break; - case FUDaeInterpolation::TCB: key = new FCDAnimationKeyTCB; break; - default: FUFail(key = new FCDAnimationKey; break;); - } - key->interpolation = (uint32) interpolation; - keys.push_back(key); - SetDirtyFlag(); - return key; -} - - -// Insert a new key into the ordered array at a certain time -FCDAnimationKey* FCDAnimationCurve::AddKey(FUDaeInterpolation::Interpolation interpolation, float input, size_t& index) -{ - FCDAnimationKey* key; - switch (interpolation) - { - case FUDaeInterpolation::STEP: key = new FCDAnimationKey; break; - case FUDaeInterpolation::LINEAR: key = new FCDAnimationKey; break; - case FUDaeInterpolation::BEZIER: key = new FCDAnimationKeyBezier; break; - case FUDaeInterpolation::TCB: key = new FCDAnimationKeyTCB; break; - default: FUFail(return NULL); - } - key->interpolation = (uint32) interpolation; - key->input = input; - FCDAnimationKeyList::iterator insertIdx = keys.begin(); - FCDAnimationKeyList::iterator finalIdx = keys.end(); - - // TODO: Not cabbage search :-) - for (index = 0; insertIdx != finalIdx; insertIdx++, index++) - { - if ((*insertIdx)->input > input) break; - } - - keys.insert(insertIdx, key); - SetDirtyFlag(); - return key; -} - -bool FCDAnimationCurve::DeleteKey(FCDAnimationKey* key) -{ - FCDAnimationKeyList::iterator kitr = keys.find(key); - if (kitr == keys.end()) return false; - - keys.erase(kitr); - delete key; - return true; -} - -void FCDAnimationCurve::AddClip(FCDAnimationClip* clip) -{ - clips.push_back(clip); -} - -bool FCDAnimationCurve::HasDriver() const -{ - return inputDriver != NULL; -} - -void FCDAnimationCurve::GetDriver(FCDAnimated*& driver, int32& index) -{ const_cast(this)->GetDriver(const_cast(driver), index); } -void FCDAnimationCurve::GetDriver(const FCDAnimated*& driver, int32& index) const -{ - driver = inputDriver; - index = inputDriverIndex; -} - -void FCDAnimationCurve::SetDriver(FCDAnimated* driver, int32 index) -{ - inputDriver = driver; - inputDriverIndex = index; - SetNewChildFlag(); -} - -FCDAnimationCurve* FCDAnimationCurve::Clone(FCDAnimationCurve* clone, bool includeClips) const -{ - if (clone == NULL) clone = new FCDAnimationCurve(const_cast(GetDocument()), parent); - - clone->SetTargetElement(targetElement); - clone->SetTargetQualifier(targetQualifier); - - // Pre-buffer the list of keys and clone them. - clone->keys.clear(); - clone->keys.reserve(keys.size()); - for (FCDAnimationKeyList::const_iterator it = keys.begin(); it != keys.end(); ++it) - { - FCDAnimationKey* key = clone->AddKey((FUDaeInterpolation::Interpolation) (*it)->interpolation); - key->input = (*it)->input; - key->output = (*it)->output; - if ((*it)->interpolation == FUDaeInterpolation::BEZIER) - { - FCDAnimationKeyBezier* bkey1 = (FCDAnimationKeyBezier*) (*it); - FCDAnimationKeyBezier* bkey2 = (FCDAnimationKeyBezier*) key; - bkey2->inTangent = bkey1->inTangent; - bkey2->outTangent = bkey1->outTangent; - } - else if ((*it)->interpolation == FUDaeInterpolation::TCB) - { - FCDAnimationKeyTCB* tkey1 = (FCDAnimationKeyTCB*) (*it); - FCDAnimationKeyTCB* tkey2 = (FCDAnimationKeyTCB*) key; - tkey2->tension = tkey1->tension; - tkey2->continuity = tkey1->continuity; - tkey2->bias = tkey1->bias; - tkey2->easeIn = tkey1->easeIn; - tkey2->easeOut = tkey1->easeOut; - } - } - - clone->preInfinity = preInfinity; - clone->postInfinity = postInfinity; - clone->inputDriver = inputDriver; - clone->inputDriverIndex = inputDriverIndex; - - if (includeClips) - { - // Animation clips that depend on this curve - for (FCDAnimationClipList::const_iterator it = clips.begin(); it != clips.end(); ++it) - { - FCDAnimationClip* clonedClip = (FCDAnimationClip*) (*it)->Clone(0, false); - clonedClip->AddClipCurve(clone); - clone->AddClip(clonedClip); - } - - for (FloatList::const_iterator it = clipOffsets.begin(); it != clipOffsets.end(); ++it) - { - clone->clipOffsets.push_back(*it); - } - } - - return clone; -} - -void FCDAnimationCurve::SetCurrentAnimationClip(FCDAnimationClip* clip) -{ - if (currentClip == clip) return; - - currentClip = NULL; - float clipOffset = 0.0f; - for (size_t i = 0; i < clips.size(); ++i) - { - if (clips[i] == clip) - { - currentClip = clips[i]; - clipOffset = clipOffsets[i]; - break; - } - } - - if (currentClip != NULL) - { - float offset = clipOffset - currentOffset; - currentOffset = clipOffset; - for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) - { - (*it)->input += offset; - } - } - - SetDirtyFlag(); -} - -// Main workhorse for the animation system: -// Evaluates the curve for a given input -float FCDAnimationCurve::Evaluate(float input) const -{ - // Check for empty curves and poses (curves with 1 key). - if (keys.size() == 0) return 0.0f; - if (keys.size() == 1) return keys.front()->output; - - float inputStart = keys.front()->input; - float inputEnd = keys.back()->input; - float inputSpan = inputEnd - inputStart; - float outputStart = keys.front()->output; - float outputEnd = keys.back()->output; - float outputSpan = outputEnd - outputStart; - - // Account for pre-infinity mode - float outputOffset = 0.0f; - if (input < inputStart) - { - float inputDifference = inputStart - input; - switch (preInfinity) - { - case FUDaeInfinity::CONSTANT: return outputStart; - case FUDaeInfinity::LINEAR: return outputStart + inputDifference * (keys[1]->output - outputStart) / (keys[1]->input - inputStart); - case FUDaeInfinity::CYCLE: { float cycleCount = ceilf(inputDifference / inputSpan); input += cycleCount * inputSpan; break; } - case FUDaeInfinity::CYCLE_RELATIVE: { float cycleCount = ceilf(inputDifference / inputSpan); input += cycleCount * inputSpan; outputOffset -= cycleCount * outputSpan; break; } - case FUDaeInfinity::OSCILLATE: { float cycleCount = ceilf(inputDifference / (2.0f * inputSpan)); input += cycleCount * 2.0f * inputSpan; input = inputEnd - fabsf(input - inputEnd); break; } - case FUDaeInfinity::UNKNOWN: default: return outputStart; - } - } - - // Account for post-infinity mode - else if (input >= inputEnd) - { - float inputDifference = input - inputEnd; - switch (postInfinity) - { - case FUDaeInfinity::CONSTANT: return outputEnd; - case FUDaeInfinity::LINEAR: return outputEnd + inputDifference * (keys[keys.size() - 2]->output - outputEnd) / (keys[keys.size() - 2]->input - inputEnd); - case FUDaeInfinity::CYCLE: { float cycleCount = ceilf(inputDifference / inputSpan); input -= cycleCount * inputSpan; break; } - case FUDaeInfinity::CYCLE_RELATIVE: { float cycleCount = ceilf(inputDifference / inputSpan); input -= cycleCount * inputSpan; outputOffset += cycleCount * outputSpan; break; } - case FUDaeInfinity::OSCILLATE: { float cycleCount = ceilf(inputDifference / (2.0f * inputSpan)); input -= cycleCount * 2.0f * inputSpan; input = inputStart + fabsf(input - inputStart); break; } - case FUDaeInfinity::UNKNOWN: default: return outputEnd; - } - } - - // Find the current interval - FCDAnimationKeyList::const_iterator it, start = keys.begin(), terminate = keys.end(); - while (terminate - start > 3) - { - // Binary search. - it = (const FCDAnimationKey**) ((((size_t) terminate) / 2 + ((size_t) start) / 2) & ~((sizeof(size_t)-1))); - if ((*it)->input > input) terminate = it; - else start = it; - } - // Linear search is more efficient on the last interval - for (it = start; it != terminate; ++it) - { - if ((*it)->input >= input) break; - } - if (it == keys.begin()) return outputOffset + outputStart; - - // Get the keys and values for this interval - const FCDAnimationKey* startKey = *(it - 1); - const FCDAnimationKey* endKey = *it; - float inputInterval = endKey->input - startKey->input; - float outputInterval = endKey->output - startKey->output; - - // Interpolate the output. - // Similar code is found in FCDAnimationMultiCurve.cpp. If you update this, update the other one too. - float output; - switch (startKey->interpolation) - { - case FUDaeInterpolation::LINEAR: { - output = startKey->output + (input - startKey->input) / inputInterval * outputInterval; - break; } - - case FUDaeInterpolation::BEZIER: { - if (endKey->interpolation == FUDaeInterpolation::LINEAR) { - output = startKey->output + (input - startKey->input) / inputInterval * outputInterval; - break; - } - if (endKey->interpolation == FUDaeInterpolation::DEFAULT || - endKey->interpolation == FUDaeInterpolation::STEP || - endKey->interpolation == FUDaeInterpolation::UNKNOWN) { - output = startKey->output; - break; - } - //Code that applies to both whether the endKey is Bezier or TCB. - FCDAnimationKeyBezier* bkey1 = (FCDAnimationKeyBezier*) startKey; - FMVector2 inTangent; - if (endKey->interpolation == FUDaeInterpolation::BEZIER) { - inTangent = ((FCDAnimationKeyBezier*) endKey)->inTangent; - } - else if (endKey->interpolation == FUDaeInterpolation::TCB) { - FCDAnimationKeyTCB* tkey2 = (FCDAnimationKeyTCB*) endKey; - FMVector2 tempTangent; - tempTangent.x = tempTangent.y = 0.0f; - const FCDAnimationKey* nextKey = (it + 1) < keys.end() ? (*(it + 1)) : NULL; - ComputeTCBTangent(startKey, endKey, nextKey, tkey2->tension, tkey2->continuity, tkey2->bias, inTangent, tempTangent); - //Change this when we've figured out the values of the vectors from TCB... - inTangent.x = endKey->input + inTangent.x; - inTangent.y = endKey->output + inTangent.y; - } - float t = (input - startKey->input) / inputInterval; - if (is2DEvaluation) t = FindT(bkey1->input, bkey1->outTangent.x, inTangent.x, endKey->input, input, t); - float b = bkey1->outTangent.y; - float c = inTangent.y; - float ti = 1.0f - t; - float br = 3.0f; - float cr = 3.0f; - if (!is2DEvaluation) { - br = inputInterval / (bkey1->outTangent.x - startKey->input); - cr = inputInterval / (endKey->input - inTangent.x); - br = FMath::Clamp(br, 0.01f, 100.0f); - cr = FMath::Clamp(cr, 0.01f, 100.0f); - } - output = startKey->output * ti * ti * ti + br * b * ti * ti * t + cr * c * ti * t * t + endKey->output * t * t * t; - break; } - case FUDaeInterpolation::TCB: { - if (endKey->interpolation == FUDaeInterpolation::LINEAR) { - output = startKey->output + (input - startKey->input) / inputInterval * outputInterval; - break; - } - if (endKey->interpolation == FUDaeInterpolation::DEFAULT || - endKey->interpolation == FUDaeInterpolation::STEP || - endKey->interpolation == FUDaeInterpolation::UNKNOWN) { - output = startKey->output; - break; - } - // Calculate the start key's out-tangent. - FCDAnimationKeyTCB* tkey1 = (FCDAnimationKeyTCB*) startKey; - FMVector2 startTangent, tempTangent, endTangent; - startTangent.x = startTangent.y = tempTangent.x = tempTangent.y = endTangent.x = endTangent.y = 0.0f; - const FCDAnimationKey* previousKey = (it - 1) > keys.begin() ? (*(it - 2)) : NULL; - ComputeTCBTangent(previousKey, startKey, endKey, tkey1->tension, tkey1->continuity, tkey1->bias, tempTangent, startTangent); - - // Calculate the end key's in-tangent. - float by = 0.0f, cy= 0.0f; //will be used in the Bezier equation. - float bx = 0.0f, cx = 0.0f; //will be used in FindT.. x equivalent of the point at b and c - if (endKey->interpolation == FUDaeInterpolation::TCB) { - FCDAnimationKeyTCB* tkey2 = (FCDAnimationKeyTCB*) endKey; - const FCDAnimationKey* nextKey = (it + 1) < keys.end() ? (*(it + 1)) : NULL; - ComputeTCBTangent(startKey, endKey, nextKey, tkey2->tension, tkey2->continuity, tkey2->bias, endTangent, tempTangent); - cy = endKey->output + endTangent.y; //Assuming the tangent is GOING from the point. - cx = endKey->output + endTangent.x; - } - else if (endKey->interpolation == FUDaeInterpolation::BEZIER) { - FCDAnimationKeyBezier* tkey2 = (FCDAnimationKeyBezier*) endKey; - endTangent = tkey2->inTangent; - cy = endTangent.y; - cx = endTangent.x; - } - float t = (input - inputStart) / inputInterval; - by = startKey->output - startTangent.y; //Assuming the tangent is GOING from the point. - bx = startKey->input - startTangent.x; - - if (is2DEvaluation) t = FindT(tkey1->input, bx, cx, endKey->input, input, t); -// else { //Need to figure out algorithm for easing in and out. -// t = Ease(t, tkey1->easeIn, tkey1->easeOut); -// } - - float ti = 1.0f - t; - output = startKey->output*ti*ti*ti + - 3*by*t*ti*ti + - 3*cy*t*t*ti + - endKey->output*t*t*t; - break; } - case FUDaeInterpolation::STEP: - case FUDaeInterpolation::UNKNOWN: - default: - output = startKey->output; - break; - } - return outputOffset + output; -} - -// Apply a conversion function on the key values and tangents -void FCDAnimationCurve::ConvertValues(FCDConversionFunction valueConversion, FCDConversionFunction tangentConversion) -{ - if (valueConversion != NULL) - { - for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) - { - (*it)->output = (*valueConversion)((*it)->output); - } - } - if (tangentConversion != NULL) - { - for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) - { - if ((*it)->interpolation == FUDaeInterpolation::BEZIER) - { - FCDAnimationKeyBezier* bkey = (FCDAnimationKeyBezier*) (*it); - bkey->inTangent.v = (*tangentConversion)(bkey->inTangent.v); - bkey->outTangent.v = (*tangentConversion)(bkey->outTangent.v); - } - } - } - SetDirtyFlag(); -} -void FCDAnimationCurve::ConvertValues(FCDConversionFunctor* valueConversion, FCDConversionFunctor* tangentConversion) -{ - if (valueConversion != NULL) - { - for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) - { - (*it)->output = (*valueConversion)((*it)->output); - } - } - if (tangentConversion != NULL) - { - for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) - { - if ((*it)->interpolation == FUDaeInterpolation::BEZIER) - { - FCDAnimationKeyBezier* bkey = (FCDAnimationKeyBezier*) (*it); - bkey->inTangent.v = (*tangentConversion)(bkey->inTangent.v); - bkey->outTangent.v = (*tangentConversion)(bkey->outTangent.v); - } - } - } - SetDirtyFlag(); -} - -// Apply a conversion function on the key times and tangent weights -void FCDAnimationCurve::ConvertInputs(FCDConversionFunction timeConversion, FCDConversionFunction tangentWeightConversion) -{ - if (timeConversion != NULL) - { - for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) - { - (*it)->input = (*timeConversion)((*it)->input); - } - } - if (tangentWeightConversion != NULL) - { - for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) - { - if ((*it)->interpolation == FUDaeInterpolation::BEZIER) - { - FCDAnimationKeyBezier* bkey = (FCDAnimationKeyBezier*) (*it); - bkey->inTangent.u = (*tangentWeightConversion)(bkey->inTangent.u); - bkey->outTangent.u = (*tangentWeightConversion)(bkey->outTangent.u); - } - } - } - SetDirtyFlag(); -} -void FCDAnimationCurve::ConvertInputs(FCDConversionFunctor* timeConversion, FCDConversionFunctor* tangentWeightConversion) -{ - if (timeConversion != NULL) - { - for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) - { - (*it)->input = (*timeConversion)((*it)->input); - } - } - if (tangentWeightConversion != NULL) - { - for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) - { - if ((*it)->interpolation == FUDaeInterpolation::BEZIER) - { - FCDAnimationKeyBezier* bkey = (FCDAnimationKeyBezier*) (*it); - bkey->inTangent.u = (*tangentWeightConversion)(bkey->inTangent.u); - bkey->outTangent.u = (*tangentWeightConversion)(bkey->outTangent.u); - } - } - } - SetDirtyFlag(); -} - -void FCDAnimationCurve::SetClipOffset(float offset, const FCDAnimationClip* clip) -{ - for (size_t i = 0; i < clips.size(); ++i) - { - if (clips[i] == clip) - { - clipOffsets[i] = offset; - break; - } - } - SetDirtyFlag(); -} - -void FCDAnimationCurve::RegisterAnimationClip(FCDAnimationClip* clip) -{ - clips.push_back(clip); - clipOffsets.push_back(-clip->GetStart()); - SetDirtyFlag(); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDAnimationCurve.h" +#include "FCDocument/FCDAnimationClip.h" +#include "FCDocument/FCDAnimationKey.h" +#include "FUtils/FUDaeEnum.h" + +// +// Local Definitions +// + +// Declaring the type of evaluation for curves once. +bool FCDAnimationCurve::is2DEvaluation = true; + +// Uses iterative method to accurately pin-point the 't' of the Bezier +// equation that corresponds to the current time. +float FindT(float cp0x, float cp1x, float cp2x, float cp3x, float input, float initialGuess) +{ + float localTolerance = 0.001f; + float highT = 1.0f; + float lowT = 0.0f; + + //Optimize here, start with a more intuitive value than 0.5 + float midT = 0.5f; + if (initialGuess <= 0.1) midT = 0.1f; //clamp to 10% or 90%, because if miss, the cost is too high. + else if (initialGuess >= 0.9) midT = 0.9f; + else midT = initialGuess; + bool once = true; + while ((highT-lowT) > localTolerance) { + if (once) once = false; + else midT = (highT - lowT) / 2.0f + lowT; + float ti = 1.0f - midT; // (1 - t) + float calculatedTime = cp0x*ti*ti*ti + 3*cp1x*midT*ti*ti + 3*cp2x*midT*midT*ti + cp3x*midT*midT*midT; + if (fabsf(calculatedTime - input) <= localTolerance) break; //If we 'fall' very close, we like it and break. + if (calculatedTime > input) highT = midT; + else lowT = midT; + } + return midT; +} + +static void ComputeTCBTangent(const FCDAnimationKey* previousKey, const FCDAnimationKey* currentKey, const FCDAnimationKey* nextKey, float tens, float cont, float bias, FMVector2& leftTangent, FMVector2& rightTangent) +{ + FUAssert(currentKey != NULL, return;); + + // Calculate the intervals and allow for time differences of both sides. + FMVector2 pCurrentMinusPrevious; + FMVector2 pNextMinusCurrent; + + //If the previous key or the last key is NULL, do make one up... + if (!previousKey) { + if (nextKey) pCurrentMinusPrevious.x = nextKey->input - currentKey->input; + else pCurrentMinusPrevious.x = 0.5f; //Case where there is only one TCB key.. should not happen. + pCurrentMinusPrevious.y = 0.0f; + } + else { + pCurrentMinusPrevious.x = previousKey->input - currentKey->input; + pCurrentMinusPrevious.y = previousKey->output - currentKey->output; + } + if (!nextKey) { + if (previousKey) pNextMinusCurrent.x = currentKey->input - previousKey->input; + else pNextMinusCurrent.x = 0.5f; //Case where there is only one TCB key.. ? + pNextMinusCurrent.y = 0.0f; + } + else { + pNextMinusCurrent.x = nextKey->input - currentKey->input; + pNextMinusCurrent.y = nextKey->output - currentKey->output; + } + + //Calculate the constants applied that contain the continuity, tension, and bias. + float k1 = ((1.0f - tens) * (1.0f - cont) * (1.0f + bias))/2; + float k2 = ((1.0f - tens) * (1.0f + cont) * (1.0f - bias))/2; + float k3 = ((1.0f - tens) * (1.0f + cont) * (1.0f + bias))/2; + float k4 = ((1.0f - tens) * (1.0f - cont) * (1.0f - bias))/2; + + leftTangent.x = k1 * pCurrentMinusPrevious.x + k2 * pNextMinusCurrent.x; + leftTangent.y = k1 * pCurrentMinusPrevious.y + k2 * pNextMinusCurrent.y; + + rightTangent.x = k3 * pCurrentMinusPrevious.x + k4 * pNextMinusCurrent.x; + rightTangent.y = k3 * pCurrentMinusPrevious.y + k4 * pNextMinusCurrent.y; +} + +// +// FCDAnimationCurve +// + +ImplementObjectType(FCDAnimationCurve); + +FCDAnimationCurve::FCDAnimationCurve(FCDocument* document, FCDAnimationChannel* _parent) + : FCDObject(document), parent(_parent), + targetElement(-1), + preInfinity(FUDaeInfinity::CONSTANT), postInfinity(FUDaeInfinity::CONSTANT), + inputDriver(NULL), inputDriverIndex(0) +{ + currentClip = NULL; + currentOffset = 0; +} + +FCDAnimationCurve::~FCDAnimationCurve() +{ + CLEAR_POINTER_VECTOR(keys); + + inputDriver = NULL; + parent = NULL; + clips.clear(); + clipOffsets.clear(); +} + +void FCDAnimationCurve::SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation) +{ + size_t oldCount = GetKeyCount(); + if (oldCount < count) + { + keys.reserve(count); + for (; oldCount < count; ++oldCount) AddKey(interpolation); + } + else if (count < oldCount) + { + for (FCDAnimationKeyList::iterator it = keys.begin() + count; it != keys.end(); ++it) delete (*it); + keys.resize(count); + } + SetDirtyFlag(); +} + +FCDAnimationKey* FCDAnimationCurve::AddKey(FUDaeInterpolation::Interpolation interpolation) +{ + FCDAnimationKey* key; + switch (interpolation) + { + case FUDaeInterpolation::STEP: key = new FCDAnimationKey; break; + case FUDaeInterpolation::LINEAR: key = new FCDAnimationKey; break; + case FUDaeInterpolation::BEZIER: key = new FCDAnimationKeyBezier; break; + case FUDaeInterpolation::TCB: key = new FCDAnimationKeyTCB; break; + default: FUFail(key = new FCDAnimationKey; break;); + } + key->interpolation = (uint32) interpolation; + keys.push_back(key); + SetDirtyFlag(); + return key; +} + + +// Insert a new key into the ordered array at a certain time +FCDAnimationKey* FCDAnimationCurve::AddKey(FUDaeInterpolation::Interpolation interpolation, float input, size_t& index) +{ + FCDAnimationKey* key; + switch (interpolation) + { + case FUDaeInterpolation::STEP: key = new FCDAnimationKey; break; + case FUDaeInterpolation::LINEAR: key = new FCDAnimationKey; break; + case FUDaeInterpolation::BEZIER: key = new FCDAnimationKeyBezier; break; + case FUDaeInterpolation::TCB: key = new FCDAnimationKeyTCB; break; + default: FUFail(return NULL); + } + key->interpolation = (uint32) interpolation; + key->input = input; + FCDAnimationKeyList::iterator insertIdx = keys.begin(); + FCDAnimationKeyList::iterator finalIdx = keys.end(); + + // TODO: Not cabbage search :-) + for (index = 0; insertIdx != finalIdx; insertIdx++, index++) + { + if ((*insertIdx)->input > input) break; + } + + keys.insert(insertIdx, key); + SetDirtyFlag(); + return key; +} + +bool FCDAnimationCurve::DeleteKey(FCDAnimationKey* key) +{ + FCDAnimationKeyList::iterator kitr = keys.find(key); + if (kitr == keys.end()) return false; + + keys.erase(kitr); + delete key; + return true; +} + +void FCDAnimationCurve::AddClip(FCDAnimationClip* clip) +{ + clips.push_back(clip); +} + +bool FCDAnimationCurve::HasDriver() const +{ + return inputDriver != NULL; +} + +void FCDAnimationCurve::GetDriver(FCDAnimated*& driver, int32& index) +{ const_cast(this)->GetDriver(const_cast(driver), index); } +void FCDAnimationCurve::GetDriver(const FCDAnimated*& driver, int32& index) const +{ + driver = inputDriver; + index = inputDriverIndex; +} + +void FCDAnimationCurve::SetDriver(FCDAnimated* driver, int32 index) +{ + inputDriver = driver; + inputDriverIndex = index; + SetNewChildFlag(); +} + +FCDAnimationCurve* FCDAnimationCurve::Clone(FCDAnimationCurve* clone, bool includeClips) const +{ + if (clone == NULL) clone = new FCDAnimationCurve(const_cast(GetDocument()), parent); + + clone->SetTargetElement(targetElement); + clone->SetTargetQualifier(targetQualifier); + + // Pre-buffer the list of keys and clone them. + clone->keys.clear(); + clone->keys.reserve(keys.size()); + for (FCDAnimationKeyList::const_iterator it = keys.begin(); it != keys.end(); ++it) + { + FCDAnimationKey* key = clone->AddKey((FUDaeInterpolation::Interpolation) (*it)->interpolation); + key->input = (*it)->input; + key->output = (*it)->output; + if ((*it)->interpolation == FUDaeInterpolation::BEZIER) + { + FCDAnimationKeyBezier* bkey1 = (FCDAnimationKeyBezier*) (*it); + FCDAnimationKeyBezier* bkey2 = (FCDAnimationKeyBezier*) key; + bkey2->inTangent = bkey1->inTangent; + bkey2->outTangent = bkey1->outTangent; + } + else if ((*it)->interpolation == FUDaeInterpolation::TCB) + { + FCDAnimationKeyTCB* tkey1 = (FCDAnimationKeyTCB*) (*it); + FCDAnimationKeyTCB* tkey2 = (FCDAnimationKeyTCB*) key; + tkey2->tension = tkey1->tension; + tkey2->continuity = tkey1->continuity; + tkey2->bias = tkey1->bias; + tkey2->easeIn = tkey1->easeIn; + tkey2->easeOut = tkey1->easeOut; + } + } + + clone->preInfinity = preInfinity; + clone->postInfinity = postInfinity; + clone->inputDriver = inputDriver; + clone->inputDriverIndex = inputDriverIndex; + + if (includeClips) + { + // Animation clips that depend on this curve + for (FCDAnimationClipList::const_iterator it = clips.begin(); it != clips.end(); ++it) + { + FCDAnimationClip* clonedClip = (FCDAnimationClip*) (*it)->Clone(0, false); + clonedClip->AddClipCurve(clone); + clone->AddClip(clonedClip); + } + + for (FloatList::const_iterator it = clipOffsets.begin(); it != clipOffsets.end(); ++it) + { + clone->clipOffsets.push_back(*it); + } + } + + return clone; +} + +void FCDAnimationCurve::SetCurrentAnimationClip(FCDAnimationClip* clip) +{ + if (currentClip == clip) return; + + currentClip = NULL; + float clipOffset = 0.0f; + for (size_t i = 0; i < clips.size(); ++i) + { + if (clips[i] == clip) + { + currentClip = clips[i]; + clipOffset = clipOffsets[i]; + break; + } + } + + if (currentClip != NULL) + { + float offset = clipOffset - currentOffset; + currentOffset = clipOffset; + for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) + { + (*it)->input += offset; + } + } + + SetDirtyFlag(); +} + +// Main workhorse for the animation system: +// Evaluates the curve for a given input +float FCDAnimationCurve::Evaluate(float input) const +{ + // Check for empty curves and poses (curves with 1 key). + if (keys.size() == 0) return 0.0f; + if (keys.size() == 1) return keys.front()->output; + + float inputStart = keys.front()->input; + float inputEnd = keys.back()->input; + float inputSpan = inputEnd - inputStart; + float outputStart = keys.front()->output; + float outputEnd = keys.back()->output; + float outputSpan = outputEnd - outputStart; + + // Account for pre-infinity mode + float outputOffset = 0.0f; + if (input < inputStart) + { + float inputDifference = inputStart - input; + switch (preInfinity) + { + case FUDaeInfinity::CONSTANT: return outputStart; + case FUDaeInfinity::LINEAR: return outputStart + inputDifference * (keys[1]->output - outputStart) / (keys[1]->input - inputStart); + case FUDaeInfinity::CYCLE: { float cycleCount = ceilf(inputDifference / inputSpan); input += cycleCount * inputSpan; break; } + case FUDaeInfinity::CYCLE_RELATIVE: { float cycleCount = ceilf(inputDifference / inputSpan); input += cycleCount * inputSpan; outputOffset -= cycleCount * outputSpan; break; } + case FUDaeInfinity::OSCILLATE: { float cycleCount = ceilf(inputDifference / (2.0f * inputSpan)); input += cycleCount * 2.0f * inputSpan; input = inputEnd - fabsf(input - inputEnd); break; } + case FUDaeInfinity::UNKNOWN: default: return outputStart; + } + } + + // Account for post-infinity mode + else if (input >= inputEnd) + { + float inputDifference = input - inputEnd; + switch (postInfinity) + { + case FUDaeInfinity::CONSTANT: return outputEnd; + case FUDaeInfinity::LINEAR: return outputEnd + inputDifference * (keys[keys.size() - 2]->output - outputEnd) / (keys[keys.size() - 2]->input - inputEnd); + case FUDaeInfinity::CYCLE: { float cycleCount = ceilf(inputDifference / inputSpan); input -= cycleCount * inputSpan; break; } + case FUDaeInfinity::CYCLE_RELATIVE: { float cycleCount = ceilf(inputDifference / inputSpan); input -= cycleCount * inputSpan; outputOffset += cycleCount * outputSpan; break; } + case FUDaeInfinity::OSCILLATE: { float cycleCount = ceilf(inputDifference / (2.0f * inputSpan)); input -= cycleCount * 2.0f * inputSpan; input = inputStart + fabsf(input - inputStart); break; } + case FUDaeInfinity::UNKNOWN: default: return outputEnd; + } + } + + // Find the current interval + FCDAnimationKeyList::const_iterator it, start = keys.begin(), terminate = keys.end(); + while (terminate - start > 3) + { + // Binary search. + it = (const FCDAnimationKey**) ((((size_t) terminate) / 2 + ((size_t) start) / 2) & ~((sizeof(size_t)-1))); + if ((*it)->input > input) terminate = it; + else start = it; + } + // Linear search is more efficient on the last interval + for (it = start; it != terminate; ++it) + { + if ((*it)->input >= input) break; + } + if (it == keys.begin()) return outputOffset + outputStart; + + // Get the keys and values for this interval + const FCDAnimationKey* startKey = *(it - 1); + const FCDAnimationKey* endKey = *it; + float inputInterval = endKey->input - startKey->input; + float outputInterval = endKey->output - startKey->output; + + // Interpolate the output. + // Similar code is found in FCDAnimationMultiCurve.cpp. If you update this, update the other one too. + float output; + switch (startKey->interpolation) + { + case FUDaeInterpolation::LINEAR: { + output = startKey->output + (input - startKey->input) / inputInterval * outputInterval; + break; } + + case FUDaeInterpolation::BEZIER: { + if (endKey->interpolation == FUDaeInterpolation::LINEAR) { + output = startKey->output + (input - startKey->input) / inputInterval * outputInterval; + break; + } + if (endKey->interpolation == FUDaeInterpolation::DEFAULT || + endKey->interpolation == FUDaeInterpolation::STEP || + endKey->interpolation == FUDaeInterpolation::UNKNOWN) { + output = startKey->output; + break; + } + //Code that applies to both whether the endKey is Bezier or TCB. + FCDAnimationKeyBezier* bkey1 = (FCDAnimationKeyBezier*) startKey; + FMVector2 inTangent; + if (endKey->interpolation == FUDaeInterpolation::BEZIER) { + inTangent = ((FCDAnimationKeyBezier*) endKey)->inTangent; + } + else if (endKey->interpolation == FUDaeInterpolation::TCB) { + FCDAnimationKeyTCB* tkey2 = (FCDAnimationKeyTCB*) endKey; + FMVector2 tempTangent; + tempTangent.x = tempTangent.y = 0.0f; + const FCDAnimationKey* nextKey = (it + 1) < keys.end() ? (*(it + 1)) : NULL; + ComputeTCBTangent(startKey, endKey, nextKey, tkey2->tension, tkey2->continuity, tkey2->bias, inTangent, tempTangent); + //Change this when we've figured out the values of the vectors from TCB... + inTangent.x = endKey->input + inTangent.x; + inTangent.y = endKey->output + inTangent.y; + } + float t = (input - startKey->input) / inputInterval; + if (is2DEvaluation) t = FindT(bkey1->input, bkey1->outTangent.x, inTangent.x, endKey->input, input, t); + float b = bkey1->outTangent.y; + float c = inTangent.y; + float ti = 1.0f - t; + float br = 3.0f; + float cr = 3.0f; + if (!is2DEvaluation) { + br = inputInterval / (bkey1->outTangent.x - startKey->input); + cr = inputInterval / (endKey->input - inTangent.x); + br = FMath::Clamp(br, 0.01f, 100.0f); + cr = FMath::Clamp(cr, 0.01f, 100.0f); + } + output = startKey->output * ti * ti * ti + br * b * ti * ti * t + cr * c * ti * t * t + endKey->output * t * t * t; + break; } + case FUDaeInterpolation::TCB: { + if (endKey->interpolation == FUDaeInterpolation::LINEAR) { + output = startKey->output + (input - startKey->input) / inputInterval * outputInterval; + break; + } + if (endKey->interpolation == FUDaeInterpolation::DEFAULT || + endKey->interpolation == FUDaeInterpolation::STEP || + endKey->interpolation == FUDaeInterpolation::UNKNOWN) { + output = startKey->output; + break; + } + // Calculate the start key's out-tangent. + FCDAnimationKeyTCB* tkey1 = (FCDAnimationKeyTCB*) startKey; + FMVector2 startTangent, tempTangent, endTangent; + startTangent.x = startTangent.y = tempTangent.x = tempTangent.y = endTangent.x = endTangent.y = 0.0f; + const FCDAnimationKey* previousKey = (it - 1) > keys.begin() ? (*(it - 2)) : NULL; + ComputeTCBTangent(previousKey, startKey, endKey, tkey1->tension, tkey1->continuity, tkey1->bias, tempTangent, startTangent); + + // Calculate the end key's in-tangent. + float by = 0.0f, cy= 0.0f; //will be used in the Bezier equation. + float bx = 0.0f, cx = 0.0f; //will be used in FindT.. x equivalent of the point at b and c + if (endKey->interpolation == FUDaeInterpolation::TCB) { + FCDAnimationKeyTCB* tkey2 = (FCDAnimationKeyTCB*) endKey; + const FCDAnimationKey* nextKey = (it + 1) < keys.end() ? (*(it + 1)) : NULL; + ComputeTCBTangent(startKey, endKey, nextKey, tkey2->tension, tkey2->continuity, tkey2->bias, endTangent, tempTangent); + cy = endKey->output + endTangent.y; //Assuming the tangent is GOING from the point. + cx = endKey->output + endTangent.x; + } + else if (endKey->interpolation == FUDaeInterpolation::BEZIER) { + FCDAnimationKeyBezier* tkey2 = (FCDAnimationKeyBezier*) endKey; + endTangent = tkey2->inTangent; + cy = endTangent.y; + cx = endTangent.x; + } + float t = (input - inputStart) / inputInterval; + by = startKey->output - startTangent.y; //Assuming the tangent is GOING from the point. + bx = startKey->input - startTangent.x; + + if (is2DEvaluation) t = FindT(tkey1->input, bx, cx, endKey->input, input, t); +// else { //Need to figure out algorithm for easing in and out. +// t = Ease(t, tkey1->easeIn, tkey1->easeOut); +// } + + float ti = 1.0f - t; + output = startKey->output*ti*ti*ti + + 3*by*t*ti*ti + + 3*cy*t*t*ti + + endKey->output*t*t*t; + break; } + case FUDaeInterpolation::STEP: + case FUDaeInterpolation::UNKNOWN: + default: + output = startKey->output; + break; + } + return outputOffset + output; +} + +// Apply a conversion function on the key values and tangents +void FCDAnimationCurve::ConvertValues(FCDConversionFunction valueConversion, FCDConversionFunction tangentConversion) +{ + if (valueConversion != NULL) + { + for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) + { + (*it)->output = (*valueConversion)((*it)->output); + } + } + if (tangentConversion != NULL) + { + for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) + { + if ((*it)->interpolation == FUDaeInterpolation::BEZIER) + { + FCDAnimationKeyBezier* bkey = (FCDAnimationKeyBezier*) (*it); + bkey->inTangent.v = (*tangentConversion)(bkey->inTangent.v); + bkey->outTangent.v = (*tangentConversion)(bkey->outTangent.v); + } + } + } + SetDirtyFlag(); +} +void FCDAnimationCurve::ConvertValues(FCDConversionFunctor* valueConversion, FCDConversionFunctor* tangentConversion) +{ + if (valueConversion != NULL) + { + for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) + { + (*it)->output = (*valueConversion)((*it)->output); + } + } + if (tangentConversion != NULL) + { + for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) + { + if ((*it)->interpolation == FUDaeInterpolation::BEZIER) + { + FCDAnimationKeyBezier* bkey = (FCDAnimationKeyBezier*) (*it); + bkey->inTangent.v = (*tangentConversion)(bkey->inTangent.v); + bkey->outTangent.v = (*tangentConversion)(bkey->outTangent.v); + } + } + } + SetDirtyFlag(); +} + +// Apply a conversion function on the key times and tangent weights +void FCDAnimationCurve::ConvertInputs(FCDConversionFunction timeConversion, FCDConversionFunction tangentWeightConversion) +{ + if (timeConversion != NULL) + { + for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) + { + (*it)->input = (*timeConversion)((*it)->input); + } + } + if (tangentWeightConversion != NULL) + { + for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) + { + if ((*it)->interpolation == FUDaeInterpolation::BEZIER) + { + FCDAnimationKeyBezier* bkey = (FCDAnimationKeyBezier*) (*it); + bkey->inTangent.u = (*tangentWeightConversion)(bkey->inTangent.u); + bkey->outTangent.u = (*tangentWeightConversion)(bkey->outTangent.u); + } + } + } + SetDirtyFlag(); +} +void FCDAnimationCurve::ConvertInputs(FCDConversionFunctor* timeConversion, FCDConversionFunctor* tangentWeightConversion) +{ + if (timeConversion != NULL) + { + for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) + { + (*it)->input = (*timeConversion)((*it)->input); + } + } + if (tangentWeightConversion != NULL) + { + for (FCDAnimationKeyList::iterator it = keys.begin(); it != keys.end(); ++it) + { + if ((*it)->interpolation == FUDaeInterpolation::BEZIER) + { + FCDAnimationKeyBezier* bkey = (FCDAnimationKeyBezier*) (*it); + bkey->inTangent.u = (*tangentWeightConversion)(bkey->inTangent.u); + bkey->outTangent.u = (*tangentWeightConversion)(bkey->outTangent.u); + } + } + } + SetDirtyFlag(); +} + +void FCDAnimationCurve::SetClipOffset(float offset, const FCDAnimationClip* clip) +{ + for (size_t i = 0; i < clips.size(); ++i) + { + if (clips[i] == clip) + { + clipOffsets[i] = offset; + break; + } + } + SetDirtyFlag(); +} + +void FCDAnimationCurve::RegisterAnimationClip(FCDAnimationClip* clip) +{ + clips.push_back(clip); + clipOffsets.push_back(-clip->GetStart()); + SetDirtyFlag(); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurve.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurve.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurve.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurve.h (revision 24247) @@ -1,323 +1,323 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDAnimationCurve.h - This file contains the FCDAnimationCurve class and the conversion functions/functors. -*/ - -#ifndef _FCD_ANIMATION_CURVE_H_ -#define _FCD_ANIMATION_CURVE_H_ - -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ - -class FCDAnimated; -class FCDAnimationClip; -class FCDAnimationChannel; -class FCDAnimationKey; -class FCDConversionFunctor; - -typedef float (*FCDConversionFunction)(float v); /**< A simple conversion function. */ - -typedef fm::pvector FCDAnimationClipList; /**< A dynamically-sized array of animation clips. */ -typedef fm::pvector FCDAnimationKeyList; /**< A dynamically-sized array of curve keys. */ - -/** - A COLLADA single-dimensional animation curve. - An animation curve holds the keyframes necessary - to animate an animatable floating-point value. - - There are multiple interpolation mechanisms supported by COLLADA. - FCollada supports the CONSTANT, LINEAR and BEZIER interpolations. - - @see FUDaeInterpolation FUDaeInfinity - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDAnimationCurve : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - // The channel owning this curve. - FCDAnimationChannel* parent; - - // Targeting information - int32 targetElement; - fm::string targetQualifier; - - // Curve information - FCDAnimationKeyList keys; - FUDaeInfinity::Infinity preInfinity, postInfinity; - - // Driver information - FUTrackedPtr inputDriver; - int32 inputDriverIndex; - - // Animation clips that depend on this curve - FCDAnimationClipList clips; - FloatList clipOffsets; - FCDAnimationClip* currentClip; - float currentOffset; - static bool is2DEvaluation; - -public: - DeclareFlag(AnimChanged, 0); // On Member Value Changed - DeclareFlagCount(1); - -public: - /** Constructor: do not use directly. - Instead, use the FCDAnimationChannel::AddCurve function. - You should also attach the new curve to an animated - element using the FCDAnimated::SetCurve function. - @param document The COLLADA document that owns the animation curve. - @param parent The animation channel that contains the curve. */ - FCDAnimationCurve(FCDocument* document, FCDAnimationChannel* parent); - - /** Destructor. */ - virtual ~FCDAnimationCurve(); - - /** Retrieves the animation channel that contains this animation curve. - @return The parent animation channel. */ - inline FCDAnimationChannel* GetParent() { return parent; } - inline const FCDAnimationChannel* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the list of keys for the animation curve. - @return The list of keys. */ - inline FCDAnimationKey** GetKeys() { return keys.begin(); } - inline const FCDAnimationKey** GetKeys() const { return keys.begin(); } /**< See above. */ - - /** Retrieves the number of keys within the animation curve. - @return The number of keys. */ - inline size_t GetKeyCount() const { return keys.size(); } - - /** Sets the number of keys within the animation curve. - @param count The new number of keys in the curve. - @param interpolation If creating new keys, the interpolation type - for the new keys. */ - void SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation); - - /** Retrieves one key in the animation curve. - @param index The index of the key to retrieve. - @return The key. */ - inline FCDAnimationKey* GetKey(size_t index) { FUAssert(index < keys.size(), return NULL); return keys.at(index); } - inline const FCDAnimationKey* GetKey(size_t index) const { FUAssert(index < keys.size(), return NULL); return keys.at(index); } /**< See above. */ - - /** Appends a key to the animation curve. - @param interpolation The interpolation type for the new key. - @return The new key. */ - FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation); - - /** Adds a new key to the animation curve at the given time. - @param interpolation The interpolation type for the new key. - @param input The input (x) value of the new key. - @return The new key. */ - FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation, float input) { size_t blah; return AddKey(interpolation, input, blah); } - - /** Adds a new key to the animation curve at the given time. - @param interpolation The interpolation type for the new key. - @param input The input (x) value of the new key. - @param index [OUT] The index in the array of the new key - @return The new key. */ - FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation, float input, size_t& index); - - /** Removes the given key from this curves list and deletes it - @param key The key to find and delete - @return True on success, false if the key is not found */ - bool DeleteKey(FCDAnimationKey* key); - - /** Retrieves the type of behavior for the curve if the input value is - outside the input interval defined by the curve keys and less than any key input value. - @see FUDaeInfinity - @return The pre-infinity behavior of the curve. */ - inline FUDaeInfinity::Infinity GetPreInfinity() const { return preInfinity; } - - /** Sets the behavior of the curve if the input value is - outside the input interval defined by the curve keys and less than any key input value. - @see FUDaeInfinity - @param infinity The pre-infinity behavior of the curve. */ - inline void SetPreInfinity(FUDaeInfinity::Infinity infinity) { preInfinity = infinity; SetDirtyFlag(); } - - /** Retrieves the type of behavior for the curve if the input value is - outside the input interval defined by the curve keys and greater than any key input value. - @see FUDaeInfinity - @return The post-infinity behavior of the curve. */ - inline FUDaeInfinity::Infinity GetPostInfinity() const { return postInfinity; } - - /** Sets the behavior of the curve if the input value is - outside the input interval defined by the curve keys and greater than any key input value. - @see FUDaeInfinity - @param infinity The post-infinity behavior of the curve. */ - inline void SetPostInfinity(FUDaeInfinity::Infinity infinity) { postInfinity = infinity; SetDirtyFlag(); } - - /** Retrieves whether this animation curve has a driver. - @return Whether there is a driver for this curve. */ - bool HasDriver() const; - - /** Retrieves the value pointer that drives this animation curve. - @param driver A reference to receive the animated input driver. This pointer will - be set to NULL when there is no input driver. - @param index A reference to receive the animated input driver element index. */ - void GetDriver(FCDAnimated*& driver, int32& index); - void GetDriver(const FCDAnimated*& driver, int32& index) const; /**< See above. */ - FCDAnimated* GetDriverPtr(){ return inputDriver; } - - /** [INTERNAL] Retrieve the driver index. - @return The driver index. - */ - int32 GetDriverIndex(){ return inputDriverIndex; } - - /** Sets the value pointer that drives the animation curve. - @param driver The driver animated value. Set this pointer to NULL - to indicate that time drives the animation curve. - @param index The driver animated value index. */ - void SetDriver(FCDAnimated* driver, int32 index); - - /** Retrieves the number of animation clips that use this animation curve. - @return The number of animation clips. */ - inline size_t GetClipCount() const { return clips.size(); } - - /** Retrieves the list of animation clips that use this animation curve. - @return The list of animation clips. */ - inline FCDAnimationClip** GetClips() { return clips.begin(); } - inline const FCDAnimationClip** GetClips() const { return clips.begin(); } /**< See above. */ - - /** Retrieves an animation clips that use this animation curve. - @param index The index of the animation clip. - @return The animation clip at the given index in the list of clips that use this curve. */ - inline FCDAnimationClip* GetClip(size_t index) { FUAssert(index < clips.size(), return NULL); return clips[index]; } - inline const FCDAnimationClip* GetClip(size_t index) const { FUAssert(index < clips.size(), return NULL); return clips[index]; } /**< See above. */ - - /** Adds an animation clip to the list of animation clips that use this curve. - @param clip An animation clip that uses this curve. */ - void AddClip(FCDAnimationClip* clip); - - /** Updates the keys to match the timing of an animation clip that has been - registered using RegisterAnimationClip, or returned from GetClips. - @param clip The clip to update the keys to. */ - void SetCurrentAnimationClip(FCDAnimationClip* clip); - - /** Gets the offset for an animation clip. When the offset is added to the - keys, it causes the animation curve to be repositioned so that the - animation clip starts at the beginning. - @param index The index of the animation clip to get offset for. - @return The offset value. */ - inline float GetClipOffset(size_t index) const { return clipOffsets.at(index); } - - /** Clones the animation curve. The animation clips can be cloned as well, - but this may lead to an infinite recursion because cloning the clips - will also clone its curves. - @param clone The cloned animation curve. If this pointer is NULL, a new - animation curve will be created for you. You will then need to release - the pointer. - @param includeClips True if want to also clone the animation clips. - @return The cloned animation curve. */ - FCDAnimationCurve* Clone(FCDAnimationCurve* clone = NULL, bool includeClips = true) const; - - /** Applies a conversion function to the key output values of the animation curve. - @param valueConversion The conversion function to use on the key outputs. - @param tangentConversion The conversion function to use on the key tangents. */ - void ConvertValues(FCDConversionFunction valueConversion, FCDConversionFunction tangentConversion); - void ConvertValues(FCDConversionFunctor* valueConversion, FCDConversionFunctor* tangentConversion); /**< See above. */ - - /** Applies a conversion function to the key input values of the animation curve. - @param timeConversion The conversion function to use on the key inputs. - @param tangentWeightConversion The conversion function to use on the key tangent weights. */ - void ConvertInputs(FCDConversionFunction timeConversion, FCDConversionFunction tangentWeightConversion); - void ConvertInputs(FCDConversionFunctor* timeConversion, FCDConversionFunctor* tangentWeightConversion); /**< See above. */ - - /** Evaluates the animation curve. - @param input An input value. - @return The sampled value of the curve at the given input value. */ - float Evaluate(float input) const; - - /** [INTERNAL] Adds an animation clip to the list of animation clips that use this curve. - @param clip An animation clip. */ - void RegisterAnimationClip(FCDAnimationClip* clip); - - /** [INTERNAL] Retrieves the target element suffix for the curve. - This will be -1 if the animated element does not belong to an - animated element list. - @return The target element suffix. */ - inline int32 GetTargetElement() const { return targetElement; } - - /** [INTERNAL] Retrieves the target qualifier for the curve. - This will be the empty string if that the curve affects - a one-dimensional animated element. - @return The target qualifier. */ - inline const fm::string& GetTargetQualifier() const { return targetQualifier; } - - /** [INTERNAL] Sets the target element suffix for the curve. - @param e The target element suffix. Set to value to -1 - if the animated element does not belong to an animated element list. */ - inline void SetTargetElement(int32 e) { targetElement = e; SetDirtyFlag(); } - - /** [INTERNAL] Sets the target qualifier for the curve. - @param q The target qualifier. You may sets this string to the empty string - only if that the curve affects a one-dimensional animated element. */ - inline void SetTargetQualifier(const fm::string& q) { targetQualifier = q; SetDirtyFlag(); } - - /** [INTERNAL] Updates the offset for a given animation clip. - @param offset The new offset. - @param clip The animation clip to associate with the offset. */ - void SetClipOffset(float offset, const FCDAnimationClip* clip); - - /** Sets the 2D Curve Evaluation flag. - This flag can be set by the user to enable the - slower, but higher quality 2D evaluation. If the - flag is negative, the faster 1D slope-based evaluation is - performed. Defaults to true. - @param flag Whether to enable 2D curve evaluation. */ - static void Set2DCurveEvaluation(bool flag) { is2DEvaluation = flag; } - - /** Returns whether 2D Curve Evaluation is on or off. - @return A boolean that indicates if the 2D Curve Evaluation is on or off. */ - static bool Is2DCurveEvaluation() {return is2DEvaluation; } -}; - -/** A simple conversion functor. */ -class FCDConversionFunctor -{ -public: - FCDConversionFunctor() {} /**< Constructor. */ - virtual ~FCDConversionFunctor() {} /**< Destructor. */ - virtual float operator() (float v) = 0; /**< Main functor to override. @param v The value to convert. @return The converted value. */ -}; - -/** A sample conversion functor: it scales the value by a given amount. */ -class FCDConversionScaleFunctor : public FCDConversionFunctor -{ -private: - float scaleFactor; - -public: - FCDConversionScaleFunctor(float factor) { scaleFactor = factor; } /**< Constructor. @param factor The scale factor. */ - void SetScaleFactor(float factor) { scaleFactor = factor; } /**< Mutator. @param factor The new scale factor. */ - virtual ~FCDConversionScaleFunctor() {} /**< Destructor. */ - virtual float operator() (float v) { return v * scaleFactor; } /**< Scales the given value. @param v The value to scale. @return The scaled value. */ - virtual FMVector3 operator() (const FMVector3& v) { return v * scaleFactor; } /**< Scales the given FMVector3. @param v The value to scale. @return The scaled value. */ - virtual FMVector4 operator() (const FMVector4& v) { return v * scaleFactor; } /**< Scales the given FMVector4. @param v The value to scale. @return The scaled value. */ -}; - -/** A sample conversion functor: it offsets the value by a given amount. */ -class FCDConversionOffsetFunctor : public FCDConversionFunctor -{ -private: - float offset; - -public: - FCDConversionOffsetFunctor(float _offset) { offset = _offset; } /**< Constructor. @param _offset The value offset. */ - virtual ~FCDConversionOffsetFunctor() {} /**< Destructor. */ - virtual float operator() (float v) { return v + offset; } /**< Offsets the given value. @param v The value to offset. @return The offseted value. */ -}; - -#endif // _FCD_ANIMATION_CURVE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDAnimationCurve.h + This file contains the FCDAnimationCurve class and the conversion functions/functors. +*/ + +#ifndef _FCD_ANIMATION_CURVE_H_ +#define _FCD_ANIMATION_CURVE_H_ + +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ + +class FCDAnimated; +class FCDAnimationClip; +class FCDAnimationChannel; +class FCDAnimationKey; +class FCDConversionFunctor; + +typedef float (*FCDConversionFunction)(float v); /**< A simple conversion function. */ + +typedef fm::pvector FCDAnimationClipList; /**< A dynamically-sized array of animation clips. */ +typedef fm::pvector FCDAnimationKeyList; /**< A dynamically-sized array of curve keys. */ + +/** + A COLLADA single-dimensional animation curve. + An animation curve holds the keyframes necessary + to animate an animatable floating-point value. + + There are multiple interpolation mechanisms supported by COLLADA. + FCollada supports the CONSTANT, LINEAR and BEZIER interpolations. + + @see FUDaeInterpolation FUDaeInfinity + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDAnimationCurve : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + // The channel owning this curve. + FCDAnimationChannel* parent; + + // Targeting information + int32 targetElement; + fm::string targetQualifier; + + // Curve information + FCDAnimationKeyList keys; + FUDaeInfinity::Infinity preInfinity, postInfinity; + + // Driver information + FUTrackedPtr inputDriver; + int32 inputDriverIndex; + + // Animation clips that depend on this curve + FCDAnimationClipList clips; + FloatList clipOffsets; + FCDAnimationClip* currentClip; + float currentOffset; + static bool is2DEvaluation; + +public: + DeclareFlag(AnimChanged, 0); // On Member Value Changed + DeclareFlagCount(1); + +public: + /** Constructor: do not use directly. + Instead, use the FCDAnimationChannel::AddCurve function. + You should also attach the new curve to an animated + element using the FCDAnimated::SetCurve function. + @param document The COLLADA document that owns the animation curve. + @param parent The animation channel that contains the curve. */ + FCDAnimationCurve(FCDocument* document, FCDAnimationChannel* parent); + + /** Destructor. */ + virtual ~FCDAnimationCurve(); + + /** Retrieves the animation channel that contains this animation curve. + @return The parent animation channel. */ + inline FCDAnimationChannel* GetParent() { return parent; } + inline const FCDAnimationChannel* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the list of keys for the animation curve. + @return The list of keys. */ + inline FCDAnimationKey** GetKeys() { return keys.begin(); } + inline const FCDAnimationKey** GetKeys() const { return keys.begin(); } /**< See above. */ + + /** Retrieves the number of keys within the animation curve. + @return The number of keys. */ + inline size_t GetKeyCount() const { return keys.size(); } + + /** Sets the number of keys within the animation curve. + @param count The new number of keys in the curve. + @param interpolation If creating new keys, the interpolation type + for the new keys. */ + void SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation); + + /** Retrieves one key in the animation curve. + @param index The index of the key to retrieve. + @return The key. */ + inline FCDAnimationKey* GetKey(size_t index) { FUAssert(index < keys.size(), return NULL); return keys.at(index); } + inline const FCDAnimationKey* GetKey(size_t index) const { FUAssert(index < keys.size(), return NULL); return keys.at(index); } /**< See above. */ + + /** Appends a key to the animation curve. + @param interpolation The interpolation type for the new key. + @return The new key. */ + FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation); + + /** Adds a new key to the animation curve at the given time. + @param interpolation The interpolation type for the new key. + @param input The input (x) value of the new key. + @return The new key. */ + FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation, float input) { size_t blah; return AddKey(interpolation, input, blah); } + + /** Adds a new key to the animation curve at the given time. + @param interpolation The interpolation type for the new key. + @param input The input (x) value of the new key. + @param index [OUT] The index in the array of the new key + @return The new key. */ + FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation, float input, size_t& index); + + /** Removes the given key from this curves list and deletes it + @param key The key to find and delete + @return True on success, false if the key is not found */ + bool DeleteKey(FCDAnimationKey* key); + + /** Retrieves the type of behavior for the curve if the input value is + outside the input interval defined by the curve keys and less than any key input value. + @see FUDaeInfinity + @return The pre-infinity behavior of the curve. */ + inline FUDaeInfinity::Infinity GetPreInfinity() const { return preInfinity; } + + /** Sets the behavior of the curve if the input value is + outside the input interval defined by the curve keys and less than any key input value. + @see FUDaeInfinity + @param infinity The pre-infinity behavior of the curve. */ + inline void SetPreInfinity(FUDaeInfinity::Infinity infinity) { preInfinity = infinity; SetDirtyFlag(); } + + /** Retrieves the type of behavior for the curve if the input value is + outside the input interval defined by the curve keys and greater than any key input value. + @see FUDaeInfinity + @return The post-infinity behavior of the curve. */ + inline FUDaeInfinity::Infinity GetPostInfinity() const { return postInfinity; } + + /** Sets the behavior of the curve if the input value is + outside the input interval defined by the curve keys and greater than any key input value. + @see FUDaeInfinity + @param infinity The post-infinity behavior of the curve. */ + inline void SetPostInfinity(FUDaeInfinity::Infinity infinity) { postInfinity = infinity; SetDirtyFlag(); } + + /** Retrieves whether this animation curve has a driver. + @return Whether there is a driver for this curve. */ + bool HasDriver() const; + + /** Retrieves the value pointer that drives this animation curve. + @param driver A reference to receive the animated input driver. This pointer will + be set to NULL when there is no input driver. + @param index A reference to receive the animated input driver element index. */ + void GetDriver(FCDAnimated*& driver, int32& index); + void GetDriver(const FCDAnimated*& driver, int32& index) const; /**< See above. */ + FCDAnimated* GetDriverPtr(){ return inputDriver; } + + /** [INTERNAL] Retrieve the driver index. + @return The driver index. + */ + int32 GetDriverIndex(){ return inputDriverIndex; } + + /** Sets the value pointer that drives the animation curve. + @param driver The driver animated value. Set this pointer to NULL + to indicate that time drives the animation curve. + @param index The driver animated value index. */ + void SetDriver(FCDAnimated* driver, int32 index); + + /** Retrieves the number of animation clips that use this animation curve. + @return The number of animation clips. */ + inline size_t GetClipCount() const { return clips.size(); } + + /** Retrieves the list of animation clips that use this animation curve. + @return The list of animation clips. */ + inline FCDAnimationClip** GetClips() { return clips.begin(); } + inline const FCDAnimationClip** GetClips() const { return clips.begin(); } /**< See above. */ + + /** Retrieves an animation clips that use this animation curve. + @param index The index of the animation clip. + @return The animation clip at the given index in the list of clips that use this curve. */ + inline FCDAnimationClip* GetClip(size_t index) { FUAssert(index < clips.size(), return NULL); return clips[index]; } + inline const FCDAnimationClip* GetClip(size_t index) const { FUAssert(index < clips.size(), return NULL); return clips[index]; } /**< See above. */ + + /** Adds an animation clip to the list of animation clips that use this curve. + @param clip An animation clip that uses this curve. */ + void AddClip(FCDAnimationClip* clip); + + /** Updates the keys to match the timing of an animation clip that has been + registered using RegisterAnimationClip, or returned from GetClips. + @param clip The clip to update the keys to. */ + void SetCurrentAnimationClip(FCDAnimationClip* clip); + + /** Gets the offset for an animation clip. When the offset is added to the + keys, it causes the animation curve to be repositioned so that the + animation clip starts at the beginning. + @param index The index of the animation clip to get offset for. + @return The offset value. */ + inline float GetClipOffset(size_t index) const { return clipOffsets.at(index); } + + /** Clones the animation curve. The animation clips can be cloned as well, + but this may lead to an infinite recursion because cloning the clips + will also clone its curves. + @param clone The cloned animation curve. If this pointer is NULL, a new + animation curve will be created for you. You will then need to release + the pointer. + @param includeClips True if want to also clone the animation clips. + @return The cloned animation curve. */ + FCDAnimationCurve* Clone(FCDAnimationCurve* clone = NULL, bool includeClips = true) const; + + /** Applies a conversion function to the key output values of the animation curve. + @param valueConversion The conversion function to use on the key outputs. + @param tangentConversion The conversion function to use on the key tangents. */ + void ConvertValues(FCDConversionFunction valueConversion, FCDConversionFunction tangentConversion); + void ConvertValues(FCDConversionFunctor* valueConversion, FCDConversionFunctor* tangentConversion); /**< See above. */ + + /** Applies a conversion function to the key input values of the animation curve. + @param timeConversion The conversion function to use on the key inputs. + @param tangentWeightConversion The conversion function to use on the key tangent weights. */ + void ConvertInputs(FCDConversionFunction timeConversion, FCDConversionFunction tangentWeightConversion); + void ConvertInputs(FCDConversionFunctor* timeConversion, FCDConversionFunctor* tangentWeightConversion); /**< See above. */ + + /** Evaluates the animation curve. + @param input An input value. + @return The sampled value of the curve at the given input value. */ + float Evaluate(float input) const; + + /** [INTERNAL] Adds an animation clip to the list of animation clips that use this curve. + @param clip An animation clip. */ + void RegisterAnimationClip(FCDAnimationClip* clip); + + /** [INTERNAL] Retrieves the target element suffix for the curve. + This will be -1 if the animated element does not belong to an + animated element list. + @return The target element suffix. */ + inline int32 GetTargetElement() const { return targetElement; } + + /** [INTERNAL] Retrieves the target qualifier for the curve. + This will be the empty string if that the curve affects + a one-dimensional animated element. + @return The target qualifier. */ + inline const fm::string& GetTargetQualifier() const { return targetQualifier; } + + /** [INTERNAL] Sets the target element suffix for the curve. + @param e The target element suffix. Set to value to -1 + if the animated element does not belong to an animated element list. */ + inline void SetTargetElement(int32 e) { targetElement = e; SetDirtyFlag(); } + + /** [INTERNAL] Sets the target qualifier for the curve. + @param q The target qualifier. You may sets this string to the empty string + only if that the curve affects a one-dimensional animated element. */ + inline void SetTargetQualifier(const fm::string& q) { targetQualifier = q; SetDirtyFlag(); } + + /** [INTERNAL] Updates the offset for a given animation clip. + @param offset The new offset. + @param clip The animation clip to associate with the offset. */ + void SetClipOffset(float offset, const FCDAnimationClip* clip); + + /** Sets the 2D Curve Evaluation flag. + This flag can be set by the user to enable the + slower, but higher quality 2D evaluation. If the + flag is negative, the faster 1D slope-based evaluation is + performed. Defaults to true. + @param flag Whether to enable 2D curve evaluation. */ + static void Set2DCurveEvaluation(bool flag) { is2DEvaluation = flag; } + + /** Returns whether 2D Curve Evaluation is on or off. + @return A boolean that indicates if the 2D Curve Evaluation is on or off. */ + static bool Is2DCurveEvaluation() {return is2DEvaluation; } +}; + +/** A simple conversion functor. */ +class FCDConversionFunctor +{ +public: + FCDConversionFunctor() {} /**< Constructor. */ + virtual ~FCDConversionFunctor() {} /**< Destructor. */ + virtual float operator() (float v) = 0; /**< Main functor to override. @param v The value to convert. @return The converted value. */ +}; + +/** A sample conversion functor: it scales the value by a given amount. */ +class FCDConversionScaleFunctor : public FCDConversionFunctor +{ +private: + float scaleFactor; + +public: + FCDConversionScaleFunctor(float factor) { scaleFactor = factor; } /**< Constructor. @param factor The scale factor. */ + void SetScaleFactor(float factor) { scaleFactor = factor; } /**< Mutator. @param factor The new scale factor. */ + virtual ~FCDConversionScaleFunctor() {} /**< Destructor. */ + virtual float operator() (float v) { return v * scaleFactor; } /**< Scales the given value. @param v The value to scale. @return The scaled value. */ + virtual FMVector3 operator() (const FMVector3& v) { return v * scaleFactor; } /**< Scales the given FMVector3. @param v The value to scale. @return The scaled value. */ + virtual FMVector4 operator() (const FMVector4& v) { return v * scaleFactor; } /**< Scales the given FMVector4. @param v The value to scale. @return The scaled value. */ +}; + +/** A sample conversion functor: it offsets the value by a given amount. */ +class FCDConversionOffsetFunctor : public FCDConversionFunctor +{ +private: + float offset; + +public: + FCDConversionOffsetFunctor(float _offset) { offset = _offset; } /**< Constructor. @param _offset The value offset. */ + virtual ~FCDConversionOffsetFunctor() {} /**< Destructor. */ + virtual float operator() (float v) { return v + offset; } /**< Offsets the given value. @param v The value to offset. @return The offseted value. */ +}; + +#endif // _FCD_ANIMATION_CURVE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurve.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurveTools.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurveTools.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurveTools.cpp (revision 24247) @@ -1,261 +1,261 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDAnimationCurve.h" -#include "FCDocument/FCDAnimationChannel.h" -#include "FCDocument/FCDAnimationCurveTools.h" -#include "FCDocument/FCDAnimationKey.h" -#include "FCDocument/FCDAnimationMultiCurve.h" - -#define SMALL_DELTA 0.001f - -namespace FCDAnimationCurveTools -{ - // Non-standard constructor used to merge together animation curves - FCDAnimationMultiCurve* MergeCurves(const FCDAnimationCurveConstList& toMerge, const FloatList& defaultValues) - { - size_t dimension = toMerge.size(); - if (dimension == 0) return NULL; - - // Look for the document pointer and select the parent curve. - FCDocument* document = NULL; - int32 targetElement = -1; - FUDaeInfinity::Infinity preInfinity = FUDaeInfinity::CONSTANT, postInfinity = FUDaeInfinity::CONSTANT; - for (size_t i = 0; i < dimension; ++i) - { - if (toMerge[i] != NULL) - { - document = const_cast(toMerge[i]->GetDocument()); - targetElement = toMerge[i]->GetTargetElement(); - preInfinity = toMerge[i]->GetPreInfinity(); - postInfinity = toMerge[i]->GetPostInfinity(); - break; - } - } - if (document == NULL) return NULL; - - // Allocate the output multiCurve. - FCDAnimationMultiCurve* multiCurve = new FCDAnimationMultiCurve(document, (uint32) dimension); - multiCurve->SetTargetElement(targetElement); - multiCurve->SetPreInfinity(preInfinity); - multiCurve->SetPostInfinity(postInfinity); - - // Calculate the merged input keys and their wanted interpolations. - FloatList mergedInputs; - UInt32List mergedInterpolations; - for (size_t i = 0; i < dimension; ++i) - { - const FCDAnimationCurve* curve = toMerge[i]; - if (curve == NULL) continue; - const FCDAnimationKey** curveKeys = curve->GetKeys(); - - // Merge each curve's keys, which should already be sorted, into the multi-curve's - size_t multiCurveKeyCount = mergedInputs.size(), m = 0; - size_t curveKeyCount = curve->GetKeyCount(), c = 0; - while (m < multiCurveKeyCount && c < curveKeyCount) - { - if (IsEquivalent(mergedInputs[m], curveKeys[c]->input)) - { - if (mergedInterpolations[m] != curveKeys[c]->interpolation) mergedInterpolations[m] = FUDaeInterpolation::BEZIER; - ++c; ++m; - } - else if (mergedInputs[m] < curveKeys[c]->input) { ++m; } - else - { - // Insert this new key within the merged list. - mergedInputs.insert(mergedInputs.begin() + m, curveKeys[c]->input); - mergedInterpolations.insert(mergedInterpolations.begin() + m, curveKeys[c]->interpolation); - ++multiCurveKeyCount; - ++m; ++c; - } - } - while (c < curveKeyCount) - { - // Insert all these extra keys at the end of the merged list. - mergedInputs.push_back(curveKeys[c]->input); - mergedInterpolations.push_back(curveKeys[c]->interpolation); - ++c; - } - } - size_t keyCount = mergedInputs.size(); - - // Create the multi-dimensional keys. - for (size_t i = 0; i < keyCount; ++i) - { - FCDAnimationMKey* key = multiCurve->AddKey((FUDaeInterpolation::Interpolation) mergedInterpolations[i]); - key->input = mergedInputs[i]; - } - FCDAnimationMKey** keys = multiCurve->GetKeys(); - - // Merge the curves one by one into the multi-curve - for (size_t i = 0; i < dimension; ++i) - { - const FCDAnimationCurve* curve = toMerge[i]; - if (curve == NULL || curve->GetKeyCount() == 0) - { - // No curve, or an empty curve, set the default value on all the keys - float defaultValue = (i < defaultValues.size()) ? defaultValues[i] : 0.0f; - for (size_t k = 0; k < keyCount; ++k) - { - keys[k]->output[i] = defaultValue; - if (keys[k]->interpolation == FUDaeInterpolation::BEZIER) - { - float previousSpan = (k > 0 ? mergedInputs[k] - mergedInputs[k - 1] : 1.0f) / 3.0f; - float nextSpan = (k < keyCount - 1 ? mergedInputs[k + 1] - mergedInputs[k] : 1.0f) / 3.0f; - - FCDAnimationMKeyBezier* bkey = (FCDAnimationMKeyBezier*) keys[k]; - bkey->inTangent[i] = FMVector2(keys[k]->input - previousSpan, defaultValue); - bkey->outTangent[i] = FMVector2(keys[k]->input + nextSpan, defaultValue); - } - } - - continue; - } - - // Merge in this curve's values, sampling when the multi-curve's key is not present in the curve. - // Calculate and retrieve the tangents in a polar-like form. - const FCDAnimationKey** curveKeys = curve->GetKeys(); - size_t curveKeyCount = curve->GetKeyCount(); - for (size_t k = 0, c = 0; k < keyCount; ++k) - { - float input = keys[k]->input; - float previousSpan = (k > 0 ? input - keys[k - 1]->input : 1.0f) / 3.0f; - float nextSpan = (k < keyCount - 1 ? keys[k + 1]->input - input : 1.0f) / 3.0f; - - if (c >= curveKeyCount || !IsEquivalent(keys[k]->input, curveKeys[c]->input)) - { - // Sample the curve - float value = keys[k]->output[i] = curve->Evaluate(input); - if (keys[k]->interpolation == FUDaeInterpolation::BEZIER) - { - // Calculate the slope at the sampled point. - // Since the curve should be smooth: the in/out tangents should be equal. - FCDAnimationMKeyBezier* bkey = (FCDAnimationMKeyBezier*) keys[k]; - float slope = (value - curve->Evaluate(input - SMALL_DELTA)) / SMALL_DELTA; - bkey->inTangent[i] = FMVector2(input - previousSpan, value - slope * previousSpan); - bkey->outTangent[i] = FMVector2(input + nextSpan, value + slope * nextSpan); - } - else if (keys[k]->interpolation == FUDaeInterpolation::TCB) - { - // Don't fool around: just set default values. - FCDAnimationMKeyTCB* tkey = (FCDAnimationMKeyTCB*) keys[k]; - tkey->tension[i] = tkey->continuity[i] = tkey->bias[i] = 0.5f; - tkey->easeIn[i] = tkey->easeOut[i] = 0.0f; - } - } - else - { - // Keys match, grab the value directly - keys[k]->output[i] = curveKeys[c]->output; - - // Check the wanted interpolation type to retrieve/calculate the extra necessary information. - if (keys[k]->interpolation == FUDaeInterpolation::BEZIER) - { - float oldPreviousSpan = (c > 0 ? curveKeys[c]->input - curveKeys[c - 1]->input : 1.0f) / 3.0f; - float oldNextSpan = (c < curveKeyCount - 1 ? curveKeys[c + 1]->input - curveKeys[c]->input : 1.0f) / 3.0f; - - // Calculate the new tangent: keep the slope proportional - FCDAnimationMKeyBezier* bkey = (FCDAnimationMKeyBezier*) keys[k]; - if (curveKeys[c]->interpolation == FUDaeInterpolation::BEZIER) - { - FCDAnimationKeyBezier* bkey2 = (FCDAnimationKeyBezier*) curveKeys[c]; - FMVector2 absolute(bkey->input, bkey->output[i]); - bkey->inTangent[i] = absolute + (bkey2->inTangent - absolute) / oldPreviousSpan * previousSpan; - bkey->outTangent[i] = absolute + (bkey2->outTangent - absolute) / oldNextSpan * nextSpan; - } - else - { - // Default to flat tangents. - bkey->inTangent[i] = FMVector2(bkey->input - previousSpan, bkey->output[i]); - bkey->outTangent[i] = FMVector2(bkey->input + nextSpan, bkey->output[i]); - } - } - else if (keys[k]->interpolation == FUDaeInterpolation::TCB) - { - FCDAnimationMKeyTCB* tkey = (FCDAnimationMKeyTCB*) keys[k]; - if (curveKeys[c]->interpolation == FUDaeInterpolation::TCB) - { - FCDAnimationKeyTCB* tkey2 = (FCDAnimationKeyTCB*) curveKeys[c]; - tkey->tension[i] = tkey2->tension; - tkey->continuity[i] = tkey2->continuity; - tkey->bias[i] = tkey2->bias; - tkey->easeIn[i] = tkey2->easeIn; - tkey->easeOut[i] = tkey2->easeOut; - } - else - { - // Default to flat values. - tkey->tension[i] = tkey->continuity[i] = tkey->bias[i] = 0.5f; - tkey->easeIn[i] = tkey->easeOut[i] = 0.0f; - } - } - - // Go to the next existing key in the 1D curve. - ++c; - } - } - } - return multiCurve; - } - - // Collapse this multi-dimensional curve into a one-dimensional curve, given a collapsing function - FCDAnimationCurve* Collapse(const FCDAnimationMultiCurve* curve, FCDCollapsingFunction collapse) - { - size_t keyCount = curve->GetKeyCount(); - size_t dimension = curve->GetDimension(); - if (keyCount == 0 || dimension== 0) return NULL; - if (collapse == NULL) collapse = Average; - const FCDAnimationMKey** inKeys = curve->GetKeys(); - - // Create the output one-dimensional curve and create the keys. - FCDAnimationCurve* out = new FCDAnimationCurve(const_cast(curve->GetDocument()), NULL); - for (size_t i = 0; i < keyCount; ++i) - { - out->AddKey((FUDaeInterpolation::Interpolation) inKeys[i]->interpolation); - } - FCDAnimationKey** outKeys = out->GetKeys(); - - // Copy the key data over, collapsing the values - float* buffer = new float[dimension]; - for (size_t i = 0; i < keyCount; ++i) - { - outKeys[i]->input = inKeys[i]->input; - - // Collapse the values and the tangents - for (uint32 j = 0; j < dimension; ++j) buffer[j] = inKeys[i]->output[j]; - outKeys[i]->output = (*collapse)(buffer, (uint32) dimension); - - if (outKeys[i]->interpolation == FUDaeInterpolation::BEZIER) - { - FCDAnimationMKeyBezier* inBKey = (FCDAnimationMKeyBezier*) inKeys + i; - FCDAnimationKeyBezier* outBKey = (FCDAnimationKeyBezier*) outKeys + i; - for (uint32 j = 0; j < dimension; ++j) buffer[j] = inBKey->inTangent[j].v; - outBKey->inTangent = FMVector2(inBKey->inTangent[0].u, (*collapse)(buffer, (uint32) dimension)); - for (uint32 j = 0; j < dimension; ++j) buffer[j] = inBKey->outTangent[j].v; - outBKey->outTangent = FMVector2(inBKey->outTangent[0].u, (*collapse)(buffer, (uint32) dimension)); - } - } - SAFE_DELETE_ARRAY(buffer); - - return out; - } - - float TakeFirst(float* values, uint32 count) - { - return (count > 0) ? *values : 0.0f; - } - - float Average(float* values, uint32 count) - { - float v = 0.0f; - for (uint32 i = 0; i < count; ++i) - v += values[i]; - return v / count; - } -}; +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDAnimationCurve.h" +#include "FCDocument/FCDAnimationChannel.h" +#include "FCDocument/FCDAnimationCurveTools.h" +#include "FCDocument/FCDAnimationKey.h" +#include "FCDocument/FCDAnimationMultiCurve.h" + +#define SMALL_DELTA 0.001f + +namespace FCDAnimationCurveTools +{ + // Non-standard constructor used to merge together animation curves + FCDAnimationMultiCurve* MergeCurves(const FCDAnimationCurveConstList& toMerge, const FloatList& defaultValues) + { + size_t dimension = toMerge.size(); + if (dimension == 0) return NULL; + + // Look for the document pointer and select the parent curve. + FCDocument* document = NULL; + int32 targetElement = -1; + FUDaeInfinity::Infinity preInfinity = FUDaeInfinity::CONSTANT, postInfinity = FUDaeInfinity::CONSTANT; + for (size_t i = 0; i < dimension; ++i) + { + if (toMerge[i] != NULL) + { + document = const_cast(toMerge[i]->GetDocument()); + targetElement = toMerge[i]->GetTargetElement(); + preInfinity = toMerge[i]->GetPreInfinity(); + postInfinity = toMerge[i]->GetPostInfinity(); + break; + } + } + if (document == NULL) return NULL; + + // Allocate the output multiCurve. + FCDAnimationMultiCurve* multiCurve = new FCDAnimationMultiCurve(document, (uint32) dimension); + multiCurve->SetTargetElement(targetElement); + multiCurve->SetPreInfinity(preInfinity); + multiCurve->SetPostInfinity(postInfinity); + + // Calculate the merged input keys and their wanted interpolations. + FloatList mergedInputs; + UInt32List mergedInterpolations; + for (size_t i = 0; i < dimension; ++i) + { + const FCDAnimationCurve* curve = toMerge[i]; + if (curve == NULL) continue; + const FCDAnimationKey** curveKeys = curve->GetKeys(); + + // Merge each curve's keys, which should already be sorted, into the multi-curve's + size_t multiCurveKeyCount = mergedInputs.size(), m = 0; + size_t curveKeyCount = curve->GetKeyCount(), c = 0; + while (m < multiCurveKeyCount && c < curveKeyCount) + { + if (IsEquivalent(mergedInputs[m], curveKeys[c]->input)) + { + if (mergedInterpolations[m] != curveKeys[c]->interpolation) mergedInterpolations[m] = FUDaeInterpolation::BEZIER; + ++c; ++m; + } + else if (mergedInputs[m] < curveKeys[c]->input) { ++m; } + else + { + // Insert this new key within the merged list. + mergedInputs.insert(mergedInputs.begin() + m, curveKeys[c]->input); + mergedInterpolations.insert(mergedInterpolations.begin() + m, curveKeys[c]->interpolation); + ++multiCurveKeyCount; + ++m; ++c; + } + } + while (c < curveKeyCount) + { + // Insert all these extra keys at the end of the merged list. + mergedInputs.push_back(curveKeys[c]->input); + mergedInterpolations.push_back(curveKeys[c]->interpolation); + ++c; + } + } + size_t keyCount = mergedInputs.size(); + + // Create the multi-dimensional keys. + for (size_t i = 0; i < keyCount; ++i) + { + FCDAnimationMKey* key = multiCurve->AddKey((FUDaeInterpolation::Interpolation) mergedInterpolations[i]); + key->input = mergedInputs[i]; + } + FCDAnimationMKey** keys = multiCurve->GetKeys(); + + // Merge the curves one by one into the multi-curve + for (size_t i = 0; i < dimension; ++i) + { + const FCDAnimationCurve* curve = toMerge[i]; + if (curve == NULL || curve->GetKeyCount() == 0) + { + // No curve, or an empty curve, set the default value on all the keys + float defaultValue = (i < defaultValues.size()) ? defaultValues[i] : 0.0f; + for (size_t k = 0; k < keyCount; ++k) + { + keys[k]->output[i] = defaultValue; + if (keys[k]->interpolation == FUDaeInterpolation::BEZIER) + { + float previousSpan = (k > 0 ? mergedInputs[k] - mergedInputs[k - 1] : 1.0f) / 3.0f; + float nextSpan = (k < keyCount - 1 ? mergedInputs[k + 1] - mergedInputs[k] : 1.0f) / 3.0f; + + FCDAnimationMKeyBezier* bkey = (FCDAnimationMKeyBezier*) keys[k]; + bkey->inTangent[i] = FMVector2(keys[k]->input - previousSpan, defaultValue); + bkey->outTangent[i] = FMVector2(keys[k]->input + nextSpan, defaultValue); + } + } + + continue; + } + + // Merge in this curve's values, sampling when the multi-curve's key is not present in the curve. + // Calculate and retrieve the tangents in a polar-like form. + const FCDAnimationKey** curveKeys = curve->GetKeys(); + size_t curveKeyCount = curve->GetKeyCount(); + for (size_t k = 0, c = 0; k < keyCount; ++k) + { + float input = keys[k]->input; + float previousSpan = (k > 0 ? input - keys[k - 1]->input : 1.0f) / 3.0f; + float nextSpan = (k < keyCount - 1 ? keys[k + 1]->input - input : 1.0f) / 3.0f; + + if (c >= curveKeyCount || !IsEquivalent(keys[k]->input, curveKeys[c]->input)) + { + // Sample the curve + float value = keys[k]->output[i] = curve->Evaluate(input); + if (keys[k]->interpolation == FUDaeInterpolation::BEZIER) + { + // Calculate the slope at the sampled point. + // Since the curve should be smooth: the in/out tangents should be equal. + FCDAnimationMKeyBezier* bkey = (FCDAnimationMKeyBezier*) keys[k]; + float slope = (value - curve->Evaluate(input - SMALL_DELTA)) / SMALL_DELTA; + bkey->inTangent[i] = FMVector2(input - previousSpan, value - slope * previousSpan); + bkey->outTangent[i] = FMVector2(input + nextSpan, value + slope * nextSpan); + } + else if (keys[k]->interpolation == FUDaeInterpolation::TCB) + { + // Don't fool around: just set default values. + FCDAnimationMKeyTCB* tkey = (FCDAnimationMKeyTCB*) keys[k]; + tkey->tension[i] = tkey->continuity[i] = tkey->bias[i] = 0.5f; + tkey->easeIn[i] = tkey->easeOut[i] = 0.0f; + } + } + else + { + // Keys match, grab the value directly + keys[k]->output[i] = curveKeys[c]->output; + + // Check the wanted interpolation type to retrieve/calculate the extra necessary information. + if (keys[k]->interpolation == FUDaeInterpolation::BEZIER) + { + float oldPreviousSpan = (c > 0 ? curveKeys[c]->input - curveKeys[c - 1]->input : 1.0f) / 3.0f; + float oldNextSpan = (c < curveKeyCount - 1 ? curveKeys[c + 1]->input - curveKeys[c]->input : 1.0f) / 3.0f; + + // Calculate the new tangent: keep the slope proportional + FCDAnimationMKeyBezier* bkey = (FCDAnimationMKeyBezier*) keys[k]; + if (curveKeys[c]->interpolation == FUDaeInterpolation::BEZIER) + { + FCDAnimationKeyBezier* bkey2 = (FCDAnimationKeyBezier*) curveKeys[c]; + FMVector2 absolute(bkey->input, bkey->output[i]); + bkey->inTangent[i] = absolute + (bkey2->inTangent - absolute) / oldPreviousSpan * previousSpan; + bkey->outTangent[i] = absolute + (bkey2->outTangent - absolute) / oldNextSpan * nextSpan; + } + else + { + // Default to flat tangents. + bkey->inTangent[i] = FMVector2(bkey->input - previousSpan, bkey->output[i]); + bkey->outTangent[i] = FMVector2(bkey->input + nextSpan, bkey->output[i]); + } + } + else if (keys[k]->interpolation == FUDaeInterpolation::TCB) + { + FCDAnimationMKeyTCB* tkey = (FCDAnimationMKeyTCB*) keys[k]; + if (curveKeys[c]->interpolation == FUDaeInterpolation::TCB) + { + FCDAnimationKeyTCB* tkey2 = (FCDAnimationKeyTCB*) curveKeys[c]; + tkey->tension[i] = tkey2->tension; + tkey->continuity[i] = tkey2->continuity; + tkey->bias[i] = tkey2->bias; + tkey->easeIn[i] = tkey2->easeIn; + tkey->easeOut[i] = tkey2->easeOut; + } + else + { + // Default to flat values. + tkey->tension[i] = tkey->continuity[i] = tkey->bias[i] = 0.5f; + tkey->easeIn[i] = tkey->easeOut[i] = 0.0f; + } + } + + // Go to the next existing key in the 1D curve. + ++c; + } + } + } + return multiCurve; + } + + // Collapse this multi-dimensional curve into a one-dimensional curve, given a collapsing function + FCDAnimationCurve* Collapse(const FCDAnimationMultiCurve* curve, FCDCollapsingFunction collapse) + { + size_t keyCount = curve->GetKeyCount(); + size_t dimension = curve->GetDimension(); + if (keyCount == 0 || dimension== 0) return NULL; + if (collapse == NULL) collapse = Average; + const FCDAnimationMKey** inKeys = curve->GetKeys(); + + // Create the output one-dimensional curve and create the keys. + FCDAnimationCurve* out = new FCDAnimationCurve(const_cast(curve->GetDocument()), NULL); + for (size_t i = 0; i < keyCount; ++i) + { + out->AddKey((FUDaeInterpolation::Interpolation) inKeys[i]->interpolation); + } + FCDAnimationKey** outKeys = out->GetKeys(); + + // Copy the key data over, collapsing the values + float* buffer = new float[dimension]; + for (size_t i = 0; i < keyCount; ++i) + { + outKeys[i]->input = inKeys[i]->input; + + // Collapse the values and the tangents + for (uint32 j = 0; j < dimension; ++j) buffer[j] = inKeys[i]->output[j]; + outKeys[i]->output = (*collapse)(buffer, (uint32) dimension); + + if (outKeys[i]->interpolation == FUDaeInterpolation::BEZIER) + { + FCDAnimationMKeyBezier* inBKey = (FCDAnimationMKeyBezier*) inKeys + i; + FCDAnimationKeyBezier* outBKey = (FCDAnimationKeyBezier*) outKeys + i; + for (uint32 j = 0; j < dimension; ++j) buffer[j] = inBKey->inTangent[j].v; + outBKey->inTangent = FMVector2(inBKey->inTangent[0].u, (*collapse)(buffer, (uint32) dimension)); + for (uint32 j = 0; j < dimension; ++j) buffer[j] = inBKey->outTangent[j].v; + outBKey->outTangent = FMVector2(inBKey->outTangent[0].u, (*collapse)(buffer, (uint32) dimension)); + } + } + SAFE_DELETE_ARRAY(buffer); + + return out; + } + + float TakeFirst(float* values, uint32 count) + { + return (count > 0) ? *values : 0.0f; + } + + float Average(float* values, uint32 count) + { + float v = 0.0f; + for (uint32 i = 0; i < count; ++i) + v += values[i]; + return v / count; + } +}; Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurveTools.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurveTools.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurveTools.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurveTools.h (revision 24247) @@ -1,61 +1,61 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDAnimationCurveTools.h - This file contains the FCDAnimationCurveTools namespace. -*/ - -#ifndef _FCD_ANIMATION_CURVE_TOOLS_H_ -#define _FCD_ANIMATION_CURVE_TOOLS_H_ - -class FCDAnimationCurve; -class FCDAnimationMultiCurve; - -typedef fm::pvector FCDAnimationCurveList; /**< A dynamically-sized array of animation curves. */ -typedef fm::pvector FCDAnimationCurveConstList; /**< A dynamically-sized array of constant animation curve pointers. */ -typedef float (*FCDCollapsingFunction)(float* values, uint32 count); /**< A collapsing function. It converts multiple floating-point values into one floating-point value. */ - -/** Contains tools to merge, collapse and otherwise modify animation curve. */ -namespace FCDAnimationCurveTools -{ - /** Merges multiple single-dimensional animation curves into one - multi-dimensional animation curve. - For each NULL element found within the 'toMerge' list, the corresponding - default value is used. If there are not enough default values provided, zero is assumed. - The number of dimensions for the output animation curve is taken as the size of the 'toMerge' list. - @param toMerge The list of single-dimensional animation curves to merge. This list may - contain NULL elements, as explained above. - @param defaultValues The list of default values to use when a NULL element is encountered. - Default values should be provided even for the elements that are not NULL. */ - FCOLLADA_EXPORT FCDAnimationMultiCurve* MergeCurves(const FCDAnimationCurveConstList& toMerge, const FloatList& defaultValues); - inline FCDAnimationMultiCurve* MergeCurves(const FCDAnimationCurveList& toMerge, const FloatList& defaultValues) { return MergeCurves(*(const FCDAnimationCurveConstList*) &toMerge, defaultValues); } /**< See above. */ - - /** Collapses a multi-dimensional curve into a one-dimensional curve. - @see Average TakeFirst - @param curve The multi-dimensional curve to collapse. - @param collapse The function to use to collapse multiple floating-point - values into one. Set this to NULL to use the default collapsing - function, which averages all the values. */ - FCOLLADA_EXPORT FCDAnimationCurve* Collapse(const FCDAnimationMultiCurve* curve, FCDCollapsingFunction collapse = NULL); - - /** Retrieves the first floating-point value of a list of floating-point values. - This is a typical conversion function. - @param values The list of floating-point values. - @param count The number of values within the given list. */ - float TakeFirst(float* values, uint32 count); - - /** Retrieves the average value of a list of floating-point values. - This is a typical conversion function. - @param values The list of floating-point values. - @param count The number of values within the given list. */ - float Average(float* values, uint32 count); -}; - -#endif // _FCD_ANIMATION_CURVE_TOOLS_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDAnimationCurveTools.h + This file contains the FCDAnimationCurveTools namespace. +*/ + +#ifndef _FCD_ANIMATION_CURVE_TOOLS_H_ +#define _FCD_ANIMATION_CURVE_TOOLS_H_ + +class FCDAnimationCurve; +class FCDAnimationMultiCurve; + +typedef fm::pvector FCDAnimationCurveList; /**< A dynamically-sized array of animation curves. */ +typedef fm::pvector FCDAnimationCurveConstList; /**< A dynamically-sized array of constant animation curve pointers. */ +typedef float (*FCDCollapsingFunction)(float* values, uint32 count); /**< A collapsing function. It converts multiple floating-point values into one floating-point value. */ + +/** Contains tools to merge, collapse and otherwise modify animation curve. */ +namespace FCDAnimationCurveTools +{ + /** Merges multiple single-dimensional animation curves into one + multi-dimensional animation curve. + For each NULL element found within the 'toMerge' list, the corresponding + default value is used. If there are not enough default values provided, zero is assumed. + The number of dimensions for the output animation curve is taken as the size of the 'toMerge' list. + @param toMerge The list of single-dimensional animation curves to merge. This list may + contain NULL elements, as explained above. + @param defaultValues The list of default values to use when a NULL element is encountered. + Default values should be provided even for the elements that are not NULL. */ + FCOLLADA_EXPORT FCDAnimationMultiCurve* MergeCurves(const FCDAnimationCurveConstList& toMerge, const FloatList& defaultValues); + inline FCDAnimationMultiCurve* MergeCurves(const FCDAnimationCurveList& toMerge, const FloatList& defaultValues) { return MergeCurves(*(const FCDAnimationCurveConstList*) &toMerge, defaultValues); } /**< See above. */ + + /** Collapses a multi-dimensional curve into a one-dimensional curve. + @see Average TakeFirst + @param curve The multi-dimensional curve to collapse. + @param collapse The function to use to collapse multiple floating-point + values into one. Set this to NULL to use the default collapsing + function, which averages all the values. */ + FCOLLADA_EXPORT FCDAnimationCurve* Collapse(const FCDAnimationMultiCurve* curve, FCDCollapsingFunction collapse = NULL); + + /** Retrieves the first floating-point value of a list of floating-point values. + This is a typical conversion function. + @param values The list of floating-point values. + @param count The number of values within the given list. */ + float TakeFirst(float* values, uint32 count); + + /** Retrieves the average value of a list of floating-point values. + This is a typical conversion function. + @param values The list of floating-point values. + @param count The number of values within the given list. */ + float Average(float* values, uint32 count); +}; + +#endif // _FCD_ANIMATION_CURVE_TOOLS_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationCurveTools.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationKey.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationKey.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationKey.cpp (revision 24247) @@ -1,65 +1,65 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDAnimationKey.h" - -// -// FCDAnimationMKey -// - -FCDAnimationMKey::FCDAnimationMKey(uint32 _dimension) -: dimension(_dimension) -{ - output = new float[dimension]; -} - -FCDAnimationMKey::~FCDAnimationMKey() -{ - SAFE_DELETE_ARRAY(output); -} - -// -// FCDAnimationMKeyBezier -// - -FCDAnimationMKeyBezier::FCDAnimationMKeyBezier(uint32 dimension) -: FCDAnimationMKey(dimension) -{ - inTangent = new FMVector2[dimension]; - outTangent = new FMVector2[dimension]; -} - -FCDAnimationMKeyBezier::~FCDAnimationMKeyBezier() -{ - SAFE_DELETE_ARRAY(inTangent); - SAFE_DELETE_ARRAY(outTangent); -} - -// -// FCDAnimationMKeyTCB -// - -FCDAnimationMKeyTCB::FCDAnimationMKeyTCB(uint32 dimension) -: FCDAnimationMKey(dimension) -{ - tension = new float[dimension]; - continuity = new float[dimension]; - bias = new float[dimension]; - easeIn = new float[dimension]; - easeOut = new float[dimension]; -} - -FCDAnimationMKeyTCB::~FCDAnimationMKeyTCB() -{ - SAFE_DELETE_ARRAY(tension); - SAFE_DELETE_ARRAY(continuity); - SAFE_DELETE_ARRAY(bias); - SAFE_DELETE_ARRAY(easeIn); - SAFE_DELETE_ARRAY(easeOut); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDAnimationKey.h" + +// +// FCDAnimationMKey +// + +FCDAnimationMKey::FCDAnimationMKey(uint32 _dimension) +: dimension(_dimension) +{ + output = new float[dimension]; +} + +FCDAnimationMKey::~FCDAnimationMKey() +{ + SAFE_DELETE_ARRAY(output); +} + +// +// FCDAnimationMKeyBezier +// + +FCDAnimationMKeyBezier::FCDAnimationMKeyBezier(uint32 dimension) +: FCDAnimationMKey(dimension) +{ + inTangent = new FMVector2[dimension]; + outTangent = new FMVector2[dimension]; +} + +FCDAnimationMKeyBezier::~FCDAnimationMKeyBezier() +{ + SAFE_DELETE_ARRAY(inTangent); + SAFE_DELETE_ARRAY(outTangent); +} + +// +// FCDAnimationMKeyTCB +// + +FCDAnimationMKeyTCB::FCDAnimationMKeyTCB(uint32 dimension) +: FCDAnimationMKey(dimension) +{ + tension = new float[dimension]; + continuity = new float[dimension]; + bias = new float[dimension]; + easeIn = new float[dimension]; + easeOut = new float[dimension]; +} + +FCDAnimationMKeyTCB::~FCDAnimationMKeyTCB() +{ + SAFE_DELETE_ARRAY(tension); + SAFE_DELETE_ARRAY(continuity); + SAFE_DELETE_ARRAY(bias); + SAFE_DELETE_ARRAY(easeIn); + SAFE_DELETE_ARRAY(easeOut); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationKey.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationKey.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationKey.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationKey.h (revision 24247) @@ -1,152 +1,152 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDAnimationKey.h - This file contains the FCDAnimationKey, FCDAnimationKeyBezier and FCDAnimationKeyTCB classes. -*/ - -#ifndef _FCD_ANIMATION_KEY_H_ -#define _FCD_ANIMATION_KEY_H_ - -/** - A simple animation key. - This class is the base for the more complex one-dimensional keys - and it is used directly for linear and step keys. - - Do not create directly. - Instead call FCDAnimationCurve::AddKey(FUDaeInterpolation::LINEAR) - or FCDAnimationCurve::AddKey(FUDaeInterpolation::STEP). -*/ -class FCDAnimationKey -{ -public: - /** The key input. Typically, this will be a time value, in seconds. - For driven curves, the dimension of this value will depend on the driver. */ - float input; - - /** The key output. */ - float output; - - /** The key interpolation type. - @see FUDaeInterpolation::Interpolation */ - uint32 interpolation; -}; - -/** - An animation key with tangents values. - This class is used for bezier keys and soon: for hermite keys as well. - - Do not create directly. - Instead call FCDAnimationCurve::AddKey(FUDaeInterpolation::BEZIER). -*/ -class FCDAnimationKeyBezier : public FCDAnimationKey -{ -public: - FMVector2 inTangent; /**< The incoming tangent value. */ - FMVector2 outTangent; /**< The outcoming tangent value. */ -}; - -/** - An animation key with tension, continuity and bias values. - This class is used for 3dsMax TCB keys. - - Do not create directly. - Instead call FCDAnimationCurve::AddKey(FUDaeInterpolation::TCB). -*/ -class FCDAnimationKeyTCB : public FCDAnimationKey -{ -public: - float tension; /**< The tension. */ - float continuity; /**< The continuity. */ - float bias; /**< The bias. */ - - float easeIn; /**< The ease-in factor. */ - float easeOut; /**< The ease-out factor. */ -}; - -/** - A simple multi-dimensional animation key. - This class is the base for the more complex multi-dimensional keys - and it is used directly for linear and step multi-dimensional keys. -*/ -class FCDAnimationMKey -{ -private: - uint32 dimension; - -public: - /** Constructor. Do not use directly. - Instead call FCDAnimationMultiCurve::AddKey(FUDaeInterpolation::LINEAR) - or FCDAnimationMultiCurve::AddKey(FUDaeInterpolation::STEP). - @param dimension The number of dimension to the key output. */ - FCDAnimationMKey(uint32 dimension); - - /** Destructor. */ - virtual ~FCDAnimationMKey(); - - /** Retrieves the number of dimensions for this key. - @return The number of dimensions. */ - uint32 GetDimension() const { return dimension; }; - - /** The key input. Typically, this will be a time value, in seconds. - For driven curves, the dimension of this value will depend on the driver. */ - float input; - - /** The key interpolation type. - @see FUDaeInterpolation::Interpolation */ - uint32 interpolation; - - /** The multi-dimensional key output. */ - float* output; -}; - -/** - A multi-dimensional animation key with tangents values. - This class is used for bezier keys and soon: for hermite keys as well. -*/ -class FCDAnimationMKeyBezier : public FCDAnimationMKey -{ -public: - /** Constructor: do not use directly. - Instead call FCDAnimationCurve::AddKey(FUDaeInterpolation::BEZIER). - @param dimension The number of dimension to the key output. */ - FCDAnimationMKeyBezier(uint32 dimension); - - /** Destructor. */ - virtual ~FCDAnimationMKeyBezier(); - - FMVector2* inTangent; /**< The incoming tangent value. */ - FMVector2* outTangent; /**< The outcoming tangent value. */ -}; - -/** - An animation key with tension, continuity and bias values. - This class is used for 3dsMax TCB keys. -*/ -class FCDAnimationMKeyTCB : public FCDAnimationMKey -{ -public: - /** Constructor: do not use directly. - Instead call FCDAnimationMultiCurve::AddKey(FUDaeInterpolation::TCB). - @param dimension The number of dimension to the key output. */ - FCDAnimationMKeyTCB(uint32 dimension); - - /** Destructor. */ - virtual ~FCDAnimationMKeyTCB(); - - float* tension; /**< The multi-dimensional tensions. */ - float* continuity; /**< The multi-dimensional continuities. */ - float* bias; /**< The multi-dimensional biases. */ - - float* easeIn; /**< The multi-dimensional ease-in factors. */ - float* easeOut; /**< The multi-dimensional ease-out factors. */ -}; - -#endif // _FCD_ANIMATION_KEY_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDAnimationKey.h + This file contains the FCDAnimationKey, FCDAnimationKeyBezier and FCDAnimationKeyTCB classes. +*/ + +#ifndef _FCD_ANIMATION_KEY_H_ +#define _FCD_ANIMATION_KEY_H_ + +/** + A simple animation key. + This class is the base for the more complex one-dimensional keys + and it is used directly for linear and step keys. + + Do not create directly. + Instead call FCDAnimationCurve::AddKey(FUDaeInterpolation::LINEAR) + or FCDAnimationCurve::AddKey(FUDaeInterpolation::STEP). +*/ +class FCDAnimationKey +{ +public: + /** The key input. Typically, this will be a time value, in seconds. + For driven curves, the dimension of this value will depend on the driver. */ + float input; + + /** The key output. */ + float output; + + /** The key interpolation type. + @see FUDaeInterpolation::Interpolation */ + uint32 interpolation; +}; + +/** + An animation key with tangents values. + This class is used for bezier keys and soon: for hermite keys as well. + + Do not create directly. + Instead call FCDAnimationCurve::AddKey(FUDaeInterpolation::BEZIER). +*/ +class FCDAnimationKeyBezier : public FCDAnimationKey +{ +public: + FMVector2 inTangent; /**< The incoming tangent value. */ + FMVector2 outTangent; /**< The outcoming tangent value. */ +}; + +/** + An animation key with tension, continuity and bias values. + This class is used for 3dsMax TCB keys. + + Do not create directly. + Instead call FCDAnimationCurve::AddKey(FUDaeInterpolation::TCB). +*/ +class FCDAnimationKeyTCB : public FCDAnimationKey +{ +public: + float tension; /**< The tension. */ + float continuity; /**< The continuity. */ + float bias; /**< The bias. */ + + float easeIn; /**< The ease-in factor. */ + float easeOut; /**< The ease-out factor. */ +}; + +/** + A simple multi-dimensional animation key. + This class is the base for the more complex multi-dimensional keys + and it is used directly for linear and step multi-dimensional keys. +*/ +class FCDAnimationMKey +{ +private: + uint32 dimension; + +public: + /** Constructor. Do not use directly. + Instead call FCDAnimationMultiCurve::AddKey(FUDaeInterpolation::LINEAR) + or FCDAnimationMultiCurve::AddKey(FUDaeInterpolation::STEP). + @param dimension The number of dimension to the key output. */ + FCDAnimationMKey(uint32 dimension); + + /** Destructor. */ + virtual ~FCDAnimationMKey(); + + /** Retrieves the number of dimensions for this key. + @return The number of dimensions. */ + uint32 GetDimension() const { return dimension; }; + + /** The key input. Typically, this will be a time value, in seconds. + For driven curves, the dimension of this value will depend on the driver. */ + float input; + + /** The key interpolation type. + @see FUDaeInterpolation::Interpolation */ + uint32 interpolation; + + /** The multi-dimensional key output. */ + float* output; +}; + +/** + A multi-dimensional animation key with tangents values. + This class is used for bezier keys and soon: for hermite keys as well. +*/ +class FCDAnimationMKeyBezier : public FCDAnimationMKey +{ +public: + /** Constructor: do not use directly. + Instead call FCDAnimationCurve::AddKey(FUDaeInterpolation::BEZIER). + @param dimension The number of dimension to the key output. */ + FCDAnimationMKeyBezier(uint32 dimension); + + /** Destructor. */ + virtual ~FCDAnimationMKeyBezier(); + + FMVector2* inTangent; /**< The incoming tangent value. */ + FMVector2* outTangent; /**< The outcoming tangent value. */ +}; + +/** + An animation key with tension, continuity and bias values. + This class is used for 3dsMax TCB keys. +*/ +class FCDAnimationMKeyTCB : public FCDAnimationMKey +{ +public: + /** Constructor: do not use directly. + Instead call FCDAnimationMultiCurve::AddKey(FUDaeInterpolation::TCB). + @param dimension The number of dimension to the key output. */ + FCDAnimationMKeyTCB(uint32 dimension); + + /** Destructor. */ + virtual ~FCDAnimationMKeyTCB(); + + float* tension; /**< The multi-dimensional tensions. */ + float* continuity; /**< The multi-dimensional continuities. */ + float* bias; /**< The multi-dimensional biases. */ + + float* easeIn; /**< The multi-dimensional ease-in factors. */ + float* easeOut; /**< The multi-dimensional ease-out factors. */ +}; + +#endif // _FCD_ANIMATION_KEY_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationKey.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationMultiCurve.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationMultiCurve.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationMultiCurve.cpp (revision 24247) @@ -1,170 +1,170 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDAnimationCurve.h" -#include "FCDocument/FCDAnimationKey.h" -#include "FCDocument/FCDAnimationMultiCurve.h" -#include "FUtils/FUDaeEnum.h" - -// Implemented in FCDAnimationCurve.cpp -extern float FindT(float cp0x, float cp1x, float cp2x, float cp3x, float input, float initialGuess); - -// Declaring the type of evaluation for curves once. -bool FCDAnimationMultiCurve::is2DEvaluation = true; - -// -// FCDAnimationMultiCurve -// - -ImplementObjectType(FCDAnimationMultiCurve); - -FCDAnimationMultiCurve::FCDAnimationMultiCurve(FCDocument* document, uint32 _dimension) -: FCDObject(document), dimension(_dimension) -, targetElement(-1) -, preInfinity(FUDaeInfinity::CONSTANT), postInfinity(FUDaeInfinity::CONSTANT) -{ - if (dimension == 0) dimension = 1; -} - -FCDAnimationMultiCurve::~FCDAnimationMultiCurve() -{ - CLEAR_POINTER_VECTOR(keys); -} - -void FCDAnimationMultiCurve::SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation) -{ - size_t oldCount = GetKeyCount(); - if (oldCount < count) - { - keys.reserve(count); - for (; oldCount < count; ++oldCount) AddKey(interpolation); - } - else if (count < oldCount) - { - for (FCDAnimationMKeyList::iterator it = keys.begin() + count; it != keys.end(); ++it) delete (*it); - keys.resize(count); - } - SetDirtyFlag(); -} - -FCDAnimationMKey* FCDAnimationMultiCurve::AddKey(FUDaeInterpolation::Interpolation interpolation) -{ - FCDAnimationMKey* key; - switch (interpolation) - { - case FUDaeInterpolation::STEP: key = new FCDAnimationMKey(dimension); break; - case FUDaeInterpolation::LINEAR: key = new FCDAnimationMKey(dimension); break; - case FUDaeInterpolation::BEZIER: key = new FCDAnimationMKeyBezier(dimension); break; - case FUDaeInterpolation::TCB: key = new FCDAnimationMKeyTCB(dimension); break; - default: FUFail(key = new FCDAnimationMKey(dimension); break;); - } - key->interpolation = (uint32) interpolation; - keys.push_back(key); - SetDirtyFlag(); - return key; -} - -// Samples all the curves for a given input -void FCDAnimationMultiCurve::Evaluate(float input, float* output) const -{ - // Check for empty curves and poses (curves with 1 key). - if (keys.size() == 0) - { - for (uint32 i = 0; i < dimension; ++i) output[i] = 0.0f; - } - else if (keys.size() == 1) - { - for (uint32 i = 0; i < dimension; ++i) output[i] = keys.front()->output[i]; - } - else - { - // Find the current interval - FCDAnimationMKeyList::const_iterator it, start = keys.begin(), terminate = keys.end(); - while (terminate - start > 3) - { - // Binary search. - it = (const FCDAnimationMKey**) ((((size_t) terminate) / 2 + ((size_t) start) / 2) & ~((sizeof(size_t)-1))); - if ((*it)->input > input) terminate = it; - else start = it; - } - // Linear search is more efficient on the last interval - for (it = start; it != terminate; ++it) - { - if ((*it)->input > input) break; - } - - if (it == keys.end()) - { - // We're sampling after the curve, return the last values - const FCDAnimationMKey* lastKey = keys.back(); - for (uint32 i = 0; i < dimension; ++i) output[i] = lastKey->output[i]; - } - else if (it == keys.begin()) - { - // We're sampling before the curve, return the first values - const FCDAnimationMKey* firstKey = keys.front(); - for (uint32 i = 0; i < dimension; ++i) output[i] = firstKey->output[i]; - } - else - { - // Get the keys and values for this interval - const FCDAnimationMKey* startKey = *(it - 1); - const FCDAnimationMKey* endKey = *it; - float inputInterval = endKey->input - startKey->input; - - // Interpolate the outputs. - // Similar code is found in FCDAnimationCurve.cpp. If you update this, update the other one too. - switch (startKey->interpolation) - { - case FUDaeInterpolation::LINEAR: - for (uint32 i = 0; i < dimension; ++i) - { - output[i] = startKey->output[i] + (input - startKey->input) / inputInterval * (endKey->output[i] - startKey->output[i]); - } - break; - - case FUDaeInterpolation::BEZIER: { - FCDAnimationMKeyBezier* bkey1 = (FCDAnimationMKeyBezier*) startKey; - for (uint32 i = 0; i < dimension; ++i) - { - FMVector2 inTangent; - if (endKey->interpolation == FUDaeInterpolation::BEZIER) inTangent = ((FCDAnimationMKeyBezier*) endKey)->inTangent[i]; - else inTangent = FMVector2(endKey->input, 0.0f); - - float t = (input - startKey->input) / inputInterval; - if (is2DEvaluation) t = FindT(startKey->input, bkey1->outTangent[i].x, inTangent.x, endKey->input, input, t); - float b = bkey1->outTangent[i].v; - float c = inTangent.v; - float ti = 1.0f - t; - float br = inputInterval / (bkey1->outTangent[i].u - startKey->input); - float cr = inputInterval / (endKey->input - inTangent.u); - br = FMath::Clamp(br, 0.01f, 100.0f); - cr = FMath::Clamp(cr, 0.01f, 100.0f); - - output[i] = startKey->output[i] * ti * ti * ti + br* b * ti * ti * t + cr * c * ti * t * t + endKey->output[i] * t * t * t; - } - break; } - - case FUDaeInterpolation::TCB: // Not implemented.. - case FUDaeInterpolation::UNKNOWN: - case FUDaeInterpolation::STEP: - default: - for (uint32 i = 0; i < dimension; ++i) output[i] = startKey->output[i]; - break; - } - } - } -} - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDAnimationCurve.h" +#include "FCDocument/FCDAnimationKey.h" +#include "FCDocument/FCDAnimationMultiCurve.h" +#include "FUtils/FUDaeEnum.h" + +// Implemented in FCDAnimationCurve.cpp +extern float FindT(float cp0x, float cp1x, float cp2x, float cp3x, float input, float initialGuess); + +// Declaring the type of evaluation for curves once. +bool FCDAnimationMultiCurve::is2DEvaluation = true; + +// +// FCDAnimationMultiCurve +// + +ImplementObjectType(FCDAnimationMultiCurve); + +FCDAnimationMultiCurve::FCDAnimationMultiCurve(FCDocument* document, uint32 _dimension) +: FCDObject(document), dimension(_dimension) +, targetElement(-1) +, preInfinity(FUDaeInfinity::CONSTANT), postInfinity(FUDaeInfinity::CONSTANT) +{ + if (dimension == 0) dimension = 1; +} + +FCDAnimationMultiCurve::~FCDAnimationMultiCurve() +{ + CLEAR_POINTER_VECTOR(keys); +} + +void FCDAnimationMultiCurve::SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation) +{ + size_t oldCount = GetKeyCount(); + if (oldCount < count) + { + keys.reserve(count); + for (; oldCount < count; ++oldCount) AddKey(interpolation); + } + else if (count < oldCount) + { + for (FCDAnimationMKeyList::iterator it = keys.begin() + count; it != keys.end(); ++it) delete (*it); + keys.resize(count); + } + SetDirtyFlag(); +} + +FCDAnimationMKey* FCDAnimationMultiCurve::AddKey(FUDaeInterpolation::Interpolation interpolation) +{ + FCDAnimationMKey* key; + switch (interpolation) + { + case FUDaeInterpolation::STEP: key = new FCDAnimationMKey(dimension); break; + case FUDaeInterpolation::LINEAR: key = new FCDAnimationMKey(dimension); break; + case FUDaeInterpolation::BEZIER: key = new FCDAnimationMKeyBezier(dimension); break; + case FUDaeInterpolation::TCB: key = new FCDAnimationMKeyTCB(dimension); break; + default: FUFail(key = new FCDAnimationMKey(dimension); break;); + } + key->interpolation = (uint32) interpolation; + keys.push_back(key); + SetDirtyFlag(); + return key; +} + +// Samples all the curves for a given input +void FCDAnimationMultiCurve::Evaluate(float input, float* output) const +{ + // Check for empty curves and poses (curves with 1 key). + if (keys.size() == 0) + { + for (uint32 i = 0; i < dimension; ++i) output[i] = 0.0f; + } + else if (keys.size() == 1) + { + for (uint32 i = 0; i < dimension; ++i) output[i] = keys.front()->output[i]; + } + else + { + // Find the current interval + FCDAnimationMKeyList::const_iterator it, start = keys.begin(), terminate = keys.end(); + while (terminate - start > 3) + { + // Binary search. + it = (const FCDAnimationMKey**) ((((size_t) terminate) / 2 + ((size_t) start) / 2) & ~((sizeof(size_t)-1))); + if ((*it)->input > input) terminate = it; + else start = it; + } + // Linear search is more efficient on the last interval + for (it = start; it != terminate; ++it) + { + if ((*it)->input > input) break; + } + + if (it == keys.end()) + { + // We're sampling after the curve, return the last values + const FCDAnimationMKey* lastKey = keys.back(); + for (uint32 i = 0; i < dimension; ++i) output[i] = lastKey->output[i]; + } + else if (it == keys.begin()) + { + // We're sampling before the curve, return the first values + const FCDAnimationMKey* firstKey = keys.front(); + for (uint32 i = 0; i < dimension; ++i) output[i] = firstKey->output[i]; + } + else + { + // Get the keys and values for this interval + const FCDAnimationMKey* startKey = *(it - 1); + const FCDAnimationMKey* endKey = *it; + float inputInterval = endKey->input - startKey->input; + + // Interpolate the outputs. + // Similar code is found in FCDAnimationCurve.cpp. If you update this, update the other one too. + switch (startKey->interpolation) + { + case FUDaeInterpolation::LINEAR: + for (uint32 i = 0; i < dimension; ++i) + { + output[i] = startKey->output[i] + (input - startKey->input) / inputInterval * (endKey->output[i] - startKey->output[i]); + } + break; + + case FUDaeInterpolation::BEZIER: { + FCDAnimationMKeyBezier* bkey1 = (FCDAnimationMKeyBezier*) startKey; + for (uint32 i = 0; i < dimension; ++i) + { + FMVector2 inTangent; + if (endKey->interpolation == FUDaeInterpolation::BEZIER) inTangent = ((FCDAnimationMKeyBezier*) endKey)->inTangent[i]; + else inTangent = FMVector2(endKey->input, 0.0f); + + float t = (input - startKey->input) / inputInterval; + if (is2DEvaluation) t = FindT(startKey->input, bkey1->outTangent[i].x, inTangent.x, endKey->input, input, t); + float b = bkey1->outTangent[i].v; + float c = inTangent.v; + float ti = 1.0f - t; + float br = inputInterval / (bkey1->outTangent[i].u - startKey->input); + float cr = inputInterval / (endKey->input - inTangent.u); + br = FMath::Clamp(br, 0.01f, 100.0f); + cr = FMath::Clamp(cr, 0.01f, 100.0f); + + output[i] = startKey->output[i] * ti * ti * ti + br* b * ti * ti * t + cr * c * ti * t * t + endKey->output[i] * t * t * t; + } + break; } + + case FUDaeInterpolation::TCB: // Not implemented.. + case FUDaeInterpolation::UNKNOWN: + case FUDaeInterpolation::STEP: + default: + for (uint32 i = 0; i < dimension; ++i) output[i] = startKey->output[i]; + break; + } + } + } +} + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationMultiCurve.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationMultiCurve.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationMultiCurve.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationMultiCurve.h (revision 24247) @@ -1,163 +1,163 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDAnimationMultiCurve.h - This file contains the FCDAnimationMultiCurve class. -*/ - -#ifndef _FCD_ANIMATION_MULTI_CURVE_H_ -#define _FCD_ANIMATION_MULTI_CURVE_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ - -class FCDocument; -class FCDAnimationMKey; - -typedef fm::pvector FCDAnimationMKeyList; /**< A dynamically-sized array of multi-dimensional animation keys. */ - -/** - A COLLADA multi-dimensional animation curve. - - This is a utility class that is used to convert multiple - animation curves into one animation curve that has multiple - dimensions, but only one list of key inputs. - - FCollada will never create a multi-dimensional animation curve - during the import of a COLLADA document. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDAnimationMultiCurve : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - // The number of merged curves - uint32 dimension; - - // Target information - int32 targetElement; - - // Input information - FCDAnimationMKeyList keys; - FUDaeInfinity::Infinity preInfinity, postInfinity; - - //What sort of evaluation we do, 1D or 2D - static bool is2DEvaluation; - -public: - /** Constructor. - The number of dimensions will not change in the lifetime of a - multi-dimensional curve. - @param document The COLLADA document that owns the animation curve. - @param dimension The number of dimensions for the animation curve. */ - FCDAnimationMultiCurve(FCDocument* document, uint32 dimension); - - /** Destructor. */ - virtual ~FCDAnimationMultiCurve(); - - /** Retrieves the number of dimensions for the curve. - @return The number of dimensions for the curve. */ - inline uint32 GetDimension() const { return dimension; } - - /** Retrieves the list of key inputs for the animation curve. - @return The list of key inputs. */ - inline FCDAnimationMKey** GetKeys() { return keys.begin(); } - inline const FCDAnimationMKey** GetKeys() const { return keys.begin(); } /**< See above. */ - - /** Retrieves the number of keys within the animation curve. - @return The number of keys. */ - inline size_t GetKeyCount() const { return keys.size(); } - - /** Sets the number of keys within the animation curve. - @param count The new number of keys in the curve. - @param interpolation If creating new keys, the interpolation type - for the new keys. */ - void SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation); - - /** Retrieve one key of the animation curve. - @param index The index of the key to retrieve. - @return The indexed key. */ - inline FCDAnimationMKey* GetKey(size_t index) { FUAssert(index < keys.size(), return NULL); return keys.at(index); } - inline const FCDAnimationMKey* GetKey(size_t index) const { FUAssert(index < keys.size(), return NULL); return keys.at(index); } /**< See above. */ - - /** Appends a key to the animation curve. - @param interpolation The interpolation type for the new key. - @return The new key. */ - FCDAnimationMKey* AddKey(FUDaeInterpolation::Interpolation interpolation); - - /** Retrieves the type of behavior for the curve if the input value is - outside the input interval defined by the curve keys and less than any key input value. - @see FUDaeInfinity - @return The pre-infinity behavior of the curve. */ - inline FUDaeInfinity::Infinity GetPreInfinity() const { return preInfinity; } - - /** Sets the behavior of the curve if the input value is - outside the input interval defined by the curve keys and less than any key input value. - @see FUDaeInfinity - @param infinity The pre-infinity behavior of the curve. */ - inline void SetPreInfinity(FUDaeInfinity::Infinity infinity) { preInfinity = infinity; SetDirtyFlag(); } - - /** Retrieves the type of behavior for the curve if the input value is - outside the input interval defined by the curve keys and greater than any key input value. - @see FUDaeInfinity - @return The post-infinity behavior of the curve. */ - inline FUDaeInfinity::Infinity GetPostInfinity() const { return postInfinity; } - - /** Sets the behavior of the curve if the input value is - outside the input interval defined by the curve keys and greater than any key input value. - @see FUDaeInfinity - @param infinity The post-infinity behavior of the curve. */ - inline void SetPostInfinity(FUDaeInfinity::Infinity infinity) { postInfinity = infinity; SetDirtyFlag(); } - - /** Evaluates the animation curve. - @param input An input value. - @param output An array of floating-point values to fill in with the sampled values. */ - void Evaluate(float input, float* output) const; - - /** [INTERNAL] Retrieves the target element suffix for the curve. - This will be -1 if the animated element does not belong to an - animated element list. - @return The target element suffix. */ - inline int32 GetTargetElement() const { return targetElement; } - - /** [INTERNAL] Sets the target element suffix for the curve. - @param e The target element suffix. Set to value to -1 - if the animated element does not belong to an animated element list. */ - inline void SetTargetElement(int32 e) { targetElement = e; SetDirtyFlag(); } - inline int32 GetTargetElement() { return targetElement; } - - /** [INTERNAL] Sets the target qualifier for the merged curve. - Target qualifiers are transient information useful when exporting animation curves. - @param index The dimension index of the target qualifier to modify. - @param qualifier The new target qualifier. */ - //inline void SetTargetQualifier(size_t index, const fm::string& qualifier) { FUAssert(index < dimension, return); targetQualifiers[index] = qualifier; } - //inline fm::string& GetTargetQualifier(size_t index) { FUAssert(index < dimension,); return targetQualifiers[index]; } - - /** Turns on or off the 2D Curve Evaluation. - @param flag An on or off boolean flag.*/ - inline void Set2DCurveEvaluation(bool flag) { is2DEvaluation = flag; } - - /** Returns whether 2D Curve Evaluation is on or off. - @return A boolean that indicates if the 2D Curve Evaluation is on or off. */ - inline bool Is2DCurveEvaluation() {return is2DEvaluation; } -}; - -#endif // _FCD_ANIMATION_MULTI_CURVE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDAnimationMultiCurve.h + This file contains the FCDAnimationMultiCurve class. +*/ + +#ifndef _FCD_ANIMATION_MULTI_CURVE_H_ +#define _FCD_ANIMATION_MULTI_CURVE_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ + +class FCDocument; +class FCDAnimationMKey; + +typedef fm::pvector FCDAnimationMKeyList; /**< A dynamically-sized array of multi-dimensional animation keys. */ + +/** + A COLLADA multi-dimensional animation curve. + + This is a utility class that is used to convert multiple + animation curves into one animation curve that has multiple + dimensions, but only one list of key inputs. + + FCollada will never create a multi-dimensional animation curve + during the import of a COLLADA document. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDAnimationMultiCurve : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + // The number of merged curves + uint32 dimension; + + // Target information + int32 targetElement; + + // Input information + FCDAnimationMKeyList keys; + FUDaeInfinity::Infinity preInfinity, postInfinity; + + //What sort of evaluation we do, 1D or 2D + static bool is2DEvaluation; + +public: + /** Constructor. + The number of dimensions will not change in the lifetime of a + multi-dimensional curve. + @param document The COLLADA document that owns the animation curve. + @param dimension The number of dimensions for the animation curve. */ + FCDAnimationMultiCurve(FCDocument* document, uint32 dimension); + + /** Destructor. */ + virtual ~FCDAnimationMultiCurve(); + + /** Retrieves the number of dimensions for the curve. + @return The number of dimensions for the curve. */ + inline uint32 GetDimension() const { return dimension; } + + /** Retrieves the list of key inputs for the animation curve. + @return The list of key inputs. */ + inline FCDAnimationMKey** GetKeys() { return keys.begin(); } + inline const FCDAnimationMKey** GetKeys() const { return keys.begin(); } /**< See above. */ + + /** Retrieves the number of keys within the animation curve. + @return The number of keys. */ + inline size_t GetKeyCount() const { return keys.size(); } + + /** Sets the number of keys within the animation curve. + @param count The new number of keys in the curve. + @param interpolation If creating new keys, the interpolation type + for the new keys. */ + void SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation); + + /** Retrieve one key of the animation curve. + @param index The index of the key to retrieve. + @return The indexed key. */ + inline FCDAnimationMKey* GetKey(size_t index) { FUAssert(index < keys.size(), return NULL); return keys.at(index); } + inline const FCDAnimationMKey* GetKey(size_t index) const { FUAssert(index < keys.size(), return NULL); return keys.at(index); } /**< See above. */ + + /** Appends a key to the animation curve. + @param interpolation The interpolation type for the new key. + @return The new key. */ + FCDAnimationMKey* AddKey(FUDaeInterpolation::Interpolation interpolation); + + /** Retrieves the type of behavior for the curve if the input value is + outside the input interval defined by the curve keys and less than any key input value. + @see FUDaeInfinity + @return The pre-infinity behavior of the curve. */ + inline FUDaeInfinity::Infinity GetPreInfinity() const { return preInfinity; } + + /** Sets the behavior of the curve if the input value is + outside the input interval defined by the curve keys and less than any key input value. + @see FUDaeInfinity + @param infinity The pre-infinity behavior of the curve. */ + inline void SetPreInfinity(FUDaeInfinity::Infinity infinity) { preInfinity = infinity; SetDirtyFlag(); } + + /** Retrieves the type of behavior for the curve if the input value is + outside the input interval defined by the curve keys and greater than any key input value. + @see FUDaeInfinity + @return The post-infinity behavior of the curve. */ + inline FUDaeInfinity::Infinity GetPostInfinity() const { return postInfinity; } + + /** Sets the behavior of the curve if the input value is + outside the input interval defined by the curve keys and greater than any key input value. + @see FUDaeInfinity + @param infinity The post-infinity behavior of the curve. */ + inline void SetPostInfinity(FUDaeInfinity::Infinity infinity) { postInfinity = infinity; SetDirtyFlag(); } + + /** Evaluates the animation curve. + @param input An input value. + @param output An array of floating-point values to fill in with the sampled values. */ + void Evaluate(float input, float* output) const; + + /** [INTERNAL] Retrieves the target element suffix for the curve. + This will be -1 if the animated element does not belong to an + animated element list. + @return The target element suffix. */ + inline int32 GetTargetElement() const { return targetElement; } + + /** [INTERNAL] Sets the target element suffix for the curve. + @param e The target element suffix. Set to value to -1 + if the animated element does not belong to an animated element list. */ + inline void SetTargetElement(int32 e) { targetElement = e; SetDirtyFlag(); } + inline int32 GetTargetElement() { return targetElement; } + + /** [INTERNAL] Sets the target qualifier for the merged curve. + Target qualifiers are transient information useful when exporting animation curves. + @param index The dimension index of the target qualifier to modify. + @param qualifier The new target qualifier. */ + //inline void SetTargetQualifier(size_t index, const fm::string& qualifier) { FUAssert(index < dimension, return); targetQualifiers[index] = qualifier; } + //inline fm::string& GetTargetQualifier(size_t index) { FUAssert(index < dimension,); return targetQualifiers[index]; } + + /** Turns on or off the 2D Curve Evaluation. + @param flag An on or off boolean flag.*/ + inline void Set2DCurveEvaluation(bool flag) { is2DEvaluation = flag; } + + /** Returns whether 2D Curve Evaluation is on or off. + @return A boolean that indicates if the 2D Curve Evaluation is on or off. */ + inline bool Is2DCurveEvaluation() {return is2DEvaluation; } +}; + +#endif // _FCD_ANIMATION_MULTI_CURVE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAnimationMultiCurve.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAsset.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAsset.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAsset.cpp (revision 24247) @@ -1,115 +1,115 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAsset.h" -#include "FUtils/FUDateTime.h" -#include "FUtils/FUFileManager.h" - -// -// FCDAsset -// - -ImplementObjectType(FCDAsset); -ImplementParameterObject(FCDAsset, FCDAssetContributor, contributors, new FCDAssetContributor(parent->GetDocument())); - -FCDAsset::FCDAsset(FCDocument* document) -: FCDObject(document) -, InitializeParameterNoArg(contributors) -, InitializeParameterNoArg(keywords) -, InitializeParameterNoArg(revision) -, InitializeParameterNoArg(subject) -, InitializeParameterNoArg(title) -, upAxis(FMVector3::YAxis) -, unitName(FC("meter")), unitConversionFactor(1.0f) -{ - creationDateTime = modifiedDateTime = FUDateTime::GetNow(); - ResetHasUnitsFlag(); - ResetHasUpAxisFlag(); -} - -FCDAsset::~FCDAsset() -{ -} - -FCDAssetContributor* FCDAsset::AddContributor() -{ - FCDAssetContributor* contributor = new FCDAssetContributor(GetDocument()); - contributors.push_back(contributor); - return contributor; -} - -// Clone another asset element. -FCDAsset* FCDAsset::Clone(FCDAsset* clone, bool cloneAllContributors) const -{ - if (clone == NULL) clone = new FCDAsset(const_cast(GetDocument())); - - // Clone all the asset-level parameters. - clone->creationDateTime = creationDateTime; - clone->modifiedDateTime = FUDateTime::GetNow(); - clone->keywords = keywords; - clone->revision = revision; - clone->subject = subject; - clone->title = title; - clone->upAxis = upAxis; - clone->unitName = unitName; - clone->unitConversionFactor = unitConversionFactor; - clone->SetFlag(TestFlag(FLAG_HasUnits | FLAG_HasUpAxis)); - - if (cloneAllContributors) - { - // Clone all the contributors - for (const FCDAssetContributor** it = contributors.begin(); it != contributors.end(); ++it) - { - FCDAssetContributor* clonedContributor = clone->AddContributor(); - (*it)->Clone(clonedContributor); - } - } - - return clone; -} - -// -// FCDAssetContributor -// - -ImplementObjectType(FCDAssetContributor); - -FCDAssetContributor::FCDAssetContributor(FCDocument* document) -: FCDObject(document) -, InitializeParameterNoArg(author) -, InitializeParameterNoArg(authoringTool) -, InitializeParameterNoArg(comments) -, InitializeParameterNoArg(copyright) -, InitializeParameterNoArg(sourceData) -{ -} - -FCDAssetContributor::~FCDAssetContributor() -{ -} - -FCDAssetContributor* FCDAssetContributor::Clone(FCDAssetContributor* clone) const -{ - if (clone == NULL) clone = new FCDAssetContributor(const_cast(GetDocument())); - - clone->author = author; - clone->authoringTool = authoringTool; - clone->comments = comments; - clone->copyright = copyright; - clone->sourceData = sourceData; - - return clone; -} - -// Returns whether this contributor element contain any valid data -bool FCDAssetContributor::IsEmpty() const -{ - return author->empty() && authoringTool->empty() && comments->empty() && copyright->empty() && sourceData->empty(); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAsset.h" +#include "FUtils/FUDateTime.h" +#include "FUtils/FUFileManager.h" + +// +// FCDAsset +// + +ImplementObjectType(FCDAsset); +ImplementParameterObject(FCDAsset, FCDAssetContributor, contributors, new FCDAssetContributor(parent->GetDocument())); + +FCDAsset::FCDAsset(FCDocument* document) +: FCDObject(document) +, InitializeParameterNoArg(contributors) +, InitializeParameterNoArg(keywords) +, InitializeParameterNoArg(revision) +, InitializeParameterNoArg(subject) +, InitializeParameterNoArg(title) +, upAxis(FMVector3::YAxis) +, unitName(FC("meter")), unitConversionFactor(1.0f) +{ + creationDateTime = modifiedDateTime = FUDateTime::GetNow(); + ResetHasUnitsFlag(); + ResetHasUpAxisFlag(); +} + +FCDAsset::~FCDAsset() +{ +} + +FCDAssetContributor* FCDAsset::AddContributor() +{ + FCDAssetContributor* contributor = new FCDAssetContributor(GetDocument()); + contributors.push_back(contributor); + return contributor; +} + +// Clone another asset element. +FCDAsset* FCDAsset::Clone(FCDAsset* clone, bool cloneAllContributors) const +{ + if (clone == NULL) clone = new FCDAsset(const_cast(GetDocument())); + + // Clone all the asset-level parameters. + clone->creationDateTime = creationDateTime; + clone->modifiedDateTime = FUDateTime::GetNow(); + clone->keywords = keywords; + clone->revision = revision; + clone->subject = subject; + clone->title = title; + clone->upAxis = upAxis; + clone->unitName = unitName; + clone->unitConversionFactor = unitConversionFactor; + clone->SetFlag(TestFlag(FLAG_HasUnits | FLAG_HasUpAxis)); + + if (cloneAllContributors) + { + // Clone all the contributors + for (const FCDAssetContributor** it = contributors.begin(); it != contributors.end(); ++it) + { + FCDAssetContributor* clonedContributor = clone->AddContributor(); + (*it)->Clone(clonedContributor); + } + } + + return clone; +} + +// +// FCDAssetContributor +// + +ImplementObjectType(FCDAssetContributor); + +FCDAssetContributor::FCDAssetContributor(FCDocument* document) +: FCDObject(document) +, InitializeParameterNoArg(author) +, InitializeParameterNoArg(authoringTool) +, InitializeParameterNoArg(comments) +, InitializeParameterNoArg(copyright) +, InitializeParameterNoArg(sourceData) +{ +} + +FCDAssetContributor::~FCDAssetContributor() +{ +} + +FCDAssetContributor* FCDAssetContributor::Clone(FCDAssetContributor* clone) const +{ + if (clone == NULL) clone = new FCDAssetContributor(const_cast(GetDocument())); + + clone->author = author; + clone->authoringTool = authoringTool; + clone->comments = comments; + clone->copyright = copyright; + clone->sourceData = sourceData; + + return clone; +} + +// Returns whether this contributor element contain any valid data +bool FCDAssetContributor::IsEmpty() const +{ + return author->empty() && authoringTool->empty() && comments->empty() && copyright->empty() && sourceData->empty(); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAsset.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAsset.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAsset.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAsset.h (revision 24247) @@ -1,328 +1,328 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/** - @file FCDAsset.h - This file contains the FCDAsset and FCDAssetContributor classes. -*/ - -#ifndef _FCD_ASSET_H_ -#define _FCD_ASSET_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_DATETIME_H_ -#include "FUtils/FUDateTime.h" -#endif // _FU_DATETIME_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -class FCDAssetContributor; - -/** - A COLLADA asset declaration structure. - - In COLLADA, there are three types of assets. - FCollada recognizes two. - - 1) The COLLADA document is the most important asset and an - asset declaration structure is always created for it. - 2) The FCDEntity objects may also contain assets structures. - 3) COLLADA also allows asset structure on entity libraries, - but FCollada does not support them. - - Every asset contains its own list of contributors. - Every COLLADA application and conditioner that modifies an asset - should attach its signature, in the form of a contributor, - to the asset. - @see FCDAssetContributor - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDAsset : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - DeclareParameterContainer(FCDAssetContributor, contributors, FC("Contributors")); - FUDateTime creationDateTime; - FUDateTime modifiedDateTime; - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, keywords, FC("Keywords")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, revision, FC("Revision")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, subject, FC("Subject")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, title, FC("Title")); - FMVector3 upAxis; - - // information - fstring unitName; - float unitConversionFactor; - -public: - /** Whether an up-axis is set for this asset. - If no up-axis is set for this asset, you should - use the up-axis of the parent's asset. */ - DeclareFlag(HasUpAxis, 0); - - /** Whether a length unit is set for this asset. - If no length unit is set for this asset, you should - use the length unit of the parent's asset. */ - DeclareFlag(HasUnits, 1); - - /** FCDAsset declares two flags. */ - DeclareFlagCount(2); - -public: - /** Constructor. - @param document The COLLADA document that owns the asset. */ - FCDAsset(FCDocument* document); - - /** Destructor. */ - virtual ~FCDAsset(); - - /** Retrieves the list of contributors to this asset. - @return The list of contributors. */ - inline const FCDAssetContributor** GetContributors() const { return contributors.begin(); } /**< See above. */ - - /** Retrieves the number of contributors to this asset. - @return The number of contributors. */ - inline size_t GetContributorCount() const { return contributors.size(); } - - /** Retrieves a contributor tied to this asset. - @param index The index of the contributor. - @return The contributor at the given index. */ - inline FCDAssetContributor* GetContributor(size_t index) { FUAssert(index < GetContributorCount(), return NULL); return contributors.at(index); } - inline const FCDAssetContributor* GetContributor(size_t index) const { FUAssert(index < GetContributorCount(), return NULL); return contributors.at(index); } /**< See above. */ - - /** Inserts a new contributor to this asset. - @return An empty contributor structure. */ - FCDAssetContributor* AddContributor(); - - /** Retrieves the creation date-time of the document. - This date-time is not modifiable. It is set automatically - when FCollada creates the document or imported when FCollada - reads in a COLLADA document. - @return The date-time at which the COLLADA document - was originally created. */ - inline const FUDateTime& GetCreationDateTime() const { return creationDateTime; } - - /** [INTERNAL] Use this function to createDateTime when you are writing an import plug-in. - see above */ - inline FUDateTime& GetCreationDateTime() { return creationDateTime; } - - /** Retrieves the last modification date-time of the document. - This date-time is not modifiable. It is set automatically - when FCollada writes out a COLLADA document to a file, when - FCollada creates an original document and when FCollada reads in - a COLLADA document from a file. - @return The date-time at which the COLLADA document - was last modified. */ - inline const FUDateTime& GetModifiedDateTime() const { return modifiedDateTime; } - - /** [INTERNAL] Use this function to retieve the modifiedDateTime when you are writing an - import plug-in. - see above */ - inline FUDateTime& GetModifiedDateTime() { return modifiedDateTime; } - - /** Retrieves the list of keywords identifying this asset. - @return The list of keywords for the asset. */ - inline const fstring& GetKeywords() const { return keywords; } - - /** Sets the list of keywords for this asset. - @param _keywords The list of keywords for the asset. */ - inline void SetKeywords(const fstring& _keywords) { keywords = _keywords; SetDirtyFlag(); } - - /** Retrieves the revision string for this asset. - COLLADA doesn't define a standard for the revisions of assets. - @return The revision string for the asset. */ - inline const fstring& GetRevision() const { return revision; } - - /** Sets the revision string for this asset. - COLLADA doesn't define a standard for the revisions of assets. - @param _revision The revision string for the asset. */ - inline void SetRevision(const fstring& _revision) { revision = _revision; SetDirtyFlag(); } - - /** Retrieves the subject of the asset. - @return The subject of the asset. */ - inline const fstring& GetSubject() const { return subject; } - - /** Sets the subject of the asset. - @param _subject The subject of the asset. */ - inline void SetSubject(const fstring& _subject) { subject = _subject; SetDirtyFlag(); } - - /** Retrieves the title of the asset. - @return The title of the asset. */ - inline const fstring& GetTitle() const { return title; } - - /** Sets the title of the asset. - @param _title The title of the asset. */ - inline void SetTitle(const fstring& _title) { title = _title; SetDirtyFlag(); } - - /** Retrieves the up-axis of the asset. - The up-axis of two entities within the same document may differ. - To avoid issues with up-axis differences, it is suggested that you use - the FCDocumentTools::StandardizeUpAxisAndLength function. - @return The up-axis of the asset. */ - inline const FMVector3& GetUpAxis() const { return upAxis; } - - /** Sets the up-axis of the asset. - Changing the up-axis of an asset does not modify its data. - @param _upAxis The up-axis of the asset. */ - inline void SetUpAxis(const FMVector3& _upAxis) { upAxis = _upAxis; SetHasUpAxisFlag(); SetDirtyFlag(); } - - /** Retrieves the name of the length unit for the asset. - @return The name of the length unit for the asset. */ - inline const fstring& GetUnitName() const { return unitName; } - - /** Sets the name of the length unit for the asset. - @param _unitName The name of the length unit for the asset. */ - inline void SetUnitName(const fstring& _unitName) { unitName = _unitName; SetDirtyFlag(); } - - /** Retrieves the length unit conversion factor, in meters, for the asset. - The length unit of two entities within the same document may differ. - To avoid issues with length unit differences, it is suggested that you use - the FCDocumentTools::StandardizeUpAxisAndLength function. - @return The length unit conversion factor. */ - inline float GetUnitConversionFactor() const { return unitConversionFactor; } - - /** Sets the length unit conversion factor for the asset. - Changing the length unit conversion factor of an asset - does not modify its data. - @param factor The new length unit conversion factor. */ - inline void SetUnitConversionFactor(float factor) { unitConversionFactor = factor; SetHasUnitsFlag(); SetDirtyFlag(); } - - /** Retrieves whether an up-axis is set for this asset. - If no up-axis is set for this asset, you should - use the up-axis of the parent's asset. - @return Whether this asset defines an up-axis. */ - DEPRECATED(3.05A, GetHasUpAxisFlag) inline bool HasUpAxis() const { return GetHasUpAxisFlag(); } - - /** Retrieves whether a length unit is set for this asset. - If no length unit is set for this asset, you should - use the length unit of the parent's asset. - @return Whether this asset defines a length unit. */ - DEPRECATED(3.05A, GetHasUnitsFlag) inline bool HasUnits() const { return GetHasUnitsFlag(); } - - /** Resets the up-axis of the asset. - The parent asset up-axis should henceforth be used. - Changing the up-axis of an asset does not modify its data. */ - DEPRECATED(3.05A, ResetHasUpAxisFlag) inline void ResetUpAxis() { ResetHasUpAxisFlag(); } - - /** Resets the length unit of the asset. - The parent asset length unit should henceforth be used. - Changing the length unit of an asset does not modify its data. */ - DEPRECATED(3.05A, ResetHasUnitsFlag) inline void ResetUnits() { ResetHasUnitsFlag(); } - - /** Clones the asset structure into another asset structure. - @param clone The asset structure that will become the copy of this asset. - When this pointer is NULL, a new asset structure will be created. - @param cloneAllContributors Whether all the contributors of this asset - should be copied into the clone. - @return The clone. */ - FCDAsset* Clone(FCDAsset* clone = NULL, bool cloneAllContributors = true) const; - - -}; - -/** - A COLLADA asset contributor. - - The asset contributor represent each step that the COLLADA document - has taken, in terms of applications and conditioners, in order - to get to its current state. - - Every COLLADA application and conditioner that modifies an asset - should therefore attach its signature, in the form of a contributor, - to the asset. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDAssetContributor : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, author, FC("Author")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, authoringTool, FC("Authoring Tool")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, comments, FC("Comments")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, copyright, FC("Copyright")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, sourceData, FC("Source Data")); - -public: - /** Constructor. - @param document The COLLADA document that owns the contributor. */ - FCDAssetContributor(FCDocument* document); - - /** Destructor. */ - virtual ~FCDAssetContributor(); - - /** Retrieves the name of the user that applied this contributor. - @return The name of the user. */ - inline const fstring& GetAuthor() const { return author; } - - /** Sets the name of the user that applies the current contributor. - It is suggested to use the following code snippet: - const char* userName = getenv("USER"); - if (userName == NULL) userName = getenv("USERNAME"); - if (userName != NULL) contributor->SetAuthor(TO_FSTRING(userName)); - @param _author The name of the user. */ - inline void SetAuthor(const fstring& _author) { author = _author; SetDirtyFlag(); } - - /** Retrieves the name of the contributor. - @return The name of the contributor. */ - inline const fstring& GetAuthoringTool() const { return authoringTool; } - - /** Sets the name of the current contributor. - It is suggested that the version number of the contributor - be included. - @param _authoringTool The name of the contributor. */ - inline void SetAuthoringTool(const fstring& _authoringTool) { authoringTool = _authoringTool; SetDirtyFlag(); } - - /** Retrieves the contributor's comment about the asset. - @return The contributor comments. */ - inline const fstring& GetComments() const { return comments; } - - /** Sets the contributor's comment about the asset. - For document-level assets, it is suggested, for debugging - purposes, to write down all the user-selected export options - instead of actual user text input. - @param _comments The contributor's comment. */ - inline void SetComments(const fstring& _comments) { comments = _comments; SetDirtyFlag(); } - - /** Retrieves the copyright information for the asset. - @return The user copyright information for the asset. */ - inline const fstring& GetCopyright() const { return copyright; } - - /** Sets the copyright information for the asset. - @param _copyright The user copyright information for the asset. */ - inline void SetCopyright(const fstring& _copyright) { copyright = _copyright; SetDirtyFlag(); } - - /** Retrieves the URI of the source data used by the contributor - to generate the COLLADA asset. - @return The URI of the source data. */ - inline const fstring& GetSourceData() const { return sourceData; } - - /** Sets the URI of the source data used by the contributor - to generate the COLLADA asset. - @param _sourceData The URI of the source data. */ - inline void SetSourceData(const fstring& _sourceData) { sourceData = _sourceData; SetDirtyFlag(); } - - /** Retrieves whether this contributor structure has any useful - information. - @return The validity of the contributor structure. */ - bool IsEmpty() const; - - /** Clones a contributor structure. - @param clone The contributor structure that will become the copy - of this contributor structure. When this pointer is NULL, - a new contributor structure is created. - @return The clone. */ - FCDAssetContributor* Clone(FCDAssetContributor* clone = NULL) const; -}; - -#endif // _FCD_ASSET_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/** + @file FCDAsset.h + This file contains the FCDAsset and FCDAssetContributor classes. +*/ + +#ifndef _FCD_ASSET_H_ +#define _FCD_ASSET_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_DATETIME_H_ +#include "FUtils/FUDateTime.h" +#endif // _FU_DATETIME_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +class FCDAssetContributor; + +/** + A COLLADA asset declaration structure. + + In COLLADA, there are three types of assets. + FCollada recognizes two. + + 1) The COLLADA document is the most important asset and an + asset declaration structure is always created for it. + 2) The FCDEntity objects may also contain assets structures. + 3) COLLADA also allows asset structure on entity libraries, + but FCollada does not support them. + + Every asset contains its own list of contributors. + Every COLLADA application and conditioner that modifies an asset + should attach its signature, in the form of a contributor, + to the asset. + @see FCDAssetContributor + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDAsset : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + DeclareParameterContainer(FCDAssetContributor, contributors, FC("Contributors")); + FUDateTime creationDateTime; + FUDateTime modifiedDateTime; + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, keywords, FC("Keywords")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, revision, FC("Revision")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, subject, FC("Subject")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, title, FC("Title")); + FMVector3 upAxis; + + // information + fstring unitName; + float unitConversionFactor; + +public: + /** Whether an up-axis is set for this asset. + If no up-axis is set for this asset, you should + use the up-axis of the parent's asset. */ + DeclareFlag(HasUpAxis, 0); + + /** Whether a length unit is set for this asset. + If no length unit is set for this asset, you should + use the length unit of the parent's asset. */ + DeclareFlag(HasUnits, 1); + + /** FCDAsset declares two flags. */ + DeclareFlagCount(2); + +public: + /** Constructor. + @param document The COLLADA document that owns the asset. */ + FCDAsset(FCDocument* document); + + /** Destructor. */ + virtual ~FCDAsset(); + + /** Retrieves the list of contributors to this asset. + @return The list of contributors. */ + inline const FCDAssetContributor** GetContributors() const { return contributors.begin(); } /**< See above. */ + + /** Retrieves the number of contributors to this asset. + @return The number of contributors. */ + inline size_t GetContributorCount() const { return contributors.size(); } + + /** Retrieves a contributor tied to this asset. + @param index The index of the contributor. + @return The contributor at the given index. */ + inline FCDAssetContributor* GetContributor(size_t index) { FUAssert(index < GetContributorCount(), return NULL); return contributors.at(index); } + inline const FCDAssetContributor* GetContributor(size_t index) const { FUAssert(index < GetContributorCount(), return NULL); return contributors.at(index); } /**< See above. */ + + /** Inserts a new contributor to this asset. + @return An empty contributor structure. */ + FCDAssetContributor* AddContributor(); + + /** Retrieves the creation date-time of the document. + This date-time is not modifiable. It is set automatically + when FCollada creates the document or imported when FCollada + reads in a COLLADA document. + @return The date-time at which the COLLADA document + was originally created. */ + inline const FUDateTime& GetCreationDateTime() const { return creationDateTime; } + + /** [INTERNAL] Use this function to createDateTime when you are writing an import plug-in. + see above */ + inline FUDateTime& GetCreationDateTime() { return creationDateTime; } + + /** Retrieves the last modification date-time of the document. + This date-time is not modifiable. It is set automatically + when FCollada writes out a COLLADA document to a file, when + FCollada creates an original document and when FCollada reads in + a COLLADA document from a file. + @return The date-time at which the COLLADA document + was last modified. */ + inline const FUDateTime& GetModifiedDateTime() const { return modifiedDateTime; } + + /** [INTERNAL] Use this function to retieve the modifiedDateTime when you are writing an + import plug-in. + see above */ + inline FUDateTime& GetModifiedDateTime() { return modifiedDateTime; } + + /** Retrieves the list of keywords identifying this asset. + @return The list of keywords for the asset. */ + inline const fstring& GetKeywords() const { return keywords; } + + /** Sets the list of keywords for this asset. + @param _keywords The list of keywords for the asset. */ + inline void SetKeywords(const fstring& _keywords) { keywords = _keywords; SetDirtyFlag(); } + + /** Retrieves the revision string for this asset. + COLLADA doesn't define a standard for the revisions of assets. + @return The revision string for the asset. */ + inline const fstring& GetRevision() const { return revision; } + + /** Sets the revision string for this asset. + COLLADA doesn't define a standard for the revisions of assets. + @param _revision The revision string for the asset. */ + inline void SetRevision(const fstring& _revision) { revision = _revision; SetDirtyFlag(); } + + /** Retrieves the subject of the asset. + @return The subject of the asset. */ + inline const fstring& GetSubject() const { return subject; } + + /** Sets the subject of the asset. + @param _subject The subject of the asset. */ + inline void SetSubject(const fstring& _subject) { subject = _subject; SetDirtyFlag(); } + + /** Retrieves the title of the asset. + @return The title of the asset. */ + inline const fstring& GetTitle() const { return title; } + + /** Sets the title of the asset. + @param _title The title of the asset. */ + inline void SetTitle(const fstring& _title) { title = _title; SetDirtyFlag(); } + + /** Retrieves the up-axis of the asset. + The up-axis of two entities within the same document may differ. + To avoid issues with up-axis differences, it is suggested that you use + the FCDocumentTools::StandardizeUpAxisAndLength function. + @return The up-axis of the asset. */ + inline const FMVector3& GetUpAxis() const { return upAxis; } + + /** Sets the up-axis of the asset. + Changing the up-axis of an asset does not modify its data. + @param _upAxis The up-axis of the asset. */ + inline void SetUpAxis(const FMVector3& _upAxis) { upAxis = _upAxis; SetHasUpAxisFlag(); SetDirtyFlag(); } + + /** Retrieves the name of the length unit for the asset. + @return The name of the length unit for the asset. */ + inline const fstring& GetUnitName() const { return unitName; } + + /** Sets the name of the length unit for the asset. + @param _unitName The name of the length unit for the asset. */ + inline void SetUnitName(const fstring& _unitName) { unitName = _unitName; SetDirtyFlag(); } + + /** Retrieves the length unit conversion factor, in meters, for the asset. + The length unit of two entities within the same document may differ. + To avoid issues with length unit differences, it is suggested that you use + the FCDocumentTools::StandardizeUpAxisAndLength function. + @return The length unit conversion factor. */ + inline float GetUnitConversionFactor() const { return unitConversionFactor; } + + /** Sets the length unit conversion factor for the asset. + Changing the length unit conversion factor of an asset + does not modify its data. + @param factor The new length unit conversion factor. */ + inline void SetUnitConversionFactor(float factor) { unitConversionFactor = factor; SetHasUnitsFlag(); SetDirtyFlag(); } + + /** Retrieves whether an up-axis is set for this asset. + If no up-axis is set for this asset, you should + use the up-axis of the parent's asset. + @return Whether this asset defines an up-axis. */ + DEPRECATED(3.05A, GetHasUpAxisFlag) inline bool HasUpAxis() const { return GetHasUpAxisFlag(); } + + /** Retrieves whether a length unit is set for this asset. + If no length unit is set for this asset, you should + use the length unit of the parent's asset. + @return Whether this asset defines a length unit. */ + DEPRECATED(3.05A, GetHasUnitsFlag) inline bool HasUnits() const { return GetHasUnitsFlag(); } + + /** Resets the up-axis of the asset. + The parent asset up-axis should henceforth be used. + Changing the up-axis of an asset does not modify its data. */ + DEPRECATED(3.05A, ResetHasUpAxisFlag) inline void ResetUpAxis() { ResetHasUpAxisFlag(); } + + /** Resets the length unit of the asset. + The parent asset length unit should henceforth be used. + Changing the length unit of an asset does not modify its data. */ + DEPRECATED(3.05A, ResetHasUnitsFlag) inline void ResetUnits() { ResetHasUnitsFlag(); } + + /** Clones the asset structure into another asset structure. + @param clone The asset structure that will become the copy of this asset. + When this pointer is NULL, a new asset structure will be created. + @param cloneAllContributors Whether all the contributors of this asset + should be copied into the clone. + @return The clone. */ + FCDAsset* Clone(FCDAsset* clone = NULL, bool cloneAllContributors = true) const; + + +}; + +/** + A COLLADA asset contributor. + + The asset contributor represent each step that the COLLADA document + has taken, in terms of applications and conditioners, in order + to get to its current state. + + Every COLLADA application and conditioner that modifies an asset + should therefore attach its signature, in the form of a contributor, + to the asset. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDAssetContributor : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, author, FC("Author")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, authoringTool, FC("Authoring Tool")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, comments, FC("Comments")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, copyright, FC("Copyright")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, sourceData, FC("Source Data")); + +public: + /** Constructor. + @param document The COLLADA document that owns the contributor. */ + FCDAssetContributor(FCDocument* document); + + /** Destructor. */ + virtual ~FCDAssetContributor(); + + /** Retrieves the name of the user that applied this contributor. + @return The name of the user. */ + inline const fstring& GetAuthor() const { return author; } + + /** Sets the name of the user that applies the current contributor. + It is suggested to use the following code snippet: + const char* userName = getenv("USER"); + if (userName == NULL) userName = getenv("USERNAME"); + if (userName != NULL) contributor->SetAuthor(TO_FSTRING(userName)); + @param _author The name of the user. */ + inline void SetAuthor(const fstring& _author) { author = _author; SetDirtyFlag(); } + + /** Retrieves the name of the contributor. + @return The name of the contributor. */ + inline const fstring& GetAuthoringTool() const { return authoringTool; } + + /** Sets the name of the current contributor. + It is suggested that the version number of the contributor + be included. + @param _authoringTool The name of the contributor. */ + inline void SetAuthoringTool(const fstring& _authoringTool) { authoringTool = _authoringTool; SetDirtyFlag(); } + + /** Retrieves the contributor's comment about the asset. + @return The contributor comments. */ + inline const fstring& GetComments() const { return comments; } + + /** Sets the contributor's comment about the asset. + For document-level assets, it is suggested, for debugging + purposes, to write down all the user-selected export options + instead of actual user text input. + @param _comments The contributor's comment. */ + inline void SetComments(const fstring& _comments) { comments = _comments; SetDirtyFlag(); } + + /** Retrieves the copyright information for the asset. + @return The user copyright information for the asset. */ + inline const fstring& GetCopyright() const { return copyright; } + + /** Sets the copyright information for the asset. + @param _copyright The user copyright information for the asset. */ + inline void SetCopyright(const fstring& _copyright) { copyright = _copyright; SetDirtyFlag(); } + + /** Retrieves the URI of the source data used by the contributor + to generate the COLLADA asset. + @return The URI of the source data. */ + inline const fstring& GetSourceData() const { return sourceData; } + + /** Sets the URI of the source data used by the contributor + to generate the COLLADA asset. + @param _sourceData The URI of the source data. */ + inline void SetSourceData(const fstring& _sourceData) { sourceData = _sourceData; SetDirtyFlag(); } + + /** Retrieves whether this contributor structure has any useful + information. + @return The validity of the contributor structure. */ + bool IsEmpty() const; + + /** Clones a contributor structure. + @param clone The contributor structure that will become the copy + of this contributor structure. When this pointer is NULL, + a new contributor structure is created. + @return The clone. */ + FCDAssetContributor* Clone(FCDAssetContributor* clone = NULL) const; +}; + +#endif // _FCD_ASSET_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDAsset.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDCamera.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDCamera.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDCamera.cpp (revision 24247) @@ -1,61 +1,61 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDCamera.h" - -// -// FCDCamera -// - -ImplementObjectType(FCDCamera); - -FCDCamera::FCDCamera(FCDocument* document) -: FCDTargetedEntity(document, "Camera") -, InitializeParameter(projection, PERSPECTIVE) -, InitializeParameterAnimatable(viewY, 60.0f) -, InitializeParameterAnimatable(viewX, 60.0f) -, InitializeParameterAnimatable(aspectRatio, 1.0f) -, InitializeParameterAnimatable(nearZ, 1.0f) -, InitializeParameterAnimatable(farZ, 1000.0f) -{ - ResetHasHorizontalViewFlag(); - ResetHasVerticalViewFlag(); -} - -FCDCamera::~FCDCamera() -{ -} - -void FCDCamera::SetFovX(float _viewX) -{ - viewX = _viewX; - if (GetHasVerticalViewFlag() && !IsEquivalent(viewX, 0.0f)) aspectRatio = viewX / viewY; - SetHasHorizontalViewFlag(); - SetDirtyFlag(); -} - -void FCDCamera::SetFovY(float _viewY) -{ - viewY = _viewY; - if (GetHasHorizontalViewFlag() && !IsEquivalent(viewX, 0.0f)) aspectRatio = viewX / viewY; - SetHasVerticalViewFlag(); - SetDirtyFlag(); -} - -void FCDCamera::SetAspectRatio(float _aspectRatio) -{ - aspectRatio = _aspectRatio; - SetDirtyFlag(); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDCamera.h" + +// +// FCDCamera +// + +ImplementObjectType(FCDCamera); + +FCDCamera::FCDCamera(FCDocument* document) +: FCDTargetedEntity(document, "Camera") +, InitializeParameter(projection, PERSPECTIVE) +, InitializeParameterAnimatable(viewY, 60.0f) +, InitializeParameterAnimatable(viewX, 60.0f) +, InitializeParameterAnimatable(aspectRatio, 1.0f) +, InitializeParameterAnimatable(nearZ, 1.0f) +, InitializeParameterAnimatable(farZ, 1000.0f) +{ + ResetHasHorizontalViewFlag(); + ResetHasVerticalViewFlag(); +} + +FCDCamera::~FCDCamera() +{ +} + +void FCDCamera::SetFovX(float _viewX) +{ + viewX = _viewX; + if (GetHasVerticalViewFlag() && !IsEquivalent(viewX, 0.0f)) aspectRatio = viewX / viewY; + SetHasHorizontalViewFlag(); + SetDirtyFlag(); +} + +void FCDCamera::SetFovY(float _viewY) +{ + viewY = _viewY; + if (GetHasHorizontalViewFlag() && !IsEquivalent(viewX, 0.0f)) aspectRatio = viewX / viewY; + SetHasVerticalViewFlag(); + SetDirtyFlag(); +} + +void FCDCamera::SetAspectRatio(float _aspectRatio) +{ + aspectRatio = _aspectRatio; + SetDirtyFlag(); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDCamera.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDCamera.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDCamera.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDCamera.h (revision 24247) @@ -1,232 +1,232 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDCamera.h - This file contains the FCDCamera class. -*/ - -#ifndef _FCD_CAMERA_H_ -#define _FCD_CAMERA_H_ - -#ifndef _FCD_TARGETED_ENTITY_H_ -#include "FCDocument/FCDTargetedEntity.h" -#endif // _FCD_TARGETED_ENTITY_H_ -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -class FCDocument; -class FCDSceneNode; - -/** - A COLLADA camera. - Based on the FCDTargetedEntity class to support aimed cameras. - COLLADA defines two types of cameras: perspective and orthographic. - Both types are fully handled by this class. - - A COLLADA perspective camera defines two of the three following parameters: horizontal field of view, - vertical field of view and aspect ratio. The missing parameter can be calculated using the following formulae: - aspect ratio = vertical field of view / horizontal field of view. The vertical and horizontal field - of view are in degrees. - - A COLLADA orthographic camera defines two of the three following parameters: horizontal magnification, - vertical magnification and aspect ratio. The missing parameter can be calculated using the following formulae: - aspect ratio = vertical magnification / horizontal magnification. You can calculate the viewport width - and height using the following formulas: viewport width = horizontal magnification * 2, viewport height - = vertical magnification * 2. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDCamera : public FCDTargetedEntity -{ -public: - /** The types of projection supported. */ - enum ProjectionType - { - PERSPECTIVE, /**< A perspective projection. Uses a truncated rectangular pyramid frustrum. */ - ORTHOGRAPHIC /**< An orthographic projection. Uses a rectangular prism frustrum. */ - }; - -private: - DeclareObjectType(FCDTargetedEntity); - - // Camera flags - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, projection, FC("Projection Type")); // ProjectionType enumerated-type. - - // Camera parameters - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, viewY, FC("Vertical View")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, viewX, FC("Horizontal View")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, aspectRatio, FC("Aspect Ratio")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, nearZ, FC("Near-Z Plane Distance")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, farZ, FC("Far-Z Plane Distance")); - -public: - DeclareFlag(HasHorizontalView, 0); - DeclareFlag(HasVerticalView, 1); - DeclareFlagCount(2); - -public: - /** Constructor: do not use directly. Create new cameras using the FCDLibrary::AddEntity function. - @param document The COLLADA document that contains this camera entity.*/ - FCDCamera(FCDocument* document); - - /** Destructor. */ - virtual ~FCDCamera(); - - /** Retrieves the entity type for this class. This function is part of the FCDEntity interface. - @return The entity type: CAMERA. */ - virtual Type GetType() const { return CAMERA; } - - /** Retrieves the type of projection of this camera. - @return The projection type. */ - inline ProjectionType GetProjectionType() const { return (ProjectionType) *projection; } - - /** Sets the type of projections for this camera. - @param type The projection type for this camera. */ - inline void SetProjectionType(ProjectionType type) { projection = type; SetDirtyFlag(); } - - /** Retrieves whether this camera is a perspective camera. - This is the default type of camera. - @return Whether this camera is a perspective camera.*/ - DEPRECATED(3.05A, GetProjectionType() == FCDCamera::PERSPECTIVE) inline bool IsPerspective() const { return projection == PERSPECTIVE; } - - /** Sets the type of this camera to perspective. */ - DEPRECATED(3.05A, SetProjectionType(FCDCamera::PERSPECTIVE)) inline void SetPerspective() { projection = PERSPECTIVE; SetDirtyFlag(); } - - /** Retrieves whether the perspective camera defines an horizontal field of view. - If the camera does not define the horizontal field of view, you can calculate - it using the following formula: horizontal field of view = vertical field of view / aspect ratio. - @return Whether the perspective camera defines an horizontal field of view. */ - inline bool HasHorizontalFov() const { return GetHasHorizontalViewFlag(); } - - /** Retrieves whether the perspective camera defines a vertical field of view. - If the camera does not define the vertical field of view, you can calculate - it using the following formula: vertical field of view = aspect ratio * horizontal field of view. - @return Whether the perspective camera defines a vertical field of view. */ - inline bool HasVerticalFov() const { return GetHasVerticalViewFlag(); } - - /** Retrieves the horizontal field of view. Before retrieving this value, - check whether the camera defines the horizontal field of view using the - HasHorizontalFov function. - @return The horizontal field of view, in degrees. */ - inline FCDParameterAnimatableFloat& GetFovX() { return viewX; } - inline const FCDParameterAnimatableFloat& GetFovX() const { return viewX; } /**< See above. */ - - /** Retrieves the vertical field of view. Before retrieving this value, - check whether the camera defines the vertical field of view using the - HasVerticalFov function. - @return The horizontal field of view, in degrees. */ - inline FCDParameterAnimatableFloat& GetFovY() { return viewY; } - inline const FCDParameterAnimatableFloat& GetFovY() const { return viewY; } /**< See above. */ - - /** Sets the horizontal field of view value for this camera. - @param fovX The new horizontal field of view, in degrees. */ - void SetFovX(float fovX); - - /** Sets the vertical field of view value for this camera. - @param fovY The new vertical field of view, in degrees. */ - void SetFovY(float fovY); - - /** Retrieves whether this camera is an orthographic camera. - @return Whether this camera is an orthographic camera. */ - DEPRECATED(3.05A, GetProjectionType() == FCDCamera::ORTHOGRAPHIC) inline bool IsOrthographic() const { return projection == ORTHOGRAPHIC; } - - /** Sets the type of this camera to orthographic. */ - DEPRECATED(3.05A, SetProjectionType(FCDCamera::ORTHOGRAPHIC)) inline void SetOrthographic() { projection = ORTHOGRAPHIC; SetDirtyFlag(); } - - /** Retrieves whether the orthographic camera defines an horizontal magnification. - If the camera does not define the horizontal magnification, you can calculate - it using the following formula: horizontal magnification = vertical magnification / aspect ratio. - @return Whether the orthographic camera defines an horizontal magnification. */ - inline bool HasHorizontalMag() const { return GetHasHorizontalViewFlag(); } - - /** Retrieves whether the perspective camera defines a vertical magnification. - If the camera does not define the vertical magnification, you can calculate - it using the following formula: vertical magnification = aspect ratio * horizontal magnification. - @return Whether the perspective camera defines a vertical magnification. */ - inline bool HasVerticalMag() const { return GetHasVerticalViewFlag(); } - - /** Retrieves the horizontal magnification. Before retrieving this value, - check whether the camera defines the horizontal magnification using the - HasHorizontalMag function. - @return The horizontal magnification. */ - inline FCDParameterAnimatableFloat& GetMagX() { return viewX; } - inline const FCDParameterAnimatableFloat& GetMagX() const { return viewX; } /**< See above. */ - - /** Retrieves the vertical magnification. Before retrieving this value, - check whether the camera defines the vertical magnification using the - HasVerticalMag function. - @return The vertical magnification. */ - inline FCDParameterAnimatableFloat& GetMagY() { return viewY; } - inline const FCDParameterAnimatableFloat& GetMagY() const { return viewY; } /**< See above. */ - - /** Sets the horizontal magnification for this camera. - @param magX The new horizontal magnification, in degrees. */ - inline void SetMagX(float magX) { return SetFovX(magX); } - - /** Sets the vertical magnification value for this camera. - @param magY The new vertical magnification, in degrees. */ - inline void SetMagY(float magY) { return SetFovY(magY); } - - /** Retrieves the near-z value for this camera. - The near-z value represent how close the near-clip - plane of the view frustum is. For orthographic cameras, - this value is solely used for depth-buffering. - @return The near-z value for this camera. */ - inline FCDParameterAnimatableFloat& GetNearZ() { return nearZ; } - inline const FCDParameterAnimatableFloat& GetNearZ() const { return nearZ; } /**< See above. */ - - /** Retrieves the far-z value for this camera. The far-z value represent - how close the far-clip plane of the view frustum is. - For orthographic cameras, this value is solely used for depth-buffering. - @return The far-z value for this camera. */ - inline FCDParameterAnimatableFloat& GetFarZ() { return farZ; } - inline const FCDParameterAnimatableFloat& GetFarZ() const { return farZ; } /**< See above. */ - - /** Retrieves whether the camera defines an aspect ratio. - @return Whether the camera defines an aspect ratio. */ - inline bool HasAspectRatio() const { return !(GetHasVerticalViewFlag() && GetHasHorizontalViewFlag()); } - - /** Retrieves the aspect ratio for the view of this camera. Before using this value, - check if there are only one of the horizontal and vertical view ratios. - If there are both of the view ratios provided for the camera, you will - need to calculate the aspect ratio using the following formula: - aspect ratio = vertical field of view / horizontal field of view. - @return The view aspect ratio. */ - inline FCDParameterAnimatableFloat& GetAspectRatio() { return aspectRatio; } - inline const FCDParameterAnimatableFloat& GetAspectRatio() const { return aspectRatio; } /**< See above. */ - - /** Sets the near-z value for this camera. - The near-z value represent how close the near-clip - plane of the view frustum is. For orthographic cameras, - this value is solely used for depth-buffering. - @param _nearZ A valid near-z value. No check is made to verify that the - near-z value is greater than the far-z value.*/ - inline void SetNearZ(float _nearZ) { nearZ = _nearZ; SetDirtyFlag(); } - - /** Sets the far-z value for this camera. The far-z value represent - how close the far-clip plane of the view frustum is. - For orthographic cameras, this value is solely used for depth-buffering. - @param _farZ A valid far-z value. No check is made to verify that the - far-z value is greater than the near-z value.*/ - inline void SetFarZ(float _farZ) { farZ = _farZ; SetDirtyFlag(); } - - /** Sets the aspect ratio for the view of this camera. - @param aspectRatio The new view aspect ratio. */ - void SetAspectRatio(float aspectRatio); -}; - -#endif // _FCD_CAMERA_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDCamera.h + This file contains the FCDCamera class. +*/ + +#ifndef _FCD_CAMERA_H_ +#define _FCD_CAMERA_H_ + +#ifndef _FCD_TARGETED_ENTITY_H_ +#include "FCDocument/FCDTargetedEntity.h" +#endif // _FCD_TARGETED_ENTITY_H_ +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +class FCDocument; +class FCDSceneNode; + +/** + A COLLADA camera. + Based on the FCDTargetedEntity class to support aimed cameras. + COLLADA defines two types of cameras: perspective and orthographic. + Both types are fully handled by this class. + + A COLLADA perspective camera defines two of the three following parameters: horizontal field of view, + vertical field of view and aspect ratio. The missing parameter can be calculated using the following formulae: + aspect ratio = vertical field of view / horizontal field of view. The vertical and horizontal field + of view are in degrees. + + A COLLADA orthographic camera defines two of the three following parameters: horizontal magnification, + vertical magnification and aspect ratio. The missing parameter can be calculated using the following formulae: + aspect ratio = vertical magnification / horizontal magnification. You can calculate the viewport width + and height using the following formulas: viewport width = horizontal magnification * 2, viewport height + = vertical magnification * 2. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDCamera : public FCDTargetedEntity +{ +public: + /** The types of projection supported. */ + enum ProjectionType + { + PERSPECTIVE, /**< A perspective projection. Uses a truncated rectangular pyramid frustrum. */ + ORTHOGRAPHIC /**< An orthographic projection. Uses a rectangular prism frustrum. */ + }; + +private: + DeclareObjectType(FCDTargetedEntity); + + // Camera flags + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, projection, FC("Projection Type")); // ProjectionType enumerated-type. + + // Camera parameters + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, viewY, FC("Vertical View")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, viewX, FC("Horizontal View")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, aspectRatio, FC("Aspect Ratio")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, nearZ, FC("Near-Z Plane Distance")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, farZ, FC("Far-Z Plane Distance")); + +public: + DeclareFlag(HasHorizontalView, 0); + DeclareFlag(HasVerticalView, 1); + DeclareFlagCount(2); + +public: + /** Constructor: do not use directly. Create new cameras using the FCDLibrary::AddEntity function. + @param document The COLLADA document that contains this camera entity.*/ + FCDCamera(FCDocument* document); + + /** Destructor. */ + virtual ~FCDCamera(); + + /** Retrieves the entity type for this class. This function is part of the FCDEntity interface. + @return The entity type: CAMERA. */ + virtual Type GetType() const { return CAMERA; } + + /** Retrieves the type of projection of this camera. + @return The projection type. */ + inline ProjectionType GetProjectionType() const { return (ProjectionType) *projection; } + + /** Sets the type of projections for this camera. + @param type The projection type for this camera. */ + inline void SetProjectionType(ProjectionType type) { projection = type; SetDirtyFlag(); } + + /** Retrieves whether this camera is a perspective camera. + This is the default type of camera. + @return Whether this camera is a perspective camera.*/ + DEPRECATED(3.05A, GetProjectionType() == FCDCamera::PERSPECTIVE) inline bool IsPerspective() const { return projection == PERSPECTIVE; } + + /** Sets the type of this camera to perspective. */ + DEPRECATED(3.05A, SetProjectionType(FCDCamera::PERSPECTIVE)) inline void SetPerspective() { projection = PERSPECTIVE; SetDirtyFlag(); } + + /** Retrieves whether the perspective camera defines an horizontal field of view. + If the camera does not define the horizontal field of view, you can calculate + it using the following formula: horizontal field of view = vertical field of view / aspect ratio. + @return Whether the perspective camera defines an horizontal field of view. */ + inline bool HasHorizontalFov() const { return GetHasHorizontalViewFlag(); } + + /** Retrieves whether the perspective camera defines a vertical field of view. + If the camera does not define the vertical field of view, you can calculate + it using the following formula: vertical field of view = aspect ratio * horizontal field of view. + @return Whether the perspective camera defines a vertical field of view. */ + inline bool HasVerticalFov() const { return GetHasVerticalViewFlag(); } + + /** Retrieves the horizontal field of view. Before retrieving this value, + check whether the camera defines the horizontal field of view using the + HasHorizontalFov function. + @return The horizontal field of view, in degrees. */ + inline FCDParameterAnimatableFloat& GetFovX() { return viewX; } + inline const FCDParameterAnimatableFloat& GetFovX() const { return viewX; } /**< See above. */ + + /** Retrieves the vertical field of view. Before retrieving this value, + check whether the camera defines the vertical field of view using the + HasVerticalFov function. + @return The horizontal field of view, in degrees. */ + inline FCDParameterAnimatableFloat& GetFovY() { return viewY; } + inline const FCDParameterAnimatableFloat& GetFovY() const { return viewY; } /**< See above. */ + + /** Sets the horizontal field of view value for this camera. + @param fovX The new horizontal field of view, in degrees. */ + void SetFovX(float fovX); + + /** Sets the vertical field of view value for this camera. + @param fovY The new vertical field of view, in degrees. */ + void SetFovY(float fovY); + + /** Retrieves whether this camera is an orthographic camera. + @return Whether this camera is an orthographic camera. */ + DEPRECATED(3.05A, GetProjectionType() == FCDCamera::ORTHOGRAPHIC) inline bool IsOrthographic() const { return projection == ORTHOGRAPHIC; } + + /** Sets the type of this camera to orthographic. */ + DEPRECATED(3.05A, SetProjectionType(FCDCamera::ORTHOGRAPHIC)) inline void SetOrthographic() { projection = ORTHOGRAPHIC; SetDirtyFlag(); } + + /** Retrieves whether the orthographic camera defines an horizontal magnification. + If the camera does not define the horizontal magnification, you can calculate + it using the following formula: horizontal magnification = vertical magnification / aspect ratio. + @return Whether the orthographic camera defines an horizontal magnification. */ + inline bool HasHorizontalMag() const { return GetHasHorizontalViewFlag(); } + + /** Retrieves whether the perspective camera defines a vertical magnification. + If the camera does not define the vertical magnification, you can calculate + it using the following formula: vertical magnification = aspect ratio * horizontal magnification. + @return Whether the perspective camera defines a vertical magnification. */ + inline bool HasVerticalMag() const { return GetHasVerticalViewFlag(); } + + /** Retrieves the horizontal magnification. Before retrieving this value, + check whether the camera defines the horizontal magnification using the + HasHorizontalMag function. + @return The horizontal magnification. */ + inline FCDParameterAnimatableFloat& GetMagX() { return viewX; } + inline const FCDParameterAnimatableFloat& GetMagX() const { return viewX; } /**< See above. */ + + /** Retrieves the vertical magnification. Before retrieving this value, + check whether the camera defines the vertical magnification using the + HasVerticalMag function. + @return The vertical magnification. */ + inline FCDParameterAnimatableFloat& GetMagY() { return viewY; } + inline const FCDParameterAnimatableFloat& GetMagY() const { return viewY; } /**< See above. */ + + /** Sets the horizontal magnification for this camera. + @param magX The new horizontal magnification, in degrees. */ + inline void SetMagX(float magX) { return SetFovX(magX); } + + /** Sets the vertical magnification value for this camera. + @param magY The new vertical magnification, in degrees. */ + inline void SetMagY(float magY) { return SetFovY(magY); } + + /** Retrieves the near-z value for this camera. + The near-z value represent how close the near-clip + plane of the view frustum is. For orthographic cameras, + this value is solely used for depth-buffering. + @return The near-z value for this camera. */ + inline FCDParameterAnimatableFloat& GetNearZ() { return nearZ; } + inline const FCDParameterAnimatableFloat& GetNearZ() const { return nearZ; } /**< See above. */ + + /** Retrieves the far-z value for this camera. The far-z value represent + how close the far-clip plane of the view frustum is. + For orthographic cameras, this value is solely used for depth-buffering. + @return The far-z value for this camera. */ + inline FCDParameterAnimatableFloat& GetFarZ() { return farZ; } + inline const FCDParameterAnimatableFloat& GetFarZ() const { return farZ; } /**< See above. */ + + /** Retrieves whether the camera defines an aspect ratio. + @return Whether the camera defines an aspect ratio. */ + inline bool HasAspectRatio() const { return !(GetHasVerticalViewFlag() && GetHasHorizontalViewFlag()); } + + /** Retrieves the aspect ratio for the view of this camera. Before using this value, + check if there are only one of the horizontal and vertical view ratios. + If there are both of the view ratios provided for the camera, you will + need to calculate the aspect ratio using the following formula: + aspect ratio = vertical field of view / horizontal field of view. + @return The view aspect ratio. */ + inline FCDParameterAnimatableFloat& GetAspectRatio() { return aspectRatio; } + inline const FCDParameterAnimatableFloat& GetAspectRatio() const { return aspectRatio; } /**< See above. */ + + /** Sets the near-z value for this camera. + The near-z value represent how close the near-clip + plane of the view frustum is. For orthographic cameras, + this value is solely used for depth-buffering. + @param _nearZ A valid near-z value. No check is made to verify that the + near-z value is greater than the far-z value.*/ + inline void SetNearZ(float _nearZ) { nearZ = _nearZ; SetDirtyFlag(); } + + /** Sets the far-z value for this camera. The far-z value represent + how close the far-clip plane of the view frustum is. + For orthographic cameras, this value is solely used for depth-buffering. + @param _farZ A valid far-z value. No check is made to verify that the + far-z value is greater than the near-z value.*/ + inline void SetFarZ(float _farZ) { farZ = _farZ; SetDirtyFlag(); } + + /** Sets the aspect ratio for the view of this camera. + @param aspectRatio The new view aspect ratio. */ + void SetAspectRatio(float aspectRatio); +}; + +#endif // _FCD_CAMERA_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDCamera.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDController.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDController.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDController.cpp (revision 24247) @@ -1,105 +1,105 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDSkinController.h" -#include "FCDocument/FCDMorphController.h" - -// -// FCDController -// - -ImplementObjectType(FCDController); -ImplementParameterObject(FCDController, FCDMorphController, morphController, new FCDMorphController(parent->GetDocument(), parent)); -ImplementParameterObject(FCDController, FCDSkinController, skinController, new FCDSkinController(parent->GetDocument(), parent)); - -FCDController::FCDController(FCDocument* document) -: FCDEntity(document, "Controller") -, InitializeParameterNoArg(skinController) -, InitializeParameterNoArg(morphController) -{ -} - -FCDController::~FCDController() -{ -} - - -// Sets the type of this controller to a skin controller. -FCDSkinController* FCDController::CreateSkinController() -{ - morphController = NULL; - skinController = new FCDSkinController(GetDocument(), this); - SetNewChildFlag(); - return skinController; -} - -// Sets the type of this controller to a morph controller. -FCDMorphController* FCDController::CreateMorphController() -{ - skinController = NULL; - morphController = new FCDMorphController(GetDocument(), this); - SetNewChildFlag(); - return morphController; -} - -FCDEntity* FCDController::GetBaseTarget() -{ - if (skinController != NULL) return skinController->GetTarget(); - else if (morphController != NULL) return morphController->GetBaseTarget(); - else return NULL; -} -const FCDEntity* FCDController::GetBaseTarget() const -{ - if (skinController != NULL) return skinController->GetTarget(); - else if (morphController != NULL) return morphController->GetBaseTarget(); - else return NULL; -} - -// Retrieves the base target geometry for this controller. -const FCDGeometry* FCDController::GetBaseGeometry() const -{ - const FCDEntity* base = GetBaseTarget(); - while (base != NULL && base->GetType() == FCDEntity::CONTROLLER) - { - base = ((const FCDController*) base)->GetBaseTarget(); - } - - if (base != NULL && base->GetType() == FCDEntity::GEOMETRY) - { - return (const FCDGeometry*) base; - } - return NULL; -} - -// Returns the first FCDController directly above the base of this controller -const FCDController* FCDController::GetBaseGeometryController() const -{ - const FCDEntity* parentBase = this; - const FCDEntity* base = GetBaseTarget(); - while (base != NULL && base->GetType() == FCDEntity::CONTROLLER) - { - parentBase = base; - base = ((const FCDController*) base)->GetBaseTarget(); - } - - if (base != NULL && base->GetType() == FCDEntity::GEOMETRY) - { - return (const FCDController*) parentBase; - } - - return NULL; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDSkinController.h" +#include "FCDocument/FCDMorphController.h" + +// +// FCDController +// + +ImplementObjectType(FCDController); +ImplementParameterObject(FCDController, FCDMorphController, morphController, new FCDMorphController(parent->GetDocument(), parent)); +ImplementParameterObject(FCDController, FCDSkinController, skinController, new FCDSkinController(parent->GetDocument(), parent)); + +FCDController::FCDController(FCDocument* document) +: FCDEntity(document, "Controller") +, InitializeParameterNoArg(skinController) +, InitializeParameterNoArg(morphController) +{ +} + +FCDController::~FCDController() +{ +} + + +// Sets the type of this controller to a skin controller. +FCDSkinController* FCDController::CreateSkinController() +{ + morphController = NULL; + skinController = new FCDSkinController(GetDocument(), this); + SetNewChildFlag(); + return skinController; +} + +// Sets the type of this controller to a morph controller. +FCDMorphController* FCDController::CreateMorphController() +{ + skinController = NULL; + morphController = new FCDMorphController(GetDocument(), this); + SetNewChildFlag(); + return morphController; +} + +FCDEntity* FCDController::GetBaseTarget() +{ + if (skinController != NULL) return skinController->GetTarget(); + else if (morphController != NULL) return morphController->GetBaseTarget(); + else return NULL; +} +const FCDEntity* FCDController::GetBaseTarget() const +{ + if (skinController != NULL) return skinController->GetTarget(); + else if (morphController != NULL) return morphController->GetBaseTarget(); + else return NULL; +} + +// Retrieves the base target geometry for this controller. +const FCDGeometry* FCDController::GetBaseGeometry() const +{ + const FCDEntity* base = GetBaseTarget(); + while (base != NULL && base->GetType() == FCDEntity::CONTROLLER) + { + base = ((const FCDController*) base)->GetBaseTarget(); + } + + if (base != NULL && base->GetType() == FCDEntity::GEOMETRY) + { + return (const FCDGeometry*) base; + } + return NULL; +} + +// Returns the first FCDController directly above the base of this controller +const FCDController* FCDController::GetBaseGeometryController() const +{ + const FCDEntity* parentBase = this; + const FCDEntity* base = GetBaseTarget(); + while (base != NULL && base->GetType() == FCDEntity::CONTROLLER) + { + parentBase = base; + base = ((const FCDController*) base)->GetBaseTarget(); + } + + if (base != NULL && base->GetType() == FCDEntity::GEOMETRY) + { + return (const FCDController*) parentBase; + } + + return NULL; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDController.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDController.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDController.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDController.h (revision 24247) @@ -1,125 +1,125 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDController.h - This file contains the FCDController class. -*/ - -#ifndef _FCD_CONTROLLER_H_ -#define _FCD_CONTROLLER_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDocument; -class FCDGeometry; -class FCDSkinController; -class FCDMorphController; - -/** - A generic COLLADA controller. - A COLLADA controller is used to influence a mesh. - COLLADA defines two types of controller: - skins (FCDSkinController) and morphers (FCDMorphController). - - @ingroup FCDGeometry -*/ -class FCOLLADA_EXPORT FCDController : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - - DeclareParameterRef(FCDSkinController, skinController, FC("Skin")); - DeclareParameterRef(FCDMorphController, morphController, FC("Morpher")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDLibrary::AddEntity function. - @param document The COLLADA document that owns the controller. */ - FCDController(FCDocument* document); - - /** Destructor. */ - virtual ~FCDController(); - - /** Retrieves the entity class type. - This function is a part of the FCDEntity interface. - @return The entity class type: CONTROLLER. */ - virtual Type GetType() const { return CONTROLLER; }; - - /** Retrieves whether this controller is a skin controller. - @return Whether this controller is a skin controller. */ - bool IsSkin() const { return skinController != NULL; } - - /** Retrieves whether this controller is a morph controller. - @return Whether this controller is a morph controller. */ - bool IsMorph() const { return morphController != NULL; } - - /** Sets the type of this controller to a skin controller. - This function will release any previously created morpher or skin. - @return The new skin controller. */ - FCDSkinController* CreateSkinController(); - - /** Sets the type of this controller to a morph controller. - This function will release any previously created morpher or skin. - @return The new morph controller. */ - FCDMorphController* CreateMorphController(); - - /** Retrieves the skin controller. - This pointer is only valid for skins. To verify that this is a skin, - check the HasSkinController function. - @return The skin controller. This pointer will be NULL, if the controller - is not a skin. */ - inline FCDSkinController* GetSkinController() { return skinController; } - inline const FCDSkinController* GetSkinController() const { return skinController; } /**< See above. */ - - /** Retrieves the morph controller. - This pointer is only valid for skins. To verify that this is a morpher, - check the HasMorphController function. - @return The morph controller. This pointer will be NULL, if the controller - is not a morpher. */ - inline FCDMorphController* GetMorphController() { return morphController; } - inline const FCDMorphController* GetMorphController() const { return morphController; } /**< See above. */ - - /** Retrieves the base target entity for this controller. - The base target entity may be another controller or a geometry entity. - To change the base target, use the FCDMorphController::SetBaseTarget - or the FCDSkinController::SetTarget functions. - @return The base target entity. This pointer will be NULL - if no base target is defined. */ - FCDEntity* GetBaseTarget(); - const FCDEntity* GetBaseTarget() const; /**< See above. */ - - /** Retrieves the base target geometry for this controller. - Controllers can be chained together. This function allows - you to retrieve the base target geometry, if there is one. - @return The base target geometry. This pointer will be NULL - if no base target is defined or if the base target entity - is not a geometry. */ - inline FCDGeometry* GetBaseGeometry() { return const_cast(const_cast(this)->GetBaseGeometry()); } - const FCDGeometry* GetBaseGeometry() const; /**< See above. */ - - /** Retrieves the lowest controller on this stack. - Controllers can be chained together. This function allows - you to retrieve the controller assigned to the base target geometry. - @return The base controller. This pointer will be NULL - if no base target is defined or if the base target entity - is not a geometry. */ - inline FCDController* GetBaseGeometryController() { return const_cast(const_cast(this)->GetBaseGeometryController()); } - const FCDController* GetBaseGeometryController() const; /**< See above. */ -}; - -#endif // _FCD_CONTROLLER_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDController.h + This file contains the FCDController class. +*/ + +#ifndef _FCD_CONTROLLER_H_ +#define _FCD_CONTROLLER_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDocument; +class FCDGeometry; +class FCDSkinController; +class FCDMorphController; + +/** + A generic COLLADA controller. + A COLLADA controller is used to influence a mesh. + COLLADA defines two types of controller: + skins (FCDSkinController) and morphers (FCDMorphController). + + @ingroup FCDGeometry +*/ +class FCOLLADA_EXPORT FCDController : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + + DeclareParameterRef(FCDSkinController, skinController, FC("Skin")); + DeclareParameterRef(FCDMorphController, morphController, FC("Morpher")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDLibrary::AddEntity function. + @param document The COLLADA document that owns the controller. */ + FCDController(FCDocument* document); + + /** Destructor. */ + virtual ~FCDController(); + + /** Retrieves the entity class type. + This function is a part of the FCDEntity interface. + @return The entity class type: CONTROLLER. */ + virtual Type GetType() const { return CONTROLLER; }; + + /** Retrieves whether this controller is a skin controller. + @return Whether this controller is a skin controller. */ + bool IsSkin() const { return skinController != NULL; } + + /** Retrieves whether this controller is a morph controller. + @return Whether this controller is a morph controller. */ + bool IsMorph() const { return morphController != NULL; } + + /** Sets the type of this controller to a skin controller. + This function will release any previously created morpher or skin. + @return The new skin controller. */ + FCDSkinController* CreateSkinController(); + + /** Sets the type of this controller to a morph controller. + This function will release any previously created morpher or skin. + @return The new morph controller. */ + FCDMorphController* CreateMorphController(); + + /** Retrieves the skin controller. + This pointer is only valid for skins. To verify that this is a skin, + check the HasSkinController function. + @return The skin controller. This pointer will be NULL, if the controller + is not a skin. */ + inline FCDSkinController* GetSkinController() { return skinController; } + inline const FCDSkinController* GetSkinController() const { return skinController; } /**< See above. */ + + /** Retrieves the morph controller. + This pointer is only valid for skins. To verify that this is a morpher, + check the HasMorphController function. + @return The morph controller. This pointer will be NULL, if the controller + is not a morpher. */ + inline FCDMorphController* GetMorphController() { return morphController; } + inline const FCDMorphController* GetMorphController() const { return morphController; } /**< See above. */ + + /** Retrieves the base target entity for this controller. + The base target entity may be another controller or a geometry entity. + To change the base target, use the FCDMorphController::SetBaseTarget + or the FCDSkinController::SetTarget functions. + @return The base target entity. This pointer will be NULL + if no base target is defined. */ + FCDEntity* GetBaseTarget(); + const FCDEntity* GetBaseTarget() const; /**< See above. */ + + /** Retrieves the base target geometry for this controller. + Controllers can be chained together. This function allows + you to retrieve the base target geometry, if there is one. + @return The base target geometry. This pointer will be NULL + if no base target is defined or if the base target entity + is not a geometry. */ + inline FCDGeometry* GetBaseGeometry() { return const_cast(const_cast(this)->GetBaseGeometry()); } + const FCDGeometry* GetBaseGeometry() const; /**< See above. */ + + /** Retrieves the lowest controller on this stack. + Controllers can be chained together. This function allows + you to retrieve the controller assigned to the base target geometry. + @return The base controller. This pointer will be NULL + if no base target is defined or if the base target entity + is not a geometry. */ + inline FCDController* GetBaseGeometryController() { return const_cast(const_cast(this)->GetBaseGeometryController()); } + const FCDController* GetBaseGeometryController() const; /**< See above. */ +}; + +#endif // _FCD_CONTROLLER_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDController.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerInstance.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerInstance.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerInstance.cpp (revision 24247) @@ -1,151 +1,151 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDControllerInstance.h" -#include "FCDocument/FCDSceneNode.h" -#include "FCDocument/FCDSkinController.h" -#include "FCDocument/FCDocument.h" - -// -// FCDControllerInstance -// - -ImplementObjectType(FCDControllerInstance); -ImplementParameterObjectNoCtr(FCDControllerInstance, FCDSceneNode, joints); - -FCDControllerInstance::FCDControllerInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType) -: FCDGeometryInstance(document, parent, entityType) -, InitializeParameterNoArg(joints) -{ -} - -FCDControllerInstance::~FCDControllerInstance() -{ -} - -FCDEntityInstance* FCDControllerInstance::Clone(FCDEntityInstance* _clone) const -{ - FCDControllerInstance* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDControllerInstance(const_cast(GetDocument()), NULL, GetEntityType()); - else if (_clone->HasType(FCDControllerInstance::GetClassType())) clone = (FCDControllerInstance*) _clone; - - Parent::Clone(_clone); - - if (clone != NULL) - { - // Clone the URI list. - clone->skeletonRoots = skeletonRoots; - - // Clone the joint list. - clone->joints = joints; - } - return _clone; -} - -// Retrieves a list of all the root joints for the controller. -void FCDControllerInstance::CalculateRootIds() -{ - skeletonRoots.clear(); - - for (const FCDSceneNode** itJ = (const FCDSceneNode**) joints.begin(); itJ != joints.end(); ++itJ) - { - const FCDSceneNode* joint = (*itJ); - if (joint == NULL) continue; - - bool addToList = true; - size_t parentCount = joint->GetParentCount(); - for (size_t p = 0; p < parentCount; ++p) - { - const FCDSceneNode* parentJoint = joint->GetParent(p); - if (FindJoint(parentJoint)) - { - addToList = false; - break; - } - } - - if (addToList) - { - fstring utf16id = TO_FSTRING(joint->GetDaeId()); - FUUri newRoot(FS("#") + utf16id); - skeletonRoots.push_back(newRoot); - } - } -} - -bool FCDControllerInstance::AddJoint(FCDSceneNode* j) -{ - if (j != NULL) - { - j->SetJointFlag(true); - AppendJoint(j); - return true; - } - return false; -} - -// Look for the information on a given joint -bool FCDControllerInstance::FindJoint(const FCDSceneNode* joint) const -{ - return joints.contains(joint); -} - - -size_t FCDControllerInstance::FindJointIndex(const FCDSceneNode* joint) const -{ - size_t i = 0; - for (const FCDSceneNode** itr = joints.begin(); itr != joints.end(); ++i, ++itr) - { - if (*itr == joint) return i; - } - return (size_t) ~0; -} - -void FCDControllerInstance::AppendJoint(FCDSceneNode* j) -{ - joints.push_back(j); -} - -const FCDSkinController* FCDControllerInstance::FindSkin(const FCDEntity* entity) const -{ - if (entity != NULL && entity->GetType() == FCDEntity::CONTROLLER) - { - const FCDController* controller = (const FCDController*) entity; - - if (controller->IsSkin()) - { - return controller->GetSkinController(); - } - else return FindSkin(controller->GetBaseTarget()); - } - return NULL; -} - -void FCDControllerInstance::FindSkeletonNodes(FCDSceneNodeList& skeletonNodes) const -{ - const FCDocument* document = GetDocument(); - size_t numRoots = skeletonRoots.size(); - skeletonNodes.reserve(numRoots); - for (size_t i = 0; i < numRoots; ++i) - { - const FCDSceneNode* aRoot = document->FindSceneNode(TO_STRING(skeletonRoots[i].GetFragment()).c_str()); - if (aRoot == NULL) - { - FUError::Error(FUError::WARNING_LEVEL, FUError::WARNING_UNKNOWN_JOINT, 0); - } - else skeletonNodes.push_back(const_cast(aRoot)); - } - - // If we have no root, add the visual scene root. - if (skeletonNodes.empty()) - { - skeletonNodes.push_back(const_cast(document->GetVisualSceneInstance())); - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDControllerInstance.h" +#include "FCDocument/FCDSceneNode.h" +#include "FCDocument/FCDSkinController.h" +#include "FCDocument/FCDocument.h" + +// +// FCDControllerInstance +// + +ImplementObjectType(FCDControllerInstance); +ImplementParameterObjectNoCtr(FCDControllerInstance, FCDSceneNode, joints); + +FCDControllerInstance::FCDControllerInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType) +: FCDGeometryInstance(document, parent, entityType) +, InitializeParameterNoArg(joints) +{ +} + +FCDControllerInstance::~FCDControllerInstance() +{ +} + +FCDEntityInstance* FCDControllerInstance::Clone(FCDEntityInstance* _clone) const +{ + FCDControllerInstance* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDControllerInstance(const_cast(GetDocument()), NULL, GetEntityType()); + else if (_clone->HasType(FCDControllerInstance::GetClassType())) clone = (FCDControllerInstance*) _clone; + + Parent::Clone(_clone); + + if (clone != NULL) + { + // Clone the URI list. + clone->skeletonRoots = skeletonRoots; + + // Clone the joint list. + clone->joints = joints; + } + return _clone; +} + +// Retrieves a list of all the root joints for the controller. +void FCDControllerInstance::CalculateRootIds() +{ + skeletonRoots.clear(); + + for (const FCDSceneNode** itJ = (const FCDSceneNode**) joints.begin(); itJ != joints.end(); ++itJ) + { + const FCDSceneNode* joint = (*itJ); + if (joint == NULL) continue; + + bool addToList = true; + size_t parentCount = joint->GetParentCount(); + for (size_t p = 0; p < parentCount; ++p) + { + const FCDSceneNode* parentJoint = joint->GetParent(p); + if (FindJoint(parentJoint)) + { + addToList = false; + break; + } + } + + if (addToList) + { + fstring utf16id = TO_FSTRING(joint->GetDaeId()); + FUUri newRoot(FS("#") + utf16id); + skeletonRoots.push_back(newRoot); + } + } +} + +bool FCDControllerInstance::AddJoint(FCDSceneNode* j) +{ + if (j != NULL) + { + j->SetJointFlag(true); + AppendJoint(j); + return true; + } + return false; +} + +// Look for the information on a given joint +bool FCDControllerInstance::FindJoint(const FCDSceneNode* joint) const +{ + return joints.contains(joint); +} + + +size_t FCDControllerInstance::FindJointIndex(const FCDSceneNode* joint) const +{ + size_t i = 0; + for (const FCDSceneNode** itr = joints.begin(); itr != joints.end(); ++i, ++itr) + { + if (*itr == joint) return i; + } + return (size_t) ~0; +} + +void FCDControllerInstance::AppendJoint(FCDSceneNode* j) +{ + joints.push_back(j); +} + +const FCDSkinController* FCDControllerInstance::FindSkin(const FCDEntity* entity) const +{ + if (entity != NULL && entity->GetType() == FCDEntity::CONTROLLER) + { + const FCDController* controller = (const FCDController*) entity; + + if (controller->IsSkin()) + { + return controller->GetSkinController(); + } + else return FindSkin(controller->GetBaseTarget()); + } + return NULL; +} + +void FCDControllerInstance::FindSkeletonNodes(FCDSceneNodeList& skeletonNodes) const +{ + const FCDocument* document = GetDocument(); + size_t numRoots = skeletonRoots.size(); + skeletonNodes.reserve(numRoots); + for (size_t i = 0; i < numRoots; ++i) + { + const FCDSceneNode* aRoot = document->FindSceneNode(TO_STRING(skeletonRoots[i].GetFragment()).c_str()); + if (aRoot == NULL) + { + FUError::Error(FUError::WARNING_LEVEL, FUError::WARNING_UNKNOWN_JOINT, 0); + } + else skeletonNodes.push_back(const_cast(aRoot)); + } + + // If we have no root, add the visual scene root. + if (skeletonNodes.empty()) + { + skeletonNodes.push_back(const_cast(document->GetVisualSceneInstance())); + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerInstance.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerTools.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerTools.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerTools.cpp (revision 24247) @@ -1,112 +1,112 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDControllerTools.h" -#include "FCDocument/FCDSkinController.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDEntity.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDMorphController.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometrySource.h" -#include "FCDocument/FCDGeometryPolygons.h" - -namespace FCDControllerTools -{ - void ApplyTranslationMap(const FCDSkinController* controller, const FCDGeometryIndexTranslationMap& translationMap, const UInt16List& packingMap, fm::pvector& skinInfluences) - { - const FCDSkinControllerVertex* influences = controller->GetVertexInfluences(); - uint32 influenceCount = (uint32)controller->GetInfluenceCount(); - - // make a copy of the influences - //FCDSkinControllerVertex* copiedInfluences = new FCDSkinControllerVertex[influenceCount]; - //for (size_t i = 0; i < influenceCount; i++) - //{ - // copiedInfluences[i] = influences[i]; - //} - - // Alright, this map contains pointers to the different weights - uint16 largestIdx = 0; - for (size_t i = 0; i < packingMap.size(); ++i) - { - if (packingMap[i] > largestIdx && packingMap[i] != (uint16)-1) - { - largestIdx = packingMap[i]; - } - } - - // This is how many vertices we are packing here! - skinInfluences.resize(largestIdx + 1); - FUAssert(largestIdx < influenceCount,); - - // Now iterate over all the vertices that we have used and come up with something - for (uint32 i = 0; i < influenceCount; ++i) - { - UInt32List uniqueIndices = translationMap[i]; - for (UInt32List::iterator uItr = uniqueIndices.begin(); uItr != uniqueIndices.end(); ++uItr) - { - if (packingMap[*uItr] != (uint16)-1) - { - skinInfluences[packingMap[*uItr]] = influences + i; - } - } - } - /* Failing on this assertion is probably because the translationMap was - not created by GenerateUniqueIndices for the target of the given - controller. It can also be caused by calling this method multiple - times for the same translationMap. * - FUAssert(translationMap.size() <= influenceCount, return;); - FUAssert(influenceCount > 0, return;); - - // find the largest index - uint32 largest = 0; - for (FCDGeometryIndexTranslationMap::const_iterator it = translationMap.begin(), itEnd = translationMap.end(); it != itEnd; ++it) - { - const UInt32List& curList = it->second; - for (UInt32List::const_iterator it = curList.begin(); it != curList.end(); ++it) - { - largest = max(largest, *it); - } - } - - // This function will create havok when re-initializing meshes - // The problem is because the skin has already been remapped, - // but the mesh has not. Condition is making assumption that - // the skin already maps to the mesh perfectly. - uint32 newInfluenceCount = largest + 1; - if (newInfluenceCount != influenceCount) // work is possible - { - // Set the new influences - controller->SetInfluenceCount(newInfluenceCount); - - for (FCDGeometryIndexTranslationMap::const_iterator it = translationMap.begin(), itEnd = translationMap.end(); it != itEnd; ++it) - { - FCDSkinControllerVertex& newInfluence = copiedInfluences[it->first]; - size_t pairCount = newInfluence.GetPairCount(); - - const UInt32List& curList = it->second; - for (UInt32List::const_iterator it = curList.begin(); it != curList.end(); it++) - { - FCDSkinControllerVertex* vertex = controller->GetVertexInfluence(*it); - vertex->SetPairCount(pairCount); - for (size_t j = 0; j < pairCount; j++) - { - FCDJointWeightPair* pair = newInfluence.GetPair(j); - FCDJointWeightPair* p = vertex->GetPair(j); - p->jointIndex = pair->jointIndex; - p->weight = pair->weight; - } - } - } - } - SAFE_DELETE_ARRAY(copiedInfluences); */ - } -} - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDControllerTools.h" +#include "FCDocument/FCDSkinController.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDEntity.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDMorphController.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometrySource.h" +#include "FCDocument/FCDGeometryPolygons.h" + +namespace FCDControllerTools +{ + void ApplyTranslationMap(const FCDSkinController* controller, const FCDGeometryIndexTranslationMap& translationMap, const UInt16List& packingMap, fm::pvector& skinInfluences) + { + const FCDSkinControllerVertex* influences = controller->GetVertexInfluences(); + uint32 influenceCount = (uint32)controller->GetInfluenceCount(); + + // make a copy of the influences + //FCDSkinControllerVertex* copiedInfluences = new FCDSkinControllerVertex[influenceCount]; + //for (size_t i = 0; i < influenceCount; i++) + //{ + // copiedInfluences[i] = influences[i]; + //} + + // Alright, this map contains pointers to the different weights + uint16 largestIdx = 0; + for (size_t i = 0; i < packingMap.size(); ++i) + { + if (packingMap[i] > largestIdx && packingMap[i] != (uint16)-1) + { + largestIdx = packingMap[i]; + } + } + + // This is how many vertices we are packing here! + skinInfluences.resize(largestIdx + 1); + FUAssert(largestIdx < influenceCount,); + + // Now iterate over all the vertices that we have used and come up with something + for (uint32 i = 0; i < influenceCount; ++i) + { + UInt32List uniqueIndices = translationMap[i]; + for (UInt32List::iterator uItr = uniqueIndices.begin(); uItr != uniqueIndices.end(); ++uItr) + { + if (packingMap[*uItr] != (uint16)-1) + { + skinInfluences[packingMap[*uItr]] = influences + i; + } + } + } + /* Failing on this assertion is probably because the translationMap was + not created by GenerateUniqueIndices for the target of the given + controller. It can also be caused by calling this method multiple + times for the same translationMap. * + FUAssert(translationMap.size() <= influenceCount, return;); + FUAssert(influenceCount > 0, return;); + + // find the largest index + uint32 largest = 0; + for (FCDGeometryIndexTranslationMap::const_iterator it = translationMap.begin(), itEnd = translationMap.end(); it != itEnd; ++it) + { + const UInt32List& curList = it->second; + for (UInt32List::const_iterator it = curList.begin(); it != curList.end(); ++it) + { + largest = max(largest, *it); + } + } + + // This function will create havok when re-initializing meshes + // The problem is because the skin has already been remapped, + // but the mesh has not. Condition is making assumption that + // the skin already maps to the mesh perfectly. + uint32 newInfluenceCount = largest + 1; + if (newInfluenceCount != influenceCount) // work is possible + { + // Set the new influences + controller->SetInfluenceCount(newInfluenceCount); + + for (FCDGeometryIndexTranslationMap::const_iterator it = translationMap.begin(), itEnd = translationMap.end(); it != itEnd; ++it) + { + FCDSkinControllerVertex& newInfluence = copiedInfluences[it->first]; + size_t pairCount = newInfluence.GetPairCount(); + + const UInt32List& curList = it->second; + for (UInt32List::const_iterator it = curList.begin(); it != curList.end(); it++) + { + FCDSkinControllerVertex* vertex = controller->GetVertexInfluence(*it); + vertex->SetPairCount(pairCount); + for (size_t j = 0; j < pairCount; j++) + { + FCDJointWeightPair* pair = newInfluence.GetPair(j); + FCDJointWeightPair* p = vertex->GetPair(j); + p->jointIndex = pair->jointIndex; + p->weight = pair->weight; + } + } + } + } + SAFE_DELETE_ARRAY(copiedInfluences); */ + } +} + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDControllerTools.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffect.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffect.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffect.cpp (revision 24247) @@ -1,122 +1,122 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffect.h" -#include "FCDocument/FCDEffectStandard.h" -#include "FCDocument/FCDEffectProfileFX.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterFactory.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDImage.h" - -// -// FCDEffect -// - -ImplementObjectType(FCDEffect); -ImplementParameterObjectNoCtr(FCDEffect, FCDEffectProfile, profiles); -ImplementParameterObjectNoCtr(FCDEffect, FCDEffectParameter, parameters); - -FCDEffect::FCDEffect(FCDocument* document) -: FCDEntity(document, "Effect") -, InitializeParameterNoArg(profiles) -, InitializeParameterNoArg(parameters) -{ -} - -FCDEffect::~FCDEffect() -{ -} - -FCDEffectParameter* FCDEffect::AddEffectParameter(uint32 type) -{ - FCDEffectParameter* parameter = FCDEffectParameterFactory::Create(GetDocument(), type); - parameters.push_back(parameter); - SetNewChildFlag(); - return parameter; -} - -// Search for a profile of the given type -const FCDEffectProfile* FCDEffect::FindProfile(FUDaeProfileType::Type type) const -{ - for (const FCDEffectProfile** itR = profiles.begin(); itR != profiles.end(); ++itR) - { - if ((*itR)->GetType() == type) return (*itR); - } - return NULL; -} - -// Search for a profile of a given type and platform -const FCDEffectProfile* FCDEffect::FindProfileByTypeAndPlatform(FUDaeProfileType::Type type, const fm::string& platform) const -{ - for (const FCDEffectProfile** itR = profiles.begin(); itR != profiles.end(); ++itR) - { - if ((*itR)->GetType() == type) - { - if (((FCDEffectProfileFX*)(*itR))->GetPlatform() == TO_FSTRING(platform)) return (*itR); - } - } - return NULL; -} - -// Create a new effect profile. -FCDEffectProfile* FCDEffect::AddProfile(FUDaeProfileType::Type type) -{ - FCDEffectProfile* profile = NULL; - - // Create the correct profile for this type. - if (type == FUDaeProfileType::COMMON) profile = new FCDEffectStandard(GetDocument(), this); - else - { - profile = new FCDEffectProfileFX(GetDocument(), this); - ((FCDEffectProfileFX*) profile)->SetType(type); - } - - profiles.push_back(profile); - SetNewChildFlag(); - return profile; -} - -// Returns a copy of the effect, with all the animations/textures attached -FCDEntity* FCDEffect::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDEffect* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDEffect(const_cast(GetDocument())); - else if (_clone->HasType(FCDEffect::GetClassType())) clone = (FCDEffect*) _clone; - - Parent::Clone(clone, cloneChildren); - - if (clone != NULL) - { - // Clone the effect profiles - for (const FCDEffectProfile** itR = profiles.begin(); itR != profiles.end(); ++itR) - { - FCDEffectProfile* clonedProfile = clone->AddProfile((*itR)->GetType()); - (*itR)->Clone(clonedProfile); - } - - // Clone the effect parameters - size_t parameterCount = parameters.size(); - for (size_t p = 0; p < parameterCount; ++p) - { - FCDEffectParameter* parameter = clone->AddEffectParameter(parameters[p]->GetType()); - parameters[p]->Clone(parameter); - } - } - return _clone; -} - - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffect.h" +#include "FCDocument/FCDEffectStandard.h" +#include "FCDocument/FCDEffectProfileFX.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterFactory.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDImage.h" + +// +// FCDEffect +// + +ImplementObjectType(FCDEffect); +ImplementParameterObjectNoCtr(FCDEffect, FCDEffectProfile, profiles); +ImplementParameterObjectNoCtr(FCDEffect, FCDEffectParameter, parameters); + +FCDEffect::FCDEffect(FCDocument* document) +: FCDEntity(document, "Effect") +, InitializeParameterNoArg(profiles) +, InitializeParameterNoArg(parameters) +{ +} + +FCDEffect::~FCDEffect() +{ +} + +FCDEffectParameter* FCDEffect::AddEffectParameter(uint32 type) +{ + FCDEffectParameter* parameter = FCDEffectParameterFactory::Create(GetDocument(), type); + parameters.push_back(parameter); + SetNewChildFlag(); + return parameter; +} + +// Search for a profile of the given type +const FCDEffectProfile* FCDEffect::FindProfile(FUDaeProfileType::Type type) const +{ + for (const FCDEffectProfile** itR = profiles.begin(); itR != profiles.end(); ++itR) + { + if ((*itR)->GetType() == type) return (*itR); + } + return NULL; +} + +// Search for a profile of a given type and platform +const FCDEffectProfile* FCDEffect::FindProfileByTypeAndPlatform(FUDaeProfileType::Type type, const fm::string& platform) const +{ + for (const FCDEffectProfile** itR = profiles.begin(); itR != profiles.end(); ++itR) + { + if ((*itR)->GetType() == type) + { + if (((FCDEffectProfileFX*)(*itR))->GetPlatform() == TO_FSTRING(platform)) return (*itR); + } + } + return NULL; +} + +// Create a new effect profile. +FCDEffectProfile* FCDEffect::AddProfile(FUDaeProfileType::Type type) +{ + FCDEffectProfile* profile = NULL; + + // Create the correct profile for this type. + if (type == FUDaeProfileType::COMMON) profile = new FCDEffectStandard(GetDocument(), this); + else + { + profile = new FCDEffectProfileFX(GetDocument(), this); + ((FCDEffectProfileFX*) profile)->SetType(type); + } + + profiles.push_back(profile); + SetNewChildFlag(); + return profile; +} + +// Returns a copy of the effect, with all the animations/textures attached +FCDEntity* FCDEffect::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDEffect* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDEffect(const_cast(GetDocument())); + else if (_clone->HasType(FCDEffect::GetClassType())) clone = (FCDEffect*) _clone; + + Parent::Clone(clone, cloneChildren); + + if (clone != NULL) + { + // Clone the effect profiles + for (const FCDEffectProfile** itR = profiles.begin(); itR != profiles.end(); ++itR) + { + FCDEffectProfile* clonedProfile = clone->AddProfile((*itR)->GetType()); + (*itR)->Clone(clonedProfile); + } + + // Clone the effect parameters + size_t parameterCount = parameters.size(); + for (size_t p = 0; p < parameterCount; ++p) + { + FCDEffectParameter* parameter = clone->AddEffectParameter(parameters[p]->GetType()); + parameters[p]->Clone(parameter); + } + } + return _clone; +} + + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffect.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectCode.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectCode.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectCode.cpp (revision 24247) @@ -1,49 +1,49 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDObjectWithId.h" -#include "FCDocument/FCDEffectCode.h" -#include "FUtils/FUFileManager.h" - -ImplementObjectType(FCDEffectCode); - -FCDEffectCode::FCDEffectCode(FCDocument* document) : FCDObject(document) -{ - type = INCLUDE; -} - -FCDEffectCode::~FCDEffectCode() -{ -} - -// Do not inline this function. No memory-creating functions should be inline -void FCDEffectCode::SetSubId(const fm::string& _sid) -{ - sid = FCDObjectWithId::CleanSubId(_sid); - SetDirtyFlag(); -} - -void FCDEffectCode::SetFilename(const fstring& _filename) -{ - filename = GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(_filename); - type = INCLUDE; - SetDirtyFlag(); -} - -// Clone -FCDEffectCode* FCDEffectCode::Clone(FCDEffectCode* clone) const -{ - if (clone == NULL) clone = new FCDEffectCode(const_cast(GetDocument())); - clone->type = type; - clone->sid = sid; - clone->filename = filename; - clone->code = code; - return clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDObjectWithId.h" +#include "FCDocument/FCDEffectCode.h" +#include "FUtils/FUFileManager.h" + +ImplementObjectType(FCDEffectCode); + +FCDEffectCode::FCDEffectCode(FCDocument* document) : FCDObject(document) +{ + type = INCLUDE; +} + +FCDEffectCode::~FCDEffectCode() +{ +} + +// Do not inline this function. No memory-creating functions should be inline +void FCDEffectCode::SetSubId(const fm::string& _sid) +{ + sid = FCDObjectWithId::CleanSubId(_sid); + SetDirtyFlag(); +} + +void FCDEffectCode::SetFilename(const fstring& _filename) +{ + filename = GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(_filename); + type = INCLUDE; + SetDirtyFlag(); +} + +// Clone +FCDEffectCode* FCDEffectCode::Clone(FCDEffectCode* clone) const +{ + if (clone == NULL) clone = new FCDEffectCode(const_cast(GetDocument())); + clone->type = type; + clone->sid = sid; + clone->filename = filename; + clone->code = code; + return clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectCode.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.cpp (revision 24247) @@ -1,218 +1,218 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument.h" -#include "FCDEffectPass.h" -#include "FCDEffectProfile.h" -#include "FCDEffectTechnique.h" -#include "FCDEffectParameter.h" -#include "FCDEffectParameterFactory.h" -#include "FCDImage.h" -#if !defined(__APPLE__) && !defined(LINUX) -#include "FCDEffectParameter.hpp" -#endif - -// -// FCDEffectParameter -// - -ImplementObjectType(FCDEffectParameter); -ImplementParameterObjectNoArg(FCDEffectParameter, FCDEffectParameterAnnotation, annotations); - -FCDEffectParameter::FCDEffectParameter(FCDocument* document) -: FCDObject(document) -, InitializeParameter(paramType, FCDEffectParameter::GENERATOR) -, InitializeParameterNoArg(reference) -, InitializeParameterNoArg(semantic) -, InitializeParameterNoArg(annotations) -{ -} - -FCDEffectParameter::~FCDEffectParameter() -{ -} - -void FCDEffectParameter::SetReference(const char* _reference) -{ - reference = FCDObjectWithId::CleanSubId(_reference); - SetDirtyFlag(); -} - -FCDEffectParameterAnnotation* FCDEffectParameter::AddAnnotation() -{ - FCDEffectParameterAnnotation* annotation = new FCDEffectParameterAnnotation(); - annotations.push_back(annotation); - SetNewChildFlag(); - return annotation; -} - -void FCDEffectParameter::AddAnnotation(const fchar* name, FCDEffectParameter::Type type, const fchar* value) -{ - FCDEffectParameterAnnotation* annotation = AddAnnotation(); - annotation->name = name; - annotation->type = type; - annotation->value = value; - SetNewChildFlag(); -} - -bool FCDEffectParameter::IsValueEqual(FCDEffectParameter* parameter) -{ - return (parameter != NULL && this->GetType() == parameter->GetType()); -} - -// Clones the base parameter values -FCDEffectParameter* FCDEffectParameter::Clone(FCDEffectParameter* clone) const -{ - if (clone == NULL) - { - // Recursively call the cloning function in an attempt to clone the up-class parameters - clone = FCDEffectParameterFactory::Create(const_cast(GetDocument()), GetType()); - return clone != NULL ? Clone(clone) : NULL; - } - else - { - clone->reference = reference; - clone->semantic = semantic; - clone->paramType = paramType; - clone->annotations.reserve(annotations.size()); - for (const FCDEffectParameterAnnotation** itA = annotations.begin(); itA != annotations.end(); ++itA) - { - clone->AddAnnotation(*(*itA)->name, (FCDEffectParameter::Type) *(*itA)->type, *(*itA)->value); - } - return clone; - } -} - -// Flattening: overwrite the target parameter with this parameter -void FCDEffectParameter::Overwrite(FCDEffectParameter* UNUSED(target)) -{ - // Do nothing on the base class, only values and animations should be overwritten -} - -// -// FCDEffectParameterAnnotation -// - -ImplementObjectType(FCDEffectParameterAnnotation); - -FCDEffectParameterAnnotation::FCDEffectParameterAnnotation() -: FUParameterizable() -, InitializeParameterNoArg(name) -, InitializeParameter(type, FCDEffectParameter::STRING) -, InitializeParameterNoArg(value) -{ -} - -FCDEffectParameterAnnotation::~FCDEffectParameterAnnotation() -{ -} - -// -// FCDEffectParameterT -// - -ImplementObjectTypeT(FCDEffectParameterInt); -ImplementObjectTypeT(FCDEffectParameterString); -ImplementObjectTypeT(FCDEffectParameterBool); - -template <> FCDEffectParameter::Type FCDEffectParameterInt::GetType() const { return FCDEffectParameter::INTEGER; } -template <> FCDEffectParameter::Type FCDEffectParameterString::GetType() const { return FCDEffectParameter::STRING; } -template <> FCDEffectParameter::Type FCDEffectParameterBool::GetType() const { return FCDEffectParameter::BOOLEAN; } - -template <> FCDEffectParameterInt::FCDEffectParameterT(FCDocument* document) -: FCDEffectParameter(document), InitializeParameter(value, 0) {} -template <> FCDEffectParameterString::FCDEffectParameterT(FCDocument* document) -: FCDEffectParameter(document), InitializeParameterNoArg(value) {} -template <> FCDEffectParameterBool::FCDEffectParameterT(FCDocument* document) -: FCDEffectParameter(document), InitializeParameter(value, false) {} - -// -// FCDEffectParameterAnimatableT -// - -ImplementObjectTypeT(FCDEffectParameterFloat); -ImplementObjectTypeT(FCDEffectParameterFloat2); -ImplementObjectTypeT(FCDEffectParameterFloat3); -ImplementObjectTypeT(FCDEffectParameterColor3); -ImplementObjectTypeT(FCDEffectParameterVector); -ImplementObjectTypeT(FCDEffectParameterColor4); -ImplementObjectTypeT(FCDEffectParameterMatrix); - -template <> FCDEffectParameter::Type FCDEffectParameterFloat::GetType() const { return FCDEffectParameter::FLOAT; } -template <> FCDEffectParameter::Type FCDEffectParameterFloat2::GetType() const { return FCDEffectParameter::FLOAT2; } -template <> FCDEffectParameter::Type FCDEffectParameterFloat3::GetType() const { return FCDEffectParameter::FLOAT3; } -template <> FCDEffectParameter::Type FCDEffectParameterColor3::GetType() const { return FCDEffectParameter::FLOAT3; } -template <> FCDEffectParameter::Type FCDEffectParameterVector::GetType() const { return FCDEffectParameter::VECTOR; } -template <> FCDEffectParameter::Type FCDEffectParameterColor4::GetType() const { return FCDEffectParameter::VECTOR; } -template <> FCDEffectParameter::Type FCDEffectParameterMatrix::GetType() const { return FCDEffectParameter::MATRIX; } - -template <> FCDEffectParameterFloat::FCDEffectParameterAnimatableT(FCDocument* document) -: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, 0.0f) {} -template <> FCDEffectParameterFloat2::FCDEffectParameterAnimatableT(FCDocument* document) -: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMVector2::Zero) {} -template <> FCDEffectParameterFloat3::FCDEffectParameterAnimatableT(FCDocument* document) -: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMVector3::Zero) {} -template <> FCDEffectParameterColor3::FCDEffectParameterAnimatableT(FCDocument* document) -: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMVector3::One) {} -template <> FCDEffectParameterVector::FCDEffectParameterAnimatableT(FCDocument* document) -: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMVector4::Zero) {} -template <> FCDEffectParameterColor4::FCDEffectParameterAnimatableT(FCDocument* document) -: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMVector4::One) {} -template <> FCDEffectParameterMatrix::FCDEffectParameterAnimatableT(FCDocument* document) -: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMMatrix44::Identity) {} - -// -// Another TrickLinker... -// - -template void TrickLinkerEffectParameterT() -{ - static bool toBe = false; - FCDEffectParameterT parameter(NULL); - parameter.GetType(); - parameter.SetValue(parameter.GetValue()); - toBe = parameter.IsValueEqual(¶meter); - if (toBe) - { - FCDEffectParameterT* other = (FCDEffectParameterT*) parameter.Clone(); - other->Overwrite(¶meter); - delete other; - } -} - -template void TrickLinkerEffectParameterAnimatableT() -{ - static bool toBe = false; - FCDEffectParameterAnimatableT parameter(NULL); - parameter.GetType(); - parameter.SetValue(parameter.GetValue()); - parameter.SetFloatType(parameter.GetFloatType()); - toBe = parameter.IsValueEqual(¶meter); - if (toBe) - { - FCDEffectParameterAnimatableT* other = (FCDEffectParameterAnimatableT*) parameter.Clone(); - other->Overwrite(¶meter); - delete other; - } -} - -extern void TrickLinkerEffectParameter() -{ - TrickLinkerEffectParameterT(); - TrickLinkerEffectParameterT(); - TrickLinkerEffectParameterT(); - - TrickLinkerEffectParameterAnimatableT(); - TrickLinkerEffectParameterAnimatableT(); - TrickLinkerEffectParameterAnimatableT(); - TrickLinkerEffectParameterAnimatableT(); - TrickLinkerEffectParameterAnimatableT(); - TrickLinkerEffectParameterAnimatableT(); - TrickLinkerEffectParameterAnimatableT(); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument.h" +#include "FCDEffectPass.h" +#include "FCDEffectProfile.h" +#include "FCDEffectTechnique.h" +#include "FCDEffectParameter.h" +#include "FCDEffectParameterFactory.h" +#include "FCDImage.h" +#if !defined(__APPLE__) && !defined(LINUX) +#include "FCDEffectParameter.hpp" +#endif + +// +// FCDEffectParameter +// + +ImplementObjectType(FCDEffectParameter); +ImplementParameterObjectNoArg(FCDEffectParameter, FCDEffectParameterAnnotation, annotations); + +FCDEffectParameter::FCDEffectParameter(FCDocument* document) +: FCDObject(document) +, InitializeParameter(paramType, FCDEffectParameter::GENERATOR) +, InitializeParameterNoArg(reference) +, InitializeParameterNoArg(semantic) +, InitializeParameterNoArg(annotations) +{ +} + +FCDEffectParameter::~FCDEffectParameter() +{ +} + +void FCDEffectParameter::SetReference(const char* _reference) +{ + reference = FCDObjectWithId::CleanSubId(_reference); + SetDirtyFlag(); +} + +FCDEffectParameterAnnotation* FCDEffectParameter::AddAnnotation() +{ + FCDEffectParameterAnnotation* annotation = new FCDEffectParameterAnnotation(); + annotations.push_back(annotation); + SetNewChildFlag(); + return annotation; +} + +void FCDEffectParameter::AddAnnotation(const fchar* name, FCDEffectParameter::Type type, const fchar* value) +{ + FCDEffectParameterAnnotation* annotation = AddAnnotation(); + annotation->name = name; + annotation->type = type; + annotation->value = value; + SetNewChildFlag(); +} + +bool FCDEffectParameter::IsValueEqual(FCDEffectParameter* parameter) +{ + return (parameter != NULL && this->GetType() == parameter->GetType()); +} + +// Clones the base parameter values +FCDEffectParameter* FCDEffectParameter::Clone(FCDEffectParameter* clone) const +{ + if (clone == NULL) + { + // Recursively call the cloning function in an attempt to clone the up-class parameters + clone = FCDEffectParameterFactory::Create(const_cast(GetDocument()), GetType()); + return clone != NULL ? Clone(clone) : NULL; + } + else + { + clone->reference = reference; + clone->semantic = semantic; + clone->paramType = paramType; + clone->annotations.reserve(annotations.size()); + for (const FCDEffectParameterAnnotation** itA = annotations.begin(); itA != annotations.end(); ++itA) + { + clone->AddAnnotation(*(*itA)->name, (FCDEffectParameter::Type) *(*itA)->type, *(*itA)->value); + } + return clone; + } +} + +// Flattening: overwrite the target parameter with this parameter +void FCDEffectParameter::Overwrite(FCDEffectParameter* UNUSED(target)) +{ + // Do nothing on the base class, only values and animations should be overwritten +} + +// +// FCDEffectParameterAnnotation +// + +ImplementObjectType(FCDEffectParameterAnnotation); + +FCDEffectParameterAnnotation::FCDEffectParameterAnnotation() +: FUParameterizable() +, InitializeParameterNoArg(name) +, InitializeParameter(type, FCDEffectParameter::STRING) +, InitializeParameterNoArg(value) +{ +} + +FCDEffectParameterAnnotation::~FCDEffectParameterAnnotation() +{ +} + +// +// FCDEffectParameterT +// + +ImplementObjectTypeT(FCDEffectParameterInt); +ImplementObjectTypeT(FCDEffectParameterString); +ImplementObjectTypeT(FCDEffectParameterBool); + +template <> FCDEffectParameter::Type FCDEffectParameterInt::GetType() const { return FCDEffectParameter::INTEGER; } +template <> FCDEffectParameter::Type FCDEffectParameterString::GetType() const { return FCDEffectParameter::STRING; } +template <> FCDEffectParameter::Type FCDEffectParameterBool::GetType() const { return FCDEffectParameter::BOOLEAN; } + +template <> FCDEffectParameterInt::FCDEffectParameterT(FCDocument* document) +: FCDEffectParameter(document), InitializeParameter(value, 0) {} +template <> FCDEffectParameterString::FCDEffectParameterT(FCDocument* document) +: FCDEffectParameter(document), InitializeParameterNoArg(value) {} +template <> FCDEffectParameterBool::FCDEffectParameterT(FCDocument* document) +: FCDEffectParameter(document), InitializeParameter(value, false) {} + +// +// FCDEffectParameterAnimatableT +// + +ImplementObjectTypeT(FCDEffectParameterFloat); +ImplementObjectTypeT(FCDEffectParameterFloat2); +ImplementObjectTypeT(FCDEffectParameterFloat3); +ImplementObjectTypeT(FCDEffectParameterColor3); +ImplementObjectTypeT(FCDEffectParameterVector); +ImplementObjectTypeT(FCDEffectParameterColor4); +ImplementObjectTypeT(FCDEffectParameterMatrix); + +template <> FCDEffectParameter::Type FCDEffectParameterFloat::GetType() const { return FCDEffectParameter::FLOAT; } +template <> FCDEffectParameter::Type FCDEffectParameterFloat2::GetType() const { return FCDEffectParameter::FLOAT2; } +template <> FCDEffectParameter::Type FCDEffectParameterFloat3::GetType() const { return FCDEffectParameter::FLOAT3; } +template <> FCDEffectParameter::Type FCDEffectParameterColor3::GetType() const { return FCDEffectParameter::FLOAT3; } +template <> FCDEffectParameter::Type FCDEffectParameterVector::GetType() const { return FCDEffectParameter::VECTOR; } +template <> FCDEffectParameter::Type FCDEffectParameterColor4::GetType() const { return FCDEffectParameter::VECTOR; } +template <> FCDEffectParameter::Type FCDEffectParameterMatrix::GetType() const { return FCDEffectParameter::MATRIX; } + +template <> FCDEffectParameterFloat::FCDEffectParameterAnimatableT(FCDocument* document) +: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, 0.0f) {} +template <> FCDEffectParameterFloat2::FCDEffectParameterAnimatableT(FCDocument* document) +: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMVector2::Zero) {} +template <> FCDEffectParameterFloat3::FCDEffectParameterAnimatableT(FCDocument* document) +: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMVector3::Zero) {} +template <> FCDEffectParameterColor3::FCDEffectParameterAnimatableT(FCDocument* document) +: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMVector3::One) {} +template <> FCDEffectParameterVector::FCDEffectParameterAnimatableT(FCDocument* document) +: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMVector4::Zero) {} +template <> FCDEffectParameterColor4::FCDEffectParameterAnimatableT(FCDocument* document) +: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMVector4::One) {} +template <> FCDEffectParameterMatrix::FCDEffectParameterAnimatableT(FCDocument* document) +: FCDEffectParameter(document), floatType(FLOAT), InitializeParameterAnimatable(value, FMMatrix44::Identity) {} + +// +// Another TrickLinker... +// + +template void TrickLinkerEffectParameterT() +{ + static bool toBe = false; + FCDEffectParameterT parameter(NULL); + parameter.GetType(); + parameter.SetValue(parameter.GetValue()); + toBe = parameter.IsValueEqual(¶meter); + if (toBe) + { + FCDEffectParameterT* other = (FCDEffectParameterT*) parameter.Clone(); + other->Overwrite(¶meter); + delete other; + } +} + +template void TrickLinkerEffectParameterAnimatableT() +{ + static bool toBe = false; + FCDEffectParameterAnimatableT parameter(NULL); + parameter.GetType(); + parameter.SetValue(parameter.GetValue()); + parameter.SetFloatType(parameter.GetFloatType()); + toBe = parameter.IsValueEqual(¶meter); + if (toBe) + { + FCDEffectParameterAnimatableT* other = (FCDEffectParameterAnimatableT*) parameter.Clone(); + other->Overwrite(¶meter); + delete other; + } +} + +extern void TrickLinkerEffectParameter() +{ + TrickLinkerEffectParameterT(); + TrickLinkerEffectParameterT(); + TrickLinkerEffectParameterT(); + + TrickLinkerEffectParameterAnimatableT(); + TrickLinkerEffectParameterAnimatableT(); + TrickLinkerEffectParameterAnimatableT(); + TrickLinkerEffectParameterAnimatableT(); + TrickLinkerEffectParameterAnimatableT(); + TrickLinkerEffectParameterAnimatableT(); + TrickLinkerEffectParameterAnimatableT(); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameter.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterFactory.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterFactory.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterFactory.cpp (revision 24247) @@ -1,37 +1,37 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterFactory.h" -#include "FCDocument/FCDEffectParameterSampler.h" -#include "FCDocument/FCDEffectParameterSurface.h" - -// Creates a new effect parameter, given a type. -FCDEffectParameter* FCDEffectParameterFactory::Create(FCDocument* document, uint32 type) -{ - FCDEffectParameter* parameter = NULL; - - switch (type) - { - case FCDEffectParameter::SAMPLER: parameter = new FCDEffectParameterSampler(document); break; - case FCDEffectParameter::INTEGER: parameter = new FCDEffectParameterInt(document); break; - case FCDEffectParameter::BOOLEAN: parameter = new FCDEffectParameterBool(document); break; - case FCDEffectParameter::FLOAT: parameter = new FCDEffectParameterFloat(document); break; - case FCDEffectParameter::FLOAT2: parameter = new FCDEffectParameterFloat2(document); break; - case FCDEffectParameter::FLOAT3: parameter = new FCDEffectParameterFloat3(document); break; - case FCDEffectParameter::VECTOR: parameter = new FCDEffectParameterVector(document); break; - case FCDEffectParameter::MATRIX: parameter = new FCDEffectParameterMatrix(document); break; - case FCDEffectParameter::STRING: parameter = new FCDEffectParameterString(document); break; - case FCDEffectParameter::SURFACE: parameter = new FCDEffectParameterSurface(document); break; - default: break; - } - - return parameter; -} - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterFactory.h" +#include "FCDocument/FCDEffectParameterSampler.h" +#include "FCDocument/FCDEffectParameterSurface.h" + +// Creates a new effect parameter, given a type. +FCDEffectParameter* FCDEffectParameterFactory::Create(FCDocument* document, uint32 type) +{ + FCDEffectParameter* parameter = NULL; + + switch (type) + { + case FCDEffectParameter::SAMPLER: parameter = new FCDEffectParameterSampler(document); break; + case FCDEffectParameter::INTEGER: parameter = new FCDEffectParameterInt(document); break; + case FCDEffectParameter::BOOLEAN: parameter = new FCDEffectParameterBool(document); break; + case FCDEffectParameter::FLOAT: parameter = new FCDEffectParameterFloat(document); break; + case FCDEffectParameter::FLOAT2: parameter = new FCDEffectParameterFloat2(document); break; + case FCDEffectParameter::FLOAT3: parameter = new FCDEffectParameterFloat3(document); break; + case FCDEffectParameter::VECTOR: parameter = new FCDEffectParameterVector(document); break; + case FCDEffectParameter::MATRIX: parameter = new FCDEffectParameterMatrix(document); break; + case FCDEffectParameter::STRING: parameter = new FCDEffectParameterString(document); break; + case FCDEffectParameter::SURFACE: parameter = new FCDEffectParameterSurface(document); break; + default: break; + } + + return parameter; +} + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterFactory.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSampler.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSampler.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSampler.h (revision 24247) @@ -1,137 +1,137 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectParameterSampler.h - This file contains the FCDEffectParameterSampler class. -*/ - -#ifndef _FCD_EFFECT_PARAMETER_SAMPLER_H_ -#define _FCD_EFFECT_PARAMETER_SAMPLER_H_ - -#ifndef _FCD_EFFECT_PARAMETER_H_ -#include "FCDocument/FCDEffectParameter.h" -#endif // _FCD_EFFECT_PARAMETER_H_ - -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ - -class FCDocument; -class FCDEffectPass; -class FCDEffectParameterSurface; - -/** - A COLLADA sampler effect parameter. - A sampler parameter provides the extra texturing information necessary - to correctly sample a surface parameter. - There are four types of samplers supported: 1D, 2D, 3D and cube. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectParameterSampler : public FCDEffectParameter -{ -public: - /** The type of sampling to execute. */ - enum SamplerType - { - SAMPLER1D, /** 1D sampling. */ - SAMPLER2D, /** 2D sampling. */ - SAMPLER3D, /** 3D sampling. */ - SAMPLERCUBE /** Cube-map sampling. */ - }; - -private: - DeclareObjectType(FCDEffectParameter); - - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, samplerType, FC("Sampler Type")); // SamplerType - DeclareParameterPtr(FCDEffectParameterSurface, surface, FC("Surface")); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, wrap_s, FC("Wrap Mode S")); // FUDaeTextureWrapMode::WrapMode - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, wrap_t, FC("Wrap Mode T")); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, wrap_p, FC("Wrap Mode P")); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, minFilter, FC("Min Filter")); // FUDaeTextureFilterFunction::FilterFunction - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, magFilter, FC("Mag Filter")); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, mipFilter, FC("Mip Filter")); - -public: - /** Constructor: do not use directly. - Instead, use the appropriate AddEffectParameter function. - @param document The COLLADA document that owns the effect parameter. */ - FCDEffectParameterSampler(FCDocument* document); - - /** Destructor. */ - virtual ~FCDEffectParameterSampler(); - - /** Retrieves the type of effect parameter class. - @return The parameter class type: SAMPLER. */ - virtual Type GetType() const { return SAMPLER; } - - /** Retrieves the parameter for the surface to sample. - @return The surface parameter. This pointer will be NULL if the sampler is - not yet linked to any surface.. */ - FCDEffectParameterSurface* GetSurface() { return surface; } - const FCDEffectParameterSurface* GetSurface() const { return surface; } /**< See above. */ - - /** Sets the surface parameter for the surface to sample. - @param surface The surface parameter. This pointer may be NULL - to unlink the sampler. */ - void SetSurface(FCDEffectParameterSurface* surface); - - /** Retrieves the type of sampling to do. - @return The sampling type. */ - SamplerType GetSamplerType() const { return (SamplerType) *samplerType; } - - /** Sets the type of sampling to do. - @param type The sampling type. */ - void SetSamplerType(SamplerType type) { samplerType = type; SetDirtyFlag(); } - - /** Retrieves the wrap mode (in dimension S, T or P) of the sampler. - @return The wrap mode.*/ - FUDaeTextureWrapMode::WrapMode GetWrapS() const { return (FUDaeTextureWrapMode::WrapMode) *wrap_s; } - FUDaeTextureWrapMode::WrapMode GetWrapT() const { return (FUDaeTextureWrapMode::WrapMode) *wrap_t; } /**< See above.*/ - FUDaeTextureWrapMode::WrapMode GetWrapP() const { return (FUDaeTextureWrapMode::WrapMode) *wrap_p; } /**< See above.*/ - - /** Sets the wrap mode (in dimension S, T or P) of the sampler. - @param mode The wrap mode.*/ - void SetWrapS(FUDaeTextureWrapMode::WrapMode mode) { wrap_s = mode; SetDirtyFlag(); } - void SetWrapT(FUDaeTextureWrapMode::WrapMode mode) { wrap_t = mode; SetDirtyFlag(); } /**< See above.*/ - void SetWrapP(FUDaeTextureWrapMode::WrapMode mode) { wrap_p = mode; SetDirtyFlag(); } /**< See above.*/ - - /** Retrieves the appropriate filter function (minification, magnification or mip map filtering) - of the sampler. - @return The filter function.*/ - FUDaeTextureFilterFunction::FilterFunction GetMinFilter() const { return (FUDaeTextureFilterFunction::FilterFunction) *minFilter; } - FUDaeTextureFilterFunction::FilterFunction GetMagFilter() const { return (FUDaeTextureFilterFunction::FilterFunction) *magFilter; } /**< See above.*/ - FUDaeTextureFilterFunction::FilterFunction GetMipFilter() const { return (FUDaeTextureFilterFunction::FilterFunction) *mipFilter; } /**< See above.*/ - - /** Sets the appropriate filter function (minification, magnification or mip map filtering) - of the sampler. - @param func The filter function.*/ - void SetMinFilter(FUDaeTextureFilterFunction::FilterFunction func) { minFilter = func; SetDirtyFlag(); } - void SetMagFilter(FUDaeTextureFilterFunction::FilterFunction func) { magFilter = func; SetDirtyFlag(); } /**< See above.*/ - void SetMipFilter(FUDaeTextureFilterFunction::FilterFunction func) { mipFilter = func; SetDirtyFlag(); } /**< See above.*/ - - /** Compares this parameter's value with another - @param parameter The given parameter to compare with. - @return true if the values are equal */ - virtual bool IsValueEqual(FCDEffectParameter *parameter); - - /** Creates a full copy of the effect parameter. - @param clone The cloned effect parameter. If this pointer is NULL, - a new effect parameter will be created and you - will need to delete this pointer. - @return The cloned effect parameter. */ - virtual FCDEffectParameter* Clone(FCDEffectParameter* clone = NULL) const; - - /** [INTERNAL] Overwrites the target parameter with this parameter. - This function is used during the flattening of materials. - @param target The target parameter to overwrite. */ - virtual void Overwrite(FCDEffectParameter* target); -}; - -#endif // _FCD_EFFECT_PARAMETER_SAMPLER_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectParameterSampler.h + This file contains the FCDEffectParameterSampler class. +*/ + +#ifndef _FCD_EFFECT_PARAMETER_SAMPLER_H_ +#define _FCD_EFFECT_PARAMETER_SAMPLER_H_ + +#ifndef _FCD_EFFECT_PARAMETER_H_ +#include "FCDocument/FCDEffectParameter.h" +#endif // _FCD_EFFECT_PARAMETER_H_ + +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ + +class FCDocument; +class FCDEffectPass; +class FCDEffectParameterSurface; + +/** + A COLLADA sampler effect parameter. + A sampler parameter provides the extra texturing information necessary + to correctly sample a surface parameter. + There are four types of samplers supported: 1D, 2D, 3D and cube. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectParameterSampler : public FCDEffectParameter +{ +public: + /** The type of sampling to execute. */ + enum SamplerType + { + SAMPLER1D, /** 1D sampling. */ + SAMPLER2D, /** 2D sampling. */ + SAMPLER3D, /** 3D sampling. */ + SAMPLERCUBE /** Cube-map sampling. */ + }; + +private: + DeclareObjectType(FCDEffectParameter); + + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, samplerType, FC("Sampler Type")); // SamplerType + DeclareParameterPtr(FCDEffectParameterSurface, surface, FC("Surface")); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, wrap_s, FC("Wrap Mode S")); // FUDaeTextureWrapMode::WrapMode + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, wrap_t, FC("Wrap Mode T")); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, wrap_p, FC("Wrap Mode P")); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, minFilter, FC("Min Filter")); // FUDaeTextureFilterFunction::FilterFunction + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, magFilter, FC("Mag Filter")); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, mipFilter, FC("Mip Filter")); + +public: + /** Constructor: do not use directly. + Instead, use the appropriate AddEffectParameter function. + @param document The COLLADA document that owns the effect parameter. */ + FCDEffectParameterSampler(FCDocument* document); + + /** Destructor. */ + virtual ~FCDEffectParameterSampler(); + + /** Retrieves the type of effect parameter class. + @return The parameter class type: SAMPLER. */ + virtual Type GetType() const { return SAMPLER; } + + /** Retrieves the parameter for the surface to sample. + @return The surface parameter. This pointer will be NULL if the sampler is + not yet linked to any surface.. */ + FCDEffectParameterSurface* GetSurface() { return surface; } + const FCDEffectParameterSurface* GetSurface() const { return surface; } /**< See above. */ + + /** Sets the surface parameter for the surface to sample. + @param surface The surface parameter. This pointer may be NULL + to unlink the sampler. */ + void SetSurface(FCDEffectParameterSurface* surface); + + /** Retrieves the type of sampling to do. + @return The sampling type. */ + SamplerType GetSamplerType() const { return (SamplerType) *samplerType; } + + /** Sets the type of sampling to do. + @param type The sampling type. */ + void SetSamplerType(SamplerType type) { samplerType = type; SetDirtyFlag(); } + + /** Retrieves the wrap mode (in dimension S, T or P) of the sampler. + @return The wrap mode.*/ + FUDaeTextureWrapMode::WrapMode GetWrapS() const { return (FUDaeTextureWrapMode::WrapMode) *wrap_s; } + FUDaeTextureWrapMode::WrapMode GetWrapT() const { return (FUDaeTextureWrapMode::WrapMode) *wrap_t; } /**< See above.*/ + FUDaeTextureWrapMode::WrapMode GetWrapP() const { return (FUDaeTextureWrapMode::WrapMode) *wrap_p; } /**< See above.*/ + + /** Sets the wrap mode (in dimension S, T or P) of the sampler. + @param mode The wrap mode.*/ + void SetWrapS(FUDaeTextureWrapMode::WrapMode mode) { wrap_s = mode; SetDirtyFlag(); } + void SetWrapT(FUDaeTextureWrapMode::WrapMode mode) { wrap_t = mode; SetDirtyFlag(); } /**< See above.*/ + void SetWrapP(FUDaeTextureWrapMode::WrapMode mode) { wrap_p = mode; SetDirtyFlag(); } /**< See above.*/ + + /** Retrieves the appropriate filter function (minification, magnification or mip map filtering) + of the sampler. + @return The filter function.*/ + FUDaeTextureFilterFunction::FilterFunction GetMinFilter() const { return (FUDaeTextureFilterFunction::FilterFunction) *minFilter; } + FUDaeTextureFilterFunction::FilterFunction GetMagFilter() const { return (FUDaeTextureFilterFunction::FilterFunction) *magFilter; } /**< See above.*/ + FUDaeTextureFilterFunction::FilterFunction GetMipFilter() const { return (FUDaeTextureFilterFunction::FilterFunction) *mipFilter; } /**< See above.*/ + + /** Sets the appropriate filter function (minification, magnification or mip map filtering) + of the sampler. + @param func The filter function.*/ + void SetMinFilter(FUDaeTextureFilterFunction::FilterFunction func) { minFilter = func; SetDirtyFlag(); } + void SetMagFilter(FUDaeTextureFilterFunction::FilterFunction func) { magFilter = func; SetDirtyFlag(); } /**< See above.*/ + void SetMipFilter(FUDaeTextureFilterFunction::FilterFunction func) { mipFilter = func; SetDirtyFlag(); } /**< See above.*/ + + /** Compares this parameter's value with another + @param parameter The given parameter to compare with. + @return true if the values are equal */ + virtual bool IsValueEqual(FCDEffectParameter *parameter); + + /** Creates a full copy of the effect parameter. + @param clone The cloned effect parameter. If this pointer is NULL, + a new effect parameter will be created and you + will need to delete this pointer. + @return The cloned effect parameter. */ + virtual FCDEffectParameter* Clone(FCDEffectParameter* clone = NULL) const; + + /** [INTERNAL] Overwrites the target parameter with this parameter. + This function is used during the flattening of materials. + @param target The target parameter to overwrite. */ + virtual void Overwrite(FCDEffectParameter* target); +}; + +#endif // _FCD_EFFECT_PARAMETER_SAMPLER_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSampler.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSurface.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSurface.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSurface.h (revision 24247) @@ -1,488 +1,488 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectParameterSurface.h - This file contains the FCDEffectParameterSurface class, - the FCDEffectParameterSurfaceInit interface and its derivate classes. -*/ - -#ifndef _FCD_EFFECT_PARAMETER_SURFACE_H_ -#define _FCD_EFFECT_PARAMETER_SURFACE_H_ - -#ifndef _FCD_EFFECT_PARAMETER_H_ -#include "FCDocument/FCDEffectParameter.h" -#endif // _FCD_EFFECT_PARAMETER_H_ - -class FCDImage; -class FCDEffectParameterSurfaceInit; - -/** Describes a surface format by providing hints as to - its properties. - Used by the FCDEffectParameterSurface class exclusively. */ -struct FCDFormatHint -{ - /** The color channels that the choosen format should have. */ - enum channelValues { CHANNEL_UNKNOWN, CHANNEL_RGB, CHANNEL_RGBA, CHANNEL_L, CHANNEL_LA, CHANNEL_D, CHANNEL_XYZ, CHANNEL_XYZW }; - - /** The range of the color values for the choosen format. */ - enum rangeValue { RANGE_UNKNOWN, RANGE_SNORM, RANGE_UNORM, RANGE_SINT, RANGE_UINT, RANGE_FLOAT, RANGE_LOW }; - - /** The precision of the color values for the choosen format. */ - enum precisionValue { PRECISION_UNKNOWN, PRECISION_LOW, PRECISION_MID, PRECISION_HIGH }; - - /** Additional options for the surface. */ - enum optionValue { OPT_SRGB_GAMMA, OPT_NORMALIZED3, OPT_NORMALIZED4, OPT_COMPRESSABLE }; - - channelValues channels; /**< The per-texel layout of the format */ - rangeValue range; /**< The range format of the channels */ - precisionValue precision; /**< Precision (number of bits) of the texel channels */ - fm::vector options; /**< Additional hints */ -}; - -/** - A COLLADA surface parameter. - This parameters hold the texture loading information. The texture - placement information should be held by the sampler parameter. - - @see FCDEffectParameterSampler - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectParameterSurface : public FCDEffectParameter -{ -private: - DeclareObjectType(FCDEffectParameter); - StringList names; /**< The list of image names contained in the surface */ - DeclareParameterTrackList(FCDImage, images, FC("Images")); /**< The list of images contained in the surface */ - FCDEffectParameterSurfaceInit* initMethod; /**< The initialization method of the surface */ - fm::string format; /**< Description of the surface format */ - FCDFormatHint* formatHint; /**< Hints describing the format of the surface if format is not recognized */ - FMVector3 size; /**< If specified, the forced size of the surface */ - float viewportRatio; /**< If specified, the surface is sized to a dimension based on this ratio of the viewport's dimensions in pixels */ - uint16 mipLevelCount; - bool generateMipmaps; - fm::string type; - -public: - /** Constructor: do not use directly. - Instead, use the appropriate AddEffectParameter function. - @param document The COLLADA document that owns the effect parameter. */ - FCDEffectParameterSurface(FCDocument* document); - - /** Destructor. */ - virtual ~FCDEffectParameterSurface(); - - /** Retrieves the type of effect parameter class. - @return The parameter class type: SURFACE. */ - virtual Type GetType() const { return SURFACE; } - - /** Retrieves the initialization method for the surface parameter. - The initialization method is a powerful method of describing how - to build complex textures, such as cube maps, from one or - multiple image files. - @return The surface initialization method. This pointer will be NULL, - if no initialization method is provided. */ - FCDEffectParameterSurfaceInit* GetInitMethod() { return initMethod; } - const FCDEffectParameterSurfaceInit* GetInitMethod() const { return initMethod; } /**< See above. */ - - /** Sets the initialization method for the surface parameter. - The initialization method is a powerful method of describing how - to build complex textures, such as cube maps, from one or - multiple image files. - @param method The new initialization method. - The old initialization method will be released. - You should create a new initialization method - for each surface parameter. */ - void SetInitMethod(FCDEffectParameterSurfaceInit* method); - - /** Retrieves the list of images that make up this surface. - There should never be more than six images to build a surface. - In the large majority of cases, expect one image. - @return The list of images. */ - const FCDImage** GetImages() const { return images.begin(); } /**< See above. */ - - /** Retrieves the number of COLLADA images that make up this surface. - There should never be more than six images to build a surface. - In the large majority of cases, expect one image. - @return The number of images. */ - size_t GetImageCount() const { return images.size(); } - - /** Retrieves a specific image. - @param index The index of the image. - @return The image. This pointer will be NULL if the index is out-of-bounds. */ - FCDImage* GetImage(size_t index = 0) { return index < images.size() ? images.at(index) : NULL; } - const FCDImage* GetImage(size_t index = 0) const { return index < images.size() ? images.at(index) : NULL; } /**< See above. */ - - /** Retrieves the index that matches the given image. - @param image The image to match. - @return The index within the list for this image. - This index may be -1 if no match was found. */ - size_t FindImage(const FCDImage* image) const; - - /** Adds an image to the list. - The initialization method indexes the images from this list. - This function will verify that this image does not already exist within the list, - so use the returned index. - @param image The new image. - @param index The index at which to insert the image. Set the index - to -1 in order to append the image to the list. - @return The index of the image within the list. */ - size_t AddImage(FCDImage* image, size_t index = (size_t) -1); - - /** Removes an image from the list. - The initialization method indexes the images from this list. - This function will shift all the indexes in the initialization method - so that they continue matching the correct image. - @param image The image to remove. Its memory is not released. */ - void RemoveImage(FCDImage* image); - - /** Retrieves the wanted dimensions of the surface. - This parameter is optional and may contain all zeroes to indicate - that you should read the surface dimensions from the image file(s). - @return The wanted dimensions. */ - const FMVector3& GetSize() const { return size; } - - /** Sets the wanted dimensions of the surface. - This parameter is optional and can contain all zeroes to indicate - that you should read the surface dimensions from the image file(s). - @param dimensions The wanted dimensions. */ - void SetSize(const FMVector3& dimensions) { size = dimensions; } - - /** Retrieves the viewport ratio to use when the surface is a render target. - @return The viewport ratio. */ - float GetViewportRatio() const { return viewportRatio; } - - /** Sets the viewport ratio to use when the surface is a render target. - @param ratio The viewport ratio. */ - void SetViewportRatio(float ratio) { viewportRatio = ratio; SetDirtyFlag(); } - - /** Retrieves the wanted number of mip-levels. - This parameter is optional and may be zero to indicate that you should - retrieve the mip-levels from the image file(s) or generate a full - mip-chain, depending on the mip-map generate flag. - @see GetMipMapGenerate - @return The wanted number of mip-levels. */ - uint16 GetMipLevelCount() const { return mipLevelCount; } - - /** Sets the wanted number of mip-levels. - This parameter is optional and can be zero to indicate that you should - retrieve the mip-levels from the image file(s) or generate a full - mip-chain, depending on the mip-map generate flag. - @param levelCount The wanted number of mip-levels. */ - void SetMipLevelCount(uint16 levelCount) { mipLevelCount = levelCount; SetDirtyFlag(); } - - /** Retrieves whether to generate the mip-map levels on load. - The alternative is to load the mip-map levels from the image files. - @return Whether to generate the mip-map levels on load. */ - bool IsGenerateMipMaps() const { return generateMipmaps; } - - /** Sets whether to generate the mip-map levels of load. - The alternative is to load the mip-map levels from the image files. - @param _generateMipmaps Whether to generate the mip-map levels on load. */ - void SetGenerateMipMaps(bool _generateMipmaps) { generateMipmaps = _generateMipmaps; SetDirtyFlag(); } - - /** Sets/Gets format*/ - void SetFormat(const fm::string& _format) { format = _format; SetDirtyFlag(); } - const fm::string& GetFormat(){ return format; } - - /** Sets type*/ - void SetSurfaceType(const fm::string& _type) { type = _type; SetDirtyFlag(); } - - /** Retrieves type. */ - const fm::string& GetSurfaceType() { return type; } - - /** Compares this parameter's value with another - @param parameter The given parameter to compare with. - @return true if the values are equal */ - virtual bool IsValueEqual(FCDEffectParameter *parameter); - - /** Creates a full copy of the effect parameter. - @param clone The cloned effect parameter. If this pointer is NULL, - a new effect parameter will be created and you - will need to delete this pointer. - @return The cloned effect parameter. */ - virtual FCDEffectParameter* Clone(FCDEffectParameter* clone = NULL) const; - - /** [INTERNAL] Overwrites the target parameter with this parameter. - This function is used during the flattening of materials. - @param target The target parameter to overwrite. */ - virtual void Overwrite(FCDEffectParameter* target); - - /** [INTERNAL] Retrieve the list of image names - */ - StringList& GetNames() { return names; } - - /** Adds a format hint to the surface parameter. - Will fail silently if one already exists. */ - FCDFormatHint* AddFormatHint(); - - /** Retrieves the format hint of the surface parameter. - @return The format hint of the parameter. If this pointer is NULL, - no format hint is provided. */ - inline FCDFormatHint* GetFormatHint() { return formatHint; } - inline const FCDFormatHint* GetFormatHint() const { return formatHint; } -}; - - -/** - [INTERNAL] The factory for COLLADA effect parameter surface initialization. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitFactory -{ -private: - // Never instantiate: this is a static class - FCDEffectParameterSurfaceInitFactory() {} - -public: - - /** The supported initialization types. */ - enum InitType - { - FROM, /**< Loads a surface from one simple image file. @see FCDEffectParameterSurfaceInitFrom */ - AS_NULL, /**< No initialization. This surface may be initialized by some future effect parameter override. */ - AS_TARGET, /**< Initializes an engine-specific render target for offscreen rendering. In this case, the dimensions should be provided by the surface effect parameter. */ - CUBE, /**< Loads a cube-map from one complex image file or six simple image files. @see FCDEffectParameterSurfaceInitCube */ - VOLUME, /**< Loads a 3D images for one image file. @see FCDEffectParameterSurfaceInitVolume */ - PLANAR /**< Loads a surface from one simple image file. */ - }; - - /** [INTERNAL] Creates a new effect surface initialization parameter, given a type. - @param type The type of initialization parameter to create.*/ - static FCDEffectParameterSurfaceInit* Create(InitType type); -}; - - -/** - A surface initialization method. - In COLLADA 1.4.1, this information was added to support complex surface types. - There are six types of initialization methods, described in the InitType enumerated type. - Expect the FROM initialization type in the large majority of cases. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectParameterSurfaceInit -{ -public: - /** Constructor: builds a new surface initialization method. */ - FCDEffectParameterSurfaceInit() {} - - /** Destructor. */ - virtual ~FCDEffectParameterSurfaceInit() {} - - /** Retrieves the initialization type. You cannot modify this value. - To change the initialization type of a surface parameter, create a new - surface initialization structure of the correct type. - @return The initialization type. */ - virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const = 0; - - /** Copies all member variables into clone. - @param clone a valid pointer to a FCDEffectParameterSurfaceInit object*/ - virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; -}; - -/** - A cube-map surface initialization method. -*/ -class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitCube : public FCDEffectParameterSurfaceInit -{ -public: - /** The types of cube-map initializations. */ - enum CubeType - { - ALL, /** Load all the mip-levels of all the cube-map faces from one image file. */ - PRIMARY, /** Load the first mip-level of all the cube-map faces from one image file. */ - FACE /** Load all the cube-map faces from separate image files. */ - }; - -public: - /** Constructor: builds a new cube-map initialization method. */ - FCDEffectParameterSurfaceInitCube(); - - /** Destructor. */ - virtual ~FCDEffectParameterSurfaceInitCube() {} - - /** Retrieves the initialization type. You cannot modify this value. - To change the initialization type of a surface parameter, create a new - surface initialization structure of the correct type. - @return The initialization type. */ - virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::CUBE;} - - /** Creates a full copy of the surface initialization parameter. - @param clone The cloned surface initialization. If this pointer is NULL, - a new surface initialization parameter will be created and you - will need to delete this pointer. - @return The cloned surface initialization. */ - virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; - - /** The type of cube-map initialization. */ - CubeType cubeType; - - /** The list of image indices. - The images are contained within the surface effect parameter. - This is used only for the FACE cube-map initialization type and indicates - how to match the faces of faces of the cube-map with the images in the surface effect parameter. */ - UInt16List order; -}; - -/** - A volumetric surface initialization method. -*/ -class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitVolume : public FCDEffectParameterSurfaceInit -{ -public: - /** The types of volumetric surfaces initialization. */ - enum VolumeType - { - ALL, /** Load all the mip-levels from the image file. */ - PRIMARY /** Load the first mip-level from the image file. */ - }; - -public: - /** Constructor: builds a new volumetric surface initialization method. */ - FCDEffectParameterSurfaceInitVolume(); - - /** Destructor. */ - virtual ~FCDEffectParameterSurfaceInitVolume() {} - - /** Retrieves the initialization type. You cannot modify this value. - To change the initialization type of a surface parameter, create a new - surface initialization structure of the correct type. - @return The initialization type. */ - virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::VOLUME;} - - /** Creates a full copy of the surface initialization parameter. - @param clone The cloned surface initialization. If this pointer is NULL, - a new surface initialization parameter will be created and you - will need to delete this pointer. - @return The cloned surface initialization. */ - virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; - - /** The type of volumetric initialization. */ - VolumeType volumeType; -}; - -/** - A simple file surface initialization method. - This is the method used for backward-compatibility. -*/ -class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitFrom : public FCDEffectParameterSurfaceInit -{ -public: - /** Constructor: builds a new file surface initialization method. */ - FCDEffectParameterSurfaceInitFrom() {} - - /** Destructor. */ - virtual ~FCDEffectParameterSurfaceInitFrom() {} - - /** Retrieves the initialization type. You cannot modify this value. - To change the initialization type of a surface parameter, create a new - surface initialization structure of the correct type. - @return The initialization type. */ - virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::FROM;} - - /** Creates a full copy of the surface initialization parameter. - @param clone The cloned surface initialization. If this pointer is NULL, - a new surface initialization parameter will be created and you - will need to delete this pointer. - @return The cloned surface initialization. */ - virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; - - /** The list of mip levels. */ - StringList mip; - - /** The list of matching slices. */ - StringList slice; - - /** The list of matching faces. */ - StringList face; -}; - -/** - This method allows to initialize the surface at a later point. -*/ -class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitAsNull : public FCDEffectParameterSurfaceInit -{ -public: - /** Constructor: builds a new file surface initialization method. */ - FCDEffectParameterSurfaceInitAsNull() {} - - /** Destructor. */ - virtual ~FCDEffectParameterSurfaceInitAsNull() {} - - /** Retrieves the initialization type. You cannot modify this value. - To change the initialization type of a surface parameter, create a new - surface initialization structure of the correct type. - @return The initialization type. */ - virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::AS_NULL;} - - /** Creates a full copy of the surface initialization parameter. - @param clone The cloned surface initialization. If this pointer is NULL, - a new surface initialization parameter will be created and you - will need to delete this pointer. - @return The cloned surface initialization. */ - virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; -}; - -/** - This method allows to initialize the surface as a rendering target. -*/ -class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitAsTarget : public FCDEffectParameterSurfaceInit -{ -public: - /** Constructor: builds a new file surface initialization method. */ - FCDEffectParameterSurfaceInitAsTarget() {}; - - /** Destructor. */ - virtual ~FCDEffectParameterSurfaceInitAsTarget() {} - - /** Retrieves the initialization type. You cannot modify this value. - To change the initialization type of a surface parameter, create a new - surface initialization structure of the correct type. - @return The initialization type. */ - virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::AS_TARGET;} - - /** Creates a full copy of the surface initialization parameter. - @param clone The cloned surface initialization. If this pointer is NULL, - a new surface initialization parameter will be created and you - will need to delete this pointer. - @return The surface initialization parameter. You will need to delete this pointer. */ - virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; -}; - -/** - This method allows to initialize the surface as planar. -*/ -class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitPlanar : public FCDEffectParameterSurfaceInit -{ -public: - /** Constructor: builds a new file surface initialization method. */ - FCDEffectParameterSurfaceInitPlanar() {}; - - /** Destructor. */ - virtual ~FCDEffectParameterSurfaceInitPlanar() {} - - /** Retrieves the initialization type. You cannot modify this value. - To change the initialization type of a surface parameter, create a new - surface initialization structure of the correct type. - @return The initialization type. */ - virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::PLANAR;} - - /** Creates a full copy of the surface initialization parameter. - @param clone The cloned surface initialization. If this pointer is NULL, - a new surface initialization parameter will be created and you - will need to delete this pointer. - @return The cloned surface initialization. */ - virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; -}; - - - -#endif // _FCD_EFFECT_PARAMETER_SURFACE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectParameterSurface.h + This file contains the FCDEffectParameterSurface class, + the FCDEffectParameterSurfaceInit interface and its derivate classes. +*/ + +#ifndef _FCD_EFFECT_PARAMETER_SURFACE_H_ +#define _FCD_EFFECT_PARAMETER_SURFACE_H_ + +#ifndef _FCD_EFFECT_PARAMETER_H_ +#include "FCDocument/FCDEffectParameter.h" +#endif // _FCD_EFFECT_PARAMETER_H_ + +class FCDImage; +class FCDEffectParameterSurfaceInit; + +/** Describes a surface format by providing hints as to + its properties. + Used by the FCDEffectParameterSurface class exclusively. */ +struct FCDFormatHint +{ + /** The color channels that the choosen format should have. */ + enum channelValues { CHANNEL_UNKNOWN, CHANNEL_RGB, CHANNEL_RGBA, CHANNEL_L, CHANNEL_LA, CHANNEL_D, CHANNEL_XYZ, CHANNEL_XYZW }; + + /** The range of the color values for the choosen format. */ + enum rangeValue { RANGE_UNKNOWN, RANGE_SNORM, RANGE_UNORM, RANGE_SINT, RANGE_UINT, RANGE_FLOAT, RANGE_LOW }; + + /** The precision of the color values for the choosen format. */ + enum precisionValue { PRECISION_UNKNOWN, PRECISION_LOW, PRECISION_MID, PRECISION_HIGH }; + + /** Additional options for the surface. */ + enum optionValue { OPT_SRGB_GAMMA, OPT_NORMALIZED3, OPT_NORMALIZED4, OPT_COMPRESSABLE }; + + channelValues channels; /**< The per-texel layout of the format */ + rangeValue range; /**< The range format of the channels */ + precisionValue precision; /**< Precision (number of bits) of the texel channels */ + fm::vector options; /**< Additional hints */ +}; + +/** + A COLLADA surface parameter. + This parameters hold the texture loading information. The texture + placement information should be held by the sampler parameter. + + @see FCDEffectParameterSampler + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectParameterSurface : public FCDEffectParameter +{ +private: + DeclareObjectType(FCDEffectParameter); + StringList names; /**< The list of image names contained in the surface */ + DeclareParameterTrackList(FCDImage, images, FC("Images")); /**< The list of images contained in the surface */ + FCDEffectParameterSurfaceInit* initMethod; /**< The initialization method of the surface */ + fm::string format; /**< Description of the surface format */ + FCDFormatHint* formatHint; /**< Hints describing the format of the surface if format is not recognized */ + FMVector3 size; /**< If specified, the forced size of the surface */ + float viewportRatio; /**< If specified, the surface is sized to a dimension based on this ratio of the viewport's dimensions in pixels */ + uint16 mipLevelCount; + bool generateMipmaps; + fm::string type; + +public: + /** Constructor: do not use directly. + Instead, use the appropriate AddEffectParameter function. + @param document The COLLADA document that owns the effect parameter. */ + FCDEffectParameterSurface(FCDocument* document); + + /** Destructor. */ + virtual ~FCDEffectParameterSurface(); + + /** Retrieves the type of effect parameter class. + @return The parameter class type: SURFACE. */ + virtual Type GetType() const { return SURFACE; } + + /** Retrieves the initialization method for the surface parameter. + The initialization method is a powerful method of describing how + to build complex textures, such as cube maps, from one or + multiple image files. + @return The surface initialization method. This pointer will be NULL, + if no initialization method is provided. */ + FCDEffectParameterSurfaceInit* GetInitMethod() { return initMethod; } + const FCDEffectParameterSurfaceInit* GetInitMethod() const { return initMethod; } /**< See above. */ + + /** Sets the initialization method for the surface parameter. + The initialization method is a powerful method of describing how + to build complex textures, such as cube maps, from one or + multiple image files. + @param method The new initialization method. + The old initialization method will be released. + You should create a new initialization method + for each surface parameter. */ + void SetInitMethod(FCDEffectParameterSurfaceInit* method); + + /** Retrieves the list of images that make up this surface. + There should never be more than six images to build a surface. + In the large majority of cases, expect one image. + @return The list of images. */ + const FCDImage** GetImages() const { return images.begin(); } /**< See above. */ + + /** Retrieves the number of COLLADA images that make up this surface. + There should never be more than six images to build a surface. + In the large majority of cases, expect one image. + @return The number of images. */ + size_t GetImageCount() const { return images.size(); } + + /** Retrieves a specific image. + @param index The index of the image. + @return The image. This pointer will be NULL if the index is out-of-bounds. */ + FCDImage* GetImage(size_t index = 0) { return index < images.size() ? images.at(index) : NULL; } + const FCDImage* GetImage(size_t index = 0) const { return index < images.size() ? images.at(index) : NULL; } /**< See above. */ + + /** Retrieves the index that matches the given image. + @param image The image to match. + @return The index within the list for this image. + This index may be -1 if no match was found. */ + size_t FindImage(const FCDImage* image) const; + + /** Adds an image to the list. + The initialization method indexes the images from this list. + This function will verify that this image does not already exist within the list, + so use the returned index. + @param image The new image. + @param index The index at which to insert the image. Set the index + to -1 in order to append the image to the list. + @return The index of the image within the list. */ + size_t AddImage(FCDImage* image, size_t index = (size_t) -1); + + /** Removes an image from the list. + The initialization method indexes the images from this list. + This function will shift all the indexes in the initialization method + so that they continue matching the correct image. + @param image The image to remove. Its memory is not released. */ + void RemoveImage(FCDImage* image); + + /** Retrieves the wanted dimensions of the surface. + This parameter is optional and may contain all zeroes to indicate + that you should read the surface dimensions from the image file(s). + @return The wanted dimensions. */ + const FMVector3& GetSize() const { return size; } + + /** Sets the wanted dimensions of the surface. + This parameter is optional and can contain all zeroes to indicate + that you should read the surface dimensions from the image file(s). + @param dimensions The wanted dimensions. */ + void SetSize(const FMVector3& dimensions) { size = dimensions; } + + /** Retrieves the viewport ratio to use when the surface is a render target. + @return The viewport ratio. */ + float GetViewportRatio() const { return viewportRatio; } + + /** Sets the viewport ratio to use when the surface is a render target. + @param ratio The viewport ratio. */ + void SetViewportRatio(float ratio) { viewportRatio = ratio; SetDirtyFlag(); } + + /** Retrieves the wanted number of mip-levels. + This parameter is optional and may be zero to indicate that you should + retrieve the mip-levels from the image file(s) or generate a full + mip-chain, depending on the mip-map generate flag. + @see GetMipMapGenerate + @return The wanted number of mip-levels. */ + uint16 GetMipLevelCount() const { return mipLevelCount; } + + /** Sets the wanted number of mip-levels. + This parameter is optional and can be zero to indicate that you should + retrieve the mip-levels from the image file(s) or generate a full + mip-chain, depending on the mip-map generate flag. + @param levelCount The wanted number of mip-levels. */ + void SetMipLevelCount(uint16 levelCount) { mipLevelCount = levelCount; SetDirtyFlag(); } + + /** Retrieves whether to generate the mip-map levels on load. + The alternative is to load the mip-map levels from the image files. + @return Whether to generate the mip-map levels on load. */ + bool IsGenerateMipMaps() const { return generateMipmaps; } + + /** Sets whether to generate the mip-map levels of load. + The alternative is to load the mip-map levels from the image files. + @param _generateMipmaps Whether to generate the mip-map levels on load. */ + void SetGenerateMipMaps(bool _generateMipmaps) { generateMipmaps = _generateMipmaps; SetDirtyFlag(); } + + /** Sets/Gets format*/ + void SetFormat(const fm::string& _format) { format = _format; SetDirtyFlag(); } + const fm::string& GetFormat(){ return format; } + + /** Sets type*/ + void SetSurfaceType(const fm::string& _type) { type = _type; SetDirtyFlag(); } + + /** Retrieves type. */ + const fm::string& GetSurfaceType() { return type; } + + /** Compares this parameter's value with another + @param parameter The given parameter to compare with. + @return true if the values are equal */ + virtual bool IsValueEqual(FCDEffectParameter *parameter); + + /** Creates a full copy of the effect parameter. + @param clone The cloned effect parameter. If this pointer is NULL, + a new effect parameter will be created and you + will need to delete this pointer. + @return The cloned effect parameter. */ + virtual FCDEffectParameter* Clone(FCDEffectParameter* clone = NULL) const; + + /** [INTERNAL] Overwrites the target parameter with this parameter. + This function is used during the flattening of materials. + @param target The target parameter to overwrite. */ + virtual void Overwrite(FCDEffectParameter* target); + + /** [INTERNAL] Retrieve the list of image names + */ + StringList& GetNames() { return names; } + + /** Adds a format hint to the surface parameter. + Will fail silently if one already exists. */ + FCDFormatHint* AddFormatHint(); + + /** Retrieves the format hint of the surface parameter. + @return The format hint of the parameter. If this pointer is NULL, + no format hint is provided. */ + inline FCDFormatHint* GetFormatHint() { return formatHint; } + inline const FCDFormatHint* GetFormatHint() const { return formatHint; } +}; + + +/** + [INTERNAL] The factory for COLLADA effect parameter surface initialization. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitFactory +{ +private: + // Never instantiate: this is a static class + FCDEffectParameterSurfaceInitFactory() {} + +public: + + /** The supported initialization types. */ + enum InitType + { + FROM, /**< Loads a surface from one simple image file. @see FCDEffectParameterSurfaceInitFrom */ + AS_NULL, /**< No initialization. This surface may be initialized by some future effect parameter override. */ + AS_TARGET, /**< Initializes an engine-specific render target for offscreen rendering. In this case, the dimensions should be provided by the surface effect parameter. */ + CUBE, /**< Loads a cube-map from one complex image file or six simple image files. @see FCDEffectParameterSurfaceInitCube */ + VOLUME, /**< Loads a 3D images for one image file. @see FCDEffectParameterSurfaceInitVolume */ + PLANAR /**< Loads a surface from one simple image file. */ + }; + + /** [INTERNAL] Creates a new effect surface initialization parameter, given a type. + @param type The type of initialization parameter to create.*/ + static FCDEffectParameterSurfaceInit* Create(InitType type); +}; + + +/** + A surface initialization method. + In COLLADA 1.4.1, this information was added to support complex surface types. + There are six types of initialization methods, described in the InitType enumerated type. + Expect the FROM initialization type in the large majority of cases. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectParameterSurfaceInit +{ +public: + /** Constructor: builds a new surface initialization method. */ + FCDEffectParameterSurfaceInit() {} + + /** Destructor. */ + virtual ~FCDEffectParameterSurfaceInit() {} + + /** Retrieves the initialization type. You cannot modify this value. + To change the initialization type of a surface parameter, create a new + surface initialization structure of the correct type. + @return The initialization type. */ + virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const = 0; + + /** Copies all member variables into clone. + @param clone a valid pointer to a FCDEffectParameterSurfaceInit object*/ + virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; +}; + +/** + A cube-map surface initialization method. +*/ +class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitCube : public FCDEffectParameterSurfaceInit +{ +public: + /** The types of cube-map initializations. */ + enum CubeType + { + ALL, /** Load all the mip-levels of all the cube-map faces from one image file. */ + PRIMARY, /** Load the first mip-level of all the cube-map faces from one image file. */ + FACE /** Load all the cube-map faces from separate image files. */ + }; + +public: + /** Constructor: builds a new cube-map initialization method. */ + FCDEffectParameterSurfaceInitCube(); + + /** Destructor. */ + virtual ~FCDEffectParameterSurfaceInitCube() {} + + /** Retrieves the initialization type. You cannot modify this value. + To change the initialization type of a surface parameter, create a new + surface initialization structure of the correct type. + @return The initialization type. */ + virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::CUBE;} + + /** Creates a full copy of the surface initialization parameter. + @param clone The cloned surface initialization. If this pointer is NULL, + a new surface initialization parameter will be created and you + will need to delete this pointer. + @return The cloned surface initialization. */ + virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; + + /** The type of cube-map initialization. */ + CubeType cubeType; + + /** The list of image indices. + The images are contained within the surface effect parameter. + This is used only for the FACE cube-map initialization type and indicates + how to match the faces of faces of the cube-map with the images in the surface effect parameter. */ + UInt16List order; +}; + +/** + A volumetric surface initialization method. +*/ +class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitVolume : public FCDEffectParameterSurfaceInit +{ +public: + /** The types of volumetric surfaces initialization. */ + enum VolumeType + { + ALL, /** Load all the mip-levels from the image file. */ + PRIMARY /** Load the first mip-level from the image file. */ + }; + +public: + /** Constructor: builds a new volumetric surface initialization method. */ + FCDEffectParameterSurfaceInitVolume(); + + /** Destructor. */ + virtual ~FCDEffectParameterSurfaceInitVolume() {} + + /** Retrieves the initialization type. You cannot modify this value. + To change the initialization type of a surface parameter, create a new + surface initialization structure of the correct type. + @return The initialization type. */ + virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::VOLUME;} + + /** Creates a full copy of the surface initialization parameter. + @param clone The cloned surface initialization. If this pointer is NULL, + a new surface initialization parameter will be created and you + will need to delete this pointer. + @return The cloned surface initialization. */ + virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; + + /** The type of volumetric initialization. */ + VolumeType volumeType; +}; + +/** + A simple file surface initialization method. + This is the method used for backward-compatibility. +*/ +class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitFrom : public FCDEffectParameterSurfaceInit +{ +public: + /** Constructor: builds a new file surface initialization method. */ + FCDEffectParameterSurfaceInitFrom() {} + + /** Destructor. */ + virtual ~FCDEffectParameterSurfaceInitFrom() {} + + /** Retrieves the initialization type. You cannot modify this value. + To change the initialization type of a surface parameter, create a new + surface initialization structure of the correct type. + @return The initialization type. */ + virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::FROM;} + + /** Creates a full copy of the surface initialization parameter. + @param clone The cloned surface initialization. If this pointer is NULL, + a new surface initialization parameter will be created and you + will need to delete this pointer. + @return The cloned surface initialization. */ + virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; + + /** The list of mip levels. */ + StringList mip; + + /** The list of matching slices. */ + StringList slice; + + /** The list of matching faces. */ + StringList face; +}; + +/** + This method allows to initialize the surface at a later point. +*/ +class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitAsNull : public FCDEffectParameterSurfaceInit +{ +public: + /** Constructor: builds a new file surface initialization method. */ + FCDEffectParameterSurfaceInitAsNull() {} + + /** Destructor. */ + virtual ~FCDEffectParameterSurfaceInitAsNull() {} + + /** Retrieves the initialization type. You cannot modify this value. + To change the initialization type of a surface parameter, create a new + surface initialization structure of the correct type. + @return The initialization type. */ + virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::AS_NULL;} + + /** Creates a full copy of the surface initialization parameter. + @param clone The cloned surface initialization. If this pointer is NULL, + a new surface initialization parameter will be created and you + will need to delete this pointer. + @return The cloned surface initialization. */ + virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; +}; + +/** + This method allows to initialize the surface as a rendering target. +*/ +class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitAsTarget : public FCDEffectParameterSurfaceInit +{ +public: + /** Constructor: builds a new file surface initialization method. */ + FCDEffectParameterSurfaceInitAsTarget() {}; + + /** Destructor. */ + virtual ~FCDEffectParameterSurfaceInitAsTarget() {} + + /** Retrieves the initialization type. You cannot modify this value. + To change the initialization type of a surface parameter, create a new + surface initialization structure of the correct type. + @return The initialization type. */ + virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::AS_TARGET;} + + /** Creates a full copy of the surface initialization parameter. + @param clone The cloned surface initialization. If this pointer is NULL, + a new surface initialization parameter will be created and you + will need to delete this pointer. + @return The surface initialization parameter. You will need to delete this pointer. */ + virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; +}; + +/** + This method allows to initialize the surface as planar. +*/ +class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitPlanar : public FCDEffectParameterSurfaceInit +{ +public: + /** Constructor: builds a new file surface initialization method. */ + FCDEffectParameterSurfaceInitPlanar() {}; + + /** Destructor. */ + virtual ~FCDEffectParameterSurfaceInitPlanar() {} + + /** Retrieves the initialization type. You cannot modify this value. + To change the initialization type of a surface parameter, create a new + surface initialization structure of the correct type. + @return The initialization type. */ + virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::PLANAR;} + + /** Creates a full copy of the surface initialization parameter. + @param clone The cloned surface initialization. If this pointer is NULL, + a new surface initialization parameter will be created and you + will need to delete this pointer. + @return The cloned surface initialization. */ + virtual FCDEffectParameterSurfaceInit* Clone(FCDEffectParameterSurfaceInit* clone) const; +}; + + + +#endif // _FCD_EFFECT_PARAMETER_SURFACE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectParameterSurface.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassShader.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassShader.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassShader.h (revision 24247) @@ -1,181 +1,181 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectPassShader.h - This file contains the FCDEffectPassShader and the FCDEffectPassBind classes. -*/ - -#ifndef _FCD_EFFECT_PASS_SHADER_H_ -#define _FCD_EFFECT_PASS_SHADER_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ - -class FCDocument; -class FCDEffectCode; - -/** - A COLLADA shader binding. - - Binds an external symbol to a COLLADA effect parameter, by reference. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectPassBind : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - -public: - /** Constructor. - @param document The document that owns this binding. */ - FCDEffectPassBind(FCDocument* document); - - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, reference, FC("Parameter Reference")); /**< A COLLADA effect parameter reference. */ - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, symbol, FC("Shader Symbol")); /**< An external symbol, used within the shader code. */ -}; - -/** - A COLLADA shader. - - The shader abstraction level in ColladaFX is contained within the effect passes. - There are two types of shaders: vertex shaders and fragment/pixel shaders. - A COLLADA shader contains a list of bindings to attach the effect parameters to the - shader input parameters. - - The shader object also contains the compiler information necessary to build - the shader: its code, the compiler target and the compiler options. -*/ -class FCOLLADA_EXPORT FCDEffectPassShader : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - FCDEffectPass* parent; - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, name, FC("Name")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, compilerTarget, FC("Compiler Target")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, compilerOptions, FC("Compiler Options")); - DeclareParameterContainer(FCDEffectPassBind, bindings, FC("Shader Bindings")); - DeclareParameterPtr(FCDEffectCode, code, FC("Shader Code")); - DeclareParameter(bool, FUParameterQualifiers::SIMPLE, isFragment, FC("Is Fragment Shader")); - -public: - /** Constructor: do not use directly. Instead, use the FCDEffectPass::AddShader, - FCDEffectPass::AddVertexShader or FCDEffectPass::AddFragmentShader functions. - @param parent The effect pass that contains this shader. */ - FCDEffectPassShader(FCDocument* document, FCDEffectPass* parent); - - /** Destructor. */ - virtual ~FCDEffectPassShader(); - - /** Retrieves the effect pass that contains this shader. - @return The effect pass. */ - inline FCDEffectPass* GetParent() { return parent; } - inline const FCDEffectPass* GetParent() const { return parent; } /**< See above. */ - - /** Sets this shader as affecting vertices. - This sets the stage of the shader to the vertex pipeline. */ - inline void AffectsVertices() { isFragment = false; SetDirtyFlag(); } - - /** Sets this shader as affecting fragments/pixels. - This sets the stage of the shader to the fragment/pixel pipeline. */ - inline void AffectsFragments() { isFragment = true; SetDirtyFlag(); } - - /** Retrieves whether this shader affects fragments/pixels. - @return Whether this shader affects fragments/pixels. */ - inline bool IsFragmentShader() const { return isFragment; } - - /** Retrieves whether this shader affects vertices. - @return Whether this shader affects vertices. */ - inline bool IsVertexShader() const { return !isFragment; } - - /** Retrieves the list of bindings for this shader. - @return The list of bindings. */ - DEPRECATED(3.05A, GetBindingCount and GetBinding(index)) void GetBindings() const {} - - /** Retrieves the number of bindings for this shader. - @return The number of bindings. */ - inline size_t GetBindingCount() const { return bindings.size(); } - - /** Retrieves a binding contained in this shader. - @param index The index of the binding. - @return The binding. This pointer will be NULL if the index is out-of-bounds. */ - inline FCDEffectPassBind* GetBinding(size_t index) { FUAssert(index < GetBindingCount(), return NULL); return bindings.at(index); } - inline const FCDEffectPassBind* GetBinding(size_t index) const { FUAssert(index < GetBindingCount(), return NULL); return bindings.at(index); } /**< See above. */ - - /** Retrieves a binding for a given COLLADA reference. - @param reference The reference of the parameter binding. - @return The binding. This pointer will be NULL if - the parameter is not bound in this shader. */ - const FCDEffectPassBind* FindBindingReference(const char* reference) const; - inline FCDEffectPassBind* FindBindingReference(const char* reference) { return const_cast(const_cast(this)->FindBindingReference(reference)); } /**< See above. */ - - /** Retrieves a binding for a given FX symbol. - @param symbol The symbol of the parameter binding. - @return The binding. This pointer will be NULL if - the parameter is not bound in this shader. */ - const FCDEffectPassBind* FindBindingSymbol(const char* symbol) const; - inline FCDEffectPassBind* FindBindingSymbol(const char* symbol) { return const_cast(const_cast(this)->FindBindingSymbol(symbol)); } /**< See above. */ - - /** Adds a new binding to this shader. - @return The new binding. */ - FCDEffectPassBind* AddBinding(); - - /** Releases a binding contained within this shader. - @param binding The binding to release. */ - DEPRECATED(3.05A, binding->Release()) void ReleaseBinding(FCDEffectPassBind* binding) { SAFE_RELEASE(binding); } - - /** Retrieves the compiler target information. - The validity of this string depends on the type of the profile that contains this shader. - @return The compiler target information string. */ - inline const fstring& GetCompilerTarget() const { return compilerTarget; } - - /** Sets the compiler target information string. - The validity of this string depends on the type of the profile that contains this shader. - @param _compilerTarget The compiler target information. */ - inline void SetCompilerTarget(const fchar* _compilerTarget) { compilerTarget = _compilerTarget; SetDirtyFlag(); } - - /** Retrieves the compiler option string. - The validity of this string depends on the type of the profile that contains this shader. - @return The compiler option string. */ - inline const fstring& GetCompilerOptions() const { return compilerOptions; } - - /** Sets the compiler option string. - The validity of this string depends on the type of the profile that contains this shader. - @param _compilerOptions The compiler option string. */ - inline void SetCompilerOptions(const fchar* _compilerOptions) { compilerOptions = _compilerOptions; SetDirtyFlag(); } - - /** Retrieves the sub-id of the shader. - @return The sub-id. */ - inline const fm::string& GetName() const { return name; } - - /** Sets the sub-id of the shader. - @param _name The sub-id. */ - inline void SetName(const char* _name) { name = _name; SetDirtyFlag(); } - - /** Retrieves the code inclusion that contains the code for this shader. - @return The code inclusion. This pointer will be NULL if this shader - is not yet attached to any code. */ - inline FCDEffectCode* GetCode() { return code; } - inline const FCDEffectCode* GetCode() const { return code; } /**< See above. */ - - /** Sets the code inclusion that contains the code for this shader. - @param _code The code inclusion. This pointer will be NULL to detach - a shader from its code. */ - inline void SetCode(FCDEffectCode* _code) { code = _code; SetDirtyFlag(); } - - /** Clones this shader. - @param clone The cloned shader. If this pointer is NULL, - a new shader is created and you will need to release this new shader. - @return The cloned shader. */ - FCDEffectPassShader* Clone(FCDEffectPassShader* clone) const; -}; - -#endif // _FCD_EFFECT_PASS_SHADER_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectPassShader.h + This file contains the FCDEffectPassShader and the FCDEffectPassBind classes. +*/ + +#ifndef _FCD_EFFECT_PASS_SHADER_H_ +#define _FCD_EFFECT_PASS_SHADER_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ + +class FCDocument; +class FCDEffectCode; + +/** + A COLLADA shader binding. + + Binds an external symbol to a COLLADA effect parameter, by reference. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectPassBind : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + +public: + /** Constructor. + @param document The document that owns this binding. */ + FCDEffectPassBind(FCDocument* document); + + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, reference, FC("Parameter Reference")); /**< A COLLADA effect parameter reference. */ + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, symbol, FC("Shader Symbol")); /**< An external symbol, used within the shader code. */ +}; + +/** + A COLLADA shader. + + The shader abstraction level in ColladaFX is contained within the effect passes. + There are two types of shaders: vertex shaders and fragment/pixel shaders. + A COLLADA shader contains a list of bindings to attach the effect parameters to the + shader input parameters. + + The shader object also contains the compiler information necessary to build + the shader: its code, the compiler target and the compiler options. +*/ +class FCOLLADA_EXPORT FCDEffectPassShader : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + FCDEffectPass* parent; + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, name, FC("Name")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, compilerTarget, FC("Compiler Target")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, compilerOptions, FC("Compiler Options")); + DeclareParameterContainer(FCDEffectPassBind, bindings, FC("Shader Bindings")); + DeclareParameterPtr(FCDEffectCode, code, FC("Shader Code")); + DeclareParameter(bool, FUParameterQualifiers::SIMPLE, isFragment, FC("Is Fragment Shader")); + +public: + /** Constructor: do not use directly. Instead, use the FCDEffectPass::AddShader, + FCDEffectPass::AddVertexShader or FCDEffectPass::AddFragmentShader functions. + @param parent The effect pass that contains this shader. */ + FCDEffectPassShader(FCDocument* document, FCDEffectPass* parent); + + /** Destructor. */ + virtual ~FCDEffectPassShader(); + + /** Retrieves the effect pass that contains this shader. + @return The effect pass. */ + inline FCDEffectPass* GetParent() { return parent; } + inline const FCDEffectPass* GetParent() const { return parent; } /**< See above. */ + + /** Sets this shader as affecting vertices. + This sets the stage of the shader to the vertex pipeline. */ + inline void AffectsVertices() { isFragment = false; SetDirtyFlag(); } + + /** Sets this shader as affecting fragments/pixels. + This sets the stage of the shader to the fragment/pixel pipeline. */ + inline void AffectsFragments() { isFragment = true; SetDirtyFlag(); } + + /** Retrieves whether this shader affects fragments/pixels. + @return Whether this shader affects fragments/pixels. */ + inline bool IsFragmentShader() const { return isFragment; } + + /** Retrieves whether this shader affects vertices. + @return Whether this shader affects vertices. */ + inline bool IsVertexShader() const { return !isFragment; } + + /** Retrieves the list of bindings for this shader. + @return The list of bindings. */ + DEPRECATED(3.05A, GetBindingCount and GetBinding(index)) void GetBindings() const {} + + /** Retrieves the number of bindings for this shader. + @return The number of bindings. */ + inline size_t GetBindingCount() const { return bindings.size(); } + + /** Retrieves a binding contained in this shader. + @param index The index of the binding. + @return The binding. This pointer will be NULL if the index is out-of-bounds. */ + inline FCDEffectPassBind* GetBinding(size_t index) { FUAssert(index < GetBindingCount(), return NULL); return bindings.at(index); } + inline const FCDEffectPassBind* GetBinding(size_t index) const { FUAssert(index < GetBindingCount(), return NULL); return bindings.at(index); } /**< See above. */ + + /** Retrieves a binding for a given COLLADA reference. + @param reference The reference of the parameter binding. + @return The binding. This pointer will be NULL if + the parameter is not bound in this shader. */ + const FCDEffectPassBind* FindBindingReference(const char* reference) const; + inline FCDEffectPassBind* FindBindingReference(const char* reference) { return const_cast(const_cast(this)->FindBindingReference(reference)); } /**< See above. */ + + /** Retrieves a binding for a given FX symbol. + @param symbol The symbol of the parameter binding. + @return The binding. This pointer will be NULL if + the parameter is not bound in this shader. */ + const FCDEffectPassBind* FindBindingSymbol(const char* symbol) const; + inline FCDEffectPassBind* FindBindingSymbol(const char* symbol) { return const_cast(const_cast(this)->FindBindingSymbol(symbol)); } /**< See above. */ + + /** Adds a new binding to this shader. + @return The new binding. */ + FCDEffectPassBind* AddBinding(); + + /** Releases a binding contained within this shader. + @param binding The binding to release. */ + DEPRECATED(3.05A, binding->Release()) void ReleaseBinding(FCDEffectPassBind* binding) { SAFE_RELEASE(binding); } + + /** Retrieves the compiler target information. + The validity of this string depends on the type of the profile that contains this shader. + @return The compiler target information string. */ + inline const fstring& GetCompilerTarget() const { return compilerTarget; } + + /** Sets the compiler target information string. + The validity of this string depends on the type of the profile that contains this shader. + @param _compilerTarget The compiler target information. */ + inline void SetCompilerTarget(const fchar* _compilerTarget) { compilerTarget = _compilerTarget; SetDirtyFlag(); } + + /** Retrieves the compiler option string. + The validity of this string depends on the type of the profile that contains this shader. + @return The compiler option string. */ + inline const fstring& GetCompilerOptions() const { return compilerOptions; } + + /** Sets the compiler option string. + The validity of this string depends on the type of the profile that contains this shader. + @param _compilerOptions The compiler option string. */ + inline void SetCompilerOptions(const fchar* _compilerOptions) { compilerOptions = _compilerOptions; SetDirtyFlag(); } + + /** Retrieves the sub-id of the shader. + @return The sub-id. */ + inline const fm::string& GetName() const { return name; } + + /** Sets the sub-id of the shader. + @param _name The sub-id. */ + inline void SetName(const char* _name) { name = _name; SetDirtyFlag(); } + + /** Retrieves the code inclusion that contains the code for this shader. + @return The code inclusion. This pointer will be NULL if this shader + is not yet attached to any code. */ + inline FCDEffectCode* GetCode() { return code; } + inline const FCDEffectCode* GetCode() const { return code; } /**< See above. */ + + /** Sets the code inclusion that contains the code for this shader. + @param _code The code inclusion. This pointer will be NULL to detach + a shader from its code. */ + inline void SetCode(FCDEffectCode* _code) { code = _code; SetDirtyFlag(); } + + /** Clones this shader. + @param clone The cloned shader. If this pointer is NULL, + a new shader is created and you will need to release this new shader. + @return The cloned shader. */ + FCDEffectPassShader* Clone(FCDEffectPassShader* clone) const; +}; + +#endif // _FCD_EFFECT_PASS_SHADER_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassShader.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassShader.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassShader.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassShader.cpp (revision 24247) @@ -1,106 +1,106 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffectCode.h" -#include "FCDocument/FCDEffectPass.h" -#include "FCDocument/FCDEffectPassShader.h" -#include "FCDocument/FCDEffectProfileFX.h" -#include "FCDocument/FCDEffectTechnique.h" - -// -// FCDEffectPassBind -// - -ImplementObjectType(FCDEffectPassBind); - -FCDEffectPassBind::FCDEffectPassBind(FCDocument* document) -: FCDObject(document) -, InitializeParameterNoArg(reference) -, InitializeParameterNoArg(symbol) -{ -} - -// -// FCDEffectPassShader -// - -ImplementObjectType(FCDEffectPassShader); -ImplementParameterObject(FCDEffectPassShader, FCDEffectPassBind, bindings, new FCDEffectPassBind(parent->GetDocument())); -ImplementParameterObjectNoCtr(FCDEffectPassShader, FCDEffectCode, code); - -FCDEffectPassShader::FCDEffectPassShader(FCDocument* document, FCDEffectPass* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(name) -, InitializeParameterNoArg(compilerTarget) -, InitializeParameterNoArg(compilerOptions) -, InitializeParameterNoArg(bindings) -, InitializeParameterNoArg(code) -, InitializeParameter(isFragment, false) -{ -} - -FCDEffectPassShader::~FCDEffectPassShader() -{ - parent = NULL; - code = NULL; -} - -// Retrieve the shader binding, given a COLLADA parameter reference. -const FCDEffectPassBind* FCDEffectPassShader::FindBindingReference(const char* reference) const -{ - for (const FCDEffectPassBind** it = bindings.begin(); it != bindings.end(); ++it) - { - if (IsEquivalent((*it)->reference, reference)) return (*it); - } - return NULL; -} - -const FCDEffectPassBind* FCDEffectPassShader::FindBindingSymbol(const char* symbol) const -{ - for (const FCDEffectPassBind** it = bindings.begin(); it != bindings.end(); ++it) - { - if (IsEquivalent((*it)->symbol, symbol)) return (*it); - } - return NULL; -} - -// Adds a new binding to this shader. -FCDEffectPassBind* FCDEffectPassShader::AddBinding() -{ - bindings.push_back(new FCDEffectPassBind(GetDocument())); - SetNewChildFlag(); - return bindings.back(); -} - -// Cloning -FCDEffectPassShader* FCDEffectPassShader::Clone(FCDEffectPassShader* clone) const -{ - if (clone == NULL) clone = new FCDEffectPassShader(const_cast(GetDocument()), parent); - - clone->isFragment = isFragment; - size_t bindingCount = bindings.size(); - for (size_t b = 0; b < bindingCount; ++b) - { - FCDEffectPassBind* binding = clone->AddBinding(); - binding->reference = bindings[b]->reference; - binding->symbol = bindings[b]->symbol; - } - clone->compilerTarget = compilerTarget; - clone->compilerOptions = compilerOptions; - clone->name = name; - - // Look for the new code within the parent. - if (code != NULL) - { - clone->code = clone->parent->GetParent()->FindCode(code->GetSubId()); - if (clone->code == NULL) clone->code = clone->parent->GetParent()->GetParent()->FindCode(code->GetSubId()); - } - return clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffectCode.h" +#include "FCDocument/FCDEffectPass.h" +#include "FCDocument/FCDEffectPassShader.h" +#include "FCDocument/FCDEffectProfileFX.h" +#include "FCDocument/FCDEffectTechnique.h" + +// +// FCDEffectPassBind +// + +ImplementObjectType(FCDEffectPassBind); + +FCDEffectPassBind::FCDEffectPassBind(FCDocument* document) +: FCDObject(document) +, InitializeParameterNoArg(reference) +, InitializeParameterNoArg(symbol) +{ +} + +// +// FCDEffectPassShader +// + +ImplementObjectType(FCDEffectPassShader); +ImplementParameterObject(FCDEffectPassShader, FCDEffectPassBind, bindings, new FCDEffectPassBind(parent->GetDocument())); +ImplementParameterObjectNoCtr(FCDEffectPassShader, FCDEffectCode, code); + +FCDEffectPassShader::FCDEffectPassShader(FCDocument* document, FCDEffectPass* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(name) +, InitializeParameterNoArg(compilerTarget) +, InitializeParameterNoArg(compilerOptions) +, InitializeParameterNoArg(bindings) +, InitializeParameterNoArg(code) +, InitializeParameter(isFragment, false) +{ +} + +FCDEffectPassShader::~FCDEffectPassShader() +{ + parent = NULL; + code = NULL; +} + +// Retrieve the shader binding, given a COLLADA parameter reference. +const FCDEffectPassBind* FCDEffectPassShader::FindBindingReference(const char* reference) const +{ + for (const FCDEffectPassBind** it = bindings.begin(); it != bindings.end(); ++it) + { + if (IsEquivalent((*it)->reference, reference)) return (*it); + } + return NULL; +} + +const FCDEffectPassBind* FCDEffectPassShader::FindBindingSymbol(const char* symbol) const +{ + for (const FCDEffectPassBind** it = bindings.begin(); it != bindings.end(); ++it) + { + if (IsEquivalent((*it)->symbol, symbol)) return (*it); + } + return NULL; +} + +// Adds a new binding to this shader. +FCDEffectPassBind* FCDEffectPassShader::AddBinding() +{ + bindings.push_back(new FCDEffectPassBind(GetDocument())); + SetNewChildFlag(); + return bindings.back(); +} + +// Cloning +FCDEffectPassShader* FCDEffectPassShader::Clone(FCDEffectPassShader* clone) const +{ + if (clone == NULL) clone = new FCDEffectPassShader(const_cast(GetDocument()), parent); + + clone->isFragment = isFragment; + size_t bindingCount = bindings.size(); + for (size_t b = 0; b < bindingCount; ++b) + { + FCDEffectPassBind* binding = clone->AddBinding(); + binding->reference = bindings[b]->reference; + binding->symbol = bindings[b]->symbol; + } + clone->compilerTarget = compilerTarget; + clone->compilerOptions = compilerOptions; + clone->name = name; + + // Look for the new code within the parent. + if (code != NULL) + { + clone->code = clone->parent->GetParent()->FindCode(code->GetSubId()); + if (clone->code == NULL) clone->code = clone->parent->GetParent()->GetParent()->FindCode(code->GetSubId()); + } + return clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassShader.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPass.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPass.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPass.h (revision 24247) @@ -1,159 +1,159 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectPass.h - This file contains the FCDEffectPass class. -*/ - -#ifndef _FCD_EFFECT_PASS_H_ -#define _FCD_EFFECT_PASS_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ - -class FCDEffectTechnique; -class FCDEffectParameter; -class FCDEffectPassShader; -class FCDEffectPassState; - -/** - A COLLADA effect pass. - - The effect pass contains a list of effect shaders. While they - may be missing, it does not make sense for the effect pass to - contain more than two shaders: a vertex shader and a fragment/pixel shader. - - For this reason, we provide the GetVertexShader and the GetFragmentShader - which we expect will be used for most applications, rather than looking - through the list of shader objects. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectPass : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - FCDEffectTechnique* parent; - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name")); - DeclareParameterContainer(FCDEffectPassShader, shaders, FC("Shaders")); - DeclareParameterContainer(FCDEffectPassState, states, FC("Render States")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDEffectTechnique::AddPass function. - @param document The FCollada document that owns this pass. - @param parent The effect technique that contains this effect pass. */ - FCDEffectPass(FCDocument* document, FCDEffectTechnique* parent); - - /** Destructor. */ - virtual ~FCDEffectPass(); - - /** Retrieves the effect techniques which contains this effect pass. - @return The parent technique. */ - inline FCDEffectTechnique* GetParent() { return parent; } - inline const FCDEffectTechnique* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the COLLADA id of the parent effect. - This function is mostly useful as a shortcut for debugging and reporting. - @return The COLLADA id of the parent effect. */ - DEPRECATED(3.05A, GetParent()->GetParent()->GetParent()->GetDaeId()) const fm::string& GetDaeId() const { return emptyString; } - - /** Retrieves the sub-id of the effect pass. - This sub-id is optional. - @return The sub-id. */ - inline const fstring& GetPassName() const { return name; } - - /** Sets the optional sub-id for the effect pass. - This sub-id is optional. - @param _name The sub-id. */ - inline void SetPassName(const fchar* _name) { name = _name; SetDirtyFlag(); } - - /** Retrieves the number of shaders contained within the effect pass. - @return The number of shaders. */ - inline size_t GetShaderCount() const { return shaders.size(); } - - /** Retrieves a specific shader. - @param index The index of the shader. - @return The shader. This pointer will be NULL if the index is out-of-bounds. */ - inline FCDEffectPassShader* GetShader(size_t index) { FUAssert(index < GetShaderCount(), return NULL); return shaders.at(index); } - inline const FCDEffectPassShader* GetShader(size_t index) const { FUAssert(index < GetShaderCount(), return NULL); return shaders.at(index); } /**< See above. */ - - /** Adds a new shader to the pass. - @return The new shader. */ - FCDEffectPassShader* AddShader(); - - /** Releases a shader contained within the pass. - @param shader The shader to release. */ - DEPRECATED(3.05A, shader->Release()) void ReleaseShader(FCDEffectPassShader* shader) { ((FCDObject*)shader)->Release(); } - - /** Retrieves the vertex shader for this effect pass. - @return The vertex shader. This pointer will be NULL if no - shader within the pass affects vertices. */ - inline FCDEffectPassShader* GetVertexShader() { return const_cast(const_cast(this)->GetVertexShader()); } - const FCDEffectPassShader* GetVertexShader() const; /**< See above. */ - - /** Retrieves the fragment shader for this effect pass. - @return The fragment shader. This pointer will be NULL if no - shader within the pass affects pixels/fragments. */ - inline FCDEffectPassShader* GetFragmentShader() { return const_cast(const_cast(this)->GetFragmentShader()); } - const FCDEffectPassShader* GetFragmentShader() const; /**< See above. */ - - /** Adds a new vertex shader to the pass. - If a vertex shader already exists within the pass, it will be released. - @return The new vertex shader. */ - FCDEffectPassShader* AddVertexShader(); - - /** Adds a new fragment shader to the pass. - If a fragment shader already exists within the pass, it will be released. - @return The new fragment shader. */ - FCDEffectPassShader* AddFragmentShader(); - - /** Retrieves the container of the render states for the pass. - @return The render state list. */ - DEPRECATED(3.05A, GetRenderStateCount and GetRenderState(index)) void GetRenderStates() const {} - - /** Retrieves the number of render states defined for the pass. - @return The render state count. */ - inline size_t GetRenderStateCount() const { return states.size(); } - - /** Retrieves a specific render state defined for the pass. - @param index The index of the render state. - @return The render state at the given index. */ - inline FCDEffectPassState* GetRenderState(size_t index) { FUAssert(index < states.size(), return NULL); return states.at(index); } - inline const FCDEffectPassState* GetRenderState(size_t index) const { FUAssert(index < states.size(), return NULL); return states.at(index); } /**< See above. */ - - /** Adds a new render state to the effect pass. - Render states automatically get sorted by type. - @param type The type of the render state to add. - If a render state of this type already exists within the effect pass, - it will be returned. - @return A render state of the given type. */ - FCDEffectPassState* AddRenderState(FUDaePassState::State type); - - /** Retrieves a specific render state defined for the pass. - @param type The type of the render state to retrieve. - @return The render state with the given type. This pointer will be NULL - if no render state has been defined for the given type. */ - inline FCDEffectPassState* FindRenderState(FUDaePassState::State type) { return const_cast(const_cast(this)->FindRenderState(type)); } - const FCDEffectPassState* FindRenderState(FUDaePassState::State type) const; /**< See above. */ - - /** Clones the effect pass and shaders. - @param clone The cloned pass. - If this pointer is NULL, a new pass is created and - you will need to release this new pass. - @return The cloned pass. */ - FCDEffectPass* Clone(FCDEffectPass* clone = NULL) const; -}; - -#endif +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectPass.h + This file contains the FCDEffectPass class. +*/ + +#ifndef _FCD_EFFECT_PASS_H_ +#define _FCD_EFFECT_PASS_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ + +class FCDEffectTechnique; +class FCDEffectParameter; +class FCDEffectPassShader; +class FCDEffectPassState; + +/** + A COLLADA effect pass. + + The effect pass contains a list of effect shaders. While they + may be missing, it does not make sense for the effect pass to + contain more than two shaders: a vertex shader and a fragment/pixel shader. + + For this reason, we provide the GetVertexShader and the GetFragmentShader + which we expect will be used for most applications, rather than looking + through the list of shader objects. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectPass : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + FCDEffectTechnique* parent; + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name")); + DeclareParameterContainer(FCDEffectPassShader, shaders, FC("Shaders")); + DeclareParameterContainer(FCDEffectPassState, states, FC("Render States")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDEffectTechnique::AddPass function. + @param document The FCollada document that owns this pass. + @param parent The effect technique that contains this effect pass. */ + FCDEffectPass(FCDocument* document, FCDEffectTechnique* parent); + + /** Destructor. */ + virtual ~FCDEffectPass(); + + /** Retrieves the effect techniques which contains this effect pass. + @return The parent technique. */ + inline FCDEffectTechnique* GetParent() { return parent; } + inline const FCDEffectTechnique* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the COLLADA id of the parent effect. + This function is mostly useful as a shortcut for debugging and reporting. + @return The COLLADA id of the parent effect. */ + DEPRECATED(3.05A, GetParent()->GetParent()->GetParent()->GetDaeId()) const fm::string& GetDaeId() const { return emptyString; } + + /** Retrieves the sub-id of the effect pass. + This sub-id is optional. + @return The sub-id. */ + inline const fstring& GetPassName() const { return name; } + + /** Sets the optional sub-id for the effect pass. + This sub-id is optional. + @param _name The sub-id. */ + inline void SetPassName(const fchar* _name) { name = _name; SetDirtyFlag(); } + + /** Retrieves the number of shaders contained within the effect pass. + @return The number of shaders. */ + inline size_t GetShaderCount() const { return shaders.size(); } + + /** Retrieves a specific shader. + @param index The index of the shader. + @return The shader. This pointer will be NULL if the index is out-of-bounds. */ + inline FCDEffectPassShader* GetShader(size_t index) { FUAssert(index < GetShaderCount(), return NULL); return shaders.at(index); } + inline const FCDEffectPassShader* GetShader(size_t index) const { FUAssert(index < GetShaderCount(), return NULL); return shaders.at(index); } /**< See above. */ + + /** Adds a new shader to the pass. + @return The new shader. */ + FCDEffectPassShader* AddShader(); + + /** Releases a shader contained within the pass. + @param shader The shader to release. */ + DEPRECATED(3.05A, shader->Release()) void ReleaseShader(FCDEffectPassShader* shader) { ((FCDObject*)shader)->Release(); } + + /** Retrieves the vertex shader for this effect pass. + @return The vertex shader. This pointer will be NULL if no + shader within the pass affects vertices. */ + inline FCDEffectPassShader* GetVertexShader() { return const_cast(const_cast(this)->GetVertexShader()); } + const FCDEffectPassShader* GetVertexShader() const; /**< See above. */ + + /** Retrieves the fragment shader for this effect pass. + @return The fragment shader. This pointer will be NULL if no + shader within the pass affects pixels/fragments. */ + inline FCDEffectPassShader* GetFragmentShader() { return const_cast(const_cast(this)->GetFragmentShader()); } + const FCDEffectPassShader* GetFragmentShader() const; /**< See above. */ + + /** Adds a new vertex shader to the pass. + If a vertex shader already exists within the pass, it will be released. + @return The new vertex shader. */ + FCDEffectPassShader* AddVertexShader(); + + /** Adds a new fragment shader to the pass. + If a fragment shader already exists within the pass, it will be released. + @return The new fragment shader. */ + FCDEffectPassShader* AddFragmentShader(); + + /** Retrieves the container of the render states for the pass. + @return The render state list. */ + DEPRECATED(3.05A, GetRenderStateCount and GetRenderState(index)) void GetRenderStates() const {} + + /** Retrieves the number of render states defined for the pass. + @return The render state count. */ + inline size_t GetRenderStateCount() const { return states.size(); } + + /** Retrieves a specific render state defined for the pass. + @param index The index of the render state. + @return The render state at the given index. */ + inline FCDEffectPassState* GetRenderState(size_t index) { FUAssert(index < states.size(), return NULL); return states.at(index); } + inline const FCDEffectPassState* GetRenderState(size_t index) const { FUAssert(index < states.size(), return NULL); return states.at(index); } /**< See above. */ + + /** Adds a new render state to the effect pass. + Render states automatically get sorted by type. + @param type The type of the render state to add. + If a render state of this type already exists within the effect pass, + it will be returned. + @return A render state of the given type. */ + FCDEffectPassState* AddRenderState(FUDaePassState::State type); + + /** Retrieves a specific render state defined for the pass. + @param type The type of the render state to retrieve. + @return The render state with the given type. This pointer will be NULL + if no render state has been defined for the given type. */ + inline FCDEffectPassState* FindRenderState(FUDaePassState::State type) { return const_cast(const_cast(this)->FindRenderState(type)); } + const FCDEffectPassState* FindRenderState(FUDaePassState::State type) const; /**< See above. */ + + /** Clones the effect pass and shaders. + @param clone The cloned pass. + If this pointer is NULL, a new pass is created and + you will need to release this new pass. + @return The cloned pass. */ + FCDEffectPass* Clone(FCDEffectPass* clone = NULL) const; +}; + +#endif Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPass.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPass.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPass.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPass.cpp (revision 24247) @@ -1,147 +1,147 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDEffectTechnique.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffectPass.h" -#include "FCDocument/FCDEffectPassShader.h" -#include "FCDocument/FCDEffectPassState.h" -#include "FCDocument/FCDEffectParameter.h" - -// -// FCDEffectPass -// - -ImplementObjectType(FCDEffectPass); -ImplementParameterObject(FCDEffectPass, FCDEffectPassShader, shaders, new FCDEffectPassShader(parent->GetDocument(), parent)); -ImplementParameterObjectNoCtr(FCDEffectPass, FCDEffectPassState, states); - -FCDEffectPass::FCDEffectPass(FCDocument* document, FCDEffectTechnique *_parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(name) -, InitializeParameterNoArg(shaders) -, InitializeParameterNoArg(states) -{ -} - -FCDEffectPass::~FCDEffectPass() -{ - parent = NULL; -} - -// Adds a new shader to the pass. -FCDEffectPassShader* FCDEffectPass::AddShader() -{ - FCDEffectPassShader* shader = new FCDEffectPassShader(GetDocument(), this); - shaders.push_back(shader); - SetNewChildFlag(); - return shader; -} - -// Adds a new vertex shader to the pass. -// If a vertex shader already exists within the pass, it will be released. -FCDEffectPassShader* FCDEffectPass::AddVertexShader() -{ - FCDEffectPassShader* vertexShader; - for (vertexShader = GetVertexShader(); vertexShader != NULL; vertexShader = GetVertexShader()) - { - SAFE_RELEASE(vertexShader); - } - - vertexShader = AddShader(); - vertexShader->AffectsVertices(); - SetNewChildFlag(); - return vertexShader; -} - -// Adds a new fragment shader to the pass. -// If a fragment shader already exists within the pass, it will be released. -FCDEffectPassShader* FCDEffectPass::AddFragmentShader() -{ - FCDEffectPassShader* fragmentShader; - for (fragmentShader = GetFragmentShader(); fragmentShader != NULL; fragmentShader = GetFragmentShader()) - { - SAFE_RELEASE(fragmentShader); - } - - fragmentShader = AddShader(); - fragmentShader->AffectsFragments(); - SetNewChildFlag(); - return fragmentShader; -} - -FCDEffectPass* FCDEffectPass::Clone(FCDEffectPass* clone) const -{ - if (clone == NULL) clone = new FCDEffectPass(const_cast(GetDocument()), parent); - - clone->name = name; - - // Clone the shaders - clone->shaders.reserve(shaders.size()); - for (const FCDEffectPassShader** itS = shaders.begin(); itS != shaders.end(); ++itS) - { - FCDEffectPassShader* clonedShader = clone->AddShader(); - (*itS)->Clone(clonedShader); - } - - // Clone the states - clone->states.reserve(states.size()); - for (const FCDEffectPassState** itS = states.begin(); itS != states.end(); ++itS) - { - FCDEffectPassState* clonedState = clone->AddRenderState((*itS)->GetType()); - (*itS)->Clone(clonedState); - } - - return clone; -} - -// Retrieve the type-specific shaders -const FCDEffectPassShader* FCDEffectPass::GetVertexShader() const -{ - for (const FCDEffectPassShader** itS = shaders.begin(); itS != shaders.end(); ++itS) - { - if ((*itS)->IsVertexShader()) return (*itS); - } - return NULL; -} - -const FCDEffectPassShader* FCDEffectPass::GetFragmentShader() const -{ - for (const FCDEffectPassShader** itS = shaders.begin(); itS != shaders.end(); ++itS) - { - if ((*itS)->IsFragmentShader()) return (*itS); - } - return NULL; -} - -FCDEffectPassState* FCDEffectPass::AddRenderState(FUDaePassState::State type) -{ - FCDEffectPassState* state = new FCDEffectPassState(GetDocument(), type); - - // Ordered-insertion into the states container. - size_t stateCount = states.size(); - size_t insertIndex; - for (insertIndex = 0; insertIndex < stateCount; ++insertIndex) - { - if (type < states[insertIndex]->GetType()) break; - } - states.insert(insertIndex, state); - - SetNewChildFlag(); - return state; -} - -const FCDEffectPassState* FCDEffectPass::FindRenderState(FUDaePassState::State type) const -{ - for (const FCDEffectPassState** itS = states.begin(); itS != states.end(); ++itS) - { - if ((*itS)->GetType() == type) return (*itS); - } - return NULL; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDEffectTechnique.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffectPass.h" +#include "FCDocument/FCDEffectPassShader.h" +#include "FCDocument/FCDEffectPassState.h" +#include "FCDocument/FCDEffectParameter.h" + +// +// FCDEffectPass +// + +ImplementObjectType(FCDEffectPass); +ImplementParameterObject(FCDEffectPass, FCDEffectPassShader, shaders, new FCDEffectPassShader(parent->GetDocument(), parent)); +ImplementParameterObjectNoCtr(FCDEffectPass, FCDEffectPassState, states); + +FCDEffectPass::FCDEffectPass(FCDocument* document, FCDEffectTechnique *_parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(name) +, InitializeParameterNoArg(shaders) +, InitializeParameterNoArg(states) +{ +} + +FCDEffectPass::~FCDEffectPass() +{ + parent = NULL; +} + +// Adds a new shader to the pass. +FCDEffectPassShader* FCDEffectPass::AddShader() +{ + FCDEffectPassShader* shader = new FCDEffectPassShader(GetDocument(), this); + shaders.push_back(shader); + SetNewChildFlag(); + return shader; +} + +// Adds a new vertex shader to the pass. +// If a vertex shader already exists within the pass, it will be released. +FCDEffectPassShader* FCDEffectPass::AddVertexShader() +{ + FCDEffectPassShader* vertexShader; + for (vertexShader = GetVertexShader(); vertexShader != NULL; vertexShader = GetVertexShader()) + { + SAFE_RELEASE(vertexShader); + } + + vertexShader = AddShader(); + vertexShader->AffectsVertices(); + SetNewChildFlag(); + return vertexShader; +} + +// Adds a new fragment shader to the pass. +// If a fragment shader already exists within the pass, it will be released. +FCDEffectPassShader* FCDEffectPass::AddFragmentShader() +{ + FCDEffectPassShader* fragmentShader; + for (fragmentShader = GetFragmentShader(); fragmentShader != NULL; fragmentShader = GetFragmentShader()) + { + SAFE_RELEASE(fragmentShader); + } + + fragmentShader = AddShader(); + fragmentShader->AffectsFragments(); + SetNewChildFlag(); + return fragmentShader; +} + +FCDEffectPass* FCDEffectPass::Clone(FCDEffectPass* clone) const +{ + if (clone == NULL) clone = new FCDEffectPass(const_cast(GetDocument()), parent); + + clone->name = name; + + // Clone the shaders + clone->shaders.reserve(shaders.size()); + for (const FCDEffectPassShader** itS = shaders.begin(); itS != shaders.end(); ++itS) + { + FCDEffectPassShader* clonedShader = clone->AddShader(); + (*itS)->Clone(clonedShader); + } + + // Clone the states + clone->states.reserve(states.size()); + for (const FCDEffectPassState** itS = states.begin(); itS != states.end(); ++itS) + { + FCDEffectPassState* clonedState = clone->AddRenderState((*itS)->GetType()); + (*itS)->Clone(clonedState); + } + + return clone; +} + +// Retrieve the type-specific shaders +const FCDEffectPassShader* FCDEffectPass::GetVertexShader() const +{ + for (const FCDEffectPassShader** itS = shaders.begin(); itS != shaders.end(); ++itS) + { + if ((*itS)->IsVertexShader()) return (*itS); + } + return NULL; +} + +const FCDEffectPassShader* FCDEffectPass::GetFragmentShader() const +{ + for (const FCDEffectPassShader** itS = shaders.begin(); itS != shaders.end(); ++itS) + { + if ((*itS)->IsFragmentShader()) return (*itS); + } + return NULL; +} + +FCDEffectPassState* FCDEffectPass::AddRenderState(FUDaePassState::State type) +{ + FCDEffectPassState* state = new FCDEffectPassState(GetDocument(), type); + + // Ordered-insertion into the states container. + size_t stateCount = states.size(); + size_t insertIndex; + for (insertIndex = 0; insertIndex < stateCount; ++insertIndex) + { + if (type < states[insertIndex]->GetType()) break; + } + states.insert(insertIndex, state); + + SetNewChildFlag(); + return state; +} + +const FCDEffectPassState* FCDEffectPass::FindRenderState(FUDaePassState::State type) const +{ + for (const FCDEffectPassState** itS = states.begin(); itS != states.end(); ++itS) + { + if ((*itS)->GetType() == type) return (*itS); + } + return NULL; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPass.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfile.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfile.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfile.h (revision 24247) @@ -1,114 +1,114 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectProfile.h - This file contains the FCDEffectProfile abstract class. -*/ - -#ifndef _FCD_EFFECT_PROFILE_H_ -#define _FCD_EFFECT_PROFILE_H_ - -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ - -class FCDocument; -class FCDEffect; -class FCDEffectParameter; -class FCDExtra; - -/** - The base for a COLLADA effect profile. - - COLLADA has multiple effect profiles: CG, HLSL, GLSL, GLES and the COMMON profile. - For each profile, there is a class which implements this abstract class. - This abstract class solely holds the parent effect and allows access to the - profile type. - - @see FCDEffectProfileFX FCDEffectStandard - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectProfile : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - FCDEffect* parent; - DeclareParameterContainer(FCDEffectParameter, parameters, FC("Effect Parameters")); - DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDEffect::AddProfile function. - @param document The FCollada document that owns this effect profile. - @param parent The effect which contains this profile. */ - FCDEffectProfile(FCDocument* document, FCDEffect* parent); - - /** Destructor. */ - virtual ~FCDEffectProfile(); - - /** Retrieves the profile type for this effect. - This function allows you to up-cast the pointer safely to a more specific - effect profile class. - @return The profile type. */ - virtual FUDaeProfileType::Type GetType() const = 0; - - /** Retrieves the parent effect. - This is the effect which contains this profile. - @return The parent effect. This pointer will never be NULL. */ - FCDEffect* GetParent() { return parent; } - const FCDEffect* GetParent() const { return parent; } /**< See above. */ - - /** [INTERNAL] Retrieves the COLLADA id of the parent effect. - This function is useful when reporting errors and warnings. - @return The COLLADA id of the parent effect. */ - DEPRECATED(3.05A, GetParent()->GetDaeId) const fm::string& GetDaeId() const { return emptyString; } - - /** Retrieves the extra information tree for this effect profile. - The prefered way to save extra information in FCollada is at - the entity level: FCDEffect. - @return The extra information tree. */ - inline FCDExtra* GetExtra() { return extra; } - inline const FCDExtra* GetExtra() const { return extra; } /**< See above. */ - - /** Clones the profile effect and its parameters. - @param clone The cloned profile. - If this pointer is NULL, a new profile is created and - you will need to release this new profile. - @return The cloned profile. This pointer will be NULL if the - abstract class' cloning function is used without a given clone. */ - virtual FCDEffectProfile* Clone(FCDEffectProfile* clone = NULL) const; - - /** Retrieves the number of local effect parameters - @return The number of local effect parameters. */ - inline size_t GetEffectParameterCount() const { return parameters.size(); } - - /** Retrieves a given local effect parameter. - @param index An index. - @return The local effect parameter at the given index. */ - inline FCDEffectParameter* GetEffectParameter(size_t index) { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } - inline const FCDEffectParameter* GetEffectParameter(size_t index) const { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } - - /** Adds a local effect parameter to the local list. - @see FCDEffectParameter::Type - @param type The value type of the effect parameter to create. - @return The new local effect parameter. */ - FCDEffectParameter* AddEffectParameter(uint32 type); - - /** [INTERNAL] Flattens this effect profile, pushing all the effect parameter overrides - into the effect parameter generators and moving all the parameters to the - effect technique level of abstraction. To flatten the material, use the - FCDMaterialInstance::FlattenMaterial function. */ - DEPRECATED(3.05A, not recommended) void Flatten() {} -}; - -#endif // _FCD_EFFECT_PROFILE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectProfile.h + This file contains the FCDEffectProfile abstract class. +*/ + +#ifndef _FCD_EFFECT_PROFILE_H_ +#define _FCD_EFFECT_PROFILE_H_ + +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ + +class FCDocument; +class FCDEffect; +class FCDEffectParameter; +class FCDExtra; + +/** + The base for a COLLADA effect profile. + + COLLADA has multiple effect profiles: CG, HLSL, GLSL, GLES and the COMMON profile. + For each profile, there is a class which implements this abstract class. + This abstract class solely holds the parent effect and allows access to the + profile type. + + @see FCDEffectProfileFX FCDEffectStandard + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectProfile : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + FCDEffect* parent; + DeclareParameterContainer(FCDEffectParameter, parameters, FC("Effect Parameters")); + DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDEffect::AddProfile function. + @param document The FCollada document that owns this effect profile. + @param parent The effect which contains this profile. */ + FCDEffectProfile(FCDocument* document, FCDEffect* parent); + + /** Destructor. */ + virtual ~FCDEffectProfile(); + + /** Retrieves the profile type for this effect. + This function allows you to up-cast the pointer safely to a more specific + effect profile class. + @return The profile type. */ + virtual FUDaeProfileType::Type GetType() const = 0; + + /** Retrieves the parent effect. + This is the effect which contains this profile. + @return The parent effect. This pointer will never be NULL. */ + FCDEffect* GetParent() { return parent; } + const FCDEffect* GetParent() const { return parent; } /**< See above. */ + + /** [INTERNAL] Retrieves the COLLADA id of the parent effect. + This function is useful when reporting errors and warnings. + @return The COLLADA id of the parent effect. */ + DEPRECATED(3.05A, GetParent()->GetDaeId) const fm::string& GetDaeId() const { return emptyString; } + + /** Retrieves the extra information tree for this effect profile. + The prefered way to save extra information in FCollada is at + the entity level: FCDEffect. + @return The extra information tree. */ + inline FCDExtra* GetExtra() { return extra; } + inline const FCDExtra* GetExtra() const { return extra; } /**< See above. */ + + /** Clones the profile effect and its parameters. + @param clone The cloned profile. + If this pointer is NULL, a new profile is created and + you will need to release this new profile. + @return The cloned profile. This pointer will be NULL if the + abstract class' cloning function is used without a given clone. */ + virtual FCDEffectProfile* Clone(FCDEffectProfile* clone = NULL) const; + + /** Retrieves the number of local effect parameters + @return The number of local effect parameters. */ + inline size_t GetEffectParameterCount() const { return parameters.size(); } + + /** Retrieves a given local effect parameter. + @param index An index. + @return The local effect parameter at the given index. */ + inline FCDEffectParameter* GetEffectParameter(size_t index) { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } + inline const FCDEffectParameter* GetEffectParameter(size_t index) const { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } + + /** Adds a local effect parameter to the local list. + @see FCDEffectParameter::Type + @param type The value type of the effect parameter to create. + @return The new local effect parameter. */ + FCDEffectParameter* AddEffectParameter(uint32 type); + + /** [INTERNAL] Flattens this effect profile, pushing all the effect parameter overrides + into the effect parameter generators and moving all the parameters to the + effect technique level of abstraction. To flatten the material, use the + FCDMaterialInstance::FlattenMaterial function. */ + DEPRECATED(3.05A, not recommended) void Flatten() {} +}; + +#endif // _FCD_EFFECT_PROFILE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfile.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTechnique.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTechnique.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTechnique.cpp (revision 24247) @@ -1,106 +1,106 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffect.h" -#include "FCDocument/FCDEffectCode.h" -#include "FCDocument/FCDEffectPass.h" -#include "FCDocument/FCDEffectProfileFX.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterFactory.h" -#include "FCDocument/FCDEffectTechnique.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDImage.h" - -// -// FCDEffectTechnique -// - -ImplementObjectType(FCDEffectTechnique); -ImplementParameterObject(FCDEffectTechnique, FCDEffectCode, codes, new FCDEffectCode(parent->GetDocument())); -ImplementParameterObject(FCDEffectTechnique, FCDEffectPass, passes, new FCDEffectPass(parent->GetDocument(), parent)); -ImplementParameterObjectNoCtr(FCDEffectTechnique, FCDEffectParameter, parameters); - -FCDEffectTechnique::FCDEffectTechnique(FCDocument* document, FCDEffectProfileFX *_parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(name) -, InitializeParameterNoArg(codes) -, InitializeParameterNoArg(passes) -, InitializeParameterNoArg(parameters) -{ -} - -FCDEffectTechnique::~FCDEffectTechnique() -{ - parent = NULL; -} - -// Adds a new pass to this effect technique. -FCDEffectPass* FCDEffectTechnique::AddPass() -{ - FCDEffectPass* pass = new FCDEffectPass(GetDocument(), this); - passes.push_back(pass); - SetNewChildFlag(); - return passes.back(); -} - -// Adds a new code inclusion to this effect profile. -FCDEffectCode* FCDEffectTechnique::AddCode() -{ - FCDEffectCode* code = new FCDEffectCode(GetDocument()); - codes.push_back(code); - SetNewChildFlag(); - return code; -} - -FCDEffectTechnique* FCDEffectTechnique::Clone(FCDEffectTechnique* clone) const -{ - if (clone == NULL) clone = new FCDEffectTechnique(const_cast(GetDocument()), NULL); - - clone->name = name; - size_t parameterCount = parameters.size(); - for (size_t p = 0; p < parameterCount; ++p) - { - FCDEffectParameter* parameter = clone->AddEffectParameter(parameters[p]->GetType()); - parameters[p]->Clone(parameter); - } - - // Clone the codes: need to happen before the passes are cloned - clone->codes.reserve(codes.size()); - for (const FCDEffectCode** itC = codes.begin(); itC != codes.end(); ++itC) - { - (*itC)->Clone(clone->AddCode()); - } - - // Clone the passes - clone->passes.reserve(passes.size()); - for (const FCDEffectPass** itP = passes.begin(); itP != passes.end(); ++itP) - { - (*itP)->Clone(clone->AddPass()); - } - - return clone; -} - -FCDEffectParameter* FCDEffectTechnique::AddEffectParameter(uint32 type) -{ - FCDEffectParameter* parameter = FCDEffectParameterFactory::Create(GetDocument(), type); - parameters.push_back(parameter); - SetNewChildFlag(); - return parameter; -} - -const FCDEffectCode* FCDEffectTechnique::FindCode(const char* sid) const -{ - for (const FCDEffectCode** itC = codes.begin(); itC != codes.end(); ++itC) - { - if ((*itC)->GetSubId() == sid) return (*itC); - } - return NULL; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffect.h" +#include "FCDocument/FCDEffectCode.h" +#include "FCDocument/FCDEffectPass.h" +#include "FCDocument/FCDEffectProfileFX.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterFactory.h" +#include "FCDocument/FCDEffectTechnique.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDImage.h" + +// +// FCDEffectTechnique +// + +ImplementObjectType(FCDEffectTechnique); +ImplementParameterObject(FCDEffectTechnique, FCDEffectCode, codes, new FCDEffectCode(parent->GetDocument())); +ImplementParameterObject(FCDEffectTechnique, FCDEffectPass, passes, new FCDEffectPass(parent->GetDocument(), parent)); +ImplementParameterObjectNoCtr(FCDEffectTechnique, FCDEffectParameter, parameters); + +FCDEffectTechnique::FCDEffectTechnique(FCDocument* document, FCDEffectProfileFX *_parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(name) +, InitializeParameterNoArg(codes) +, InitializeParameterNoArg(passes) +, InitializeParameterNoArg(parameters) +{ +} + +FCDEffectTechnique::~FCDEffectTechnique() +{ + parent = NULL; +} + +// Adds a new pass to this effect technique. +FCDEffectPass* FCDEffectTechnique::AddPass() +{ + FCDEffectPass* pass = new FCDEffectPass(GetDocument(), this); + passes.push_back(pass); + SetNewChildFlag(); + return passes.back(); +} + +// Adds a new code inclusion to this effect profile. +FCDEffectCode* FCDEffectTechnique::AddCode() +{ + FCDEffectCode* code = new FCDEffectCode(GetDocument()); + codes.push_back(code); + SetNewChildFlag(); + return code; +} + +FCDEffectTechnique* FCDEffectTechnique::Clone(FCDEffectTechnique* clone) const +{ + if (clone == NULL) clone = new FCDEffectTechnique(const_cast(GetDocument()), NULL); + + clone->name = name; + size_t parameterCount = parameters.size(); + for (size_t p = 0; p < parameterCount; ++p) + { + FCDEffectParameter* parameter = clone->AddEffectParameter(parameters[p]->GetType()); + parameters[p]->Clone(parameter); + } + + // Clone the codes: need to happen before the passes are cloned + clone->codes.reserve(codes.size()); + for (const FCDEffectCode** itC = codes.begin(); itC != codes.end(); ++itC) + { + (*itC)->Clone(clone->AddCode()); + } + + // Clone the passes + clone->passes.reserve(passes.size()); + for (const FCDEffectPass** itP = passes.begin(); itP != passes.end(); ++itP) + { + (*itP)->Clone(clone->AddPass()); + } + + return clone; +} + +FCDEffectParameter* FCDEffectTechnique::AddEffectParameter(uint32 type) +{ + FCDEffectParameter* parameter = FCDEffectParameterFactory::Create(GetDocument(), type); + parameters.push_back(parameter); + SetNewChildFlag(); + return parameter; +} + +const FCDEffectCode* FCDEffectTechnique::FindCode(const char* sid) const +{ + for (const FCDEffectCode** itC = codes.begin(); itC != codes.end(); ++itC) + { + if ((*itC)->GetSubId() == sid) return (*itC); + } + return NULL; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTechnique.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitter.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitter.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitter.cpp (revision 24247) @@ -1,44 +1,44 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEmitter.h" -#include "FCDocument/FCDForceField.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDEmitterParticle.h" - -// -// FCDEmitter -// - -ImplementObjectType(FCDEmitter); - -FCDEmitter::FCDEmitter(FCDocument* document) -: FCDEntity(document, "Emitter") -{ -} - -FCDEmitter::~FCDEmitter() -{ -} - -FCDEntity* FCDEmitter::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDEmitter* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDEmitter(const_cast(GetDocument())); - else if (_clone->HasType(FCDEmitter::GetClassType())) clone = (FCDEmitter*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - } - return _clone; -} - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEmitter.h" +#include "FCDocument/FCDForceField.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDEmitterParticle.h" + +// +// FCDEmitter +// + +ImplementObjectType(FCDEmitter); + +FCDEmitter::FCDEmitter(FCDocument* document) +: FCDEntity(document, "Emitter") +{ +} + +FCDEmitter::~FCDEmitter() +{ +} + +FCDEntity* FCDEmitter::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDEmitter* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDEmitter(const_cast(GetDocument())); + else if (_clone->HasType(FCDEmitter::GetClassType())) clone = (FCDEmitter*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + } + return _clone; +} + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitter.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterObject.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterObject.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterObject.cpp (revision 24247) @@ -1,9 +1,9 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterObject.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntity.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntity.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntity.cpp (revision 24247) @@ -1,131 +1,131 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAsset.h" -#include "FCDocument/FCDEntity.h" -#include "FCDocument/FCDExtra.h" - -// -// Constants -// - -static const size_t MAX_NAME_LENGTH = 512; - -// -// FCDEntity -// - -ImplementObjectType(FCDEntity); -ImplementParameterObject(FCDEntity, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObject(FCDEntity, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); - -FCDEntity::FCDEntity(FCDocument* document, const char* baseId) -: FCDObjectWithId(document, baseId) -, InitializeParameterNoArg(name) -, InitializeParameterNoArg(extra) -, InitializeParameterNoArg(asset) -, InitializeParameterNoArg(note) -{ - extra = new FCDExtra(document, this); -} - -FCDEntity::~FCDEntity() -{ -} - -// Structure cloning -FCDEntity* FCDEntity::Clone(FCDEntity* clone, bool UNUSED(cloneChildren)) const -{ - if (clone == NULL) - { - clone = new FCDEntity(const_cast(GetDocument())); - } - - FCDObjectWithId::Clone(clone); - clone->name = name; - clone->note = note; - if (extra != NULL) - { - extra->Clone(clone->extra); - } - return clone; -} - -fstring FCDEntity::CleanName(const fchar* c) -{ - size_t len = 0; - for (; len < MAX_NAME_LENGTH; len++) { if (c[len] == 0) break; } - fstring cleanName(len, *c); - fchar* id = cleanName.begin(); - if (*c != 0) - { - - // First character: alphabetic or '_'. - if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') *id = *c; - else *id = '_'; - - // Other characters: alphabetic, numeric, '_'. - // NOTE: ':' and '.' are NOT acceptable characters. - for (size_t i = 1; i < len; ++i) - { - ++id; ++c; - if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_' || *c == '-') *id = *c; - else *id = '_'; - } - *(++id) = 0; - } - return cleanName; -} - -void FCDEntity::SetName(const fstring& _name) -{ - name = CleanName(_name.c_str()); - SetDirtyFlag(); -} - -FCDAsset* FCDEntity::GetAsset() -{ - return (asset != NULL) ? asset : (asset = new FCDAsset(GetDocument())); -} - -void FCDEntity::GetHierarchicalAssets(FCDAssetConstList& assets) const -{ - if (asset != NULL) assets.push_back(asset); - else assets.push_back(GetDocument()->GetAsset()); -} - -// Look for a children with the given COLLADA Id. -const FCDEntity* FCDEntity::FindDaeId(const fm::string& _daeId) const -{ - if (GetDaeId() == _daeId) return this; - return NULL; -} - -bool FCDEntity::HasNote() const -{ - return !note->empty(); -} - -const fstring& FCDEntity::GetNote() const -{ - return *note; -} - -void FCDEntity::SetNote(const fstring& _note) -{ - note = _note; - SetDirtyFlag(); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAsset.h" +#include "FCDocument/FCDEntity.h" +#include "FCDocument/FCDExtra.h" + +// +// Constants +// + +static const size_t MAX_NAME_LENGTH = 512; + +// +// FCDEntity +// + +ImplementObjectType(FCDEntity); +ImplementParameterObject(FCDEntity, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObject(FCDEntity, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); + +FCDEntity::FCDEntity(FCDocument* document, const char* baseId) +: FCDObjectWithId(document, baseId) +, InitializeParameterNoArg(name) +, InitializeParameterNoArg(extra) +, InitializeParameterNoArg(asset) +, InitializeParameterNoArg(note) +{ + extra = new FCDExtra(document, this); +} + +FCDEntity::~FCDEntity() +{ +} + +// Structure cloning +FCDEntity* FCDEntity::Clone(FCDEntity* clone, bool UNUSED(cloneChildren)) const +{ + if (clone == NULL) + { + clone = new FCDEntity(const_cast(GetDocument())); + } + + FCDObjectWithId::Clone(clone); + clone->name = name; + clone->note = note; + if (extra != NULL) + { + extra->Clone(clone->extra); + } + return clone; +} + +fstring FCDEntity::CleanName(const fchar* c) +{ + size_t len = 0; + for (; len < MAX_NAME_LENGTH; len++) { if (c[len] == 0) break; } + fstring cleanName(len, *c); + fchar* id = cleanName.begin(); + if (*c != 0) + { + + // First character: alphabetic or '_'. + if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') *id = *c; + else *id = '_'; + + // Other characters: alphabetic, numeric, '_'. + // NOTE: ':' and '.' are NOT acceptable characters. + for (size_t i = 1; i < len; ++i) + { + ++id; ++c; + if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_' || *c == '-') *id = *c; + else *id = '_'; + } + *(++id) = 0; + } + return cleanName; +} + +void FCDEntity::SetName(const fstring& _name) +{ + name = CleanName(_name.c_str()); + SetDirtyFlag(); +} + +FCDAsset* FCDEntity::GetAsset() +{ + return (asset != NULL) ? asset : (asset = new FCDAsset(GetDocument())); +} + +void FCDEntity::GetHierarchicalAssets(FCDAssetConstList& assets) const +{ + if (asset != NULL) assets.push_back(asset); + else assets.push_back(GetDocument()->GetAsset()); +} + +// Look for a children with the given COLLADA Id. +const FCDEntity* FCDEntity::FindDaeId(const fm::string& _daeId) const +{ + if (GetDaeId() == _daeId) return this; + return NULL; +} + +bool FCDEntity::HasNote() const +{ + return !note->empty(); +} + +const fstring& FCDEntity::GetNote() const +{ + return *note; +} + +void FCDEntity::SetNote(const fstring& _note) +{ + note = _note; + SetDirtyFlag(); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntity.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityReference.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityReference.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityReference.cpp (revision 24247) @@ -1,193 +1,193 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEntity.h" -#include "FCDocument/FCDEntityReference.h" -#include "FCDocument/FCDExternalReferenceManager.h" -#include "FCDocument/FCDPlaceHolder.h" -#include "FUtils/FUFileManager.h" - -// -// FCDEntityReference -// - -ImplementObjectType(FCDEntityReference); - -FCDEntityReference::FCDEntityReference(FCDocument* document, FCDObjectWithId* _parent) -: FCDObject(document) -, entity(NULL) -, placeHolder(NULL) -, baseObject(_parent) -{ - // No need to track base object - it must track us! - // If it is deleted, it will delete us - // (Also, we never use that ptr) -} - -FCDEntityReference::~FCDEntityReference() -{ - SetPlaceHolder(NULL); - - UntrackObject(entity); - entity = NULL; -} - -FUUri FCDEntityReference::GetUri() const -{ - fstring path; - if (placeHolder != NULL) - { - FUUri uri(placeHolder->GetFileUrl()); - path = uri.GetAbsoluteUri(); - } - path.append(FC("#")); - if (entity != NULL) path.append(TO_FSTRING(entity->GetDaeId())); - else path.append(TO_FSTRING(entityId)); - return FUUri(path); -} - -const FCDEntity* FCDEntityReference::GetEntity() const -{ - if (entity == NULL) - { - // This is the part Stephen doesn't like.. - const_cast(this)->LoadEntity(); - } - return entity; -} - -void FCDEntityReference::SetUri(const FUUri& uri) -{ - entityId = TO_STRING(uri.GetFragment()); - entityId = FCDObjectWithId::CleanId(entityId); - FCDPlaceHolder* documentPlaceHolder = NULL; - - if (uri.IsFile()) - { - fstring fileUrl = GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(uri.GetAbsolutePath()); - - documentPlaceHolder = GetDocument()->GetExternalReferenceManager()->FindPlaceHolder(fileUrl); - if (documentPlaceHolder == NULL) - { - documentPlaceHolder = GetDocument()->GetExternalReferenceManager()->AddPlaceHolder(fileUrl); - } - } - SetPlaceHolder(documentPlaceHolder); - SetDirtyFlag(); -} - - - -void FCDEntityReference::SetEntity(FCDEntity* _entity) -{ - // Stop tracking the old entity - if (entity != NULL) UntrackObject(entity); - - // Track the new entity - entity = _entity; - - if (_entity != NULL) - { - TrackObject(_entity); - entityId = _entity->GetDaeId(); - // Update the external references (this takes care of the placeHolder reference) - SetEntityDocument(_entity->GetDocument()); - } - else - { - SetEntityDocument(NULL); - } - - SetNewChildFlag(); -} - - -void FCDEntityReference::SetPlaceHolder(FCDPlaceHolder* _placeHolder) -{ - if (_placeHolder != placeHolder) - { - if (placeHolder != NULL) - { - placeHolder->RemoveExternalReference(this); - UntrackObject(placeHolder); - if (placeHolder->GetExternalReferenceCount() == 0) - { - SAFE_RELEASE(placeHolder); - } - } - placeHolder = _placeHolder; - if (placeHolder != NULL) - { - placeHolder->AddExternalReference(this); - TrackObject(placeHolder); - } - SetNewChildFlag(); - } -} - -void FCDEntityReference::LoadEntity() -{ - FCDocument* entityDocument; - if (placeHolder == NULL) entityDocument = GetDocument(); - else - { - entityDocument = placeHolder->GetTarget(FCollada::GetDereferenceFlag()); - } - - if (entityDocument == NULL) - { - if (FCollada::GetDereferenceFlag()) - { - FUError::Error(FUError::ERROR_LEVEL, FUError::WARNING_MISSING_URI_TARGET); - FUFail(;); - } - return; - } - - if (!entityId.empty()) - { - entity = entityDocument->FindEntity(entityId); - if (entity != NULL) TrackObject(entity); - else - { - FUError::Error(FUError::ERROR_LEVEL, FUError::ERROR_INVALID_URI); - FUFail(return); - } - } -} - -void FCDEntityReference::SetEntityDocument(FCDocument* document) -{ - FCDPlaceHolder* documentPlaceHolder = NULL; - if (document != NULL && document != GetDocument()) - { - documentPlaceHolder = GetDocument()->GetExternalReferenceManager()->FindPlaceHolder(document); - if (documentPlaceHolder == NULL) - { - documentPlaceHolder = GetDocument()->GetExternalReferenceManager()->AddPlaceHolder(document); - } - } - SetPlaceHolder(documentPlaceHolder); -} - -void FCDEntityReference::OnObjectReleased(FUTrackable* object) -{ - if (placeHolder == object) - { - placeHolder = NULL; - } - else if (entity == object) - { - if (placeHolder == NULL) entityId.clear(); - else entityId = ((FCDObjectWithId*) object)->GetDaeId(); - entity = NULL; - } - else { FUBreak; } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEntity.h" +#include "FCDocument/FCDEntityReference.h" +#include "FCDocument/FCDExternalReferenceManager.h" +#include "FCDocument/FCDPlaceHolder.h" +#include "FUtils/FUFileManager.h" + +// +// FCDEntityReference +// + +ImplementObjectType(FCDEntityReference); + +FCDEntityReference::FCDEntityReference(FCDocument* document, FCDObjectWithId* _parent) +: FCDObject(document) +, entity(NULL) +, placeHolder(NULL) +, baseObject(_parent) +{ + // No need to track base object - it must track us! + // If it is deleted, it will delete us + // (Also, we never use that ptr) +} + +FCDEntityReference::~FCDEntityReference() +{ + SetPlaceHolder(NULL); + + UntrackObject(entity); + entity = NULL; +} + +FUUri FCDEntityReference::GetUri() const +{ + fstring path; + if (placeHolder != NULL) + { + FUUri uri(placeHolder->GetFileUrl()); + path = uri.GetAbsoluteUri(); + } + path.append(FC("#")); + if (entity != NULL) path.append(TO_FSTRING(entity->GetDaeId())); + else path.append(TO_FSTRING(entityId)); + return FUUri(path); +} + +const FCDEntity* FCDEntityReference::GetEntity() const +{ + if (entity == NULL) + { + // This is the part Stephen doesn't like.. + const_cast(this)->LoadEntity(); + } + return entity; +} + +void FCDEntityReference::SetUri(const FUUri& uri) +{ + entityId = TO_STRING(uri.GetFragment()); + entityId = FCDObjectWithId::CleanId(entityId); + FCDPlaceHolder* documentPlaceHolder = NULL; + + if (uri.IsFile()) + { + fstring fileUrl = GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(uri.GetAbsolutePath()); + + documentPlaceHolder = GetDocument()->GetExternalReferenceManager()->FindPlaceHolder(fileUrl); + if (documentPlaceHolder == NULL) + { + documentPlaceHolder = GetDocument()->GetExternalReferenceManager()->AddPlaceHolder(fileUrl); + } + } + SetPlaceHolder(documentPlaceHolder); + SetDirtyFlag(); +} + + + +void FCDEntityReference::SetEntity(FCDEntity* _entity) +{ + // Stop tracking the old entity + if (entity != NULL) UntrackObject(entity); + + // Track the new entity + entity = _entity; + + if (_entity != NULL) + { + TrackObject(_entity); + entityId = _entity->GetDaeId(); + // Update the external references (this takes care of the placeHolder reference) + SetEntityDocument(_entity->GetDocument()); + } + else + { + SetEntityDocument(NULL); + } + + SetNewChildFlag(); +} + + +void FCDEntityReference::SetPlaceHolder(FCDPlaceHolder* _placeHolder) +{ + if (_placeHolder != placeHolder) + { + if (placeHolder != NULL) + { + placeHolder->RemoveExternalReference(this); + UntrackObject(placeHolder); + if (placeHolder->GetExternalReferenceCount() == 0) + { + SAFE_RELEASE(placeHolder); + } + } + placeHolder = _placeHolder; + if (placeHolder != NULL) + { + placeHolder->AddExternalReference(this); + TrackObject(placeHolder); + } + SetNewChildFlag(); + } +} + +void FCDEntityReference::LoadEntity() +{ + FCDocument* entityDocument; + if (placeHolder == NULL) entityDocument = GetDocument(); + else + { + entityDocument = placeHolder->GetTarget(FCollada::GetDereferenceFlag()); + } + + if (entityDocument == NULL) + { + if (FCollada::GetDereferenceFlag()) + { + FUError::Error(FUError::ERROR_LEVEL, FUError::WARNING_MISSING_URI_TARGET); + FUFail(;); + } + return; + } + + if (!entityId.empty()) + { + entity = entityDocument->FindEntity(entityId); + if (entity != NULL) TrackObject(entity); + else + { + FUError::Error(FUError::ERROR_LEVEL, FUError::ERROR_INVALID_URI); + FUFail(return); + } + } +} + +void FCDEntityReference::SetEntityDocument(FCDocument* document) +{ + FCDPlaceHolder* documentPlaceHolder = NULL; + if (document != NULL && document != GetDocument()) + { + documentPlaceHolder = GetDocument()->GetExternalReferenceManager()->FindPlaceHolder(document); + if (documentPlaceHolder == NULL) + { + documentPlaceHolder = GetDocument()->GetExternalReferenceManager()->AddPlaceHolder(document); + } + } + SetPlaceHolder(documentPlaceHolder); +} + +void FCDEntityReference::OnObjectReleased(FUTrackable* object) +{ + if (placeHolder == object) + { + placeHolder = NULL; + } + else if (entity == object) + { + if (placeHolder == NULL) entityId.clear(); + else entityId = ((FCDObjectWithId*) object)->GetDaeId(); + entity = NULL; + } + else { FUBreak; } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityReference.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExtra.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExtra.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExtra.cpp (revision 24247) @@ -1,413 +1,413 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDExtra.h" -#include "FColladaPlugin.h" - - -namespace FCollada { extern FColladaPluginManager* pluginManager; } - -// -// FCDExtra -// - -ImplementObjectType(FCDExtra); -ImplementParameterObject(FCDExtra, FCDEType, types, new FCDEType(parent->GetDocument(), parent, emptyCharString)); - -FCDExtra::FCDExtra(FCDocument* document, FUObject* _parent) -: FCDObject(document) -, parent(_parent) -, InitializeParameterNoArg(types) -{ - // Create the default extra type. - types.push_back(new FCDEType(document, this, emptyCharString)); - document->RegisterExtraTree(this); -} - -FCDExtra::~FCDExtra() -{ - GetDocument()->UnregisterExtraTree(this); -} - -// Adds a type of the given name (or return the existing type with this name). -FCDEType* FCDExtra::AddType(const char* name) -{ - FCDEType* type = FindType(name); - if (type == NULL) - { - type = new FCDEType(GetDocument(), this, emptyCharString); - types.push_back(type); - type->SetName(name); - SetNewChildFlag(); - } - return type; -} - -// Search for a profile-specific type -const FCDEType* FCDExtra::FindType(const char* name) const -{ - for (const FCDEType** itT = types.begin(); itT != types.end(); ++itT) - { - if (IsEquivalent((*itT)->GetName(), name)) return *itT; - } - return NULL; -} - -bool FCDExtra::HasContent() const -{ - if (types.empty()) return false; - for (const FCDEType** itT = types.begin(); itT != types.end(); ++itT) - { - size_t techniqueCount = (*itT)->GetTechniqueCount(); - for (size_t i = 0; i < techniqueCount; ++i) - { - const FCDETechnique* technique = (*itT)->GetTechnique(i); - if (technique->GetChildNodeCount() > 0) return true; - } - } - return false; -} - -FCDExtra* FCDExtra::Clone(FCDExtra* clone) const -{ - if (clone == NULL) clone = new FCDExtra(const_cast(GetDocument()), NULL); - - // Create all the types - clone->types.reserve(types.size()); - for (const FCDEType** itT = types.begin(); itT != types.end(); ++itT) - { - FCDEType* cloneT = clone->AddType((*itT)->GetName()); - (*itT)->Clone(cloneT); - } - return clone; -} - -// -// FCDEType -// - -ImplementObjectType(FCDEType); -ImplementParameterObject(FCDEType, FCDETechnique, techniques, new FCDETechnique(parent->GetDocument(), parent, emptyCharString)); - -FCDEType::FCDEType(FCDocument* document, FCDExtra* _parent, const char* _name) -: FCDObject(document) -, parent(_parent) -, InitializeParameter(name, _name) -, InitializeParameterNoArg(techniques) -{ -} - -FCDEType::~FCDEType() -{ -} - -// Adds a technique of the given profile (or return the existing technique with this profile). -FCDETechnique* FCDEType::AddTechnique(const char* profile) -{ - FCDETechnique* technique = FindTechnique(profile); - if (technique == NULL) - { - technique = new FCDETechnique(GetDocument(), this, profile); - techniques.push_back(technique); - SetNewChildFlag(); - } - return technique; -} - -// Search for a profile-specific technique -const FCDETechnique* FCDEType::FindTechnique(const char* profile) const -{ - for (const FCDETechnique** itT = techniques.begin(); itT != techniques.end(); ++itT) - { - if (IsEquivalent((*itT)->GetProfile(), profile)) return *itT; - } - return NULL; -} - -// Search for a root node with a specific element name -const FCDENode* FCDEType::FindRootNode(const char* name) const -{ - const FCDENode* rootNode = NULL; - for (const FCDETechnique** itT = techniques.begin(); itT != techniques.end(); ++itT) - { - rootNode = (*itT)->FindChildNode(name); - if (rootNode != NULL) break; - } - return rootNode; -} - -FCDEType* FCDEType::Clone(FCDEType* clone) const -{ - // If no clone is given: create one - if (clone == NULL) - { - clone = new FCDEType(const_cast(GetDocument()), NULL, name->c_str()); - } - - clone->techniques.reserve(techniques.size()); - for (const FCDETechnique** itT = techniques.begin(); itT != techniques.end(); ++itT) - { - FCDETechnique* cloneT = clone->AddTechnique((*itT)->GetProfile()); - (*itT)->Clone(cloneT); - } - return clone; -} - -// -// FCDENode -// - -ImplementObjectType(FCDENode); -ImplementParameterObject(FCDENode, FCDENode, children, new FCDENode(parent->GetDocument(), parent)); -ImplementParameterObjectNoArg(FCDENode, FCDEAttribute, attributes); -ImplementParameterObject(FCDENode, FCDAnimatedCustom, animated, new FCDAnimatedCustom(parent->GetDocument())); - -FCDENode::FCDENode(FCDocument* document, FCDENode* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(name) -, InitializeParameterNoArg(content) -, InitializeParameterNoArg(children) -, InitializeParameterNoArg(attributes) -, InitializeParameterNoArg(animated) -{ - animated = new FCDAnimatedCustom(this); -} - -FCDENode::~FCDENode() -{ - parent = NULL; -} - -void FCDENode::SetContent(const fchar* _content) -{ - // As COLLADA doesn't allow for mixed content, release all the children. - while (!children.empty()) - { - children.back()->Release(); - } - - content = _content; - SetDirtyFlag(); -} - -void FCDENode::SetAnimated(FCDAnimatedCustom* animatedCustom) -{ - SAFE_RELEASE(animated); - animated = animatedCustom; -} - -// Search for a children with a specific name -const FCDENode* FCDENode::FindChildNode(const char* name) const -{ - for (const FCDENode** itN = children.begin(); itN != children.end(); ++itN) - { - if (IsEquivalent((*itN)->GetName(), name)) return (*itN); - } - return NULL; -} - -void FCDENode::FindChildrenNodes(const char* name, FCDENodeList& nodes) const -{ - for (const FCDENode** itN = children.begin(); itN != children.end(); ++itN) - { - if (IsEquivalent((*itN)->GetName(), name)) nodes.push_back(const_cast(*itN)); - } -} - -const FCDENode* FCDENode::FindParameter(const char* name) const -{ - for (const FCDENode** itN = children.begin(); itN != children.end(); ++itN) - { - const FCDENode* node = (*itN); - if (IsEquivalent(node->GetName(), name)) return node; - } - return NULL; -} - -void FCDENode::FindParameters(FCDENodeList& nodes, StringList& names) -{ - for (const FCDENode** itN = (const FCDENode**) children.begin(); itN != children.end(); ++itN) - { - const FCDENode* node = (*itN); - if (node->GetChildNodeCount() == 0) - { - nodes.push_back(const_cast(node)); - names.push_back(node->GetName()); - } - } -} - -void FCDENode::SetName(fm::string& _name) -{ - name = _name; - CleanName(name); - SetDirtyFlag(); -} - -void FCDENode::CleanName(fm::string& n) -{ - size_t length = n.length(); - if (length == 0) return; - - // First character must be alphabetic or the underscore. - if (n[0] != '_' && !(n[0] >= 'a' && n[0] <= 'z') && !(n[0] >= 'A' && n[0] <= 'Z')) - { - n[0] = '_'; - } - - // Other characters must be alpha-numeric or the underscore. - for (size_t i = 1; i < length; ++i) - { - char& c = n[i]; - if (c != '_' && !(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && !(c >= '0' && c <= '9')) - { - c = '_'; - } - } -} - -const fchar* FCDENode::GetContent() const -{ - return content->c_str(); -} - -// Adds a new attribute to this extra tree node. -FCDEAttribute* FCDENode::AddAttribute(fm::string& _name, const fchar* _value) -{ - CleanName(_name); - FCDEAttribute* attribute = FindAttribute(_name.c_str()); - if (attribute == NULL) - { - attribute = new FCDEAttribute(); - attributes.push_back(attribute); - attribute->SetName(_name); - } - - attribute->SetValue(_value); - SetNewChildFlag(); - return attribute; -} - -// Search for an attribute with a specific name -const FCDEAttribute* FCDENode::FindAttribute(const char* name) const -{ - for (const FCDEAttribute** itA = attributes.begin(); itA != attributes.end(); ++itA) - { - if (IsEquivalent((*itA)->GetName(), name)) return (*itA); - } - return NULL; -} - -const fstring& FCDENode::ReadAttribute(const char* name) const -{ - const FCDEAttribute* attribute = FindAttribute(name); - return (attribute != NULL) ? attribute->GetValue() : emptyFString; -} - -FCDENode* FCDENode::AddParameter(const char* name, const fchar* value) -{ - FCDENode* parameter = AddChildNode(); - parameter->SetName(name); - parameter->SetContent(value); - SetNewChildFlag(); - return parameter; -} - -FCDENode* FCDENode::Clone(FCDENode* clone) const -{ - if (clone == NULL) return NULL; - - clone->name = name; - clone->content = content; - - clone->attributes.reserve(attributes.size()); - for (const FCDEAttribute** itA = attributes.begin(); itA != attributes.end(); ++itA) - { - clone->AddAttribute((*itA)->GetName(), (*itA)->GetValue()); - } - - clone->children.reserve(children.size()); - for (const FCDENode** itC = children.begin(); itC != children.end(); ++itC) - { - FCDENode* clonedChild = clone->AddChildNode(); - (*itC)->Clone(clonedChild); - } - - // TODO: Clone the animated custom.. - - return clone; -} - -FCDENode* FCDENode::AddChildNode() -{ - FCDENode* node = new FCDENode(GetDocument(), this); - children.push_back(node); - SetNewChildFlag(); - return node; -} - -FCDENode* FCDENode::AddChildNode(const char* name) -{ - FCDENode* node = new FCDENode(GetDocument(), this); - children.push_back(node); - node->SetName(name); - SetNewChildFlag(); - return node; -} - -// -// FCDETechnique -// - -ImplementObjectType(FCDETechnique); -ImplementParameterObjectNoCtr(FCDETechnique, FUObject, pluginOverride); - -FCDETechnique::FCDETechnique(FCDocument* document, FCDEType* _parent, const char* _profile) -: FCDENode(document, NULL), parent(_parent) -, InitializeParameterNoArg(pluginOverride) -, InitializeParameter(profile, _profile) -{ -} - -FCDETechnique::~FCDETechnique() {} - -FCDENode* FCDETechnique::Clone(FCDENode* clone) const -{ - if (clone == NULL) - { - clone = new FCDETechnique(const_cast(GetDocument()), NULL, profile->c_str()); - } - else if (clone->GetObjectType().Includes(FCDETechnique::GetClassType())) - { - ((FCDETechnique*) clone)->profile = profile; - } - - FCDENode::Clone(clone); - return clone; -} - -// -// FCDEAttribute -// - -FCDEAttribute::FCDEAttribute() -: FUParameterizable() -, InitializeParameterNoArg(name) -, InitializeParameterNoArg(value) -{ -} - -FCDEAttribute::FCDEAttribute(const char* _name, const fchar* _value) -: FUParameterizable() -, InitializeParameter(name, _name) -, InitializeParameter(value, _value) -{ -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDExtra.h" +#include "FColladaPlugin.h" + + +namespace FCollada { extern FColladaPluginManager* pluginManager; } + +// +// FCDExtra +// + +ImplementObjectType(FCDExtra); +ImplementParameterObject(FCDExtra, FCDEType, types, new FCDEType(parent->GetDocument(), parent, emptyCharString)); + +FCDExtra::FCDExtra(FCDocument* document, FUObject* _parent) +: FCDObject(document) +, parent(_parent) +, InitializeParameterNoArg(types) +{ + // Create the default extra type. + types.push_back(new FCDEType(document, this, emptyCharString)); + document->RegisterExtraTree(this); +} + +FCDExtra::~FCDExtra() +{ + GetDocument()->UnregisterExtraTree(this); +} + +// Adds a type of the given name (or return the existing type with this name). +FCDEType* FCDExtra::AddType(const char* name) +{ + FCDEType* type = FindType(name); + if (type == NULL) + { + type = new FCDEType(GetDocument(), this, emptyCharString); + types.push_back(type); + type->SetName(name); + SetNewChildFlag(); + } + return type; +} + +// Search for a profile-specific type +const FCDEType* FCDExtra::FindType(const char* name) const +{ + for (const FCDEType** itT = types.begin(); itT != types.end(); ++itT) + { + if (IsEquivalent((*itT)->GetName(), name)) return *itT; + } + return NULL; +} + +bool FCDExtra::HasContent() const +{ + if (types.empty()) return false; + for (const FCDEType** itT = types.begin(); itT != types.end(); ++itT) + { + size_t techniqueCount = (*itT)->GetTechniqueCount(); + for (size_t i = 0; i < techniqueCount; ++i) + { + const FCDETechnique* technique = (*itT)->GetTechnique(i); + if (technique->GetChildNodeCount() > 0) return true; + } + } + return false; +} + +FCDExtra* FCDExtra::Clone(FCDExtra* clone) const +{ + if (clone == NULL) clone = new FCDExtra(const_cast(GetDocument()), NULL); + + // Create all the types + clone->types.reserve(types.size()); + for (const FCDEType** itT = types.begin(); itT != types.end(); ++itT) + { + FCDEType* cloneT = clone->AddType((*itT)->GetName()); + (*itT)->Clone(cloneT); + } + return clone; +} + +// +// FCDEType +// + +ImplementObjectType(FCDEType); +ImplementParameterObject(FCDEType, FCDETechnique, techniques, new FCDETechnique(parent->GetDocument(), parent, emptyCharString)); + +FCDEType::FCDEType(FCDocument* document, FCDExtra* _parent, const char* _name) +: FCDObject(document) +, parent(_parent) +, InitializeParameter(name, _name) +, InitializeParameterNoArg(techniques) +{ +} + +FCDEType::~FCDEType() +{ +} + +// Adds a technique of the given profile (or return the existing technique with this profile). +FCDETechnique* FCDEType::AddTechnique(const char* profile) +{ + FCDETechnique* technique = FindTechnique(profile); + if (technique == NULL) + { + technique = new FCDETechnique(GetDocument(), this, profile); + techniques.push_back(technique); + SetNewChildFlag(); + } + return technique; +} + +// Search for a profile-specific technique +const FCDETechnique* FCDEType::FindTechnique(const char* profile) const +{ + for (const FCDETechnique** itT = techniques.begin(); itT != techniques.end(); ++itT) + { + if (IsEquivalent((*itT)->GetProfile(), profile)) return *itT; + } + return NULL; +} + +// Search for a root node with a specific element name +const FCDENode* FCDEType::FindRootNode(const char* name) const +{ + const FCDENode* rootNode = NULL; + for (const FCDETechnique** itT = techniques.begin(); itT != techniques.end(); ++itT) + { + rootNode = (*itT)->FindChildNode(name); + if (rootNode != NULL) break; + } + return rootNode; +} + +FCDEType* FCDEType::Clone(FCDEType* clone) const +{ + // If no clone is given: create one + if (clone == NULL) + { + clone = new FCDEType(const_cast(GetDocument()), NULL, name->c_str()); + } + + clone->techniques.reserve(techniques.size()); + for (const FCDETechnique** itT = techniques.begin(); itT != techniques.end(); ++itT) + { + FCDETechnique* cloneT = clone->AddTechnique((*itT)->GetProfile()); + (*itT)->Clone(cloneT); + } + return clone; +} + +// +// FCDENode +// + +ImplementObjectType(FCDENode); +ImplementParameterObject(FCDENode, FCDENode, children, new FCDENode(parent->GetDocument(), parent)); +ImplementParameterObjectNoArg(FCDENode, FCDEAttribute, attributes); +ImplementParameterObject(FCDENode, FCDAnimatedCustom, animated, new FCDAnimatedCustom(parent->GetDocument())); + +FCDENode::FCDENode(FCDocument* document, FCDENode* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(name) +, InitializeParameterNoArg(content) +, InitializeParameterNoArg(children) +, InitializeParameterNoArg(attributes) +, InitializeParameterNoArg(animated) +{ + animated = new FCDAnimatedCustom(this); +} + +FCDENode::~FCDENode() +{ + parent = NULL; +} + +void FCDENode::SetContent(const fchar* _content) +{ + // As COLLADA doesn't allow for mixed content, release all the children. + while (!children.empty()) + { + children.back()->Release(); + } + + content = _content; + SetDirtyFlag(); +} + +void FCDENode::SetAnimated(FCDAnimatedCustom* animatedCustom) +{ + SAFE_RELEASE(animated); + animated = animatedCustom; +} + +// Search for a children with a specific name +const FCDENode* FCDENode::FindChildNode(const char* name) const +{ + for (const FCDENode** itN = children.begin(); itN != children.end(); ++itN) + { + if (IsEquivalent((*itN)->GetName(), name)) return (*itN); + } + return NULL; +} + +void FCDENode::FindChildrenNodes(const char* name, FCDENodeList& nodes) const +{ + for (const FCDENode** itN = children.begin(); itN != children.end(); ++itN) + { + if (IsEquivalent((*itN)->GetName(), name)) nodes.push_back(const_cast(*itN)); + } +} + +const FCDENode* FCDENode::FindParameter(const char* name) const +{ + for (const FCDENode** itN = children.begin(); itN != children.end(); ++itN) + { + const FCDENode* node = (*itN); + if (IsEquivalent(node->GetName(), name)) return node; + } + return NULL; +} + +void FCDENode::FindParameters(FCDENodeList& nodes, StringList& names) +{ + for (const FCDENode** itN = (const FCDENode**) children.begin(); itN != children.end(); ++itN) + { + const FCDENode* node = (*itN); + if (node->GetChildNodeCount() == 0) + { + nodes.push_back(const_cast(node)); + names.push_back(node->GetName()); + } + } +} + +void FCDENode::SetName(fm::string& _name) +{ + name = _name; + CleanName(name); + SetDirtyFlag(); +} + +void FCDENode::CleanName(fm::string& n) +{ + size_t length = n.length(); + if (length == 0) return; + + // First character must be alphabetic or the underscore. + if (n[0] != '_' && !(n[0] >= 'a' && n[0] <= 'z') && !(n[0] >= 'A' && n[0] <= 'Z')) + { + n[0] = '_'; + } + + // Other characters must be alpha-numeric or the underscore. + for (size_t i = 1; i < length; ++i) + { + char& c = n[i]; + if (c != '_' && !(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && !(c >= '0' && c <= '9')) + { + c = '_'; + } + } +} + +const fchar* FCDENode::GetContent() const +{ + return content->c_str(); +} + +// Adds a new attribute to this extra tree node. +FCDEAttribute* FCDENode::AddAttribute(fm::string& _name, const fchar* _value) +{ + CleanName(_name); + FCDEAttribute* attribute = FindAttribute(_name.c_str()); + if (attribute == NULL) + { + attribute = new FCDEAttribute(); + attributes.push_back(attribute); + attribute->SetName(_name); + } + + attribute->SetValue(_value); + SetNewChildFlag(); + return attribute; +} + +// Search for an attribute with a specific name +const FCDEAttribute* FCDENode::FindAttribute(const char* name) const +{ + for (const FCDEAttribute** itA = attributes.begin(); itA != attributes.end(); ++itA) + { + if (IsEquivalent((*itA)->GetName(), name)) return (*itA); + } + return NULL; +} + +const fstring& FCDENode::ReadAttribute(const char* name) const +{ + const FCDEAttribute* attribute = FindAttribute(name); + return (attribute != NULL) ? attribute->GetValue() : emptyFString; +} + +FCDENode* FCDENode::AddParameter(const char* name, const fchar* value) +{ + FCDENode* parameter = AddChildNode(); + parameter->SetName(name); + parameter->SetContent(value); + SetNewChildFlag(); + return parameter; +} + +FCDENode* FCDENode::Clone(FCDENode* clone) const +{ + if (clone == NULL) return NULL; + + clone->name = name; + clone->content = content; + + clone->attributes.reserve(attributes.size()); + for (const FCDEAttribute** itA = attributes.begin(); itA != attributes.end(); ++itA) + { + clone->AddAttribute((*itA)->GetName(), (*itA)->GetValue()); + } + + clone->children.reserve(children.size()); + for (const FCDENode** itC = children.begin(); itC != children.end(); ++itC) + { + FCDENode* clonedChild = clone->AddChildNode(); + (*itC)->Clone(clonedChild); + } + + // TODO: Clone the animated custom.. + + return clone; +} + +FCDENode* FCDENode::AddChildNode() +{ + FCDENode* node = new FCDENode(GetDocument(), this); + children.push_back(node); + SetNewChildFlag(); + return node; +} + +FCDENode* FCDENode::AddChildNode(const char* name) +{ + FCDENode* node = new FCDENode(GetDocument(), this); + children.push_back(node); + node->SetName(name); + SetNewChildFlag(); + return node; +} + +// +// FCDETechnique +// + +ImplementObjectType(FCDETechnique); +ImplementParameterObjectNoCtr(FCDETechnique, FUObject, pluginOverride); + +FCDETechnique::FCDETechnique(FCDocument* document, FCDEType* _parent, const char* _profile) +: FCDENode(document, NULL), parent(_parent) +, InitializeParameterNoArg(pluginOverride) +, InitializeParameter(profile, _profile) +{ +} + +FCDETechnique::~FCDETechnique() {} + +FCDENode* FCDETechnique::Clone(FCDENode* clone) const +{ + if (clone == NULL) + { + clone = new FCDETechnique(const_cast(GetDocument()), NULL, profile->c_str()); + } + else if (clone->GetObjectType().Includes(FCDETechnique::GetClassType())) + { + ((FCDETechnique*) clone)->profile = profile; + } + + FCDENode::Clone(clone); + return clone; +} + +// +// FCDEAttribute +// + +FCDEAttribute::FCDEAttribute() +: FUParameterizable() +, InitializeParameterNoArg(name) +, InitializeParameterNoArg(value) +{ +} + +FCDEAttribute::FCDEAttribute(const char* _name, const fchar* _value) +: FUParameterizable() +, InitializeParameter(name, _name) +, InitializeParameter(value, _value) +{ +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExtra.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDrag.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDrag.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDrag.cpp (revision 24247) @@ -1,13 +1,13 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDForceDrag.h" - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDForceDrag.h" + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDrag.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfile.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfile.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfile.cpp (revision 24247) @@ -1,59 +1,59 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffect.h" -#include "FCDocument/FCDEffectProfile.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterFactory.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDImage.h" -#include "FCDocument/FCDLibrary.h" - -// -// FCDEffectProfile -// - -ImplementObjectType(FCDEffectProfile); -ImplementParameterObjectNoCtr(FCDEffectProfile, FCDEffectParameter, parameters); -ImplementParameterObject(FCDEffectProfile, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); - -FCDEffectProfile::FCDEffectProfile(FCDocument* document, FCDEffect* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(parameters) -, InitializeParameterNoArg(extra) -{ - extra = new FCDExtra(GetDocument(), this); -} - -FCDEffectProfile::~FCDEffectProfile() -{ - parent = NULL; -} - -FCDEffectProfile* FCDEffectProfile::Clone(FCDEffectProfile* clone) const -{ - if (clone == NULL) return NULL; - size_t parameterCount = parameters.size(); - for (size_t p = 0; p < parameterCount; ++p) - { - FCDEffectParameter* parameter = clone->AddEffectParameter(parameters[p]->GetType()); - parameters[p]->Clone(parameter); - } - extra->Clone(clone->extra); - return clone; -} - -FCDEffectParameter* FCDEffectProfile::AddEffectParameter(uint32 type) -{ - FCDEffectParameter* parameter = FCDEffectParameterFactory::Create(GetDocument(), type); - parameters.push_back(parameter); - SetNewChildFlag(); - return parameter; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffect.h" +#include "FCDocument/FCDEffectProfile.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterFactory.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDImage.h" +#include "FCDocument/FCDLibrary.h" + +// +// FCDEffectProfile +// + +ImplementObjectType(FCDEffectProfile); +ImplementParameterObjectNoCtr(FCDEffectProfile, FCDEffectParameter, parameters); +ImplementParameterObject(FCDEffectProfile, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); + +FCDEffectProfile::FCDEffectProfile(FCDocument* document, FCDEffect* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(parameters) +, InitializeParameterNoArg(extra) +{ + extra = new FCDExtra(GetDocument(), this); +} + +FCDEffectProfile::~FCDEffectProfile() +{ + parent = NULL; +} + +FCDEffectProfile* FCDEffectProfile::Clone(FCDEffectProfile* clone) const +{ + if (clone == NULL) return NULL; + size_t parameterCount = parameters.size(); + for (size_t p = 0; p < parameterCount; ++p) + { + FCDEffectParameter* parameter = clone->AddEffectParameter(parameters[p]->GetType()); + parameters[p]->Clone(parameter); + } + extra->Clone(clone->extra); + return clone; +} + +FCDEffectParameter* FCDEffectProfile::AddEffectParameter(uint32 type) +{ + FCDEffectParameter* parameter = FCDEffectParameterFactory::Create(GetDocument(), type); + parameters.push_back(parameter); + SetNewChildFlag(); + return parameter; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfile.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectStandard.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectStandard.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectStandard.cpp (revision 24247) @@ -1,366 +1,366 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDEffect.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterFactory.h" -#include "FCDocument/FCDEffectStandard.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDMaterial.h" -#include "FCDocument/FCDTexture.h" -#include "FCDocument/FCDVersion.h" -#include "FUtils/FUDaeEnum.h" -#include "FUtils/FUStringConversion.h" - -// -// FCDEffectStandard -// - -ImplementObjectType(FCDEffectStandard); -ImplementParameterObject(FCDEffectStandard, FCDTexture, emissionTextures, new FCDTexture(parent->GetDocument(), parent)); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, emissionColor, new FCDEffectParameterColor4(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, emissionFactor, new FCDEffectParameterFloat(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDTexture, reflectivityTextures, new FCDTexture(parent->GetDocument(), parent)); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, reflectivityColor, new FCDEffectParameterColor4(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, reflectivityFactor, new FCDEffectParameterFloat(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDTexture, refractionTextures, new FCDTexture(parent->GetDocument(), parent)); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, indexOfRefraction, new FCDEffectParameterFloat(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDTexture, translucencyTextures, new FCDTexture(parent->GetDocument(), parent)); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, translucencyColor, new FCDEffectParameterColor4(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, translucencyFactor, new FCDEffectParameterFloat(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDTexture, diffuseTextures, new FCDTexture(parent->GetDocument(), parent)); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, diffuseColor, new FCDEffectParameterColor4(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDTexture, ambientTextures, new FCDTexture(parent->GetDocument(), parent)); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, ambientColor, new FCDEffectParameterColor4(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDTexture, specularTextures, new FCDTexture(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, specularColor, new FCDEffectParameterColor4(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDTexture, specularFactorTextures, new FCDTexture(parent->GetDocument(), parent)); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, specularFactor, new FCDEffectParameterFloat(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDTexture, shininessTextures, new FCDTexture(parent->GetDocument(), parent)); -ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, shininess, new FCDEffectParameterFloat(parent->GetDocument())); -ImplementParameterObject(FCDEffectStandard, FCDTexture, bumpTextures, new FCDTexture(parent->GetDocument(), parent)); -ImplementParameterObject(FCDEffectStandard, FCDTexture, displacementTextures, new FCDTexture(parent->GetDocument(), parent)); -ImplementParameterObject(FCDEffectStandard, FCDTexture, filterTextures, new FCDTexture(parent->GetDocument())); - -const fm::string FCDEffectStandard::EmissionColorSemantic("EMISSION"); -const fm::string FCDEffectStandard::EmissionFactorSemantic("EMISSIONFACTOR"); -const fm::string FCDEffectStandard::ReflectivityColorSemantic("REFLECTIVITY"); -const fm::string FCDEffectStandard::ReflectivityFactorSemantic("REFLECTIVITYFACTOR"); -const fm::string FCDEffectStandard::IndexOfRefractionSemantic("INDEXOFREFRACTION"); -const fm::string FCDEffectStandard::TranslucencyColorSemantic("TRANSLUCENCY"); -const fm::string FCDEffectStandard::TranslucencyFactorSemantic("TRANSLUCENCYFACTOR"); -const fm::string FCDEffectStandard::DiffuseColorSemantic("DIFFUSE"); -const fm::string FCDEffectStandard::AmbientColorSemantic("AMBIENT"); -const fm::string FCDEffectStandard::SpecularColorSemantic("SPECULAR"); -const fm::string FCDEffectStandard::SpecularFactorSemantic("SPECULARFACTOR"); -const fm::string FCDEffectStandard::ShininessSemantic("SHININESS"); - -FCDEffectStandard::FCDEffectStandard(FCDocument* document, FCDEffect* _parent) -: FCDEffectProfile(document, _parent) -, InitializeParameter(type, CONSTANT) -, InitializeParameterNoArg(emissionTextures) -, InitializeParameterNoArg(emissionColor) -, InitializeParameterNoArg(emissionFactor) -, InitializeParameter(isEmissionFactor, false) -, InitializeParameterNoArg(reflectivityTextures) -, InitializeParameterNoArg(reflectivityColor) -, InitializeParameterNoArg(reflectivityFactor) -, InitializeParameter(isReflective, false) -, InitializeParameterNoArg(refractionTextures) -, InitializeParameterNoArg(indexOfRefraction) -, InitializeParameter(isRefractive, false) -, InitializeParameterNoArg(translucencyTextures) -, InitializeParameterNoArg(translucencyColor) -, InitializeParameterNoArg(translucencyFactor) -, InitializeParameter(transparencyMode, A_ONE) -, InitializeParameterNoArg(diffuseTextures) -, InitializeParameterNoArg(diffuseColor) -, InitializeParameterNoArg(ambientTextures) -, InitializeParameterNoArg(ambientColor) -, InitializeParameterNoArg(specularTextures) -, InitializeParameterNoArg(specularColor) -, InitializeParameterNoArg(specularFactorTextures) -, InitializeParameterNoArg(specularFactor) -, InitializeParameterNoArg(shininessTextures) -, InitializeParameterNoArg(shininess) -, InitializeParameterNoArg(bumpTextures) -, InitializeParameterNoArg(displacementTextures) -, InitializeParameterNoArg(filterTextures) -{ - emissionColor = new FCDEffectParameterColor4(GetDocument()); - emissionColor->SetValue(FMVector4::AlphaOne); - emissionColor->SetConstant(); - emissionFactor = new FCDEffectParameterFloat(GetDocument()); - emissionFactor->SetValue(1.0f); - emissionFactor->SetConstant(); - reflectivityColor = new FCDEffectParameterColor4(GetDocument()); - reflectivityColor->SetValue(FMVector4::One); - reflectivityColor->SetConstant(); - reflectivityFactor = new FCDEffectParameterFloat(GetDocument()); - reflectivityFactor->SetValue(1.0f); - reflectivityFactor->SetConstant(); - indexOfRefraction = new FCDEffectParameterFloat(GetDocument()); - indexOfRefraction->SetValue(1.0f); - indexOfRefraction->SetConstant(); - translucencyColor = new FCDEffectParameterColor4(GetDocument()); - translucencyColor->SetValue(FMVector4::AlphaOne); - translucencyColor->SetConstant(); - translucencyFactor = new FCDEffectParameterFloat(GetDocument()); - translucencyFactor->SetValue(1.0f); - translucencyFactor->SetConstant(); - diffuseColor = new FCDEffectParameterColor4(GetDocument()); - diffuseColor->SetValue(FMVector4::AlphaOne); - diffuseColor->SetConstant(); - ambientColor = new FCDEffectParameterColor4(GetDocument()); - ambientColor->SetValue(FMVector4::AlphaOne); - ambientColor->SetConstant(); - specularColor = new FCDEffectParameterColor4(GetDocument()); - specularColor->SetValue(FMVector4::AlphaOne); - specularColor->SetConstant(); - specularFactor = new FCDEffectParameterFloat(GetDocument()); - specularFactor->SetValue(1.0f); - specularFactor->SetConstant(); - shininess = new FCDEffectParameterFloat(GetDocument()); - shininess->SetValue(20.0f); - shininess->SetConstant(); - - // Note: the 1.4.1 spec calls for A_ONE as default, which breaks backwards compatibility - // with 1.3 by having a transparency factor of 1 for opaque instead of 0 in 1.3. - // If we're lower than 1.4.1, we default to RGB_ZERO and a transparency (or translucency) - // factor of 0.0. - if (GetDocument()->GetVersion() < FCDVersion(1,4,1)) transparencyMode = RGB_ZERO; -} - -FCDEffectStandard::~FCDEffectStandard() -{ -} - -// Retrieve one of the buckets -const FCDTexture** FCDEffectStandard::GetTextureBucket(uint32 bucket) const -{ - switch (bucket) - { - case FUDaeTextureChannel::AMBIENT: return ambientTextures.begin(); - case FUDaeTextureChannel::BUMP: return bumpTextures.begin(); - case FUDaeTextureChannel::DIFFUSE: return diffuseTextures.begin(); - case FUDaeTextureChannel::DISPLACEMENT: return displacementTextures.begin(); - case FUDaeTextureChannel::EMISSION: return emissionTextures.begin(); - case FUDaeTextureChannel::FILTER: return filterTextures.begin(); - case FUDaeTextureChannel::REFLECTION: return reflectivityTextures.begin(); - case FUDaeTextureChannel::REFRACTION: return refractionTextures.begin(); - case FUDaeTextureChannel::SHININESS: return shininessTextures.begin(); - case FUDaeTextureChannel::SPECULAR: return specularTextures.begin(); - case FUDaeTextureChannel::SPECULAR_LEVEL: return specularFactorTextures.begin(); - case FUDaeTextureChannel::TRANSPARENT: return translucencyTextures.begin(); - - case FUDaeTextureChannel::UNKNOWN: - default: - FUFail(return filterTextures.begin()); // because I think this one will almost always be empty. - } -} - -size_t FCDEffectStandard::GetTextureCount(uint32 bucket) const -{ - switch (bucket) - { - case FUDaeTextureChannel::AMBIENT: return ambientTextures.size(); - case FUDaeTextureChannel::BUMP: return bumpTextures.size(); - case FUDaeTextureChannel::DIFFUSE: return diffuseTextures.size(); - case FUDaeTextureChannel::DISPLACEMENT: return displacementTextures.size(); - case FUDaeTextureChannel::EMISSION: return emissionTextures.size(); - case FUDaeTextureChannel::FILTER: return filterTextures.size(); - case FUDaeTextureChannel::REFLECTION: return reflectivityTextures.size(); - case FUDaeTextureChannel::REFRACTION: return refractionTextures.size(); - case FUDaeTextureChannel::SHININESS: return shininessTextures.size(); - case FUDaeTextureChannel::SPECULAR: return specularTextures.size(); - case FUDaeTextureChannel::SPECULAR_LEVEL: return specularFactorTextures.size(); - case FUDaeTextureChannel::TRANSPARENT: return translucencyTextures.size(); - - case FUDaeTextureChannel::UNKNOWN: - default: - FUFail(return 0); - } -} - -// Adds a texture to a specific channel. -FCDTexture* FCDEffectStandard::AddTexture(uint32 bucket) -{ - FCDTexture* texture = new FCDTexture(GetDocument(), this); - switch (bucket) - { - case FUDaeTextureChannel::AMBIENT: ambientTextures.push_back(texture); break; - case FUDaeTextureChannel::BUMP: bumpTextures.push_back(texture); break; - case FUDaeTextureChannel::DIFFUSE: diffuseTextures.push_back(texture); break; - case FUDaeTextureChannel::DISPLACEMENT: displacementTextures.push_back(texture); break; - case FUDaeTextureChannel::EMISSION: emissionTextures.push_back(texture); break; - case FUDaeTextureChannel::FILTER: filterTextures.push_back(texture); break; - case FUDaeTextureChannel::REFLECTION: reflectivityTextures.push_back(texture); break; - case FUDaeTextureChannel::REFRACTION: refractionTextures.push_back(texture); break; - case FUDaeTextureChannel::SHININESS: shininessTextures.push_back(texture); break; - case FUDaeTextureChannel::SPECULAR: specularTextures.push_back(texture); break; - case FUDaeTextureChannel::SPECULAR_LEVEL: specularFactorTextures.push_back(texture); break; - case FUDaeTextureChannel::TRANSPARENT: translucencyTextures.push_back(texture); break; - - case FUDaeTextureChannel::UNKNOWN: - default: - FUFail(texture->Release(); return NULL); - } - SetNewChildFlag(); - return texture; -} - -// Calculate the opacity for this material -float FCDEffectStandard::GetOpacity() const -{ - if (transparencyMode == RGB_ZERO) - return 1.0f - (translucencyColor->GetValue()->x + translucencyColor->GetValue()->x + translucencyColor->GetValue()->x) / 3.0f * translucencyFactor->GetValue(); - else - return translucencyColor->GetValue()->w * translucencyFactor->GetValue(); -} - -// Calculate the overall reflectivity for this material -float FCDEffectStandard::GetReflectivity() const -{ - return (reflectivityColor->GetValue()->x + reflectivityColor->GetValue()->x + reflectivityColor->GetValue()->x) / 3.0f * reflectivityFactor->GetValue(); -} - -// Clone the standard effect -FCDEffectProfile* FCDEffectStandard::Clone(FCDEffectProfile* _clone) const -{ - FCDEffectStandard* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDEffectStandard(const_cast(GetDocument()), const_cast(GetParent())); - else if (_clone->GetObjectType() == FCDEffectStandard::GetClassType()) clone = (FCDEffectStandard*) _clone; - - if (_clone != NULL) FCDEffectProfile::Clone(_clone); - if (clone != NULL) - { - clone->type = type; - for (uint32 i = 0; i < FUDaeTextureChannel::COUNT; ++i) - { - size_t count = GetTextureCount(i); - for (size_t t = 0; t < count; ++t) - { - const FCDTexture* texture = GetTexture(i, t); - texture->Clone(clone->AddTexture(i)); - } - } - clone->transparencyMode = transparencyMode; - -#define CLONE_ANIMATED(value) clone->value->SetValue(value->GetValue()); if (value->GetValue().IsAnimated()) value->GetValue().GetAnimated()->Clone(clone->value->GetValue().GetAnimated()); - - CLONE_ANIMATED(emissionColor); CLONE_ANIMATED(emissionFactor); clone->isEmissionFactor = isEmissionFactor; - CLONE_ANIMATED(translucencyColor); CLONE_ANIMATED(translucencyFactor); - CLONE_ANIMATED(diffuseColor); CLONE_ANIMATED(ambientColor); - CLONE_ANIMATED(specularColor); CLONE_ANIMATED(specularFactor); CLONE_ANIMATED(shininess); - CLONE_ANIMATED(reflectivityColor); CLONE_ANIMATED(reflectivityFactor); CLONE_ANIMATED(indexOfRefraction); - -#undef CLONE_ANIMATED - } - - return _clone; -} - -void FCDEffectStandard::AddExtraAttribute(const char* profile, const char* key, const fchar* value) -{ - FUAssert(GetParent() != NULL, return); - FCDETechnique* extraTech = GetParent()->GetExtra()->GetDefaultType()->FindTechnique(profile); - if (extraTech == NULL) extraTech = GetParent()->GetExtra()->GetDefaultType()->AddTechnique(profile); - FCDENode *enode= extraTech->AddParameter(key, value); - enode->SetName(key); - enode->SetContent(value); - SetNewChildFlag(); -} - -const fchar* FCDEffectStandard::GetExtraAttribute(const char* profile, const char* key) const -{ - FUAssert(GetParent() != NULL, return NULL); - const FCDETechnique * extraTech = GetParent()->GetExtra()->GetDefaultType()->FindTechnique(profile); - if (extraTech == NULL) return NULL; - const FCDENode * enode = extraTech->FindParameter(key); - if (enode == NULL) return NULL; - return enode->GetContent(); -} - -FCDEffectParameter* FCDEffectStandard::GetParam(const fm::string& semantic, bool* isFloat) -{ - if (semantic == FCDEffectStandard::AmbientColorSemantic) - { - *isFloat = false; - return ambientColor; - } - else if (semantic == FCDEffectStandard::DiffuseColorSemantic) - { - *isFloat = false; - return diffuseColor; - } - else if (semantic == FCDEffectStandard::EmissionColorSemantic) - { - *isFloat = false; - return emissionColor; - } - else if (semantic == FCDEffectStandard::EmissionFactorSemantic) - { - *isFloat = true; - return emissionFactor; - } - else if (semantic == FCDEffectStandard::IndexOfRefractionSemantic) - { - *isFloat = true; - return indexOfRefraction; - } - else if (semantic == FCDEffectStandard::ReflectivityColorSemantic) - { - *isFloat = false; - return reflectivityColor; - } - else if (semantic == FCDEffectStandard::ReflectivityFactorSemantic) - { - *isFloat = true; - return reflectivityFactor; - } - else if (semantic == FCDEffectStandard::ShininessSemantic) - { - *isFloat = true; - return shininess; - } - else if (semantic == FCDEffectStandard::SpecularColorSemantic) - { - *isFloat = false; - return specularColor; - } - else if (semantic == FCDEffectStandard::SpecularFactorSemantic) - { - *isFloat = true; - return specularFactor; - } - else if (semantic == FCDEffectStandard::TranslucencyColorSemantic) - { - *isFloat = false; - return translucencyColor; - } - else if (semantic == FCDEffectStandard::TranslucencyFactorSemantic) - { - *isFloat = true; - return translucencyFactor; - } - else - { - *isFloat = true; - return NULL; - } -} - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDEffect.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterFactory.h" +#include "FCDocument/FCDEffectStandard.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDMaterial.h" +#include "FCDocument/FCDTexture.h" +#include "FCDocument/FCDVersion.h" +#include "FUtils/FUDaeEnum.h" +#include "FUtils/FUStringConversion.h" + +// +// FCDEffectStandard +// + +ImplementObjectType(FCDEffectStandard); +ImplementParameterObject(FCDEffectStandard, FCDTexture, emissionTextures, new FCDTexture(parent->GetDocument(), parent)); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, emissionColor, new FCDEffectParameterColor4(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, emissionFactor, new FCDEffectParameterFloat(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDTexture, reflectivityTextures, new FCDTexture(parent->GetDocument(), parent)); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, reflectivityColor, new FCDEffectParameterColor4(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, reflectivityFactor, new FCDEffectParameterFloat(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDTexture, refractionTextures, new FCDTexture(parent->GetDocument(), parent)); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, indexOfRefraction, new FCDEffectParameterFloat(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDTexture, translucencyTextures, new FCDTexture(parent->GetDocument(), parent)); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, translucencyColor, new FCDEffectParameterColor4(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, translucencyFactor, new FCDEffectParameterFloat(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDTexture, diffuseTextures, new FCDTexture(parent->GetDocument(), parent)); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, diffuseColor, new FCDEffectParameterColor4(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDTexture, ambientTextures, new FCDTexture(parent->GetDocument(), parent)); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, ambientColor, new FCDEffectParameterColor4(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDTexture, specularTextures, new FCDTexture(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterColor4, specularColor, new FCDEffectParameterColor4(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDTexture, specularFactorTextures, new FCDTexture(parent->GetDocument(), parent)); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, specularFactor, new FCDEffectParameterFloat(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDTexture, shininessTextures, new FCDTexture(parent->GetDocument(), parent)); +ImplementParameterObject(FCDEffectStandard, FCDEffectParameterFloat, shininess, new FCDEffectParameterFloat(parent->GetDocument())); +ImplementParameterObject(FCDEffectStandard, FCDTexture, bumpTextures, new FCDTexture(parent->GetDocument(), parent)); +ImplementParameterObject(FCDEffectStandard, FCDTexture, displacementTextures, new FCDTexture(parent->GetDocument(), parent)); +ImplementParameterObject(FCDEffectStandard, FCDTexture, filterTextures, new FCDTexture(parent->GetDocument())); + +const fm::string FCDEffectStandard::EmissionColorSemantic("EMISSION"); +const fm::string FCDEffectStandard::EmissionFactorSemantic("EMISSIONFACTOR"); +const fm::string FCDEffectStandard::ReflectivityColorSemantic("REFLECTIVITY"); +const fm::string FCDEffectStandard::ReflectivityFactorSemantic("REFLECTIVITYFACTOR"); +const fm::string FCDEffectStandard::IndexOfRefractionSemantic("INDEXOFREFRACTION"); +const fm::string FCDEffectStandard::TranslucencyColorSemantic("TRANSLUCENCY"); +const fm::string FCDEffectStandard::TranslucencyFactorSemantic("TRANSLUCENCYFACTOR"); +const fm::string FCDEffectStandard::DiffuseColorSemantic("DIFFUSE"); +const fm::string FCDEffectStandard::AmbientColorSemantic("AMBIENT"); +const fm::string FCDEffectStandard::SpecularColorSemantic("SPECULAR"); +const fm::string FCDEffectStandard::SpecularFactorSemantic("SPECULARFACTOR"); +const fm::string FCDEffectStandard::ShininessSemantic("SHININESS"); + +FCDEffectStandard::FCDEffectStandard(FCDocument* document, FCDEffect* _parent) +: FCDEffectProfile(document, _parent) +, InitializeParameter(type, CONSTANT) +, InitializeParameterNoArg(emissionTextures) +, InitializeParameterNoArg(emissionColor) +, InitializeParameterNoArg(emissionFactor) +, InitializeParameter(isEmissionFactor, false) +, InitializeParameterNoArg(reflectivityTextures) +, InitializeParameterNoArg(reflectivityColor) +, InitializeParameterNoArg(reflectivityFactor) +, InitializeParameter(isReflective, false) +, InitializeParameterNoArg(refractionTextures) +, InitializeParameterNoArg(indexOfRefraction) +, InitializeParameter(isRefractive, false) +, InitializeParameterNoArg(translucencyTextures) +, InitializeParameterNoArg(translucencyColor) +, InitializeParameterNoArg(translucencyFactor) +, InitializeParameter(transparencyMode, A_ONE) +, InitializeParameterNoArg(diffuseTextures) +, InitializeParameterNoArg(diffuseColor) +, InitializeParameterNoArg(ambientTextures) +, InitializeParameterNoArg(ambientColor) +, InitializeParameterNoArg(specularTextures) +, InitializeParameterNoArg(specularColor) +, InitializeParameterNoArg(specularFactorTextures) +, InitializeParameterNoArg(specularFactor) +, InitializeParameterNoArg(shininessTextures) +, InitializeParameterNoArg(shininess) +, InitializeParameterNoArg(bumpTextures) +, InitializeParameterNoArg(displacementTextures) +, InitializeParameterNoArg(filterTextures) +{ + emissionColor = new FCDEffectParameterColor4(GetDocument()); + emissionColor->SetValue(FMVector4::AlphaOne); + emissionColor->SetConstant(); + emissionFactor = new FCDEffectParameterFloat(GetDocument()); + emissionFactor->SetValue(1.0f); + emissionFactor->SetConstant(); + reflectivityColor = new FCDEffectParameterColor4(GetDocument()); + reflectivityColor->SetValue(FMVector4::One); + reflectivityColor->SetConstant(); + reflectivityFactor = new FCDEffectParameterFloat(GetDocument()); + reflectivityFactor->SetValue(1.0f); + reflectivityFactor->SetConstant(); + indexOfRefraction = new FCDEffectParameterFloat(GetDocument()); + indexOfRefraction->SetValue(1.0f); + indexOfRefraction->SetConstant(); + translucencyColor = new FCDEffectParameterColor4(GetDocument()); + translucencyColor->SetValue(FMVector4::AlphaOne); + translucencyColor->SetConstant(); + translucencyFactor = new FCDEffectParameterFloat(GetDocument()); + translucencyFactor->SetValue(1.0f); + translucencyFactor->SetConstant(); + diffuseColor = new FCDEffectParameterColor4(GetDocument()); + diffuseColor->SetValue(FMVector4::AlphaOne); + diffuseColor->SetConstant(); + ambientColor = new FCDEffectParameterColor4(GetDocument()); + ambientColor->SetValue(FMVector4::AlphaOne); + ambientColor->SetConstant(); + specularColor = new FCDEffectParameterColor4(GetDocument()); + specularColor->SetValue(FMVector4::AlphaOne); + specularColor->SetConstant(); + specularFactor = new FCDEffectParameterFloat(GetDocument()); + specularFactor->SetValue(1.0f); + specularFactor->SetConstant(); + shininess = new FCDEffectParameterFloat(GetDocument()); + shininess->SetValue(20.0f); + shininess->SetConstant(); + + // Note: the 1.4.1 spec calls for A_ONE as default, which breaks backwards compatibility + // with 1.3 by having a transparency factor of 1 for opaque instead of 0 in 1.3. + // If we're lower than 1.4.1, we default to RGB_ZERO and a transparency (or translucency) + // factor of 0.0. + if (GetDocument()->GetVersion() < FCDVersion(1,4,1)) transparencyMode = RGB_ZERO; +} + +FCDEffectStandard::~FCDEffectStandard() +{ +} + +// Retrieve one of the buckets +const FCDTexture** FCDEffectStandard::GetTextureBucket(uint32 bucket) const +{ + switch (bucket) + { + case FUDaeTextureChannel::AMBIENT: return ambientTextures.begin(); + case FUDaeTextureChannel::BUMP: return bumpTextures.begin(); + case FUDaeTextureChannel::DIFFUSE: return diffuseTextures.begin(); + case FUDaeTextureChannel::DISPLACEMENT: return displacementTextures.begin(); + case FUDaeTextureChannel::EMISSION: return emissionTextures.begin(); + case FUDaeTextureChannel::FILTER: return filterTextures.begin(); + case FUDaeTextureChannel::REFLECTION: return reflectivityTextures.begin(); + case FUDaeTextureChannel::REFRACTION: return refractionTextures.begin(); + case FUDaeTextureChannel::SHININESS: return shininessTextures.begin(); + case FUDaeTextureChannel::SPECULAR: return specularTextures.begin(); + case FUDaeTextureChannel::SPECULAR_LEVEL: return specularFactorTextures.begin(); + case FUDaeTextureChannel::TRANSPARENT: return translucencyTextures.begin(); + + case FUDaeTextureChannel::UNKNOWN: + default: + FUFail(return filterTextures.begin()); // because I think this one will almost always be empty. + } +} + +size_t FCDEffectStandard::GetTextureCount(uint32 bucket) const +{ + switch (bucket) + { + case FUDaeTextureChannel::AMBIENT: return ambientTextures.size(); + case FUDaeTextureChannel::BUMP: return bumpTextures.size(); + case FUDaeTextureChannel::DIFFUSE: return diffuseTextures.size(); + case FUDaeTextureChannel::DISPLACEMENT: return displacementTextures.size(); + case FUDaeTextureChannel::EMISSION: return emissionTextures.size(); + case FUDaeTextureChannel::FILTER: return filterTextures.size(); + case FUDaeTextureChannel::REFLECTION: return reflectivityTextures.size(); + case FUDaeTextureChannel::REFRACTION: return refractionTextures.size(); + case FUDaeTextureChannel::SHININESS: return shininessTextures.size(); + case FUDaeTextureChannel::SPECULAR: return specularTextures.size(); + case FUDaeTextureChannel::SPECULAR_LEVEL: return specularFactorTextures.size(); + case FUDaeTextureChannel::TRANSPARENT: return translucencyTextures.size(); + + case FUDaeTextureChannel::UNKNOWN: + default: + FUFail(return 0); + } +} + +// Adds a texture to a specific channel. +FCDTexture* FCDEffectStandard::AddTexture(uint32 bucket) +{ + FCDTexture* texture = new FCDTexture(GetDocument(), this); + switch (bucket) + { + case FUDaeTextureChannel::AMBIENT: ambientTextures.push_back(texture); break; + case FUDaeTextureChannel::BUMP: bumpTextures.push_back(texture); break; + case FUDaeTextureChannel::DIFFUSE: diffuseTextures.push_back(texture); break; + case FUDaeTextureChannel::DISPLACEMENT: displacementTextures.push_back(texture); break; + case FUDaeTextureChannel::EMISSION: emissionTextures.push_back(texture); break; + case FUDaeTextureChannel::FILTER: filterTextures.push_back(texture); break; + case FUDaeTextureChannel::REFLECTION: reflectivityTextures.push_back(texture); break; + case FUDaeTextureChannel::REFRACTION: refractionTextures.push_back(texture); break; + case FUDaeTextureChannel::SHININESS: shininessTextures.push_back(texture); break; + case FUDaeTextureChannel::SPECULAR: specularTextures.push_back(texture); break; + case FUDaeTextureChannel::SPECULAR_LEVEL: specularFactorTextures.push_back(texture); break; + case FUDaeTextureChannel::TRANSPARENT: translucencyTextures.push_back(texture); break; + + case FUDaeTextureChannel::UNKNOWN: + default: + FUFail(texture->Release(); return NULL); + } + SetNewChildFlag(); + return texture; +} + +// Calculate the opacity for this material +float FCDEffectStandard::GetOpacity() const +{ + if (transparencyMode == RGB_ZERO) + return 1.0f - (translucencyColor->GetValue()->x + translucencyColor->GetValue()->x + translucencyColor->GetValue()->x) / 3.0f * translucencyFactor->GetValue(); + else + return translucencyColor->GetValue()->w * translucencyFactor->GetValue(); +} + +// Calculate the overall reflectivity for this material +float FCDEffectStandard::GetReflectivity() const +{ + return (reflectivityColor->GetValue()->x + reflectivityColor->GetValue()->x + reflectivityColor->GetValue()->x) / 3.0f * reflectivityFactor->GetValue(); +} + +// Clone the standard effect +FCDEffectProfile* FCDEffectStandard::Clone(FCDEffectProfile* _clone) const +{ + FCDEffectStandard* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDEffectStandard(const_cast(GetDocument()), const_cast(GetParent())); + else if (_clone->GetObjectType() == FCDEffectStandard::GetClassType()) clone = (FCDEffectStandard*) _clone; + + if (_clone != NULL) FCDEffectProfile::Clone(_clone); + if (clone != NULL) + { + clone->type = type; + for (uint32 i = 0; i < FUDaeTextureChannel::COUNT; ++i) + { + size_t count = GetTextureCount(i); + for (size_t t = 0; t < count; ++t) + { + const FCDTexture* texture = GetTexture(i, t); + texture->Clone(clone->AddTexture(i)); + } + } + clone->transparencyMode = transparencyMode; + +#define CLONE_ANIMATED(value) clone->value->SetValue(value->GetValue()); if (value->GetValue().IsAnimated()) value->GetValue().GetAnimated()->Clone(clone->value->GetValue().GetAnimated()); + + CLONE_ANIMATED(emissionColor); CLONE_ANIMATED(emissionFactor); clone->isEmissionFactor = isEmissionFactor; + CLONE_ANIMATED(translucencyColor); CLONE_ANIMATED(translucencyFactor); + CLONE_ANIMATED(diffuseColor); CLONE_ANIMATED(ambientColor); + CLONE_ANIMATED(specularColor); CLONE_ANIMATED(specularFactor); CLONE_ANIMATED(shininess); + CLONE_ANIMATED(reflectivityColor); CLONE_ANIMATED(reflectivityFactor); CLONE_ANIMATED(indexOfRefraction); + +#undef CLONE_ANIMATED + } + + return _clone; +} + +void FCDEffectStandard::AddExtraAttribute(const char* profile, const char* key, const fchar* value) +{ + FUAssert(GetParent() != NULL, return); + FCDETechnique* extraTech = GetParent()->GetExtra()->GetDefaultType()->FindTechnique(profile); + if (extraTech == NULL) extraTech = GetParent()->GetExtra()->GetDefaultType()->AddTechnique(profile); + FCDENode *enode= extraTech->AddParameter(key, value); + enode->SetName(key); + enode->SetContent(value); + SetNewChildFlag(); +} + +const fchar* FCDEffectStandard::GetExtraAttribute(const char* profile, const char* key) const +{ + FUAssert(GetParent() != NULL, return NULL); + const FCDETechnique * extraTech = GetParent()->GetExtra()->GetDefaultType()->FindTechnique(profile); + if (extraTech == NULL) return NULL; + const FCDENode * enode = extraTech->FindParameter(key); + if (enode == NULL) return NULL; + return enode->GetContent(); +} + +FCDEffectParameter* FCDEffectStandard::GetParam(const fm::string& semantic, bool* isFloat) +{ + if (semantic == FCDEffectStandard::AmbientColorSemantic) + { + *isFloat = false; + return ambientColor; + } + else if (semantic == FCDEffectStandard::DiffuseColorSemantic) + { + *isFloat = false; + return diffuseColor; + } + else if (semantic == FCDEffectStandard::EmissionColorSemantic) + { + *isFloat = false; + return emissionColor; + } + else if (semantic == FCDEffectStandard::EmissionFactorSemantic) + { + *isFloat = true; + return emissionFactor; + } + else if (semantic == FCDEffectStandard::IndexOfRefractionSemantic) + { + *isFloat = true; + return indexOfRefraction; + } + else if (semantic == FCDEffectStandard::ReflectivityColorSemantic) + { + *isFloat = false; + return reflectivityColor; + } + else if (semantic == FCDEffectStandard::ReflectivityFactorSemantic) + { + *isFloat = true; + return reflectivityFactor; + } + else if (semantic == FCDEffectStandard::ShininessSemantic) + { + *isFloat = true; + return shininess; + } + else if (semantic == FCDEffectStandard::SpecularColorSemantic) + { + *isFloat = false; + return specularColor; + } + else if (semantic == FCDEffectStandard::SpecularFactorSemantic) + { + *isFloat = true; + return specularFactor; + } + else if (semantic == FCDEffectStandard::TranslucencyColorSemantic) + { + *isFloat = false; + return translucencyColor; + } + else if (semantic == FCDEffectStandard::TranslucencyFactorSemantic) + { + *isFloat = true; + return translucencyFactor; + } + else + { + *isFloat = true; + return NULL; + } +} + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectStandard.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTools.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTools.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTools.h (revision 24247) @@ -1,162 +1,162 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/** - @file FCDEffectTools.h - This file contains FCDEffectTools namespace. -*/ - -#ifndef _FCD_EFFECT_TOOLS_H_ -#define _FCD_EFFECT_TOOLS_H_ - -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -/** Contains functions to post-process parameters into a list from a specific instance of an effect. - @ingroup FCDEffect */ - -class FCDMaterialInstance; -class FCDEffectStandard; -class FCDEffectTechnique; -class FCDGeometryInstance; - -#if defined(WIN32) -template class FCOLLADA_EXPORT FCDEffectParameterAnimatableT; /**< Trick Doxygen. */ -#elif defined(LINUX) || defined(__APPLE__) -template class FCDEffectParameterAnimatableT; /**< Trick Doxygen. */ -#endif // LINUX -typedef FCDEffectParameterAnimatableT FCDEffectParameterColor4; /**< A RGBA color effect parameter. */ -typedef FCDEffectParameterAnimatableT FCDEffectParameterFloat; /**< A floating-point value effect parameter. */ - -typedef fm::pvector FCDEffectParameterList; /**< A dynamically-sized array of effect parameters. */ - -namespace FCDEffectTools -{ - /** Synchronizes the standard effect parameters associated with - a material instance. Does nothing if there is no profile_COMMON. - @param instance The specific material instance to be synchronized. */ - FCOLLADA_EXPORT void SynchronizeAnimatedParams(FCDGeometryInstance* geometryInstance, FCDMaterialInstance* materialInstance); - - /** {INTERNAL] Synchronizes a standard effect's float parameter from the three - lists that can affect it with newparam's and setparam's. - @param semantic The FCDEffectStandard semantic for the specific parameter. - @param param One of the FCDEffectStandard color parameters. - @param materialList The parameters list from a material instance. - @param effectList The parameters list from the effect. - @param profileList The parameters list from the effect profile. Should be COMMON. */ - FCOLLADA_EXPORT void LinkAnimatedParamCommonFloat(const fm::string& semantic, FCDEffectParameterFloat* param, FCDGeometryInstance* geometry, FCDMaterial* material, FCDEffect* effect, FCDEffectProfile* profile); - - /** [INTERNAL] Synchronizes a standard effect's vector parameter from the three - lists that can affect it with newparam's and setparam's. - @param semantic The FCDEffectStandard semantic for the specific parameter. - @param param One of the FCDEffectStandard color parameters. - @param materialList The parameters list from a material instance. - @param effectList The parameters list from the effect. - @param profileList The parameters list from the effect profile. Should be COMMON. */ - FCOLLADA_EXPORT void LinkAnimatedParamCommonVector(const fm::string& semantic, FCDEffectParameterColor4* param, FCDGeometryInstance* geometry, FCDMaterial* material, FCDEffect* effect, FCDEffectProfile* profile); - - /** document.... */ - FCOLLADA_EXPORT FCDParameterAnimatableColor4* GetAnimatedColor(FCDGeometryInstance* geometryInstance, FCDMaterial* material, const fm::string& semantic, bool* isFloat3); - - /** document... */ - FCOLLADA_EXPORT FCDParameterAnimatableFloat* GetAnimatedFloat(FCDGeometryInstance* geometryInstance, FCDMaterial* material, const fm::string& semantic); - - /** document... */ - FCOLLADA_EXPORT FMVector4* GetDefaultColor(FCDMaterial* material, const fm::string& semantic, bool* isFloat3); - - /** document... */ - FCOLLADA_EXPORT float* GetDefaultFloat(FCDMaterial* material, const fm::string& semantic); - - /** Retrieves a common effect parameter. Looks for the common effect parameter with the correct - semantic, in order to bind or override its value. - This function searches through the given level of abstractions and the ones below. - @todo Some iterator structure to replace all these functions. - @param materialInstance The material instance being considered. - @param semantic The effect parameter semantic to match. - @param localOnly Whether to search below this level of abstraction. - @return The first effect parameter that matches the semantic. - This pointer will be NULL if no effect parameter matches the given semantic. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDMaterialInstance* materialInstance, const char* semantic, bool localOnly = false); - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDMaterialInstance* materialInstance, const char* semantic, bool localOnly = false) { return const_cast(FindEffectParameterBySemantic(const_cast(materialInstance), semantic, localOnly)); } /**< See above. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDGeometryInstance* geometryInstance, const char* semantic); /**< See above. */ - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDGeometryInstance* geometryInstance, const char* semantic) { return const_cast(FindEffectParameterBySemantic(const_cast(geometryInstance), semantic)); } /**< See above. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDMaterial* material, const char* semantic, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDMaterial* material, const char* semantic, bool localOnly = false) { return const_cast(FindEffectParameterBySemantic(const_cast(material), semantic, localOnly)); } /**< See above. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffect* effect, const char* semantic, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDEffect* effect, const char* semantic, bool localOnly = false) { return const_cast(FindEffectParameterBySemantic(const_cast(effect), semantic, localOnly)); } /**< See above. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffectProfile* profile, const char* semantic, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDEffectProfile* profile, const char* semantic, bool localOnly = false) { return const_cast(FindEffectParameterBySemantic(const_cast(profile), semantic, localOnly)); } /**< See above. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffectTechnique* technique, const char* semantic, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDEffectTechnique* technique, const char* semantic, bool localOnly = false) { return const_cast(FindEffectParameterBySemantic(const_cast(technique), semantic, localOnly)); } /**< See above. */ - - /** Retrieves a common effect parameter. Looks for the common effect parameter with the correct - reference, in order to bind or override its value. - This function searches through the given level of abstractions and the ones below. - @todo Some iterator structure to replace all these functions. - @param materialInstance The material instance being considered. - @param reference The effect parameter reference to match. - @return The first effect parameter that matches the reference. - This pointer will be NULL if no effect parameter matches the given reference. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDMaterialInstance* materialInstance, const char* reference, bool localOnly = false); - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDMaterialInstance* materialInstance, const char* reference, bool localOnly = false) { return const_cast(FindEffectParameterByReference(const_cast(materialInstance), reference, localOnly)); } /**< See above. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDGeometryInstance* geometryInstance, const char* reference); /**< See above. */ - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDGeometryInstance* geometryInstance, const char* reference) { return const_cast(FindEffectParameterByReference(const_cast(geometryInstance), reference)); } /**< See above. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDMaterial* material, const char* reference, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDMaterial* material, const char* reference, bool localOnly = false) { return const_cast(FindEffectParameterByReference(const_cast(material), reference, localOnly)); } /**< See above. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDEffect* effect, const char* reference, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDEffect* effect, const char* reference, bool localOnly = false) { return const_cast(FindEffectParameterByReference(const_cast(effect), reference, localOnly)); } /**< See above. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDEffectProfile* profile, const char* reference, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDEffectProfile* profile, const char* reference, bool localOnly = false) { return const_cast(FindEffectParameterByReference(const_cast(profile), reference, localOnly)); } /**< See above. */ - FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDEffectTechnique* technique, const char* reference, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDEffectTechnique* technique, const char* reference, bool localOnly = false) { return const_cast(FindEffectParameterByReference(const_cast(technique), reference, localOnly)); } /**< See above. */ - - /** Retrieves a subset of the common effect parameter list. - Look for the effect parameter generators with the correct semantic. - This function searches through the geometry instance and the level of abstractions below. - @todo Some iterator structure to replace all these functions. - @param materialInstance The material instance being considered. - @param semantic The effect parameter semantic to match. - @param parameters The list of parameters to fill in. This list is not cleared. */ - FCOLLADA_EXPORT void FindEffectParametersBySemantic(const FCDMaterialInstance* materialInstance, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false); - FCOLLADA_EXPORT inline void FindEffectParametersBySemantic(FCDMaterialInstance* materialInstance, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersBySemantic(const_cast(materialInstance), semantic, parameters, localOnly); } /**< See above. */ - FCOLLADA_EXPORT void FindEffectParametersBySemantic(const FCDMaterial* material, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline void FindEffectParametersBySemantic(FCDMaterial* material, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersBySemantic(const_cast(material), semantic, parameters, localOnly); } /**< See above. */ - FCOLLADA_EXPORT void FindEffectParametersBySemantic(const FCDEffect* effect, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline void FindEffectParametersBySemantic(FCDEffect* effect, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersBySemantic(const_cast(effect), semantic, parameters, localOnly); } /**< See above. */ - FCOLLADA_EXPORT void FindEffectParametersBySemantic(const FCDEffectProfile* profile, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline void FindEffectParametersBySemantic(FCDEffectProfile* profile, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersBySemantic(const_cast(profile), semantic, parameters, localOnly); } /**< See above. */ - FCOLLADA_EXPORT void FindEffectParametersBySemantic(const FCDEffectTechnique* technique, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline void FindEffectParametersBySemantic(FCDEffectTechnique* technique, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersBySemantic(const_cast(technique), semantic, parameters, localOnly); } /**< See above. */ - - /** Retrieves a subset of the common effect parameter list. - Look for the effect parameter generators with the correct reference. - This function searches through the geometry instance and the level of abstractions below. - @todo Some iterator structure to replace all these functions. - @param materialInstance The material instance being considered. - @param reference The effect parameter reference to match. In the case of effect - parameter generators, the reference is replaced by the sub-id. - @param parameters The list of parameters to fill in. This list is not cleared. */ - FCOLLADA_EXPORT void FindEffectParametersByReference(const FCDMaterialInstance* materialInstance, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false); - FCOLLADA_EXPORT inline void FindEffectParametersByReference(FCDMaterialInstance* materialInstance, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersByReference(const_cast(materialInstance), reference, parameters, localOnly); } /**< See above. */ - FCOLLADA_EXPORT void FindEffectParametersByReference(const FCDMaterial* material, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline void FindEffectParametersByReference(FCDMaterial* material, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersByReference(const_cast(material), reference, parameters, localOnly); } /**< See above. */ - FCOLLADA_EXPORT void FindEffectParametersByReference(const FCDEffect* effect, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline void FindEffectParametersByReference(FCDEffect* effect, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersByReference(const_cast(effect), reference, parameters, localOnly); } /**< See above. */ - FCOLLADA_EXPORT void FindEffectParametersByReference(const FCDEffectProfile* profile, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline void FindEffectParametersByReference(FCDEffectProfile* profile, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersByReference(const_cast(profile), reference, parameters, localOnly); } /**< See above. */ - FCOLLADA_EXPORT void FindEffectParametersByReference(const FCDEffectTechnique* technique, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ - FCOLLADA_EXPORT inline void FindEffectParametersByReference(FCDEffectTechnique* technique, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersByReference(const_cast(technique), reference, parameters, localOnly); } /**< See above. */ -}; - -#endif //_FCD_EFFECT_TOOLS_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/** + @file FCDEffectTools.h + This file contains FCDEffectTools namespace. +*/ + +#ifndef _FCD_EFFECT_TOOLS_H_ +#define _FCD_EFFECT_TOOLS_H_ + +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +/** Contains functions to post-process parameters into a list from a specific instance of an effect. + @ingroup FCDEffect */ + +class FCDMaterialInstance; +class FCDEffectStandard; +class FCDEffectTechnique; +class FCDGeometryInstance; + +#if defined(WIN32) +template class FCOLLADA_EXPORT FCDEffectParameterAnimatableT; /**< Trick Doxygen. */ +#elif defined(LINUX) || defined(__APPLE__) +template class FCDEffectParameterAnimatableT; /**< Trick Doxygen. */ +#endif // LINUX +typedef FCDEffectParameterAnimatableT FCDEffectParameterColor4; /**< A RGBA color effect parameter. */ +typedef FCDEffectParameterAnimatableT FCDEffectParameterFloat; /**< A floating-point value effect parameter. */ + +typedef fm::pvector FCDEffectParameterList; /**< A dynamically-sized array of effect parameters. */ + +namespace FCDEffectTools +{ + /** Synchronizes the standard effect parameters associated with + a material instance. Does nothing if there is no profile_COMMON. + @param instance The specific material instance to be synchronized. */ + FCOLLADA_EXPORT void SynchronizeAnimatedParams(FCDGeometryInstance* geometryInstance, FCDMaterialInstance* materialInstance); + + /** {INTERNAL] Synchronizes a standard effect's float parameter from the three + lists that can affect it with newparam's and setparam's. + @param semantic The FCDEffectStandard semantic for the specific parameter. + @param param One of the FCDEffectStandard color parameters. + @param materialList The parameters list from a material instance. + @param effectList The parameters list from the effect. + @param profileList The parameters list from the effect profile. Should be COMMON. */ + FCOLLADA_EXPORT void LinkAnimatedParamCommonFloat(const fm::string& semantic, FCDEffectParameterFloat* param, FCDGeometryInstance* geometry, FCDMaterial* material, FCDEffect* effect, FCDEffectProfile* profile); + + /** [INTERNAL] Synchronizes a standard effect's vector parameter from the three + lists that can affect it with newparam's and setparam's. + @param semantic The FCDEffectStandard semantic for the specific parameter. + @param param One of the FCDEffectStandard color parameters. + @param materialList The parameters list from a material instance. + @param effectList The parameters list from the effect. + @param profileList The parameters list from the effect profile. Should be COMMON. */ + FCOLLADA_EXPORT void LinkAnimatedParamCommonVector(const fm::string& semantic, FCDEffectParameterColor4* param, FCDGeometryInstance* geometry, FCDMaterial* material, FCDEffect* effect, FCDEffectProfile* profile); + + /** document.... */ + FCOLLADA_EXPORT FCDParameterAnimatableColor4* GetAnimatedColor(FCDGeometryInstance* geometryInstance, FCDMaterial* material, const fm::string& semantic, bool* isFloat3); + + /** document... */ + FCOLLADA_EXPORT FCDParameterAnimatableFloat* GetAnimatedFloat(FCDGeometryInstance* geometryInstance, FCDMaterial* material, const fm::string& semantic); + + /** document... */ + FCOLLADA_EXPORT FMVector4* GetDefaultColor(FCDMaterial* material, const fm::string& semantic, bool* isFloat3); + + /** document... */ + FCOLLADA_EXPORT float* GetDefaultFloat(FCDMaterial* material, const fm::string& semantic); + + /** Retrieves a common effect parameter. Looks for the common effect parameter with the correct + semantic, in order to bind or override its value. + This function searches through the given level of abstractions and the ones below. + @todo Some iterator structure to replace all these functions. + @param materialInstance The material instance being considered. + @param semantic The effect parameter semantic to match. + @param localOnly Whether to search below this level of abstraction. + @return The first effect parameter that matches the semantic. + This pointer will be NULL if no effect parameter matches the given semantic. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDMaterialInstance* materialInstance, const char* semantic, bool localOnly = false); + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDMaterialInstance* materialInstance, const char* semantic, bool localOnly = false) { return const_cast(FindEffectParameterBySemantic(const_cast(materialInstance), semantic, localOnly)); } /**< See above. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDGeometryInstance* geometryInstance, const char* semantic); /**< See above. */ + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDGeometryInstance* geometryInstance, const char* semantic) { return const_cast(FindEffectParameterBySemantic(const_cast(geometryInstance), semantic)); } /**< See above. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDMaterial* material, const char* semantic, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDMaterial* material, const char* semantic, bool localOnly = false) { return const_cast(FindEffectParameterBySemantic(const_cast(material), semantic, localOnly)); } /**< See above. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffect* effect, const char* semantic, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDEffect* effect, const char* semantic, bool localOnly = false) { return const_cast(FindEffectParameterBySemantic(const_cast(effect), semantic, localOnly)); } /**< See above. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffectProfile* profile, const char* semantic, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDEffectProfile* profile, const char* semantic, bool localOnly = false) { return const_cast(FindEffectParameterBySemantic(const_cast(profile), semantic, localOnly)); } /**< See above. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffectTechnique* technique, const char* semantic, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterBySemantic(FCDEffectTechnique* technique, const char* semantic, bool localOnly = false) { return const_cast(FindEffectParameterBySemantic(const_cast(technique), semantic, localOnly)); } /**< See above. */ + + /** Retrieves a common effect parameter. Looks for the common effect parameter with the correct + reference, in order to bind or override its value. + This function searches through the given level of abstractions and the ones below. + @todo Some iterator structure to replace all these functions. + @param materialInstance The material instance being considered. + @param reference The effect parameter reference to match. + @return The first effect parameter that matches the reference. + This pointer will be NULL if no effect parameter matches the given reference. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDMaterialInstance* materialInstance, const char* reference, bool localOnly = false); + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDMaterialInstance* materialInstance, const char* reference, bool localOnly = false) { return const_cast(FindEffectParameterByReference(const_cast(materialInstance), reference, localOnly)); } /**< See above. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDGeometryInstance* geometryInstance, const char* reference); /**< See above. */ + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDGeometryInstance* geometryInstance, const char* reference) { return const_cast(FindEffectParameterByReference(const_cast(geometryInstance), reference)); } /**< See above. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDMaterial* material, const char* reference, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDMaterial* material, const char* reference, bool localOnly = false) { return const_cast(FindEffectParameterByReference(const_cast(material), reference, localOnly)); } /**< See above. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDEffect* effect, const char* reference, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDEffect* effect, const char* reference, bool localOnly = false) { return const_cast(FindEffectParameterByReference(const_cast(effect), reference, localOnly)); } /**< See above. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDEffectProfile* profile, const char* reference, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDEffectProfile* profile, const char* reference, bool localOnly = false) { return const_cast(FindEffectParameterByReference(const_cast(profile), reference, localOnly)); } /**< See above. */ + FCOLLADA_EXPORT const FCDEffectParameter* FindEffectParameterByReference(const FCDEffectTechnique* technique, const char* reference, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline FCDEffectParameter* FindEffectParameterByReference(FCDEffectTechnique* technique, const char* reference, bool localOnly = false) { return const_cast(FindEffectParameterByReference(const_cast(technique), reference, localOnly)); } /**< See above. */ + + /** Retrieves a subset of the common effect parameter list. + Look for the effect parameter generators with the correct semantic. + This function searches through the geometry instance and the level of abstractions below. + @todo Some iterator structure to replace all these functions. + @param materialInstance The material instance being considered. + @param semantic The effect parameter semantic to match. + @param parameters The list of parameters to fill in. This list is not cleared. */ + FCOLLADA_EXPORT void FindEffectParametersBySemantic(const FCDMaterialInstance* materialInstance, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false); + FCOLLADA_EXPORT inline void FindEffectParametersBySemantic(FCDMaterialInstance* materialInstance, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersBySemantic(const_cast(materialInstance), semantic, parameters, localOnly); } /**< See above. */ + FCOLLADA_EXPORT void FindEffectParametersBySemantic(const FCDMaterial* material, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline void FindEffectParametersBySemantic(FCDMaterial* material, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersBySemantic(const_cast(material), semantic, parameters, localOnly); } /**< See above. */ + FCOLLADA_EXPORT void FindEffectParametersBySemantic(const FCDEffect* effect, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline void FindEffectParametersBySemantic(FCDEffect* effect, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersBySemantic(const_cast(effect), semantic, parameters, localOnly); } /**< See above. */ + FCOLLADA_EXPORT void FindEffectParametersBySemantic(const FCDEffectProfile* profile, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline void FindEffectParametersBySemantic(FCDEffectProfile* profile, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersBySemantic(const_cast(profile), semantic, parameters, localOnly); } /**< See above. */ + FCOLLADA_EXPORT void FindEffectParametersBySemantic(const FCDEffectTechnique* technique, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline void FindEffectParametersBySemantic(FCDEffectTechnique* technique, const char* semantic, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersBySemantic(const_cast(technique), semantic, parameters, localOnly); } /**< See above. */ + + /** Retrieves a subset of the common effect parameter list. + Look for the effect parameter generators with the correct reference. + This function searches through the geometry instance and the level of abstractions below. + @todo Some iterator structure to replace all these functions. + @param materialInstance The material instance being considered. + @param reference The effect parameter reference to match. In the case of effect + parameter generators, the reference is replaced by the sub-id. + @param parameters The list of parameters to fill in. This list is not cleared. */ + FCOLLADA_EXPORT void FindEffectParametersByReference(const FCDMaterialInstance* materialInstance, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false); + FCOLLADA_EXPORT inline void FindEffectParametersByReference(FCDMaterialInstance* materialInstance, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersByReference(const_cast(materialInstance), reference, parameters, localOnly); } /**< See above. */ + FCOLLADA_EXPORT void FindEffectParametersByReference(const FCDMaterial* material, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline void FindEffectParametersByReference(FCDMaterial* material, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersByReference(const_cast(material), reference, parameters, localOnly); } /**< See above. */ + FCOLLADA_EXPORT void FindEffectParametersByReference(const FCDEffect* effect, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline void FindEffectParametersByReference(FCDEffect* effect, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersByReference(const_cast(effect), reference, parameters, localOnly); } /**< See above. */ + FCOLLADA_EXPORT void FindEffectParametersByReference(const FCDEffectProfile* profile, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline void FindEffectParametersByReference(FCDEffectProfile* profile, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersByReference(const_cast(profile), reference, parameters, localOnly); } /**< See above. */ + FCOLLADA_EXPORT void FindEffectParametersByReference(const FCDEffectTechnique* technique, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false); /**< See above. */ + FCOLLADA_EXPORT inline void FindEffectParametersByReference(FCDEffectTechnique* technique, const char* reference, FCDEffectParameterList& parameters, bool localOnly = false) { FindEffectParametersByReference(const_cast(technique), reference, parameters, localOnly); } /**< See above. */ +}; + +#endif //_FCD_EFFECT_TOOLS_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTools.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterInstance.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterInstance.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterInstance.h (revision 24247) @@ -1,55 +1,55 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEmitterInstance.h - This file contains the FCDEmitterInstance class. - - @ingroup FCDEmitters -*/ - -#ifndef _FCD_EMITTER_INSTANCE_H_ -#define _FCD_EMITTER_INSTANCE_H_ - -#ifndef _FCD_ENTITY_INSTANCE_H_ -#include "FCDocument/FCDEntityInstance.h" -#endif // _FCD_ENTITY_INSTANCE_H_ - -class FCDGeometryPolygons; -class FCDMaterial; -class FCDMaterialInstance; -class FCDForceField; - -/** - A COLLADA emitter instance. - - The types of particles emitted are instance dependent. - Instances also contain the FCDForceInstances pointers to forces applied to the particles. -*/ -class FCOLLADA_EXPORT FCDEmitterInstance : public FCDEntityInstance -{ -private: - DeclareObjectType(FCDEntityInstance); - friend class FCDEntityInstanceFactory; - -protected: - /** Constructor: do not use directly. - Instead, use the FCDSceneNode::AddInstance function. - @param document The COLLADA document that owns the emitter instance. - @param parent The parent visual scene node. - @param entityType The type of the entity to instantiate. Unless this class - is overwritten, FCDEntity::EMITTER should be given. */ - FCDEmitterInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType = FCDEntity::EMITTER); - -public: - /** Destructor. */ - virtual ~FCDEmitterInstance(); - -}; - -#endif // _FCD_EMITTER_INSTANCE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEmitterInstance.h + This file contains the FCDEmitterInstance class. + + @ingroup FCDEmitters +*/ + +#ifndef _FCD_EMITTER_INSTANCE_H_ +#define _FCD_EMITTER_INSTANCE_H_ + +#ifndef _FCD_ENTITY_INSTANCE_H_ +#include "FCDocument/FCDEntityInstance.h" +#endif // _FCD_ENTITY_INSTANCE_H_ + +class FCDGeometryPolygons; +class FCDMaterial; +class FCDMaterialInstance; +class FCDForceField; + +/** + A COLLADA emitter instance. + + The types of particles emitted are instance dependent. + Instances also contain the FCDForceInstances pointers to forces applied to the particles. +*/ +class FCOLLADA_EXPORT FCDEmitterInstance : public FCDEntityInstance +{ +private: + DeclareObjectType(FCDEntityInstance); + friend class FCDEntityInstanceFactory; + +protected: + /** Constructor: do not use directly. + Instead, use the FCDSceneNode::AddInstance function. + @param document The COLLADA document that owns the emitter instance. + @param parent The parent visual scene node. + @param entityType The type of the entity to instantiate. Unless this class + is overwritten, FCDEntity::EMITTER should be given. */ + FCDEmitterInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType = FCDEntity::EMITTER); + +public: + /** Destructor. */ + virtual ~FCDEmitterInstance(); + +}; + +#endif // _FCD_EMITTER_INSTANCE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterInstance.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterParticle.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterParticle.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterParticle.h (revision 24247) @@ -1,18 +1,18 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEmitterParticle.h - This file defines a base class for particle emitters in FCollada. - The base class contains the particle emitter type, and contains a few utility functions -*/ - -#ifndef _FCD_EMITTER_PARTICLE_H_ -#define _FCD_EMITTER_PARTICLE_H_ - -#endif // _FCD_EMITTER_PARTICLE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEmitterParticle.h + This file defines a base class for particle emitters in FCollada. + The base class contains the particle emitter type, and contains a few utility functions +*/ + +#ifndef _FCD_EMITTER_PARTICLE_H_ +#define _FCD_EMITTER_PARTICLE_H_ + +#endif // _FCD_EMITTER_PARTICLE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterParticle.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityInstance.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityInstance.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityInstance.h (revision 24247) @@ -1,235 +1,235 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEntityInstance.h - This file contains the FCDEntityInstance class. -*/ - -#ifndef _FCD_ENTITY_INSTANCE_H_ -#define _FCD_ENTITY_INSTANCE_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDocument; -class FCDENode; -class FCDSceneNode; -class FCDEntityInstanceFactory; -class FCDEntityReference; -class FCDEntityInstance; -class FUUri; - -template class FUUniqueStringMapT; -typedef FUUniqueStringMapT FUSUniqueStringMap; /**< A set of unique strings. */ - -/** - A COLLADA entity instance. - COLLADA allows for quite a bit of per-instance settings - for entities. This information is held by the up-classes of this class. - This base class is simply meant to hold the entity that is instantiated. - - The entity instance tracks the entity, so that when an entity is released, - all its instances are released. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDEntityInstance : public FCDObject, FUTracker -{ -public: - /** The class type of the entity instance class. - Used this information to up-cast an entity instance. */ - enum Type - { - SIMPLE, /**< A simple entity instance that has no per-instance information. - This is used for lights, cameras, physics materials and force fields: there is no up-class. */ - GEOMETRY, /**< A geometry entity(FCDGeometryInstance). */ - CONTROLLER, /**< A controller entity(FCDControllerInstance). */ - MATERIAL, /**< A material entity(FCDMaterialInstance). */ - PHYSICS_MODEL, /**< A physics model(FCDPhysicsModelInstance). */ - PHYSICS_RIGID_BODY, /**< A physics rigid body(FCDPhysicsRigidBodyInstance). */ - PHYSICS_RIGID_CONSTRAINT, /**< A physics rigid constraint(FCDPhysicsRigidConstraintInstance). */ - PHYSICS_FORCE_FIELD, /**< A physics force field (FCDPhysicsForceFieldInstance). */ - TYPE_COUNT - }; - -private: - DeclareObjectType(FCDObject); - friend class FCDEntityInstanceFactory; - - FCDSceneNode* parent; // May be NULL for non-scene graph instances. - FCDEntity::Type entityType; - DeclareParameterPtr(FCDEntityReference, entityReference, FC("Entity Reference")); - - // common attributes for instances - fstring name; - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, wantedSubId, FC("Instance Sub-id")); - - // Extra information for the entity instance. - DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); - -protected: - /** Constructor: do not use directly. - Instead, use the appropriate allocation function. - For scene node instance: FCDSceneNode::AddInstance. - @param document The COLLADA document that owns the entity instance. - @param parent The visual scene node that contains the entity instance. This pointer will be NULL for - instances that are not directly under a visual scene node. - @param type The type of entity to instantiate. */ - FCDEntityInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type type); - -public: - /** Destructor. */ - virtual ~FCDEntityInstance(); - - /** Retrieves the entity instance class type. - This is used to determine the up-class for the entity instance object. - @deprecated Instead use: FCDEntityInstance::HasType(). - @return The class type: SIMPLE for entity instances with no up-class. */ - virtual Type GetType() const { return SIMPLE; } - - /** Retrieves the instantiated entity type. - The instantiated entity type will never change. - @return The instantiated entity type. */ - inline FCDEntity::Type GetEntityType() const { return entityType; } - - /** Retrieves the instantiated entity. If the entity is an external reference, - this may load the external document and retrieve the entity. - @return The instantiated entity. */ - FCDEntity* GetEntity(); - - /** Retrieves the instantiated entity. If the entity is an external reference, - this function will load the entity. Be careful when using this function - since it will change the object. - @return The instantiated entity, if loaded. */ - inline const FCDEntity* GetEntity() const { return ((FCDEntityInstance*)(this))->GetEntity(); } - - /** Retrieves the Uri to the skin target. - This can be an internal or external link - @return The uri to the target */ - const FUUri GetEntityUri() const; - - /** Sets the URI of the target mesh. - @param uri The Uri to a local or external controller or geometry */ - void SetEntityUri(const FUUri& uri); - - /** Sets the instantiated entity. - The type of the entity will be verified. - @param entity The instantiated entity. */ - void SetEntity(FCDEntity* entity); - - /** Get the contained EntityReference object. */ - inline FCDEntityReference* GetEntityReference() { return entityReference; } - inline const FCDEntityReference* GetEntityReference() const { return entityReference; } /**< See above */ - - /** Retrieves the name of the entity instance. This value has no direct use - in COLLADA but is useful to track the user-friendly name of an entity - instance. - @return The name. */ - inline const fstring& GetName() const { return name; } - - /** Sets the name of the entity instance. This value has no direct use in - COLLADA but is useful to track the user-friendly name of an entity - instance. - @param name The name. */ - void SetName(const fstring& name); - - /** Retrieves the optional sub id and is not garanteed to exist. - This id is the same as that given in SetSubId or from the COLLADA document using LoadFromXML unless it clashes with another id and - CleanSubId has been called. - @return The set sub id of the node. */ - inline const fm::string& GetWantedSubId() const { return wantedSubId; } - - /** Sets the sub id for this object. - This id must be unique within the scope of the parent element. If it is not, it can be corrected by calling CleanSubId. - @param _wantedSubId The new sub id of the object. */ - inline void SetWantedSubId(const fm::string& _wantedSubId) { wantedSubId = _wantedSubId; } - - /** Retrieves the extra information tree for this entity instance. The - prefered way to save extra information in FCollada is at the entity - level. Use this extra information tree to store any information you - want exported and imported back. - @return The extra information tree. */ - FCDExtra* GetExtra(); - inline const FCDExtra* GetExtra() const { return const_cast(this)->GetExtra(); } /**< See above. */ - - /** Retrieves whether this entity instance points to an external entity. - @return Whether this is an external entity instantiation. */ - bool IsExternalReference() const; - - /** Retrieves the parent of the entity instance. - @return the parent visual scene node. This pointer will be NULL - when the instance is not created in the visual scene graph. */ - inline FCDSceneNode* GetParent() { return parent; } - inline const FCDSceneNode* GetParent() const { return parent; } /**< See above. */ - - /** Checks whether or not this instance is below the given scene node in - the scene hierarchy. - @param node The scene node. - @return True if parent is above this instance in the hierarchy, false otherwise.*/ - bool HasForParent(FCDSceneNode* node) const; - - /** [INTERNAL] Cleans up the sub identifiers. - The sub identifiers must be unique with respect to its parent. This method corrects the sub ids if there are conflicts. - @param parentStringMap The string map from the parent of this instance in which the sub ids must be unique. */ - virtual void CleanSubId(FUSUniqueStringMap* parentStringMap = NULL); - - /** Clones the entity instance. - @param clone The entity instance to become the clone. - @return The cloned entity instance. */ - virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; - -protected: - /** [INTERNAL] Retrieves the COLLADA name for the instantiation of a given entity type. - Children can override this method to easily add more class types. - @param type The entity class type. - @return The COLLADA name to instantiate an entity of the given class type. */ - //virtual const char* GetInstanceClassType(FCDEntity::Type type) const; - - /** Callback when the instantiated entity is being released. - @param object A tracked object. */ - virtual void OnObjectReleased(FUTrackable* object); -}; - -/** - [INTERNAL] A factory for COLLADA Entity instances. - Creates the correct instance object for a given entity type/XML tree node. - To create new instances, use the FCDSceneNode::AddInstance function. -*/ -class FCOLLADA_EXPORT FCDEntityInstanceFactory -{ -private: - FCDEntityInstanceFactory() {} // Static class: do not instantiate. - -public: - /** Creates a new COLLADA instance, given a entity type. - @param document The COLLADA document that will own the new instance. - @param parent The visual scene node that will contain the instance. - @param type The type of instance object to create. - @return The new COLLADA instance. This pointer will be NULL - if the given type is invalid. */ - static FCDEntityInstance* CreateInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type type); - - /** Creates a new COLLADA instance of a given entity. - @param document The COLLADA document that will own the new instance. - @param parent The visual scene node that will contain the instance. - @param entity The entity to create an instance of. - @return The new COLLADA instance. This pointer will be NULL - if the given type is invalid. */ - static FCDEntityInstance* CreateInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity *entity); -}; - - -#endif // _FCD_ENTITY_INSTANCE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEntityInstance.h + This file contains the FCDEntityInstance class. +*/ + +#ifndef _FCD_ENTITY_INSTANCE_H_ +#define _FCD_ENTITY_INSTANCE_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDocument; +class FCDENode; +class FCDSceneNode; +class FCDEntityInstanceFactory; +class FCDEntityReference; +class FCDEntityInstance; +class FUUri; + +template class FUUniqueStringMapT; +typedef FUUniqueStringMapT FUSUniqueStringMap; /**< A set of unique strings. */ + +/** + A COLLADA entity instance. + COLLADA allows for quite a bit of per-instance settings + for entities. This information is held by the up-classes of this class. + This base class is simply meant to hold the entity that is instantiated. + + The entity instance tracks the entity, so that when an entity is released, + all its instances are released. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDEntityInstance : public FCDObject, FUTracker +{ +public: + /** The class type of the entity instance class. + Used this information to up-cast an entity instance. */ + enum Type + { + SIMPLE, /**< A simple entity instance that has no per-instance information. + This is used for lights, cameras, physics materials and force fields: there is no up-class. */ + GEOMETRY, /**< A geometry entity(FCDGeometryInstance). */ + CONTROLLER, /**< A controller entity(FCDControllerInstance). */ + MATERIAL, /**< A material entity(FCDMaterialInstance). */ + PHYSICS_MODEL, /**< A physics model(FCDPhysicsModelInstance). */ + PHYSICS_RIGID_BODY, /**< A physics rigid body(FCDPhysicsRigidBodyInstance). */ + PHYSICS_RIGID_CONSTRAINT, /**< A physics rigid constraint(FCDPhysicsRigidConstraintInstance). */ + PHYSICS_FORCE_FIELD, /**< A physics force field (FCDPhysicsForceFieldInstance). */ + TYPE_COUNT + }; + +private: + DeclareObjectType(FCDObject); + friend class FCDEntityInstanceFactory; + + FCDSceneNode* parent; // May be NULL for non-scene graph instances. + FCDEntity::Type entityType; + DeclareParameterPtr(FCDEntityReference, entityReference, FC("Entity Reference")); + + // common attributes for instances + fstring name; + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, wantedSubId, FC("Instance Sub-id")); + + // Extra information for the entity instance. + DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); + +protected: + /** Constructor: do not use directly. + Instead, use the appropriate allocation function. + For scene node instance: FCDSceneNode::AddInstance. + @param document The COLLADA document that owns the entity instance. + @param parent The visual scene node that contains the entity instance. This pointer will be NULL for + instances that are not directly under a visual scene node. + @param type The type of entity to instantiate. */ + FCDEntityInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type type); + +public: + /** Destructor. */ + virtual ~FCDEntityInstance(); + + /** Retrieves the entity instance class type. + This is used to determine the up-class for the entity instance object. + @deprecated Instead use: FCDEntityInstance::HasType(). + @return The class type: SIMPLE for entity instances with no up-class. */ + virtual Type GetType() const { return SIMPLE; } + + /** Retrieves the instantiated entity type. + The instantiated entity type will never change. + @return The instantiated entity type. */ + inline FCDEntity::Type GetEntityType() const { return entityType; } + + /** Retrieves the instantiated entity. If the entity is an external reference, + this may load the external document and retrieve the entity. + @return The instantiated entity. */ + FCDEntity* GetEntity(); + + /** Retrieves the instantiated entity. If the entity is an external reference, + this function will load the entity. Be careful when using this function + since it will change the object. + @return The instantiated entity, if loaded. */ + inline const FCDEntity* GetEntity() const { return ((FCDEntityInstance*)(this))->GetEntity(); } + + /** Retrieves the Uri to the skin target. + This can be an internal or external link + @return The uri to the target */ + const FUUri GetEntityUri() const; + + /** Sets the URI of the target mesh. + @param uri The Uri to a local or external controller or geometry */ + void SetEntityUri(const FUUri& uri); + + /** Sets the instantiated entity. + The type of the entity will be verified. + @param entity The instantiated entity. */ + void SetEntity(FCDEntity* entity); + + /** Get the contained EntityReference object. */ + inline FCDEntityReference* GetEntityReference() { return entityReference; } + inline const FCDEntityReference* GetEntityReference() const { return entityReference; } /**< See above */ + + /** Retrieves the name of the entity instance. This value has no direct use + in COLLADA but is useful to track the user-friendly name of an entity + instance. + @return The name. */ + inline const fstring& GetName() const { return name; } + + /** Sets the name of the entity instance. This value has no direct use in + COLLADA but is useful to track the user-friendly name of an entity + instance. + @param name The name. */ + void SetName(const fstring& name); + + /** Retrieves the optional sub id and is not garanteed to exist. + This id is the same as that given in SetSubId or from the COLLADA document using LoadFromXML unless it clashes with another id and + CleanSubId has been called. + @return The set sub id of the node. */ + inline const fm::string& GetWantedSubId() const { return wantedSubId; } + + /** Sets the sub id for this object. + This id must be unique within the scope of the parent element. If it is not, it can be corrected by calling CleanSubId. + @param _wantedSubId The new sub id of the object. */ + inline void SetWantedSubId(const fm::string& _wantedSubId) { wantedSubId = _wantedSubId; } + + /** Retrieves the extra information tree for this entity instance. The + prefered way to save extra information in FCollada is at the entity + level. Use this extra information tree to store any information you + want exported and imported back. + @return The extra information tree. */ + FCDExtra* GetExtra(); + inline const FCDExtra* GetExtra() const { return const_cast(this)->GetExtra(); } /**< See above. */ + + /** Retrieves whether this entity instance points to an external entity. + @return Whether this is an external entity instantiation. */ + bool IsExternalReference() const; + + /** Retrieves the parent of the entity instance. + @return the parent visual scene node. This pointer will be NULL + when the instance is not created in the visual scene graph. */ + inline FCDSceneNode* GetParent() { return parent; } + inline const FCDSceneNode* GetParent() const { return parent; } /**< See above. */ + + /** Checks whether or not this instance is below the given scene node in + the scene hierarchy. + @param node The scene node. + @return True if parent is above this instance in the hierarchy, false otherwise.*/ + bool HasForParent(FCDSceneNode* node) const; + + /** [INTERNAL] Cleans up the sub identifiers. + The sub identifiers must be unique with respect to its parent. This method corrects the sub ids if there are conflicts. + @param parentStringMap The string map from the parent of this instance in which the sub ids must be unique. */ + virtual void CleanSubId(FUSUniqueStringMap* parentStringMap = NULL); + + /** Clones the entity instance. + @param clone The entity instance to become the clone. + @return The cloned entity instance. */ + virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; + +protected: + /** [INTERNAL] Retrieves the COLLADA name for the instantiation of a given entity type. + Children can override this method to easily add more class types. + @param type The entity class type. + @return The COLLADA name to instantiate an entity of the given class type. */ + //virtual const char* GetInstanceClassType(FCDEntity::Type type) const; + + /** Callback when the instantiated entity is being released. + @param object A tracked object. */ + virtual void OnObjectReleased(FUTrackable* object); +}; + +/** + [INTERNAL] A factory for COLLADA Entity instances. + Creates the correct instance object for a given entity type/XML tree node. + To create new instances, use the FCDSceneNode::AddInstance function. +*/ +class FCOLLADA_EXPORT FCDEntityInstanceFactory +{ +private: + FCDEntityInstanceFactory() {} // Static class: do not instantiate. + +public: + /** Creates a new COLLADA instance, given a entity type. + @param document The COLLADA document that will own the new instance. + @param parent The visual scene node that will contain the instance. + @param type The type of instance object to create. + @return The new COLLADA instance. This pointer will be NULL + if the given type is invalid. */ + static FCDEntityInstance* CreateInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type type); + + /** Creates a new COLLADA instance of a given entity. + @param document The COLLADA document that will own the new instance. + @param parent The visual scene node that will contain the instance. + @param entity The entity to create an instance of. + @return The new COLLADA instance. This pointer will be NULL + if the given type is invalid. */ + static FCDEntityInstance* CreateInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity *entity); +}; + + +#endif // _FCD_ENTITY_INSTANCE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityInstance.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExternalReferenceManager.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExternalReferenceManager.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExternalReferenceManager.h (revision 24247) @@ -1,96 +1,96 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDExternalReferenceManager.h - This file contains the FCDExternalReferenceManager class. -*/ - -#ifndef _FCD_EXTERNAL_REFERENCE_MANAGER_H_ -#define _FCD_EXTERNAL_REFERENCE_MANAGER_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ - -class FCDEntityInstance; -class FCDEntityReference; -class FCDPlaceHolder; - -/** - A FCollada document external reference manager. - - Each FCollada document has one and only one external reference manager. - It keeps track of all the external document's, whether they are loaded or not. - - By default, all external references are handled automatically. - You will have to access this structure only for informational purposes or - if you have disabled the automatic de-referencing feature using the - FCollada::SetDereferenceFlag function. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDExternalReferenceManager : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - FUObjectContainer placeHolders; - -public: - /** Constructor. - @param document The COLLADA document that owns the external reference manager. */ - FCDExternalReferenceManager(FCDocument* document); - - /** Destructor. */ - virtual ~FCDExternalReferenceManager(); - - /** Adds a new FCollada document placeholder to this document. - @param document The external FCollada document to track. */ - FCDPlaceHolder* AddPlaceHolder(FCDocument* document); - - /** Adds a new FCollada document placeholder to this document. - @param fileUrl The URI of the external FCollada document to track. */ - FCDPlaceHolder* AddPlaceHolder(const fstring& fileUrl); - - /** Retrieves the number of FCollada document that are automatically - tracked by this document. - @return The number of tracked document. */ - inline size_t GetPlaceHolderCount() const { return placeHolders.size(); } - - /** Retrieves a FCollada document placeholder. - @param index The index of the placeholder. - @return The placeholder at the given index. */ - inline FCDPlaceHolder* GetPlaceHolder(size_t index) { FUAssert(index < placeHolders.size(), return NULL); return placeHolders.at(index); } - inline const FCDPlaceHolder* GetPlaceHolder(size_t index) const { FUAssert(index < placeHolders.size(), return NULL); return placeHolders.at(index); } /**< See above. */ - - /** Retrieves the placeholder that references the FCollada document at the given URI. - @param fileUrl The URI of the FCollada document. - @return The placeholder for the FCollada document. This pointer will be NULL - if no local entity instances reference entities within the document - at the given URI. */ - const FCDPlaceHolder* FindPlaceHolder(const fstring& fileUrl) const; - inline FCDPlaceHolder* FindPlaceHolder(const fstring& fileUrl) { return const_cast(const_cast(this)->FindPlaceHolder(fileUrl)); } /**< See above. */ - - /** Retrieves the placeholder that references the given FCollada document. - @param document A FCollada document. - @return The placeholder for the given FCollada document. This pointer will be NULL - if no local entity instances reference entities within the given document. */ - const FCDPlaceHolder* FindPlaceHolder(const FCDocument* document) const; - inline FCDPlaceHolder* FindPlaceHolder(FCDocument* document) { return const_cast(const_cast(this)->FindPlaceHolder(document)); } /**< See above. */ - - /** [INTERNAL] Registers a newly-loaded FCollada document - with the other existing FCollada document. This callback is used - to update all the entity instances that reference external entities. - Any entity instance that references an entity within the newly-loaded - FCollada document will be updated. - @param document The newly-loaded FCollada document. */ - static void RegisterLoadedDocument(FCDocument* document); -}; - -#endif // _FCD_EXTERNAL_REFERENCE_MANAGER_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDExternalReferenceManager.h + This file contains the FCDExternalReferenceManager class. +*/ + +#ifndef _FCD_EXTERNAL_REFERENCE_MANAGER_H_ +#define _FCD_EXTERNAL_REFERENCE_MANAGER_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ + +class FCDEntityInstance; +class FCDEntityReference; +class FCDPlaceHolder; + +/** + A FCollada document external reference manager. + + Each FCollada document has one and only one external reference manager. + It keeps track of all the external document's, whether they are loaded or not. + + By default, all external references are handled automatically. + You will have to access this structure only for informational purposes or + if you have disabled the automatic de-referencing feature using the + FCollada::SetDereferenceFlag function. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDExternalReferenceManager : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + FUObjectContainer placeHolders; + +public: + /** Constructor. + @param document The COLLADA document that owns the external reference manager. */ + FCDExternalReferenceManager(FCDocument* document); + + /** Destructor. */ + virtual ~FCDExternalReferenceManager(); + + /** Adds a new FCollada document placeholder to this document. + @param document The external FCollada document to track. */ + FCDPlaceHolder* AddPlaceHolder(FCDocument* document); + + /** Adds a new FCollada document placeholder to this document. + @param fileUrl The URI of the external FCollada document to track. */ + FCDPlaceHolder* AddPlaceHolder(const fstring& fileUrl); + + /** Retrieves the number of FCollada document that are automatically + tracked by this document. + @return The number of tracked document. */ + inline size_t GetPlaceHolderCount() const { return placeHolders.size(); } + + /** Retrieves a FCollada document placeholder. + @param index The index of the placeholder. + @return The placeholder at the given index. */ + inline FCDPlaceHolder* GetPlaceHolder(size_t index) { FUAssert(index < placeHolders.size(), return NULL); return placeHolders.at(index); } + inline const FCDPlaceHolder* GetPlaceHolder(size_t index) const { FUAssert(index < placeHolders.size(), return NULL); return placeHolders.at(index); } /**< See above. */ + + /** Retrieves the placeholder that references the FCollada document at the given URI. + @param fileUrl The URI of the FCollada document. + @return The placeholder for the FCollada document. This pointer will be NULL + if no local entity instances reference entities within the document + at the given URI. */ + const FCDPlaceHolder* FindPlaceHolder(const fstring& fileUrl) const; + inline FCDPlaceHolder* FindPlaceHolder(const fstring& fileUrl) { return const_cast(const_cast(this)->FindPlaceHolder(fileUrl)); } /**< See above. */ + + /** Retrieves the placeholder that references the given FCollada document. + @param document A FCollada document. + @return The placeholder for the given FCollada document. This pointer will be NULL + if no local entity instances reference entities within the given document. */ + const FCDPlaceHolder* FindPlaceHolder(const FCDocument* document) const; + inline FCDPlaceHolder* FindPlaceHolder(FCDocument* document) { return const_cast(const_cast(this)->FindPlaceHolder(document)); } /**< See above. */ + + /** [INTERNAL] Registers a newly-loaded FCollada document + with the other existing FCollada document. This callback is used + to update all the entity instances that reference external entities. + Any entity instance that references an entity within the newly-loaded + FCollada document will be updated. + @param document The newly-loaded FCollada document. */ + static void RegisterLoadedDocument(FCDocument* document); +}; + +#endif // _FCD_EXTERNAL_REFERENCE_MANAGER_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExternalReferenceManager.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDeflector.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDeflector.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDeflector.h (revision 24247) @@ -1,17 +1,17 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDForceDeflector.h - This file contains the FCDForceDeflector class. -*/ - -#ifndef _FCD_FORCE_DEFLECTOR_H_ -#define _FCD_FORCE_DEFLECTOR_H_ - -#endif // _FCD_FORCE_DEFLECTOR_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDForceDeflector.h + This file contains the FCDForceDeflector class. +*/ + +#ifndef _FCD_FORCE_DEFLECTOR_H_ +#define _FCD_FORCE_DEFLECTOR_H_ + +#endif // _FCD_FORCE_DEFLECTOR_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDeflector.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceField.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceField.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceField.h (revision 24247) @@ -1,69 +1,69 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#ifndef _FCD_FORCE_FIELD_H_ -#define _FCD_FORCE_FIELD_H_ - -class FCDocument; -class FCDExtra; -class FCDForce; - -#ifndef _FCD_FORCE_TYPED_H_ -#include "FCDocument/FCDForceTyped.h" -#endif // _FCD_FORCE_TYPED_H_ -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -/** - A COLLADA physics force field. - - This class does not have any parameters in the COMMON profile. - You can use the custom extra tree to enter/retrieve your - specific customized information. - - @ingroup FCDocument -*/ - -class FCOLLADA_EXPORT FCDForceField : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - DeclareParameterRef(FCDExtra, information, FC("Information")); - -public: - /** Constructor. - @param document The COLLADA document that owns the force field. */ - FCDForceField(FCDocument* document); - - /** Destructor. */ - virtual ~FCDForceField(); - - /** Retrieves the extra tree for all the force field information. - @return The extra tree. */ - inline FCDExtra* GetInformation() { return const_cast(const_cast(this)->GetInformation()); } - const FCDExtra* GetInformation() const; - - /** [INTERNAL] Set the information. - @param info The new information to set. */ - inline void SetInformation(FCDExtra* info){ information = info; } - - /** Retrieves the entity class type. - @return The entity class type: FORCE_FIELD */ - virtual Type GetType() const { return FORCE_FIELD; } - - /** Clones the force field information. - @param clone The cloned force field. - If this pointer is NULL, a new force field is created and - you will need to release it manually. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; -}; - -#endif // _FCD_FORCE_FIELD_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef _FCD_FORCE_FIELD_H_ +#define _FCD_FORCE_FIELD_H_ + +class FCDocument; +class FCDExtra; +class FCDForce; + +#ifndef _FCD_FORCE_TYPED_H_ +#include "FCDocument/FCDForceTyped.h" +#endif // _FCD_FORCE_TYPED_H_ +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +/** + A COLLADA physics force field. + + This class does not have any parameters in the COMMON profile. + You can use the custom extra tree to enter/retrieve your + specific customized information. + + @ingroup FCDocument +*/ + +class FCOLLADA_EXPORT FCDForceField : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + DeclareParameterRef(FCDExtra, information, FC("Information")); + +public: + /** Constructor. + @param document The COLLADA document that owns the force field. */ + FCDForceField(FCDocument* document); + + /** Destructor. */ + virtual ~FCDForceField(); + + /** Retrieves the extra tree for all the force field information. + @return The extra tree. */ + inline FCDExtra* GetInformation() { return const_cast(const_cast(this)->GetInformation()); } + const FCDExtra* GetInformation() const; + + /** [INTERNAL] Set the information. + @param info The new information to set. */ + inline void SetInformation(FCDExtra* info){ information = info; } + + /** Retrieves the entity class type. + @return The entity class type: FORCE_FIELD */ + virtual Type GetType() const { return FORCE_FIELD; } + + /** Clones the force field information. + @param clone The cloned force field. + If this pointer is NULL, a new force field is created and + you will need to release it manually. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; +}; + +#endif // _FCD_FORCE_FIELD_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceField.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassState.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassState.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassState.h (revision 24247) @@ -1,84 +1,84 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectPassState.h - This file contains the FCDEffectPassState class. -*/ - -#ifndef _FCD_EFFECT_PASS_STATE_H_ -#define _FCD_EFFECT_PASS_STATE_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -/** - This class holds the information necessary to set or apply - one render state for a given pass. - To get more information about the render state and how to interpret the data - they hold, see the FUDaePassState namespace and its enumerated type. - @see FUDaePassState::State - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectPassState : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, type, FC("Type")); // FUDaePassState::State - - // Data remains state-specific, un-parameterizable and will - // pretty much always require custom UI. - uint8* data; - size_t dataSize; - -public: - /** Constructor. - Once built, the render state associated with this object should never change - and the data pointer should be allocated to the correct size and never - re-allocated. - @param document The COLLADA document that owns this render state. - @param renderState The render state type. */ - FCDEffectPassState(FCDocument* document, FUDaePassState::State renderState); - - /** Destructor. */ - virtual ~FCDEffectPassState(); - - /** Retrieves the type of the pass render state. - @return The render state type. */ - FUDaePassState::State GetType() const { return (FUDaePassState::State) *type; } - - /** Retrieves the data size of the pass render state. - @return The size of the render state data. */ - size_t GetDataSize() const { return dataSize; } - - /** Retrieves the data pointer for the pass render state. - @return The data pointer. */ - uint8* GetData() { return data; } - const uint8* GetData() const { return data; } /**< See above. */ - - /** Use this method to reset the state back to its default value. This method - is called in the constructor.*/ - void SetDefaultValue(); - - /** Clones the effect pass and shaders. - @param clone The cloned pass. - If this pointer is NULL, a new pass is created and - you will need to release this new pass. - @return The cloned pass. */ - FCDEffectPassState* Clone(FCDEffectPassState* clone = NULL) const; -}; - -#endif // _FCD_EFFECT_PASS_STATE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectPassState.h + This file contains the FCDEffectPassState class. +*/ + +#ifndef _FCD_EFFECT_PASS_STATE_H_ +#define _FCD_EFFECT_PASS_STATE_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +/** + This class holds the information necessary to set or apply + one render state for a given pass. + To get more information about the render state and how to interpret the data + they hold, see the FUDaePassState namespace and its enumerated type. + @see FUDaePassState::State + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectPassState : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, type, FC("Type")); // FUDaePassState::State + + // Data remains state-specific, un-parameterizable and will + // pretty much always require custom UI. + uint8* data; + size_t dataSize; + +public: + /** Constructor. + Once built, the render state associated with this object should never change + and the data pointer should be allocated to the correct size and never + re-allocated. + @param document The COLLADA document that owns this render state. + @param renderState The render state type. */ + FCDEffectPassState(FCDocument* document, FUDaePassState::State renderState); + + /** Destructor. */ + virtual ~FCDEffectPassState(); + + /** Retrieves the type of the pass render state. + @return The render state type. */ + FUDaePassState::State GetType() const { return (FUDaePassState::State) *type; } + + /** Retrieves the data size of the pass render state. + @return The size of the render state data. */ + size_t GetDataSize() const { return dataSize; } + + /** Retrieves the data pointer for the pass render state. + @return The data pointer. */ + uint8* GetData() { return data; } + const uint8* GetData() const { return data; } /**< See above. */ + + /** Use this method to reset the state back to its default value. This method + is called in the constructor.*/ + void SetDefaultValue(); + + /** Clones the effect pass and shaders. + @param clone The cloned pass. + If this pointer is NULL, a new pass is created and + you will need to release this new pass. + @return The cloned pass. */ + FCDEffectPassState* Clone(FCDEffectPassState* clone = NULL) const; +}; + +#endif // _FCD_EFFECT_PASS_STATE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassState.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfileFX.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfileFX.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfileFX.h (revision 24247) @@ -1,156 +1,156 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectProfileFX.h - This file declares the FCDEffectProfileFX class. -*/ - -#ifndef _FCD_EFFECT_PROFILE_FX_H_ -#define _FCD_EFFECT_PROFILE_FX_H_ - -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ -#ifndef _FCD_EFFECT_PROFILE_H_ -#include "FCDocument/FCDEffectProfile.h" -#endif // _FCD_EFFECT_PROFILE_H_ - -class FCDocument; -class FCDEffect; -class FCDEffectCode; -class FCDEffectParameter; -class FCDEffectParameterSurface; -class FCDEffectTechnique; - -/** - A general effect profile description. - - The general effect profile contains all the information necessary - to implement the advanced effect profiles, such as CG, HLSL, GLSL and GLES. - Since these effect profiles contains extremely similar information, they - use the same description structure. For the COMMON profile, - see the FCDEffectStandard class. - - You should use the GetType function to figure out which profile this structure - addresses. You can then retrieve one or many of the FCDEffectTechnique objects - that describe how to render for this profile. You may want to check the - FCDEffectMaterialTechniqueHint objects at the FCDMaterial level, in order to - determine which technique(s) to use for your platform. At the profile - level of abstraction, parameters may be generated within the FCDEffectParamterList. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectProfileFX : public FCDEffectProfile -{ -private: - DeclareObjectType(FCDEffectProfile); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, type, FC("Profile Language")); // FUDaeProfileType::Type - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, platform, FC("Platform")); - - DeclareParameterContainer(FCDEffectCode, codes, FC("Code Inclusions")); - DeclareParameterContainer(FCDEffectTechnique, techniques, FC("Effect Techniques")); - -public: - /** Constructor: do not use directly. Instead, use the FCDEffect::AddProfile function. - @param parent The effect which contains this profile. - @param type The type of profile. */ - FCDEffectProfileFX(FCDocument* document, FCDEffect* parent); - - /** Destructor. */ - virtual ~FCDEffectProfileFX(); - - /** Retrieves the profile type for this effect. - This function is a part of the FCDEffectProfile interface and allows you - to up-cast an effect profile pointer safely to this class. - @return The profile type. This should never be the value: 'COMMON', - but all other profiles currently derive from this class. */ - virtual FUDaeProfileType::Type GetType() const { return (FUDaeProfileType::Type) *type; } - - /** Sets the profile type for this effect. - Do not change the profile type of a completed effect. */ - void SetType(FUDaeProfileType::Type _type) { type = _type; } - - /** Retrieves the name of the platform in which to use the effect profile. - This parameter is very optional. - @return The platform name. */ - const fstring& GetPlatform() const { return platform; } - - /** Sets the name of the platform in which to use the effect profile. - This parameter is very optional. - @param _platform The platform name. */ - void SetPlatform(const fstring& _platform) { platform = _platform; SetDirtyFlag(); } - - /** Retrieves the list of techniques contained within this effect profile. - You may want to check the FCDEffectMaterialTechniqueHint objects at the FCDMaterial level, - in order to determine which technique(s) to use for your platform. - @return The list of inner techniques. */ - DEPRECATED(3.05A, GetTechniqueCount and GetTechnique(index)) void GetTechniqueList() const {} - - /** Retrieves the number of techniques contained within this effect profile. - @return The number of inner techniques. */ - size_t GetTechniqueCount() const { return techniques.size(); } - - /** Retrieves a technique contained within this effect profile. - You may want to check the FCDEffectMaterialTechniqueHint objects at the FCDMaterial level, - in order to determine which technique(s) to use for your platform. - @param index The index of the technique. - @return The inner technique. This pointer will be NULL if the index is out-of-bounds. */ - FCDEffectTechnique* GetTechnique(size_t index) { FUAssert(index < GetTechniqueCount(), return NULL); return techniques.at(index); } - const FCDEffectTechnique* GetTechnique(size_t index) const { FUAssert(index < GetTechniqueCount(), return NULL); return techniques.at(index); } /**< See above. */ - - /** Adds a new technique to this effect profile. - @return The new technique object. */ - FCDEffectTechnique* AddTechnique(); - - /** Retrieves the list of code inclusions. - @return The list of code inclusions. */ - DEPRECATED(3.05A, GetCodeCount and GetCode(index)) void GetCodeList() {} - - /** Retrieves the number of code inclusions contained within the effect profile. - @return The number of code inclusions. */ - size_t GetCodeCount() const { return codes.size(); } - - /** Retrieves a code inclusion contained within the effect profile. - @param index The index of the code inclusion. - @return The code inclusion. This pointer will be NULL if the index is out-of-bounds. */ - inline FCDEffectCode* GetCode(size_t index) { FUAssert(index < GetCodeCount(), return NULL); return codes.at(index); } - inline const FCDEffectCode* GetCode(size_t index) const { FUAssert(index < GetCodeCount(), return NULL); return codes.at(index); } /**< See above. */ - - /** Retrieves the code inclusion with the given sub-id. - @param sid A COLLADA sub-id. - @return The code inclusion with the given sub-id. This pointer will be NULL, - if there are no code inclusions that match the given sub-id. */ - inline FCDEffectCode* FindCode(const char* sid) { return const_cast(const_cast(this)->FindCode(sid)); } - const FCDEffectCode* FindCode(const char* sid) const; /**< See above. */ - - /** Adds a new code inclusion to this effect profile. - @return The new code inclusion. */ - FCDEffectCode* AddCode(); - - /** Clones the full effect profile. - @param clone The cloned profile. - If this pointer is NULL, a new profile is created and - you will need to release this new profile. - @return The cloned profile. This pointer will never be NULL. */ - virtual FCDEffectProfile* Clone(FCDEffectProfile* clone = NULL) const; - - /** [INTERNAL] Flattens this effect profile. Pushes all the effect parameter overrides - into the effect parameter generators and moves all the parameters to the - effect technique level of abstraction. To flatten the material, use the - FCDMaterialInstance::FlattenMaterial function. */ - DEPRECATED(3.05A, not recommended) void Flatten() {} -}; - -#endif // _FCD_EFFECT_PROFILE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectProfileFX.h + This file declares the FCDEffectProfileFX class. +*/ + +#ifndef _FCD_EFFECT_PROFILE_FX_H_ +#define _FCD_EFFECT_PROFILE_FX_H_ + +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ +#ifndef _FCD_EFFECT_PROFILE_H_ +#include "FCDocument/FCDEffectProfile.h" +#endif // _FCD_EFFECT_PROFILE_H_ + +class FCDocument; +class FCDEffect; +class FCDEffectCode; +class FCDEffectParameter; +class FCDEffectParameterSurface; +class FCDEffectTechnique; + +/** + A general effect profile description. + + The general effect profile contains all the information necessary + to implement the advanced effect profiles, such as CG, HLSL, GLSL and GLES. + Since these effect profiles contains extremely similar information, they + use the same description structure. For the COMMON profile, + see the FCDEffectStandard class. + + You should use the GetType function to figure out which profile this structure + addresses. You can then retrieve one or many of the FCDEffectTechnique objects + that describe how to render for this profile. You may want to check the + FCDEffectMaterialTechniqueHint objects at the FCDMaterial level, in order to + determine which technique(s) to use for your platform. At the profile + level of abstraction, parameters may be generated within the FCDEffectParamterList. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectProfileFX : public FCDEffectProfile +{ +private: + DeclareObjectType(FCDEffectProfile); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, type, FC("Profile Language")); // FUDaeProfileType::Type + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, platform, FC("Platform")); + + DeclareParameterContainer(FCDEffectCode, codes, FC("Code Inclusions")); + DeclareParameterContainer(FCDEffectTechnique, techniques, FC("Effect Techniques")); + +public: + /** Constructor: do not use directly. Instead, use the FCDEffect::AddProfile function. + @param parent The effect which contains this profile. + @param type The type of profile. */ + FCDEffectProfileFX(FCDocument* document, FCDEffect* parent); + + /** Destructor. */ + virtual ~FCDEffectProfileFX(); + + /** Retrieves the profile type for this effect. + This function is a part of the FCDEffectProfile interface and allows you + to up-cast an effect profile pointer safely to this class. + @return The profile type. This should never be the value: 'COMMON', + but all other profiles currently derive from this class. */ + virtual FUDaeProfileType::Type GetType() const { return (FUDaeProfileType::Type) *type; } + + /** Sets the profile type for this effect. + Do not change the profile type of a completed effect. */ + void SetType(FUDaeProfileType::Type _type) { type = _type; } + + /** Retrieves the name of the platform in which to use the effect profile. + This parameter is very optional. + @return The platform name. */ + const fstring& GetPlatform() const { return platform; } + + /** Sets the name of the platform in which to use the effect profile. + This parameter is very optional. + @param _platform The platform name. */ + void SetPlatform(const fstring& _platform) { platform = _platform; SetDirtyFlag(); } + + /** Retrieves the list of techniques contained within this effect profile. + You may want to check the FCDEffectMaterialTechniqueHint objects at the FCDMaterial level, + in order to determine which technique(s) to use for your platform. + @return The list of inner techniques. */ + DEPRECATED(3.05A, GetTechniqueCount and GetTechnique(index)) void GetTechniqueList() const {} + + /** Retrieves the number of techniques contained within this effect profile. + @return The number of inner techniques. */ + size_t GetTechniqueCount() const { return techniques.size(); } + + /** Retrieves a technique contained within this effect profile. + You may want to check the FCDEffectMaterialTechniqueHint objects at the FCDMaterial level, + in order to determine which technique(s) to use for your platform. + @param index The index of the technique. + @return The inner technique. This pointer will be NULL if the index is out-of-bounds. */ + FCDEffectTechnique* GetTechnique(size_t index) { FUAssert(index < GetTechniqueCount(), return NULL); return techniques.at(index); } + const FCDEffectTechnique* GetTechnique(size_t index) const { FUAssert(index < GetTechniqueCount(), return NULL); return techniques.at(index); } /**< See above. */ + + /** Adds a new technique to this effect profile. + @return The new technique object. */ + FCDEffectTechnique* AddTechnique(); + + /** Retrieves the list of code inclusions. + @return The list of code inclusions. */ + DEPRECATED(3.05A, GetCodeCount and GetCode(index)) void GetCodeList() {} + + /** Retrieves the number of code inclusions contained within the effect profile. + @return The number of code inclusions. */ + size_t GetCodeCount() const { return codes.size(); } + + /** Retrieves a code inclusion contained within the effect profile. + @param index The index of the code inclusion. + @return The code inclusion. This pointer will be NULL if the index is out-of-bounds. */ + inline FCDEffectCode* GetCode(size_t index) { FUAssert(index < GetCodeCount(), return NULL); return codes.at(index); } + inline const FCDEffectCode* GetCode(size_t index) const { FUAssert(index < GetCodeCount(), return NULL); return codes.at(index); } /**< See above. */ + + /** Retrieves the code inclusion with the given sub-id. + @param sid A COLLADA sub-id. + @return The code inclusion with the given sub-id. This pointer will be NULL, + if there are no code inclusions that match the given sub-id. */ + inline FCDEffectCode* FindCode(const char* sid) { return const_cast(const_cast(this)->FindCode(sid)); } + const FCDEffectCode* FindCode(const char* sid) const; /**< See above. */ + + /** Adds a new code inclusion to this effect profile. + @return The new code inclusion. */ + FCDEffectCode* AddCode(); + + /** Clones the full effect profile. + @param clone The cloned profile. + If this pointer is NULL, a new profile is created and + you will need to release this new profile. + @return The cloned profile. This pointer will never be NULL. */ + virtual FCDEffectProfile* Clone(FCDEffectProfile* clone = NULL) const; + + /** [INTERNAL] Flattens this effect profile. Pushes all the effect parameter overrides + into the effect parameter generators and moves all the parameters to the + effect technique level of abstraction. To flatten the material, use the + FCDMaterialInstance::FlattenMaterial function. */ + DEPRECATED(3.05A, not recommended) void Flatten() {} +}; + +#endif // _FCD_EFFECT_PROFILE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfileFX.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTools.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTools.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTools.cpp (revision 24247) @@ -1,896 +1,896 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffect.h" -#include "FCDocument/FCDEffectStandard.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectProfileFX.h" -#include "FCDocument/FCDEffectTools.h" -#include "FCDocument/FCDEffectTechnique.h" -#include "FCDocument/FCDMaterialInstance.h" -#include "FCDocument/FCDGeometryInstance.h" -#include "FCDocument/FCDMaterial.h" -#include "FCDocument/FCDTexture.h" -#include "FUtils/FUDaeEnum.h" - -// -// FCDEffectTools -// - -namespace FCDEffectTools -{ - void SynchronizeAnimatedParams(FCDGeometryInstance* geometryInstance, FCDMaterialInstance* materialInstance) - { - //Find the different classes that are needed. - FUAssert(geometryInstance != NULL && materialInstance != NULL, return); - FCDMaterial* material = materialInstance->GetMaterial(); - FUAssert(material != NULL, return); - FCDEffect* effect = material->GetEffect(); - FUAssert(effect != NULL, return); - FCDEffectProfile* effectProfile = effect->FindProfile(FUDaeProfileType::COMMON); - if (!effectProfile) return; - FCDEffectStandard* effectStandard = (FCDEffectStandard*) effectProfile; - - //Synchronize each parameter from the FCDEffectStandard class. - if (effectStandard->GetEmissionColorParam()->IsReferencer()) - LinkAnimatedParamCommonVector(FCDEffectStandard::EmissionColorSemantic, effectStandard->GetEmissionColorParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetEmissionFactorParam()->IsReferencer()) - LinkAnimatedParamCommonFloat(FCDEffectStandard::EmissionFactorSemantic, effectStandard->GetEmissionFactorParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetReflectivityColorParam()->IsReferencer()) - LinkAnimatedParamCommonVector(FCDEffectStandard::ReflectivityColorSemantic, effectStandard->GetReflectivityColorParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetReflectivityFactorParam()->IsReferencer()) - LinkAnimatedParamCommonFloat(FCDEffectStandard::ReflectivityFactorSemantic, effectStandard->GetReflectivityFactorParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetIndexOfRefractionParam()->IsReferencer()) - LinkAnimatedParamCommonFloat(FCDEffectStandard::IndexOfRefractionSemantic, effectStandard->GetIndexOfRefractionParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetTranslucencyColorParam()->IsReferencer()) - LinkAnimatedParamCommonVector(FCDEffectStandard::TranslucencyColorSemantic, effectStandard->GetTranslucencyColorParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetTranslucencyFactorParam()->IsReferencer()) - LinkAnimatedParamCommonFloat(FCDEffectStandard::TranslucencyFactorSemantic, effectStandard->GetTranslucencyFactorParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetDiffuseColorParam()->IsReferencer()) - LinkAnimatedParamCommonVector(FCDEffectStandard::DiffuseColorSemantic, effectStandard->GetDiffuseColorParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetAmbientColorParam()->IsReferencer()) - LinkAnimatedParamCommonVector(FCDEffectStandard::AmbientColorSemantic, effectStandard->GetAmbientColorParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetSpecularColorParam()->IsReferencer()) - LinkAnimatedParamCommonVector(FCDEffectStandard::SpecularColorSemantic, effectStandard->GetSpecularColorParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetSpecularFactorParam()->IsReferencer()) - LinkAnimatedParamCommonFloat(FCDEffectStandard::SpecularFactorSemantic, effectStandard->GetSpecularFactorParam(), geometryInstance, material, effect, effectProfile); - if (effectStandard->GetShininessParam()->IsReferencer()) - LinkAnimatedParamCommonFloat(FCDEffectStandard::ShininessSemantic, effectStandard->GetShininessParam(), geometryInstance, material, effect, effectProfile); - } - - void LinkAnimatedParamCommonFloat(const fm::string& semantic, FCDEffectParameterFloat* param, FCDGeometryInstance* geometry, FCDMaterial* material, FCDEffect* effect, FCDEffectProfile* profile) - { - const fm::string& reference = param->GetReference(); - if (reference.empty()) return; - FCDEffectParameter* geometryParam = FindEffectParameterBySemantic(geometry, semantic); - FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); - FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); - FCDEffectParameter* profileParam = FindEffectParameterByReference(profile, reference, false); - if (!geometryParam && !materialParam && !effectParam && !profileParam) return; - - // If there's ANIMATORS, link them. - if (geometryParam && geometryParam->GetType() == FCDEffectParameter::FLOAT) - { - FCDEffectParameterFloat* animatedParam = (FCDEffectParameterFloat*) geometryParam; - if (materialParam && materialParam->GetType() == FCDEffectParameter::FLOAT) - { - FCDEffectParameterFloat* floatParam = (FCDEffectParameterFloat*) materialParam; - animatedParam->SetValue(floatParam->GetValue()); - } - else if (effectParam && effectParam->GetType() == FCDEffectParameter::FLOAT) - { - FCDEffectParameterFloat* floatParam = (FCDEffectParameterFloat*) effectParam; - animatedParam->SetValue(floatParam->GetValue()); - } - else if (profileParam && profileParam->GetType() == FCDEffectParameter::FLOAT) - { - FCDEffectParameterFloat* floatParam = (FCDEffectParameterFloat*) profileParam; - animatedParam->SetValue(floatParam->GetValue()); - } - } - } - - void LinkAnimatedParamCommonVector(const fm::string& semantic, FCDEffectParameterColor4* param, FCDGeometryInstance* geometry, FCDMaterial* material, FCDEffect* effect, FCDEffectProfile* profile) - { - //Change this to account for the animated params in geometryInstance list. - const fm::string& reference = param->GetReference(); - if (reference.empty()) return; - FCDEffectParameter* geometryParam = FindEffectParameterBySemantic(geometry, semantic); - FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); - FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); - FCDEffectParameter* profileParam = FindEffectParameterByReference(profile, reference, false); - if (!geometryParam && !materialParam && !effectParam && !profileParam) return; - if (geometryParam && geometryParam->GetType() == FCDEffectParameter::FLOAT3) - { - FCDEffectParameterFloat3* animatedParam = (FCDEffectParameterFloat3*) geometryParam; - if (materialParam && materialParam->GetType() == FCDEffectParameter::FLOAT3) - { - FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) materialParam; - animatedParam->SetValue(float3Param->GetValue()); - return; - } - else if (materialParam && materialParam->GetType() == FCDEffectParameter::VECTOR) - { - FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) materialParam; - animatedParam->SetValue(FMVector3((const FMVector4&) vectorParam->GetValue())); - return; - } - else if (effectParam && effectParam->GetType() == FCDEffectParameter::FLOAT3) - { - FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) effectParam; - animatedParam->SetValue(float3Param->GetValue()); - return; - } - else if (effectParam && effectParam->GetType() == FCDEffectParameter::VECTOR) - { - FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) effectParam; - animatedParam->SetValue(FMVector3((const FMVector4&) vectorParam->GetValue())); - return; - } - else if (profileParam && profileParam->GetType() == FCDEffectParameter::FLOAT3) - { - FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) profileParam; - animatedParam->SetValue(float3Param->GetValue()); - return; - } - else if (profileParam && profileParam->GetType() == FCDEffectParameter::VECTOR) - { - FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) profileParam; - animatedParam->SetValue(FMVector3((const FMVector4&) vectorParam->GetValue())); - return; - } - } - else if (geometryParam && geometryParam->GetType() == FCDEffectParameter::VECTOR) - { - FCDEffectParameterColor4* animatedParam = (FCDEffectParameterColor4*) geometryParam; - if (materialParam && materialParam->GetType() == FCDEffectParameter::FLOAT3) - { - FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) materialParam; - animatedParam->SetValue(FMVector4(float3Param->GetValue(), 1.0f)); - return; - } - else if (materialParam && materialParam->GetType() == FCDEffectParameter::VECTOR) - { - FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) materialParam; - animatedParam->SetValue(vectorParam->GetValue()); - return; - } - else if (effectParam && effectParam->GetType() == FCDEffectParameter::FLOAT3) - { - FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) effectParam; - animatedParam->SetValue(FMVector4(float3Param->GetValue(), 1.0f)); - return; - } - else if (effectParam && effectParam->GetType() == FCDEffectParameter::VECTOR) - { - FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) effectParam; - animatedParam->SetValue(vectorParam->GetValue()); - return; - } - else if (profileParam && profileParam->GetType() == FCDEffectParameter::FLOAT3) - { - FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) profileParam; - animatedParam->SetValue(FMVector4(float3Param->GetValue(), 1.0f)); - return; - } - else if (profileParam && profileParam->GetType() == FCDEffectParameter::VECTOR) - { - FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) profileParam; - animatedParam->SetValue(vectorParam->GetValue()); - return; - } - } - } - - FCDParameterAnimatableColor4* GetAnimatedColor(FCDGeometryInstance* geometryInstance, FCDMaterial* material, const fm::string& semantic, bool* isFloat3) - { - //Find the different classes that are needed. - //FCDMaterial* material = materialInstance->GetMaterial(); - if (material == NULL) return NULL; - FCDEffect* effect = material->GetEffect(); - if (effect == NULL) return NULL; - FCDEffectProfile* effectProfile = effect->FindProfile(FUDaeProfileType::COMMON); - if (effectProfile == NULL) return NULL; - FCDEffectStandard* effectStandard = (FCDEffectStandard*) effectProfile; - bool isFloat = true; - - //Find out if the parameter is animated - FCDEffectParameter* effectStandardParam = effectStandard->GetParam(semantic, &isFloat); - if (effectStandardParam == NULL) return NULL; - const fm::string& reference = effectStandardParam->GetReference(); - if (reference.empty()) - { - if (isFloat) return NULL; - else return &(((FCDEffectParameterColor4*)effectStandardParam)->GetValue()); - } - FCDEffectParameter* geometryParam = geometryInstance != NULL ? FindEffectParameterBySemantic(geometryInstance, semantic) : NULL; - FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); - FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); - FCDEffectParameter* effectProfileParam = FindEffectParameterByReference(effectProfile, reference, false); - - //Do the figuring out .. ;) - if (isFloat) return NULL; - else - { - if (geometryParam) - { - if (geometryParam->GetType() == FCDEffectParameter::FLOAT3) - { - *isFloat3 = true; - FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) geometryParam; - return (FCDParameterAnimatableColor4*) &tempParam->GetValue(); - } - else if (geometryParam->GetType() == FCDEffectParameter::VECTOR) - { - *isFloat3 = false; - return &((FCDEffectParameterColor4*)geometryParam)->GetValue(); - } - else return NULL; - } - //Could call GetDefaultColor from here on out... - else if (materialParam) - { - if (materialParam->GetType() == FCDEffectParameter::FLOAT3) - { - *isFloat3 = true; - FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) materialParam; - return (FCDParameterAnimatableColor4*) &tempParam->GetValue(); - } - else if (materialParam->GetType() == FCDEffectParameter::VECTOR) - { - *isFloat3 = false; - return &((FCDEffectParameterColor4*)materialParam)->GetValue(); - } - else return NULL; - } - else if (effectParam) - { - if (effectParam->GetType() == FCDEffectParameter::FLOAT3) - { - *isFloat3 = true; - FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) effectParam; - return (FCDParameterAnimatableColor4*) &tempParam->GetValue(); - } - else if (effectParam->GetType() == FCDEffectParameter::VECTOR) - { - *isFloat3 = false; - return &((FCDEffectParameterColor4*)effectParam)->GetValue(); - } - else return NULL; - } - else if (effectProfileParam) - { - if (effectProfileParam->GetType() == FCDEffectParameter::FLOAT3) - { - *isFloat3 = true; - FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) effectProfileParam; - return (FCDParameterAnimatableColor4*) &tempParam->GetValue(); - } - else if (effectProfileParam->GetType() == FCDEffectParameter::VECTOR) - { - *isFloat3 = false; - return &((FCDEffectParameterColor4*)effectProfileParam)->GetValue(); - } - else return NULL; - } - else - { - *isFloat3 = true; - return &((FCDEffectParameterColor4*)effectStandardParam)->GetValue(); - } - } - } - - FCDParameterAnimatableFloat* GetAnimatedFloat(FCDGeometryInstance* geometryInstance, FCDMaterial* material, const fm::string& semantic) - { - //Find the different classes that are needed. - //FCDMaterial* material = materialInstance->GetMaterial(); - if (material == NULL) return NULL; - FCDEffect* effect = material->GetEffect(); - if (effect == NULL) return NULL; - FCDEffectProfile* effectProfile = effect->FindProfile(FUDaeProfileType::COMMON); - if (effectProfile == NULL) return NULL; - FCDEffectStandard* effectStandard = (FCDEffectStandard*) effectProfile; - bool isFloat = true; - - //Find out if the parameter is animated - FCDEffectParameter* effectStandardParam = effectStandard->GetParam(semantic, &isFloat); - if (!effectStandardParam) return NULL; - const fm::string& reference = effectStandardParam->GetReference(); - if (reference.empty()) - { - if (isFloat) return &(((FCDEffectParameterFloat*)effectStandardParam)->GetValue()); - else return NULL; - } - FCDEffectParameter* geometryParam = geometryInstance != NULL ? FindEffectParameterBySemantic(geometryInstance, semantic) : NULL; - FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); - FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); - FCDEffectParameter* effectProfileParam = FindEffectParameterByReference(effectProfile, reference, false); - - if (isFloat) - { - if (geometryParam) - { - if (geometryParam->GetType() != FCDEffectParameter::FLOAT) return NULL; - else return &((FCDEffectParameterFloat*)geometryParam)->GetValue(); - } - //From this on out, could call GetDefaultFloat... and return that? - else if (materialParam) - { - if (materialParam->GetType() != FCDEffectParameter::FLOAT) return NULL; - else return &((FCDEffectParameterFloat*)materialParam)->GetValue(); - } - else if (effectParam) - { - if (effectParam->GetType() != FCDEffectParameter::FLOAT) return NULL; - else return &((FCDEffectParameterFloat*)effectParam)->GetValue(); - } - else if (effectProfileParam) - { - if (effectProfileParam->GetType() != FCDEffectParameter::FLOAT) return NULL; - else return &((FCDEffectParameterFloat*)effectProfileParam)->GetValue(); - } - else return &((FCDEffectParameterFloat*)effectStandardParam)->GetValue(); - } - else return NULL; - } - - FMVector4* GetDefaultColor(FCDMaterial* material, const fm::string& semantic, bool* isFloat3) - { - //Find the different classes that are needed. - FCDEffect* effect = material->GetEffect(); - FCDEffectProfile* effectProfile = effect->FindProfile(FUDaeProfileType::COMMON); - FCDEffectStandard* effectStandard = (FCDEffectStandard*) effectProfile; - bool isFloat = true; - - //Find out if the parameter is animated - FCDEffectParameter* effectStandardParam = effectStandard->GetParam(semantic, &isFloat); - if (!effectStandardParam) return NULL; - const fm::string& reference = effectStandardParam->GetReference(); - if (reference.empty()) - { - if (isFloat) return NULL; - else return &(FMVector4&)(((FCDEffectParameterColor4*)effectStandardParam)->GetValue()); - } - FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); - FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); - FCDEffectParameter* effectProfileParam = FindEffectParameterByReference(effectProfile, reference, false); - - //Do the figuring out .. ;) - if (isFloat) return NULL; - else - { - // Don't look at the geometry instance parameters: these are only used for animations! - if (materialParam) - { - if (materialParam->GetType() == FCDEffectParameter::FLOAT3) - { - *isFloat3 = true; - FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) materialParam; - return (FMVector4*) &(FMVector3&) tempParam->GetValue(); - } - else if (materialParam->GetType() == FCDEffectParameter::VECTOR) - { - *isFloat3 = false; - return &(FMVector4&) ((FCDEffectParameterColor4*)materialParam)->GetValue(); - } - else return NULL; - } - else if (effectParam) - { - if (effectParam->GetType() == FCDEffectParameter::FLOAT3) - { - *isFloat3 = true; - FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) effectParam; - return (FMVector4*) &(FMVector3&) tempParam->GetValue(); - } - else if (effectParam->GetType() == FCDEffectParameter::VECTOR) - { - *isFloat3 = false; - return &(FMVector4&) ((FCDEffectParameterColor4*)effectParam)->GetValue(); - } - else return NULL; - } - else if (effectProfileParam) - { - if (effectProfileParam->GetType() == FCDEffectParameter::FLOAT3) - { - *isFloat3 = true; - FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) effectProfileParam; - return (FMVector4*) &(FMVector3&) tempParam->GetValue(); - } - else if (effectProfileParam->GetType() == FCDEffectParameter::VECTOR) - { - *isFloat3 = false; - return &(FMVector4&) ((FCDEffectParameterColor4*)effectProfileParam)->GetValue(); - } - else return NULL; - } - else - { - *isFloat3 = true; - return &(FMVector4&) ((FCDEffectParameterColor4*)effectStandardParam)->GetValue(); - } - } - } - - float* GetDefaultFloat(FCDMaterial* material, const fm::string& semantic) - { - //Find the different classes that are needed. - FCDEffect* effect = material->GetEffect(); - FCDEffectProfile* effectProfile = effect->FindProfile(FUDaeProfileType::COMMON); - FCDEffectStandard* effectStandard = (FCDEffectStandard*) effectProfile; - bool isFloat = true; - - //Find out if the parameter is animated - FCDEffectParameter* effectStandardParam = effectStandard->GetParam(semantic, &isFloat); - if (!effectStandardParam) return NULL; - const fm::string& reference = effectStandardParam->GetReference(); - if (reference.empty()) - { - if (isFloat) return &(float&) ((FCDEffectParameterFloat*)effectStandardParam)->GetValue(); - else return NULL; - } - FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); - FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); - FCDEffectParameter* effectProfileParam = FindEffectParameterByReference(effectProfile, reference, false); - - if (isFloat) - { - if (materialParam) - { - if (materialParam->GetType() != FCDEffectParameter::FLOAT) return NULL; - else return &(float&) ((FCDEffectParameterFloat*)materialParam)->GetValue(); - } - else if (effectParam) - { - if (effectParam->GetType() != FCDEffectParameter::FLOAT) return NULL; - else return &(float&) ((FCDEffectParameterFloat*)effectParam)->GetValue(); - } - else if (effectProfileParam) - { - if (effectProfileParam->GetType() != FCDEffectParameter::FLOAT) return NULL; - else return &(float&) ((FCDEffectParameterFloat*)effectProfileParam)->GetValue(); - } - else return &(float&) ((FCDEffectParameterFloat*)effectStandardParam)->GetValue(); - } - else return NULL; - } - - // - // FindEffectParameterBySemantic - // - - const FCDEffectParameter* FindEffectParameterBySemantic(const FCDGeometryInstance* geometryInstance, const char* semantic) - { - if (geometryInstance == NULL || semantic == NULL || *semantic == 0) return NULL; - size_t count = geometryInstance->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; - } - return NULL; - } - - const FCDEffectParameter* FindEffectParameterBySemantic(const FCDMaterialInstance* materialInstance, const char* semantic, bool localOnly) - { - if (materialInstance == NULL || semantic == NULL || *semantic == 0) return NULL; - const FCDGeometryInstance* geometryInstance = (FCDGeometryInstance*) materialInstance->GetParent(); - size_t count = geometryInstance->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; - } - return !localOnly ? FindEffectParameterBySemantic(materialInstance->GetMaterial(), semantic) : NULL; - } - - const FCDEffectParameter* FindEffectParameterBySemantic(const FCDMaterial* material, const char* semantic, bool localOnly) - { - if (material == NULL || semantic == NULL || *semantic == 0) return NULL; - size_t count = material->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = material->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; - } - return !localOnly ? FindEffectParameterBySemantic(material->GetEffect(), semantic) : NULL; - } - - const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffect* effect, const char* semantic, bool localOnly) - { - if (effect == NULL || semantic == NULL || *semantic == 0) return NULL; - size_t count = effect->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = effect->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; - } - if (!localOnly) - { - size_t profileCount = effect->GetProfileCount(); - for (size_t p = 0; p < profileCount; ++p) - { - const FCDEffectParameter* effectParameter = FindEffectParameterBySemantic(effect->GetProfile(p), semantic); - if (effectParameter != NULL) return effectParameter; - } - } - return NULL; - } - - const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffectProfile* profile, const char* semantic, bool localOnly) - { - // Look within the local parameters. - if (profile == NULL || semantic == NULL || *semantic == 0) return NULL; - size_t count = profile->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = profile->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; - } - - if (profile->HasType(FCDEffectProfileFX::GetClassType()) && !localOnly) - { - // Look within the parameters. - FCDEffectProfileFX* fx = (FCDEffectProfileFX*) profile; - size_t techniqueCount = fx->GetTechniqueCount(); - for (size_t t = 0; t < techniqueCount; ++t) - { - const FCDEffectParameter* effectParameter = FindEffectParameterBySemantic(fx->GetTechnique(t), semantic); - if (effectParameter != NULL) return effectParameter; - } - } - else if (profile->HasType(FCDEffectStandard::GetClassType())) - { - // Look within the textures which have their own parameters. - FCDEffectStandard* std = (FCDEffectStandard*) profile; - for (uint32 i = 0; i < FUDaeTextureChannel::COUNT; ++i) - { - size_t bucketSize = std->GetTextureCount(i); - for (size_t t = 0; t < bucketSize; ++t) - { - FCDTexture* texture = std->GetTexture(i, t); - if (IsEquivalent(texture->GetSet()->GetSemantic(), semantic)) return texture->GetSet(); - } - } - } - return NULL; - } - - const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffectTechnique* technique, const char* semantic, bool UNUSED(localOnly)) - { - if (technique == NULL || semantic == NULL || *semantic == 0) return NULL; - size_t count = technique->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = technique->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; - } - return NULL; - } - - // - // FindEffectParameterByReference - // - - const FCDEffectParameter* FindEffectParameterByReference(const FCDGeometryInstance* geometryInstance, const char* reference) - { - if (geometryInstance == NULL || reference == NULL || *reference == 0) return NULL; - size_t count = geometryInstance->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; - } - return NULL; - } - - const FCDEffectParameter* FindEffectParameterByReference(const FCDMaterialInstance* materialInstance, const char* reference, bool localOnly) - { - if (materialInstance == NULL || reference == NULL || *reference == 0) return NULL; - const FCDGeometryInstance* geometryInstance = (FCDGeometryInstance*) materialInstance->GetParent(); - size_t count = geometryInstance->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; - } - return !localOnly ? FindEffectParameterByReference(materialInstance->GetMaterial(), reference) : NULL; - } - - const FCDEffectParameter* FindEffectParameterByReference(const FCDMaterial* material, const char* reference, bool localOnly) - { - if (material == NULL || reference == NULL || *reference == 0) return NULL; - size_t count = material->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = material->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; - } - return !localOnly ? FindEffectParameterByReference(material->GetEffect(), reference) : NULL; - } - - const FCDEffectParameter* FindEffectParameterByReference(const FCDEffect* effect, const char* reference, bool localOnly) - { - if (effect == NULL || reference == NULL || *reference == 0) return NULL; - size_t count = effect->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = effect->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; - } - if (!localOnly) - { - size_t profileCount = effect->GetProfileCount(); - for (size_t p = 0; p < profileCount; ++p) - { - const FCDEffectParameter* effectParameter = FindEffectParameterByReference(effect->GetProfile(p), reference); - if (effectParameter != NULL) return effectParameter; - } - } - return NULL; - } - - const FCDEffectParameter* FindEffectParameterByReference(const FCDEffectProfile* profile, const char* reference, bool localOnly) - { - // Look within the local parameters. - if (profile == NULL || reference == NULL || *reference == 0) return NULL; - size_t count = profile->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = profile->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; - } - - if (profile->HasType(FCDEffectProfileFX::GetClassType()) && !localOnly) - { - // Look within the parameters. - FCDEffectProfileFX* fx = (FCDEffectProfileFX*) profile; - size_t techniqueCount = fx->GetTechniqueCount(); - for (size_t t = 0; t < techniqueCount; ++t) - { - const FCDEffectParameter* effectParameter = FindEffectParameterByReference(fx->GetTechnique(t), reference); - if (effectParameter != NULL) return effectParameter; - } - } - else if (profile->HasType(FCDEffectStandard::GetClassType())) - { - // Look within the textures which have their own parameters. - FCDEffectStandard* std = (FCDEffectStandard*) profile; - for (uint32 i = 0; i < FUDaeTextureChannel::COUNT; ++i) - { - size_t bucketSize = std->GetTextureCount(i); - for (size_t t = 0; t < bucketSize; ++t) - { - FCDTexture* texture = std->GetTexture(i, t); - if (IsEquivalent(texture->GetSet()->GetReference(), reference)) return texture->GetSet(); - } - } - } - return NULL; - } - - const FCDEffectParameter* FindEffectParameterByReference(const FCDEffectTechnique* technique, const char* reference, bool UNUSED(localOnly)) - { - if (technique == NULL || reference == NULL || *reference == 0) return NULL; - size_t count = technique->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = technique->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; - } - return NULL; - } - - // - // FindEffectParametersBySemantic - // - - void FindEffectParametersBySemantic(const FCDMaterialInstance* materialInstance, const char* semantic, FCDEffectParameterList& parameters, bool localOnly) - { - if (materialInstance == NULL || semantic == NULL || *semantic == 0) return; - const FCDGeometryInstance* geometryInstance = (FCDGeometryInstance*) materialInstance->GetParent(); - size_t count = geometryInstance->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) parameters.push_back(effectParameter); - } - if (!localOnly) - { - FindEffectParametersBySemantic(materialInstance->GetMaterial(), semantic, parameters); - } - } - - void FindEffectParametersBySemantic(const FCDMaterial* material, const char* semantic, FCDEffectParameterList& parameters, bool localOnly) - { - if (material == NULL || semantic == NULL || *semantic == 0) return; - size_t count = material->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = material->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) parameters.push_back(effectParameter); - } - if (!localOnly) - { - FindEffectParametersBySemantic(material->GetEffect(), semantic, parameters); - } - } - - void FindEffectParametersBySemantic(const FCDEffect* effect, const char* semantic, FCDEffectParameterList& parameters, bool localOnly) - { - if (effect == NULL || semantic == NULL || *semantic == 0) return; - size_t count = effect->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = effect->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) parameters.push_back(effectParameter); - } - if (!localOnly) - { - size_t profileCount = effect->GetProfileCount(); - for (size_t p = 0; p < profileCount; ++p) - { - FindEffectParametersBySemantic(effect->GetProfile(p), semantic, parameters); - } - } - } - - void FindEffectParametersBySemantic(const FCDEffectProfile* profile, const char* semantic, FCDEffectParameterList& parameters, bool localOnly) - { - // Look within the local parameters. - if (profile == NULL || semantic == NULL || *semantic == 0) return; - size_t count = profile->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = profile->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) parameters.push_back(effectParameter); - } - - if (profile->HasType(FCDEffectProfileFX::GetClassType()) && !localOnly) - { - // Look within the parameters. - FCDEffectProfileFX* fx = (FCDEffectProfileFX*) profile; - size_t techniqueCount = fx->GetTechniqueCount(); - for (size_t t = 0; t < techniqueCount; ++t) - { - FindEffectParametersBySemantic(fx->GetTechnique(t), semantic, parameters); - } - } - else if (profile->HasType(FCDEffectStandard::GetClassType())) - { - // Look within the textures which have their own parameters. - FCDEffectStandard* std = (FCDEffectStandard*) profile; - for (uint32 i = 0; i < FUDaeTextureChannel::COUNT; ++i) - { - size_t bucketSize = std->GetTextureCount(i); - for (size_t t = 0; t < bucketSize; ++t) - { - FCDTexture* texture = std->GetTexture(i, t); - if (IsEquivalent(texture->GetSet()->GetSemantic(), semantic)) parameters.push_back(texture->GetSet()); - } - } - } - } - - void FindEffectParametersBySemantic(const FCDEffectTechnique* technique, const char* semantic, FCDEffectParameterList& parameters, bool UNUSED(localOnly)) - { - if (technique == NULL || semantic == NULL || *semantic == 0) return; - size_t count = technique->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = technique->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetSemantic(), semantic)) parameters.push_back(effectParameter); - } - } - - // - // FindEffectParametersByReference - // - - void FindEffectParametersByReference(const FCDMaterialInstance* materialInstance, const char* reference, FCDEffectParameterList& parameters, bool localOnly) - { - if (materialInstance == NULL || reference == NULL || *reference == 0) return; - const FCDGeometryInstance* geometryInstance = (FCDGeometryInstance*) materialInstance->GetParent(); - size_t count = geometryInstance->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) parameters.push_back(effectParameter); - } - if (!localOnly) - { - FindEffectParametersByReference(materialInstance->GetMaterial(), reference, parameters); - } - } - - void FindEffectParametersByReference(const FCDMaterial* material, const char* reference, FCDEffectParameterList& parameters, bool localOnly) - { - if (material == NULL || reference == NULL || *reference == 0) return; - size_t count = material->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = material->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) parameters.push_back(effectParameter); - } - if (!localOnly) - { - FindEffectParametersByReference(material->GetEffect(), reference, parameters); - } - } - - void FindEffectParametersByReference(const FCDEffect* effect, const char* reference, FCDEffectParameterList& parameters, bool localOnly) - { - if (effect == NULL || reference == NULL || *reference == 0) return; - size_t count = effect->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = effect->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) parameters.push_back(effectParameter); - } - if (!localOnly) - { - size_t profileCount = effect->GetProfileCount(); - for (size_t p = 0; p < profileCount; ++p) - { - FindEffectParametersByReference(effect->GetProfile(p), reference, parameters); - } - } - } - - void FindEffectParametersByReference(const FCDEffectProfile* profile, const char* reference, FCDEffectParameterList& parameters, bool localOnly) - { - // Look within the local parameters. - if (profile == NULL || reference == NULL || *reference == 0) return; - size_t count = profile->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = profile->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) parameters.push_back(effectParameter); - } - - if (profile->HasType(FCDEffectProfileFX::GetClassType()) && !localOnly) - { - // Look within the parameters. - FCDEffectProfileFX* fx = (FCDEffectProfileFX*) profile; - size_t techniqueCount = fx->GetTechniqueCount(); - for (size_t t = 0; t < techniqueCount; ++t) - { - FindEffectParametersByReference(fx->GetTechnique(t), reference, parameters); - } - } - else if (profile->HasType(FCDEffectStandard::GetClassType())) - { - // Look within the textures which have their own parameters. - FCDEffectStandard* std = (FCDEffectStandard*) profile; - for (uint32 i = 0; i < FUDaeTextureChannel::COUNT; ++i) - { - size_t bucketSize = std->GetTextureCount(i); - for (size_t t = 0; t < bucketSize; ++t) - { - FCDTexture* texture = std->GetTexture(i, t); - if (IsEquivalent(texture->GetSet()->GetReference(), reference)) parameters.push_back(texture->GetSet()); - } - } - } - } - - void FindEffectParametersByReference(const FCDEffectTechnique* technique, const char* reference, FCDEffectParameterList& parameters, bool UNUSED(localOnly)) - { - if (technique == NULL || reference == NULL || *reference == 0) return; - size_t count = technique->GetEffectParameterCount(); - for (size_t p = 0; p < count; ++p) - { - const FCDEffectParameter* effectParameter = technique->GetEffectParameter(p); - if (IsEquivalent(effectParameter->GetReference(), reference)) parameters.push_back(effectParameter); - } - } -}; +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffect.h" +#include "FCDocument/FCDEffectStandard.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectProfileFX.h" +#include "FCDocument/FCDEffectTools.h" +#include "FCDocument/FCDEffectTechnique.h" +#include "FCDocument/FCDMaterialInstance.h" +#include "FCDocument/FCDGeometryInstance.h" +#include "FCDocument/FCDMaterial.h" +#include "FCDocument/FCDTexture.h" +#include "FUtils/FUDaeEnum.h" + +// +// FCDEffectTools +// + +namespace FCDEffectTools +{ + void SynchronizeAnimatedParams(FCDGeometryInstance* geometryInstance, FCDMaterialInstance* materialInstance) + { + //Find the different classes that are needed. + FUAssert(geometryInstance != NULL && materialInstance != NULL, return); + FCDMaterial* material = materialInstance->GetMaterial(); + FUAssert(material != NULL, return); + FCDEffect* effect = material->GetEffect(); + FUAssert(effect != NULL, return); + FCDEffectProfile* effectProfile = effect->FindProfile(FUDaeProfileType::COMMON); + if (!effectProfile) return; + FCDEffectStandard* effectStandard = (FCDEffectStandard*) effectProfile; + + //Synchronize each parameter from the FCDEffectStandard class. + if (effectStandard->GetEmissionColorParam()->IsReferencer()) + LinkAnimatedParamCommonVector(FCDEffectStandard::EmissionColorSemantic, effectStandard->GetEmissionColorParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetEmissionFactorParam()->IsReferencer()) + LinkAnimatedParamCommonFloat(FCDEffectStandard::EmissionFactorSemantic, effectStandard->GetEmissionFactorParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetReflectivityColorParam()->IsReferencer()) + LinkAnimatedParamCommonVector(FCDEffectStandard::ReflectivityColorSemantic, effectStandard->GetReflectivityColorParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetReflectivityFactorParam()->IsReferencer()) + LinkAnimatedParamCommonFloat(FCDEffectStandard::ReflectivityFactorSemantic, effectStandard->GetReflectivityFactorParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetIndexOfRefractionParam()->IsReferencer()) + LinkAnimatedParamCommonFloat(FCDEffectStandard::IndexOfRefractionSemantic, effectStandard->GetIndexOfRefractionParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetTranslucencyColorParam()->IsReferencer()) + LinkAnimatedParamCommonVector(FCDEffectStandard::TranslucencyColorSemantic, effectStandard->GetTranslucencyColorParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetTranslucencyFactorParam()->IsReferencer()) + LinkAnimatedParamCommonFloat(FCDEffectStandard::TranslucencyFactorSemantic, effectStandard->GetTranslucencyFactorParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetDiffuseColorParam()->IsReferencer()) + LinkAnimatedParamCommonVector(FCDEffectStandard::DiffuseColorSemantic, effectStandard->GetDiffuseColorParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetAmbientColorParam()->IsReferencer()) + LinkAnimatedParamCommonVector(FCDEffectStandard::AmbientColorSemantic, effectStandard->GetAmbientColorParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetSpecularColorParam()->IsReferencer()) + LinkAnimatedParamCommonVector(FCDEffectStandard::SpecularColorSemantic, effectStandard->GetSpecularColorParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetSpecularFactorParam()->IsReferencer()) + LinkAnimatedParamCommonFloat(FCDEffectStandard::SpecularFactorSemantic, effectStandard->GetSpecularFactorParam(), geometryInstance, material, effect, effectProfile); + if (effectStandard->GetShininessParam()->IsReferencer()) + LinkAnimatedParamCommonFloat(FCDEffectStandard::ShininessSemantic, effectStandard->GetShininessParam(), geometryInstance, material, effect, effectProfile); + } + + void LinkAnimatedParamCommonFloat(const fm::string& semantic, FCDEffectParameterFloat* param, FCDGeometryInstance* geometry, FCDMaterial* material, FCDEffect* effect, FCDEffectProfile* profile) + { + const fm::string& reference = param->GetReference(); + if (reference.empty()) return; + FCDEffectParameter* geometryParam = FindEffectParameterBySemantic(geometry, semantic); + FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); + FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); + FCDEffectParameter* profileParam = FindEffectParameterByReference(profile, reference, false); + if (!geometryParam && !materialParam && !effectParam && !profileParam) return; + + // If there's ANIMATORS, link them. + if (geometryParam && geometryParam->GetType() == FCDEffectParameter::FLOAT) + { + FCDEffectParameterFloat* animatedParam = (FCDEffectParameterFloat*) geometryParam; + if (materialParam && materialParam->GetType() == FCDEffectParameter::FLOAT) + { + FCDEffectParameterFloat* floatParam = (FCDEffectParameterFloat*) materialParam; + animatedParam->SetValue(floatParam->GetValue()); + } + else if (effectParam && effectParam->GetType() == FCDEffectParameter::FLOAT) + { + FCDEffectParameterFloat* floatParam = (FCDEffectParameterFloat*) effectParam; + animatedParam->SetValue(floatParam->GetValue()); + } + else if (profileParam && profileParam->GetType() == FCDEffectParameter::FLOAT) + { + FCDEffectParameterFloat* floatParam = (FCDEffectParameterFloat*) profileParam; + animatedParam->SetValue(floatParam->GetValue()); + } + } + } + + void LinkAnimatedParamCommonVector(const fm::string& semantic, FCDEffectParameterColor4* param, FCDGeometryInstance* geometry, FCDMaterial* material, FCDEffect* effect, FCDEffectProfile* profile) + { + //Change this to account for the animated params in geometryInstance list. + const fm::string& reference = param->GetReference(); + if (reference.empty()) return; + FCDEffectParameter* geometryParam = FindEffectParameterBySemantic(geometry, semantic); + FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); + FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); + FCDEffectParameter* profileParam = FindEffectParameterByReference(profile, reference, false); + if (!geometryParam && !materialParam && !effectParam && !profileParam) return; + if (geometryParam && geometryParam->GetType() == FCDEffectParameter::FLOAT3) + { + FCDEffectParameterFloat3* animatedParam = (FCDEffectParameterFloat3*) geometryParam; + if (materialParam && materialParam->GetType() == FCDEffectParameter::FLOAT3) + { + FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) materialParam; + animatedParam->SetValue(float3Param->GetValue()); + return; + } + else if (materialParam && materialParam->GetType() == FCDEffectParameter::VECTOR) + { + FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) materialParam; + animatedParam->SetValue(FMVector3((const FMVector4&) vectorParam->GetValue())); + return; + } + else if (effectParam && effectParam->GetType() == FCDEffectParameter::FLOAT3) + { + FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) effectParam; + animatedParam->SetValue(float3Param->GetValue()); + return; + } + else if (effectParam && effectParam->GetType() == FCDEffectParameter::VECTOR) + { + FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) effectParam; + animatedParam->SetValue(FMVector3((const FMVector4&) vectorParam->GetValue())); + return; + } + else if (profileParam && profileParam->GetType() == FCDEffectParameter::FLOAT3) + { + FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) profileParam; + animatedParam->SetValue(float3Param->GetValue()); + return; + } + else if (profileParam && profileParam->GetType() == FCDEffectParameter::VECTOR) + { + FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) profileParam; + animatedParam->SetValue(FMVector3((const FMVector4&) vectorParam->GetValue())); + return; + } + } + else if (geometryParam && geometryParam->GetType() == FCDEffectParameter::VECTOR) + { + FCDEffectParameterColor4* animatedParam = (FCDEffectParameterColor4*) geometryParam; + if (materialParam && materialParam->GetType() == FCDEffectParameter::FLOAT3) + { + FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) materialParam; + animatedParam->SetValue(FMVector4(float3Param->GetValue(), 1.0f)); + return; + } + else if (materialParam && materialParam->GetType() == FCDEffectParameter::VECTOR) + { + FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) materialParam; + animatedParam->SetValue(vectorParam->GetValue()); + return; + } + else if (effectParam && effectParam->GetType() == FCDEffectParameter::FLOAT3) + { + FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) effectParam; + animatedParam->SetValue(FMVector4(float3Param->GetValue(), 1.0f)); + return; + } + else if (effectParam && effectParam->GetType() == FCDEffectParameter::VECTOR) + { + FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) effectParam; + animatedParam->SetValue(vectorParam->GetValue()); + return; + } + else if (profileParam && profileParam->GetType() == FCDEffectParameter::FLOAT3) + { + FCDEffectParameterFloat3* float3Param = (FCDEffectParameterFloat3*) profileParam; + animatedParam->SetValue(FMVector4(float3Param->GetValue(), 1.0f)); + return; + } + else if (profileParam && profileParam->GetType() == FCDEffectParameter::VECTOR) + { + FCDEffectParameterColor4* vectorParam = (FCDEffectParameterColor4*) profileParam; + animatedParam->SetValue(vectorParam->GetValue()); + return; + } + } + } + + FCDParameterAnimatableColor4* GetAnimatedColor(FCDGeometryInstance* geometryInstance, FCDMaterial* material, const fm::string& semantic, bool* isFloat3) + { + //Find the different classes that are needed. + //FCDMaterial* material = materialInstance->GetMaterial(); + if (material == NULL) return NULL; + FCDEffect* effect = material->GetEffect(); + if (effect == NULL) return NULL; + FCDEffectProfile* effectProfile = effect->FindProfile(FUDaeProfileType::COMMON); + if (effectProfile == NULL) return NULL; + FCDEffectStandard* effectStandard = (FCDEffectStandard*) effectProfile; + bool isFloat = true; + + //Find out if the parameter is animated + FCDEffectParameter* effectStandardParam = effectStandard->GetParam(semantic, &isFloat); + if (effectStandardParam == NULL) return NULL; + const fm::string& reference = effectStandardParam->GetReference(); + if (reference.empty()) + { + if (isFloat) return NULL; + else return &(((FCDEffectParameterColor4*)effectStandardParam)->GetValue()); + } + FCDEffectParameter* geometryParam = geometryInstance != NULL ? FindEffectParameterBySemantic(geometryInstance, semantic) : NULL; + FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); + FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); + FCDEffectParameter* effectProfileParam = FindEffectParameterByReference(effectProfile, reference, false); + + //Do the figuring out .. ;) + if (isFloat) return NULL; + else + { + if (geometryParam) + { + if (geometryParam->GetType() == FCDEffectParameter::FLOAT3) + { + *isFloat3 = true; + FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) geometryParam; + return (FCDParameterAnimatableColor4*) &tempParam->GetValue(); + } + else if (geometryParam->GetType() == FCDEffectParameter::VECTOR) + { + *isFloat3 = false; + return &((FCDEffectParameterColor4*)geometryParam)->GetValue(); + } + else return NULL; + } + //Could call GetDefaultColor from here on out... + else if (materialParam) + { + if (materialParam->GetType() == FCDEffectParameter::FLOAT3) + { + *isFloat3 = true; + FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) materialParam; + return (FCDParameterAnimatableColor4*) &tempParam->GetValue(); + } + else if (materialParam->GetType() == FCDEffectParameter::VECTOR) + { + *isFloat3 = false; + return &((FCDEffectParameterColor4*)materialParam)->GetValue(); + } + else return NULL; + } + else if (effectParam) + { + if (effectParam->GetType() == FCDEffectParameter::FLOAT3) + { + *isFloat3 = true; + FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) effectParam; + return (FCDParameterAnimatableColor4*) &tempParam->GetValue(); + } + else if (effectParam->GetType() == FCDEffectParameter::VECTOR) + { + *isFloat3 = false; + return &((FCDEffectParameterColor4*)effectParam)->GetValue(); + } + else return NULL; + } + else if (effectProfileParam) + { + if (effectProfileParam->GetType() == FCDEffectParameter::FLOAT3) + { + *isFloat3 = true; + FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) effectProfileParam; + return (FCDParameterAnimatableColor4*) &tempParam->GetValue(); + } + else if (effectProfileParam->GetType() == FCDEffectParameter::VECTOR) + { + *isFloat3 = false; + return &((FCDEffectParameterColor4*)effectProfileParam)->GetValue(); + } + else return NULL; + } + else + { + *isFloat3 = true; + return &((FCDEffectParameterColor4*)effectStandardParam)->GetValue(); + } + } + } + + FCDParameterAnimatableFloat* GetAnimatedFloat(FCDGeometryInstance* geometryInstance, FCDMaterial* material, const fm::string& semantic) + { + //Find the different classes that are needed. + //FCDMaterial* material = materialInstance->GetMaterial(); + if (material == NULL) return NULL; + FCDEffect* effect = material->GetEffect(); + if (effect == NULL) return NULL; + FCDEffectProfile* effectProfile = effect->FindProfile(FUDaeProfileType::COMMON); + if (effectProfile == NULL) return NULL; + FCDEffectStandard* effectStandard = (FCDEffectStandard*) effectProfile; + bool isFloat = true; + + //Find out if the parameter is animated + FCDEffectParameter* effectStandardParam = effectStandard->GetParam(semantic, &isFloat); + if (!effectStandardParam) return NULL; + const fm::string& reference = effectStandardParam->GetReference(); + if (reference.empty()) + { + if (isFloat) return &(((FCDEffectParameterFloat*)effectStandardParam)->GetValue()); + else return NULL; + } + FCDEffectParameter* geometryParam = geometryInstance != NULL ? FindEffectParameterBySemantic(geometryInstance, semantic) : NULL; + FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); + FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); + FCDEffectParameter* effectProfileParam = FindEffectParameterByReference(effectProfile, reference, false); + + if (isFloat) + { + if (geometryParam) + { + if (geometryParam->GetType() != FCDEffectParameter::FLOAT) return NULL; + else return &((FCDEffectParameterFloat*)geometryParam)->GetValue(); + } + //From this on out, could call GetDefaultFloat... and return that? + else if (materialParam) + { + if (materialParam->GetType() != FCDEffectParameter::FLOAT) return NULL; + else return &((FCDEffectParameterFloat*)materialParam)->GetValue(); + } + else if (effectParam) + { + if (effectParam->GetType() != FCDEffectParameter::FLOAT) return NULL; + else return &((FCDEffectParameterFloat*)effectParam)->GetValue(); + } + else if (effectProfileParam) + { + if (effectProfileParam->GetType() != FCDEffectParameter::FLOAT) return NULL; + else return &((FCDEffectParameterFloat*)effectProfileParam)->GetValue(); + } + else return &((FCDEffectParameterFloat*)effectStandardParam)->GetValue(); + } + else return NULL; + } + + FMVector4* GetDefaultColor(FCDMaterial* material, const fm::string& semantic, bool* isFloat3) + { + //Find the different classes that are needed. + FCDEffect* effect = material->GetEffect(); + FCDEffectProfile* effectProfile = effect->FindProfile(FUDaeProfileType::COMMON); + FCDEffectStandard* effectStandard = (FCDEffectStandard*) effectProfile; + bool isFloat = true; + + //Find out if the parameter is animated + FCDEffectParameter* effectStandardParam = effectStandard->GetParam(semantic, &isFloat); + if (!effectStandardParam) return NULL; + const fm::string& reference = effectStandardParam->GetReference(); + if (reference.empty()) + { + if (isFloat) return NULL; + else return &(FMVector4&)(((FCDEffectParameterColor4*)effectStandardParam)->GetValue()); + } + FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); + FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); + FCDEffectParameter* effectProfileParam = FindEffectParameterByReference(effectProfile, reference, false); + + //Do the figuring out .. ;) + if (isFloat) return NULL; + else + { + // Don't look at the geometry instance parameters: these are only used for animations! + if (materialParam) + { + if (materialParam->GetType() == FCDEffectParameter::FLOAT3) + { + *isFloat3 = true; + FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) materialParam; + return (FMVector4*) &(FMVector3&) tempParam->GetValue(); + } + else if (materialParam->GetType() == FCDEffectParameter::VECTOR) + { + *isFloat3 = false; + return &(FMVector4&) ((FCDEffectParameterColor4*)materialParam)->GetValue(); + } + else return NULL; + } + else if (effectParam) + { + if (effectParam->GetType() == FCDEffectParameter::FLOAT3) + { + *isFloat3 = true; + FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) effectParam; + return (FMVector4*) &(FMVector3&) tempParam->GetValue(); + } + else if (effectParam->GetType() == FCDEffectParameter::VECTOR) + { + *isFloat3 = false; + return &(FMVector4&) ((FCDEffectParameterColor4*)effectParam)->GetValue(); + } + else return NULL; + } + else if (effectProfileParam) + { + if (effectProfileParam->GetType() == FCDEffectParameter::FLOAT3) + { + *isFloat3 = true; + FCDEffectParameterFloat3* tempParam = (FCDEffectParameterFloat3*) effectProfileParam; + return (FMVector4*) &(FMVector3&) tempParam->GetValue(); + } + else if (effectProfileParam->GetType() == FCDEffectParameter::VECTOR) + { + *isFloat3 = false; + return &(FMVector4&) ((FCDEffectParameterColor4*)effectProfileParam)->GetValue(); + } + else return NULL; + } + else + { + *isFloat3 = true; + return &(FMVector4&) ((FCDEffectParameterColor4*)effectStandardParam)->GetValue(); + } + } + } + + float* GetDefaultFloat(FCDMaterial* material, const fm::string& semantic) + { + //Find the different classes that are needed. + FCDEffect* effect = material->GetEffect(); + FCDEffectProfile* effectProfile = effect->FindProfile(FUDaeProfileType::COMMON); + FCDEffectStandard* effectStandard = (FCDEffectStandard*) effectProfile; + bool isFloat = true; + + //Find out if the parameter is animated + FCDEffectParameter* effectStandardParam = effectStandard->GetParam(semantic, &isFloat); + if (!effectStandardParam) return NULL; + const fm::string& reference = effectStandardParam->GetReference(); + if (reference.empty()) + { + if (isFloat) return &(float&) ((FCDEffectParameterFloat*)effectStandardParam)->GetValue(); + else return NULL; + } + FCDEffectParameter* materialParam = FindEffectParameterByReference(material, reference, true); + FCDEffectParameter* effectParam = FindEffectParameterByReference(effect, reference, true); + FCDEffectParameter* effectProfileParam = FindEffectParameterByReference(effectProfile, reference, false); + + if (isFloat) + { + if (materialParam) + { + if (materialParam->GetType() != FCDEffectParameter::FLOAT) return NULL; + else return &(float&) ((FCDEffectParameterFloat*)materialParam)->GetValue(); + } + else if (effectParam) + { + if (effectParam->GetType() != FCDEffectParameter::FLOAT) return NULL; + else return &(float&) ((FCDEffectParameterFloat*)effectParam)->GetValue(); + } + else if (effectProfileParam) + { + if (effectProfileParam->GetType() != FCDEffectParameter::FLOAT) return NULL; + else return &(float&) ((FCDEffectParameterFloat*)effectProfileParam)->GetValue(); + } + else return &(float&) ((FCDEffectParameterFloat*)effectStandardParam)->GetValue(); + } + else return NULL; + } + + // + // FindEffectParameterBySemantic + // + + const FCDEffectParameter* FindEffectParameterBySemantic(const FCDGeometryInstance* geometryInstance, const char* semantic) + { + if (geometryInstance == NULL || semantic == NULL || *semantic == 0) return NULL; + size_t count = geometryInstance->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; + } + return NULL; + } + + const FCDEffectParameter* FindEffectParameterBySemantic(const FCDMaterialInstance* materialInstance, const char* semantic, bool localOnly) + { + if (materialInstance == NULL || semantic == NULL || *semantic == 0) return NULL; + const FCDGeometryInstance* geometryInstance = (FCDGeometryInstance*) materialInstance->GetParent(); + size_t count = geometryInstance->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; + } + return !localOnly ? FindEffectParameterBySemantic(materialInstance->GetMaterial(), semantic) : NULL; + } + + const FCDEffectParameter* FindEffectParameterBySemantic(const FCDMaterial* material, const char* semantic, bool localOnly) + { + if (material == NULL || semantic == NULL || *semantic == 0) return NULL; + size_t count = material->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = material->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; + } + return !localOnly ? FindEffectParameterBySemantic(material->GetEffect(), semantic) : NULL; + } + + const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffect* effect, const char* semantic, bool localOnly) + { + if (effect == NULL || semantic == NULL || *semantic == 0) return NULL; + size_t count = effect->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = effect->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; + } + if (!localOnly) + { + size_t profileCount = effect->GetProfileCount(); + for (size_t p = 0; p < profileCount; ++p) + { + const FCDEffectParameter* effectParameter = FindEffectParameterBySemantic(effect->GetProfile(p), semantic); + if (effectParameter != NULL) return effectParameter; + } + } + return NULL; + } + + const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffectProfile* profile, const char* semantic, bool localOnly) + { + // Look within the local parameters. + if (profile == NULL || semantic == NULL || *semantic == 0) return NULL; + size_t count = profile->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = profile->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; + } + + if (profile->HasType(FCDEffectProfileFX::GetClassType()) && !localOnly) + { + // Look within the parameters. + FCDEffectProfileFX* fx = (FCDEffectProfileFX*) profile; + size_t techniqueCount = fx->GetTechniqueCount(); + for (size_t t = 0; t < techniqueCount; ++t) + { + const FCDEffectParameter* effectParameter = FindEffectParameterBySemantic(fx->GetTechnique(t), semantic); + if (effectParameter != NULL) return effectParameter; + } + } + else if (profile->HasType(FCDEffectStandard::GetClassType())) + { + // Look within the textures which have their own parameters. + FCDEffectStandard* std = (FCDEffectStandard*) profile; + for (uint32 i = 0; i < FUDaeTextureChannel::COUNT; ++i) + { + size_t bucketSize = std->GetTextureCount(i); + for (size_t t = 0; t < bucketSize; ++t) + { + FCDTexture* texture = std->GetTexture(i, t); + if (IsEquivalent(texture->GetSet()->GetSemantic(), semantic)) return texture->GetSet(); + } + } + } + return NULL; + } + + const FCDEffectParameter* FindEffectParameterBySemantic(const FCDEffectTechnique* technique, const char* semantic, bool UNUSED(localOnly)) + { + if (technique == NULL || semantic == NULL || *semantic == 0) return NULL; + size_t count = technique->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = technique->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) return effectParameter; + } + return NULL; + } + + // + // FindEffectParameterByReference + // + + const FCDEffectParameter* FindEffectParameterByReference(const FCDGeometryInstance* geometryInstance, const char* reference) + { + if (geometryInstance == NULL || reference == NULL || *reference == 0) return NULL; + size_t count = geometryInstance->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; + } + return NULL; + } + + const FCDEffectParameter* FindEffectParameterByReference(const FCDMaterialInstance* materialInstance, const char* reference, bool localOnly) + { + if (materialInstance == NULL || reference == NULL || *reference == 0) return NULL; + const FCDGeometryInstance* geometryInstance = (FCDGeometryInstance*) materialInstance->GetParent(); + size_t count = geometryInstance->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; + } + return !localOnly ? FindEffectParameterByReference(materialInstance->GetMaterial(), reference) : NULL; + } + + const FCDEffectParameter* FindEffectParameterByReference(const FCDMaterial* material, const char* reference, bool localOnly) + { + if (material == NULL || reference == NULL || *reference == 0) return NULL; + size_t count = material->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = material->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; + } + return !localOnly ? FindEffectParameterByReference(material->GetEffect(), reference) : NULL; + } + + const FCDEffectParameter* FindEffectParameterByReference(const FCDEffect* effect, const char* reference, bool localOnly) + { + if (effect == NULL || reference == NULL || *reference == 0) return NULL; + size_t count = effect->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = effect->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; + } + if (!localOnly) + { + size_t profileCount = effect->GetProfileCount(); + for (size_t p = 0; p < profileCount; ++p) + { + const FCDEffectParameter* effectParameter = FindEffectParameterByReference(effect->GetProfile(p), reference); + if (effectParameter != NULL) return effectParameter; + } + } + return NULL; + } + + const FCDEffectParameter* FindEffectParameterByReference(const FCDEffectProfile* profile, const char* reference, bool localOnly) + { + // Look within the local parameters. + if (profile == NULL || reference == NULL || *reference == 0) return NULL; + size_t count = profile->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = profile->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; + } + + if (profile->HasType(FCDEffectProfileFX::GetClassType()) && !localOnly) + { + // Look within the parameters. + FCDEffectProfileFX* fx = (FCDEffectProfileFX*) profile; + size_t techniqueCount = fx->GetTechniqueCount(); + for (size_t t = 0; t < techniqueCount; ++t) + { + const FCDEffectParameter* effectParameter = FindEffectParameterByReference(fx->GetTechnique(t), reference); + if (effectParameter != NULL) return effectParameter; + } + } + else if (profile->HasType(FCDEffectStandard::GetClassType())) + { + // Look within the textures which have their own parameters. + FCDEffectStandard* std = (FCDEffectStandard*) profile; + for (uint32 i = 0; i < FUDaeTextureChannel::COUNT; ++i) + { + size_t bucketSize = std->GetTextureCount(i); + for (size_t t = 0; t < bucketSize; ++t) + { + FCDTexture* texture = std->GetTexture(i, t); + if (IsEquivalent(texture->GetSet()->GetReference(), reference)) return texture->GetSet(); + } + } + } + return NULL; + } + + const FCDEffectParameter* FindEffectParameterByReference(const FCDEffectTechnique* technique, const char* reference, bool UNUSED(localOnly)) + { + if (technique == NULL || reference == NULL || *reference == 0) return NULL; + size_t count = technique->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = technique->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) return effectParameter; + } + return NULL; + } + + // + // FindEffectParametersBySemantic + // + + void FindEffectParametersBySemantic(const FCDMaterialInstance* materialInstance, const char* semantic, FCDEffectParameterList& parameters, bool localOnly) + { + if (materialInstance == NULL || semantic == NULL || *semantic == 0) return; + const FCDGeometryInstance* geometryInstance = (FCDGeometryInstance*) materialInstance->GetParent(); + size_t count = geometryInstance->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) parameters.push_back(effectParameter); + } + if (!localOnly) + { + FindEffectParametersBySemantic(materialInstance->GetMaterial(), semantic, parameters); + } + } + + void FindEffectParametersBySemantic(const FCDMaterial* material, const char* semantic, FCDEffectParameterList& parameters, bool localOnly) + { + if (material == NULL || semantic == NULL || *semantic == 0) return; + size_t count = material->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = material->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) parameters.push_back(effectParameter); + } + if (!localOnly) + { + FindEffectParametersBySemantic(material->GetEffect(), semantic, parameters); + } + } + + void FindEffectParametersBySemantic(const FCDEffect* effect, const char* semantic, FCDEffectParameterList& parameters, bool localOnly) + { + if (effect == NULL || semantic == NULL || *semantic == 0) return; + size_t count = effect->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = effect->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) parameters.push_back(effectParameter); + } + if (!localOnly) + { + size_t profileCount = effect->GetProfileCount(); + for (size_t p = 0; p < profileCount; ++p) + { + FindEffectParametersBySemantic(effect->GetProfile(p), semantic, parameters); + } + } + } + + void FindEffectParametersBySemantic(const FCDEffectProfile* profile, const char* semantic, FCDEffectParameterList& parameters, bool localOnly) + { + // Look within the local parameters. + if (profile == NULL || semantic == NULL || *semantic == 0) return; + size_t count = profile->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = profile->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) parameters.push_back(effectParameter); + } + + if (profile->HasType(FCDEffectProfileFX::GetClassType()) && !localOnly) + { + // Look within the parameters. + FCDEffectProfileFX* fx = (FCDEffectProfileFX*) profile; + size_t techniqueCount = fx->GetTechniqueCount(); + for (size_t t = 0; t < techniqueCount; ++t) + { + FindEffectParametersBySemantic(fx->GetTechnique(t), semantic, parameters); + } + } + else if (profile->HasType(FCDEffectStandard::GetClassType())) + { + // Look within the textures which have their own parameters. + FCDEffectStandard* std = (FCDEffectStandard*) profile; + for (uint32 i = 0; i < FUDaeTextureChannel::COUNT; ++i) + { + size_t bucketSize = std->GetTextureCount(i); + for (size_t t = 0; t < bucketSize; ++t) + { + FCDTexture* texture = std->GetTexture(i, t); + if (IsEquivalent(texture->GetSet()->GetSemantic(), semantic)) parameters.push_back(texture->GetSet()); + } + } + } + } + + void FindEffectParametersBySemantic(const FCDEffectTechnique* technique, const char* semantic, FCDEffectParameterList& parameters, bool UNUSED(localOnly)) + { + if (technique == NULL || semantic == NULL || *semantic == 0) return; + size_t count = technique->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = technique->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetSemantic(), semantic)) parameters.push_back(effectParameter); + } + } + + // + // FindEffectParametersByReference + // + + void FindEffectParametersByReference(const FCDMaterialInstance* materialInstance, const char* reference, FCDEffectParameterList& parameters, bool localOnly) + { + if (materialInstance == NULL || reference == NULL || *reference == 0) return; + const FCDGeometryInstance* geometryInstance = (FCDGeometryInstance*) materialInstance->GetParent(); + size_t count = geometryInstance->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = geometryInstance->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) parameters.push_back(effectParameter); + } + if (!localOnly) + { + FindEffectParametersByReference(materialInstance->GetMaterial(), reference, parameters); + } + } + + void FindEffectParametersByReference(const FCDMaterial* material, const char* reference, FCDEffectParameterList& parameters, bool localOnly) + { + if (material == NULL || reference == NULL || *reference == 0) return; + size_t count = material->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = material->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) parameters.push_back(effectParameter); + } + if (!localOnly) + { + FindEffectParametersByReference(material->GetEffect(), reference, parameters); + } + } + + void FindEffectParametersByReference(const FCDEffect* effect, const char* reference, FCDEffectParameterList& parameters, bool localOnly) + { + if (effect == NULL || reference == NULL || *reference == 0) return; + size_t count = effect->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = effect->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) parameters.push_back(effectParameter); + } + if (!localOnly) + { + size_t profileCount = effect->GetProfileCount(); + for (size_t p = 0; p < profileCount; ++p) + { + FindEffectParametersByReference(effect->GetProfile(p), reference, parameters); + } + } + } + + void FindEffectParametersByReference(const FCDEffectProfile* profile, const char* reference, FCDEffectParameterList& parameters, bool localOnly) + { + // Look within the local parameters. + if (profile == NULL || reference == NULL || *reference == 0) return; + size_t count = profile->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = profile->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) parameters.push_back(effectParameter); + } + + if (profile->HasType(FCDEffectProfileFX::GetClassType()) && !localOnly) + { + // Look within the parameters. + FCDEffectProfileFX* fx = (FCDEffectProfileFX*) profile; + size_t techniqueCount = fx->GetTechniqueCount(); + for (size_t t = 0; t < techniqueCount; ++t) + { + FindEffectParametersByReference(fx->GetTechnique(t), reference, parameters); + } + } + else if (profile->HasType(FCDEffectStandard::GetClassType())) + { + // Look within the textures which have their own parameters. + FCDEffectStandard* std = (FCDEffectStandard*) profile; + for (uint32 i = 0; i < FUDaeTextureChannel::COUNT; ++i) + { + size_t bucketSize = std->GetTextureCount(i); + for (size_t t = 0; t < bucketSize; ++t) + { + FCDTexture* texture = std->GetTexture(i, t); + if (IsEquivalent(texture->GetSet()->GetReference(), reference)) parameters.push_back(texture->GetSet()); + } + } + } + } + + void FindEffectParametersByReference(const FCDEffectTechnique* technique, const char* reference, FCDEffectParameterList& parameters, bool UNUSED(localOnly)) + { + if (technique == NULL || reference == NULL || *reference == 0) return; + size_t count = technique->GetEffectParameterCount(); + for (size_t p = 0; p < count; ++p) + { + const FCDEffectParameter* effectParameter = technique->GetEffectParameter(p); + if (IsEquivalent(effectParameter->GetReference(), reference)) parameters.push_back(effectParameter); + } + } +}; Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTools.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterInstance.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterInstance.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterInstance.cpp (revision 24247) @@ -1,36 +1,36 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEmitter.h" -#include "FCDocument/FCDEmitterInstance.h" -#include "FCDocument/FCDEntity.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDMaterial.h" -#include "FCDocument/FCDMaterialInstance.h" - -// -// FCDEmitterInstance -// - -ImplementObjectType(FCDEmitterInstance); -ImplementParameterObjectNoCtr(FCDEmitterInstance, FCDEntityInstance, forceInstances); -ImplementParameterObjectNoCtr(FCDEmitterInstance, FCDEntityInstance, emittedInstances); - -FCDEmitterInstance::FCDEmitterInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType) -: FCDEntityInstance(document, parent, entityType) -{ -} - -FCDEmitterInstance::~FCDEmitterInstance() -{ -} - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEmitter.h" +#include "FCDocument/FCDEmitterInstance.h" +#include "FCDocument/FCDEntity.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDMaterial.h" +#include "FCDocument/FCDMaterialInstance.h" + +// +// FCDEmitterInstance +// + +ImplementObjectType(FCDEmitterInstance); +ImplementParameterObjectNoCtr(FCDEmitterInstance, FCDEntityInstance, forceInstances); +ImplementParameterObjectNoCtr(FCDEmitterInstance, FCDEntityInstance, emittedInstances); + +FCDEmitterInstance::FCDEmitterInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType) +: FCDEntityInstance(document, parent, entityType) +{ +} + +FCDEmitterInstance::~FCDEmitterInstance() +{ +} + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterInstance.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterParticle.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterParticle.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterParticle.cpp (revision 24247) @@ -1,15 +1,15 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEmitter.h" -#include "FCDocument/FCDEmitterParticle.h" -#include "FCDocument/FCDEmitterObject.h" -#include "FCDocument/FCDParticleModifier.h" - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEmitter.h" +#include "FCDocument/FCDEmitterParticle.h" +#include "FCDocument/FCDEmitterObject.h" +#include "FCDocument/FCDParticleModifier.h" + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterParticle.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityInstance.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityInstance.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityInstance.cpp (revision 24247) @@ -1,196 +1,196 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument.h" -#include "FCDEntity.h" -#include "FCDEntityInstance.h" -#include "FCDExtra.h" -#include "FCDSceneNode.h" -#include "FCDControllerInstance.h" -#include "FCDEmitterInstance.h" -#include "FCDGeometryInstance.h" -#include "FCDPhysicsForceFieldInstance.h" -#include "FCDEntityReference.h" -#include -#include - -// -// FCDEntityInstance -// - -ImplementObjectType(FCDEntityInstance); -ImplementParameterObject(FCDEntityInstance, FCDEntityReference, entityReference, new FCDEntityReference(parent->GetDocument(), parent->GetParent())); -ImplementParameterObject(FCDEntityInstance, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); - -FCDEntityInstance::FCDEntityInstance(FCDocument* document, FCDSceneNode* _parent, FCDEntity::Type type) -: FCDObject(document), parent(_parent) -, entityType(type) -, InitializeParameterNoArg(entityReference) -, InitializeParameterNoArg(wantedSubId) -, InitializeParameterNoArg(extra) -{ - // Always create this - entityReference = new FCDEntityReference(document, _parent); - TrackObject(entityReference); -} - -FCDEntityInstance::~FCDEntityInstance() -{ - - if (entityReference != NULL) - { - UntrackObject(entityReference); - SAFE_RELEASE(entityReference); - } -} - -FCDEntity* FCDEntityInstance::GetEntity() -{ - return entityReference->GetEntity(); -} - -void FCDEntityInstance::SetEntity(FCDEntity* entity) -{ - entityReference->SetEntity(entity); -} - -const FUUri FCDEntityInstance::GetEntityUri() const -{ - return entityReference->GetUri(); -} - -void FCDEntityInstance::SetEntityUri(const FUUri& uri) -{ - entityReference->SetUri(uri); -} - -void FCDEntityInstance::SetName(const fstring& _name) -{ - name = FCDEntity::CleanName(_name.c_str()); - SetDirtyFlag(); -} - -FCDExtra* FCDEntityInstance::GetExtra() -{ - return (extra != NULL) ? extra : (extra = new FCDExtra(GetDocument(), this)); -} - -bool FCDEntityInstance::IsExternalReference() const -{ - return entityReference->GetPlaceHolder() != NULL; -} - -/* -void FCDEntityInstance::LoadExternalEntity(FCDocument* externalDocument, const fm::string& daeId) -{ - if (externalDocument == NULL || entity != NULL) return; - - FCDEntity* instancedEntity = NULL; - switch (entityType) - { - case FCDEntity::ANIMATION: instancedEntity = (FCDEntity*) externalDocument->FindAnimation(daeId); break; - case FCDEntity::CAMERA: instancedEntity = (FCDEntity*) externalDocument->FindCamera(daeId); break; - case FCDEntity::EMITTER: instancedEntity = (FCDEntity*) externalDocument->FindEmitter(daeId); break; - case FCDEntity::LIGHT: instancedEntity = (FCDEntity*) externalDocument->FindLight(daeId); break; - case FCDEntity::GEOMETRY: instancedEntity = (FCDEntity*) externalDocument->FindGeometry(daeId); break; - case FCDEntity::CONTROLLER: instancedEntity = (FCDEntity*) externalDocument->FindController(daeId); break; - case FCDEntity::MATERIAL: instancedEntity = (FCDEntity*) externalDocument->FindMaterial(daeId); break; - case FCDEntity::EFFECT: instancedEntity = (FCDEntity*) externalDocument->FindEffect(daeId); break; - case FCDEntity::SCENE_NODE: instancedEntity = (FCDEntity*) externalDocument->FindSceneNode(daeId); break; - case FCDEntity::FORCE_FIELD: instancedEntity = (FCDEntity*) externalDocument->FindForceField(daeId); break; - case FCDEntity::PHYSICS_MATERIAL: instancedEntity = (FCDEntity*) externalDocument->FindPhysicsMaterial(daeId); break; - case FCDEntity::PHYSICS_MODEL: instancedEntity = (FCDEntity*) externalDocument->FindPhysicsModel(daeId); break; - default: break; - } - - if (instancedEntity != NULL) - { - SetEntity(instancedEntity); - } -} -*/ -bool FCDEntityInstance::HasForParent(FCDSceneNode* node) const -{ - if (node == NULL) return false; - if (parent == NULL) return false; - FCDSceneNodeList parentStack; - parentStack.push_back(parent); - while (!parentStack.empty()) - { - FCDSceneNode* p = parentStack.front(); - if (p == node) return true; - for (size_t i = 0; i < p->GetParentCount(); ++i) - { - parentStack.push_back(p->GetParent(i)); - } - parentStack.pop_front(); - } - return false; -} - -void FCDEntityInstance::CleanSubId(FUSUniqueStringMap* parentStringMap) -{ - if (!wantedSubId->empty() && (parentStringMap != NULL)) - { - parentStringMap->insert(wantedSubId); - } -} - -FCDEntityInstance* FCDEntityInstance::Clone(FCDEntityInstance* clone) const -{ - if (clone == NULL) - { - clone = new FCDEntityInstance(const_cast(GetDocument()), const_cast(parent), entityType); - } - - clone->SetEntity(const_cast(entityReference->GetEntity())); - return clone; -} - -void FCDEntityInstance::OnObjectReleased(FUTrackable* object) -{ - FUAssert(object == entityReference, return); - entityReference = NULL; - Release(); -} - - -/******************* FCDEntityInstanceFactory implementation ***********************/ - - -FCDEntityInstance* FCDEntityInstanceFactory::CreateInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type type) -{ - switch (type) - { - case FCDEntity::CONTROLLER: return new FCDControllerInstance(document, parent, type); break; - case FCDEntity::EMITTER: return new FCDEmitterInstance(document, parent, type); break; - case FCDEntity::GEOMETRY: return new FCDGeometryInstance(document, parent, type); break; - case FCDEntity::FORCE_FIELD: return new FCDPhysicsForceFieldInstance(document, parent, type); break; - case FCDEntity::PHYSICS_MATERIAL: - case FCDEntity::CAMERA: - case FCDEntity::LIGHT: - case FCDEntity::ANIMATION: - case FCDEntity::SCENE_NODE: return new FCDEntityInstance(document, parent, type); break; - - default: - FUFail(;); - // Default to always return something. - return new FCDEntityInstance(document, parent, type); - break; - } -} - -FCDEntityInstance* FCDEntityInstanceFactory::CreateInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity* entity) -{ - FUAssert(entity != NULL, return NULL); - - FCDEntityInstance* instance = CreateInstance(document, parent, entity->GetType()); - instance->SetEntity(entity); - return instance; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument.h" +#include "FCDEntity.h" +#include "FCDEntityInstance.h" +#include "FCDExtra.h" +#include "FCDSceneNode.h" +#include "FCDControllerInstance.h" +#include "FCDEmitterInstance.h" +#include "FCDGeometryInstance.h" +#include "FCDPhysicsForceFieldInstance.h" +#include "FCDEntityReference.h" +#include +#include + +// +// FCDEntityInstance +// + +ImplementObjectType(FCDEntityInstance); +ImplementParameterObject(FCDEntityInstance, FCDEntityReference, entityReference, new FCDEntityReference(parent->GetDocument(), parent->GetParent())); +ImplementParameterObject(FCDEntityInstance, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); + +FCDEntityInstance::FCDEntityInstance(FCDocument* document, FCDSceneNode* _parent, FCDEntity::Type type) +: FCDObject(document), parent(_parent) +, entityType(type) +, InitializeParameterNoArg(entityReference) +, InitializeParameterNoArg(wantedSubId) +, InitializeParameterNoArg(extra) +{ + // Always create this + entityReference = new FCDEntityReference(document, _parent); + TrackObject(entityReference); +} + +FCDEntityInstance::~FCDEntityInstance() +{ + + if (entityReference != NULL) + { + UntrackObject(entityReference); + SAFE_RELEASE(entityReference); + } +} + +FCDEntity* FCDEntityInstance::GetEntity() +{ + return entityReference->GetEntity(); +} + +void FCDEntityInstance::SetEntity(FCDEntity* entity) +{ + entityReference->SetEntity(entity); +} + +const FUUri FCDEntityInstance::GetEntityUri() const +{ + return entityReference->GetUri(); +} + +void FCDEntityInstance::SetEntityUri(const FUUri& uri) +{ + entityReference->SetUri(uri); +} + +void FCDEntityInstance::SetName(const fstring& _name) +{ + name = FCDEntity::CleanName(_name.c_str()); + SetDirtyFlag(); +} + +FCDExtra* FCDEntityInstance::GetExtra() +{ + return (extra != NULL) ? extra : (extra = new FCDExtra(GetDocument(), this)); +} + +bool FCDEntityInstance::IsExternalReference() const +{ + return entityReference->GetPlaceHolder() != NULL; +} + +/* +void FCDEntityInstance::LoadExternalEntity(FCDocument* externalDocument, const fm::string& daeId) +{ + if (externalDocument == NULL || entity != NULL) return; + + FCDEntity* instancedEntity = NULL; + switch (entityType) + { + case FCDEntity::ANIMATION: instancedEntity = (FCDEntity*) externalDocument->FindAnimation(daeId); break; + case FCDEntity::CAMERA: instancedEntity = (FCDEntity*) externalDocument->FindCamera(daeId); break; + case FCDEntity::EMITTER: instancedEntity = (FCDEntity*) externalDocument->FindEmitter(daeId); break; + case FCDEntity::LIGHT: instancedEntity = (FCDEntity*) externalDocument->FindLight(daeId); break; + case FCDEntity::GEOMETRY: instancedEntity = (FCDEntity*) externalDocument->FindGeometry(daeId); break; + case FCDEntity::CONTROLLER: instancedEntity = (FCDEntity*) externalDocument->FindController(daeId); break; + case FCDEntity::MATERIAL: instancedEntity = (FCDEntity*) externalDocument->FindMaterial(daeId); break; + case FCDEntity::EFFECT: instancedEntity = (FCDEntity*) externalDocument->FindEffect(daeId); break; + case FCDEntity::SCENE_NODE: instancedEntity = (FCDEntity*) externalDocument->FindSceneNode(daeId); break; + case FCDEntity::FORCE_FIELD: instancedEntity = (FCDEntity*) externalDocument->FindForceField(daeId); break; + case FCDEntity::PHYSICS_MATERIAL: instancedEntity = (FCDEntity*) externalDocument->FindPhysicsMaterial(daeId); break; + case FCDEntity::PHYSICS_MODEL: instancedEntity = (FCDEntity*) externalDocument->FindPhysicsModel(daeId); break; + default: break; + } + + if (instancedEntity != NULL) + { + SetEntity(instancedEntity); + } +} +*/ +bool FCDEntityInstance::HasForParent(FCDSceneNode* node) const +{ + if (node == NULL) return false; + if (parent == NULL) return false; + FCDSceneNodeList parentStack; + parentStack.push_back(parent); + while (!parentStack.empty()) + { + FCDSceneNode* p = parentStack.front(); + if (p == node) return true; + for (size_t i = 0; i < p->GetParentCount(); ++i) + { + parentStack.push_back(p->GetParent(i)); + } + parentStack.pop_front(); + } + return false; +} + +void FCDEntityInstance::CleanSubId(FUSUniqueStringMap* parentStringMap) +{ + if (!wantedSubId->empty() && (parentStringMap != NULL)) + { + parentStringMap->insert(wantedSubId); + } +} + +FCDEntityInstance* FCDEntityInstance::Clone(FCDEntityInstance* clone) const +{ + if (clone == NULL) + { + clone = new FCDEntityInstance(const_cast(GetDocument()), const_cast(parent), entityType); + } + + clone->SetEntity(const_cast(entityReference->GetEntity())); + return clone; +} + +void FCDEntityInstance::OnObjectReleased(FUTrackable* object) +{ + FUAssert(object == entityReference, return); + entityReference = NULL; + Release(); +} + + +/******************* FCDEntityInstanceFactory implementation ***********************/ + + +FCDEntityInstance* FCDEntityInstanceFactory::CreateInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type type) +{ + switch (type) + { + case FCDEntity::CONTROLLER: return new FCDControllerInstance(document, parent, type); break; + case FCDEntity::EMITTER: return new FCDEmitterInstance(document, parent, type); break; + case FCDEntity::GEOMETRY: return new FCDGeometryInstance(document, parent, type); break; + case FCDEntity::FORCE_FIELD: return new FCDPhysicsForceFieldInstance(document, parent, type); break; + case FCDEntity::PHYSICS_MATERIAL: + case FCDEntity::CAMERA: + case FCDEntity::LIGHT: + case FCDEntity::ANIMATION: + case FCDEntity::SCENE_NODE: return new FCDEntityInstance(document, parent, type); break; + + default: + FUFail(;); + // Default to always return something. + return new FCDEntityInstance(document, parent, type); + break; + } +} + +FCDEntityInstance* FCDEntityInstanceFactory::CreateInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity* entity) +{ + FUAssert(entity != NULL, return NULL); + + FCDEntityInstance* instance = CreateInstance(document, parent, entity->GetType()); + instance->SetEntity(entity); + return instance; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityInstance.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExternalReferenceManager.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExternalReferenceManager.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExternalReferenceManager.cpp (revision 24247) @@ -1,94 +1,94 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEntityReference.h" -#include "FCDocument/FCDExternalReferenceManager.h" -#include "FCDocument/FCDPlaceHolder.h" -#include "FUtils/FUFileManager.h" - -// -// FCDExternalReferenceManager -// - -ImplementObjectType(FCDExternalReferenceManager); - -FCDExternalReferenceManager::FCDExternalReferenceManager(FCDocument* document) -: FCDObject(document) -{ -} - -FCDExternalReferenceManager::~FCDExternalReferenceManager() -{ -} - -FCDPlaceHolder* FCDExternalReferenceManager::AddPlaceHolder(const fstring& _fileUrl) -{ - fstring fileUrl = GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(_fileUrl); - FCDPlaceHolder* holder = placeHolders.Add(GetDocument()); - holder->SetFileUrl(fileUrl); - SetNewChildFlag(); - return holder; -} - -const FCDPlaceHolder* FCDExternalReferenceManager::FindPlaceHolder(const fstring& _fileUrl) const -{ - fstring fileUrl = GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(_fileUrl); - for (const FCDPlaceHolder** it = placeHolders.begin(); it != placeHolders.end(); ++it) - { - if ((*it)->GetFileUrl() == fileUrl) return *it; - } - return NULL; -} - -FCDPlaceHolder* FCDExternalReferenceManager::AddPlaceHolder(FCDocument* document) -{ - FCDPlaceHolder* placeHolder = placeHolders.Add(GetDocument(), document); - SetNewChildFlag(); - return placeHolder; -} - -const FCDPlaceHolder* FCDExternalReferenceManager::FindPlaceHolder(const FCDocument* document) const -{ - for (const FCDPlaceHolder** it = placeHolders.begin(); it != placeHolders.end(); ++it) - { - if ((*it)->GetTarget() == document) return *it; - } - return NULL; -} - -void FCDExternalReferenceManager::RegisterLoadedDocument(FCDocument* document) -{ - fm::pvector allDocuments; - FCollada::GetAllDocuments(allDocuments); - for (FCDocument** it = allDocuments.begin(); it != allDocuments.end(); ++it) - { - if ((*it) != document) - { - FCDExternalReferenceManager* xrefManager = (*it)->GetExternalReferenceManager(); - - for (FCDPlaceHolder** itP = xrefManager->placeHolders.begin(); itP != xrefManager->placeHolders.end(); ++itP) - { - // Set the document to the placeholders that targets it. - if ((*itP)->GetFileUrl() == document->GetFileUrl()) (*itP)->LoadTarget(document); - } - } - } - - // On the newly-loaded document, there may be placeholders to process. - FCDExternalReferenceManager* xrefManager = document->GetExternalReferenceManager(); - for (FCDPlaceHolder** itP = xrefManager->placeHolders.begin(); itP != xrefManager->placeHolders.end(); ++itP) - { - // Set the document to the placeholders that targets it. - for (FCDocument** itD = allDocuments.begin(); itD != allDocuments.end(); ++itD) - { - if ((*itP)->GetFileUrl() == (*itD)->GetFileUrl()) (*itP)->LoadTarget(*itD); - } - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEntityReference.h" +#include "FCDocument/FCDExternalReferenceManager.h" +#include "FCDocument/FCDPlaceHolder.h" +#include "FUtils/FUFileManager.h" + +// +// FCDExternalReferenceManager +// + +ImplementObjectType(FCDExternalReferenceManager); + +FCDExternalReferenceManager::FCDExternalReferenceManager(FCDocument* document) +: FCDObject(document) +{ +} + +FCDExternalReferenceManager::~FCDExternalReferenceManager() +{ +} + +FCDPlaceHolder* FCDExternalReferenceManager::AddPlaceHolder(const fstring& _fileUrl) +{ + fstring fileUrl = GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(_fileUrl); + FCDPlaceHolder* holder = placeHolders.Add(GetDocument()); + holder->SetFileUrl(fileUrl); + SetNewChildFlag(); + return holder; +} + +const FCDPlaceHolder* FCDExternalReferenceManager::FindPlaceHolder(const fstring& _fileUrl) const +{ + fstring fileUrl = GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(_fileUrl); + for (const FCDPlaceHolder** it = placeHolders.begin(); it != placeHolders.end(); ++it) + { + if ((*it)->GetFileUrl() == fileUrl) return *it; + } + return NULL; +} + +FCDPlaceHolder* FCDExternalReferenceManager::AddPlaceHolder(FCDocument* document) +{ + FCDPlaceHolder* placeHolder = placeHolders.Add(GetDocument(), document); + SetNewChildFlag(); + return placeHolder; +} + +const FCDPlaceHolder* FCDExternalReferenceManager::FindPlaceHolder(const FCDocument* document) const +{ + for (const FCDPlaceHolder** it = placeHolders.begin(); it != placeHolders.end(); ++it) + { + if ((*it)->GetTarget() == document) return *it; + } + return NULL; +} + +void FCDExternalReferenceManager::RegisterLoadedDocument(FCDocument* document) +{ + fm::pvector allDocuments; + FCollada::GetAllDocuments(allDocuments); + for (FCDocument** it = allDocuments.begin(); it != allDocuments.end(); ++it) + { + if ((*it) != document) + { + FCDExternalReferenceManager* xrefManager = (*it)->GetExternalReferenceManager(); + + for (FCDPlaceHolder** itP = xrefManager->placeHolders.begin(); itP != xrefManager->placeHolders.end(); ++itP) + { + // Set the document to the placeholders that targets it. + if ((*itP)->GetFileUrl() == document->GetFileUrl()) (*itP)->LoadTarget(document); + } + } + } + + // On the newly-loaded document, there may be placeholders to process. + FCDExternalReferenceManager* xrefManager = document->GetExternalReferenceManager(); + for (FCDPlaceHolder** itP = xrefManager->placeHolders.begin(); itP != xrefManager->placeHolders.end(); ++itP) + { + // Set the document to the placeholders that targets it. + for (FCDocument** itD = allDocuments.begin(); itD != allDocuments.end(); ++itD) + { + if ((*itP)->GetFileUrl() == (*itD)->GetFileUrl()) (*itP)->LoadTarget(*itD); + } + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExternalReferenceManager.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDeflector.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDeflector.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDeflector.cpp (revision 24247) @@ -1,12 +1,12 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDForceDeflector.h" - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDForceDeflector.h" + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDeflector.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceField.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceField.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceField.cpp (revision 24247) @@ -1,61 +1,61 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDForceField.h" -#include "FCDocument/FCDForceDeflector.h" -#include "FCDocument/FCDForceDrag.h" -#include "FCDocument/FCDForceGravity.h" -#include "FCDocument/FCDForcePBomb.h" -#include "FCDocument/FCDForceWind.h" - -// -// FCDForceField -// - -ImplementObjectType(FCDForceField); -ImplementParameterObject(FCDForceField, FCDExtra, information, new FCDExtra(parent->GetDocument(), parent)) - -FCDForceField::FCDForceField(FCDocument* document) -: FCDEntity(document, "ForceField") -, InitializeParameterNoArg(information) -{ - information = new FCDExtra(GetDocument(), this); -} - -FCDForceField::~FCDForceField() -{ -} - -const FCDExtra* FCDForceField::GetInformation() const -{ - if (information == NULL) - { - const_cast(this)->information = new FCDExtra(const_cast(GetDocument()), const_cast(this)); - } - return information; -} - -FCDEntity* FCDForceField::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDForceField* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDForceField(const_cast(GetDocument())); - else if (_clone->HasType(FCDForceField::GetClassType())) clone = (FCDForceField*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - - // Clone the extra information. - information->Clone(clone->information); - } - return _clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDForceField.h" +#include "FCDocument/FCDForceDeflector.h" +#include "FCDocument/FCDForceDrag.h" +#include "FCDocument/FCDForceGravity.h" +#include "FCDocument/FCDForcePBomb.h" +#include "FCDocument/FCDForceWind.h" + +// +// FCDForceField +// + +ImplementObjectType(FCDForceField); +ImplementParameterObject(FCDForceField, FCDExtra, information, new FCDExtra(parent->GetDocument(), parent)) + +FCDForceField::FCDForceField(FCDocument* document) +: FCDEntity(document, "ForceField") +, InitializeParameterNoArg(information) +{ + information = new FCDExtra(GetDocument(), this); +} + +FCDForceField::~FCDForceField() +{ +} + +const FCDExtra* FCDForceField::GetInformation() const +{ + if (information == NULL) + { + const_cast(this)->information = new FCDExtra(const_cast(GetDocument()), const_cast(this)); + } + return information; +} + +FCDEntity* FCDForceField::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDForceField* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDForceField(const_cast(GetDocument())); + else if (_clone->HasType(FCDForceField::GetClassType())) clone = (FCDForceField*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + + // Clone the extra information. + information->Clone(clone->information); + } + return _clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceField.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassState.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassState.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassState.cpp (revision 24247) @@ -1,383 +1,383 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDEffectPassState.h" -//#include "FUtils/FUDaeSyntax.h" - -// -// Translation Tables -// - -static const size_t dataSizeTable[FUDaePassState::COUNT] = -{ - 8, 8, 16, 4, 8, 8, 4, 4, 4, 4, // [ 0- 9] - 4, 4, 4, 8, 4, 6, 12, 10, 16, 5, // [ 10- 19] - 2, 17, 17, 17, 17, 5, 5, 5, 5, 17, 5, // [ 20- 30] - 5, 5, 5, 5, 5, 5, 2, 2, 2, 2, 2, 2, 17, 256, // [ 31- 44] - 17, 2, 16, 16, 4, 4, 4, 8, 1, 8, // [ 45- 54] - 4, 4, 4, 16, 16, 1, 4, 4, // [ 55- 62] - 16, 16, 16, 4, 16, 64, 12, 4, 4, 4, 4, // [ 63- 73] - 8, 64, 16, 4, 1, 1, 1, 1, 1, 1, // [ 74- 83] - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // [ 84- 94] - 1, 1, 1, 1, 1, 1, 1, 1, // [ 95-102] - 1, 1, 1, 1, 1 // [103-107] -}; - -// -// FCDEffectPassState -// - -ImplementObjectType(FCDEffectPassState); - -FCDEffectPassState::FCDEffectPassState(FCDocument* document, FUDaePassState::State renderState) -: FCDObject(document) -, InitializeParameter(type, renderState) -, data(NULL), dataSize(0) -{ - // Use the translation table to figure out the necessary memory to hold the data. - if (renderState >= 0 && renderState < FUDaePassState::COUNT) dataSize = dataSizeTable[type]; - else FUFail(dataSize = 1); - - // Allocate the data array right away and only once. - data = new uint8[dataSize]; - - // Set the render state to its default value(s) - SetDefaultValue(); -} - -void FCDEffectPassState::SetDefaultValue() -{ - -#define SET_VALUE(offset, valueType, actualValue) *((valueType*)(data + offset)) = actualValue; -#define SET_ENUM(offset, nameSpace, actualValue) *((uint32*)(data + offset)) = nameSpace::actualValue; - - switch ((uint32) type) - { - case FUDaePassState::ALPHA_FUNC: - SET_ENUM(0, FUDaePassStateFunction, ALWAYS); - SET_VALUE(4, float, 0.0f); - break; - - case FUDaePassState::BLEND_FUNC: - SET_ENUM(0, FUDaePassStateBlendType, ONE); - SET_ENUM(4, FUDaePassStateBlendType, ZERO); - break; - - case FUDaePassState::BLEND_FUNC_SEPARATE: - SET_ENUM(0, FUDaePassStateBlendType, ONE); - SET_ENUM(4, FUDaePassStateBlendType, ZERO); - SET_ENUM(8, FUDaePassStateBlendType, ONE); - SET_ENUM(12, FUDaePassStateBlendType, ZERO); - break; - - case FUDaePassState::BLEND_EQUATION: - SET_ENUM(0, FUDaePassStateBlendEquation, ADD); - break; - - case FUDaePassState::BLEND_EQUATION_SEPARATE: - SET_ENUM(0, FUDaePassStateBlendEquation, ADD); - SET_ENUM(4, FUDaePassStateBlendEquation, ADD); - break; - - case FUDaePassState::COLOR_MATERIAL: - SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); - SET_ENUM(4, FUDaePassStateMaterialType, AMBIENT_AND_DIFFUSE); - break; - - case FUDaePassState::CULL_FACE: - SET_ENUM(0, FUDaePassStateFaceType, BACK); - break; - - case FUDaePassState::DEPTH_FUNC: - SET_ENUM(0, FUDaePassStateFunction, ALWAYS); - break; - - case FUDaePassState::FOG_MODE: - SET_ENUM(0, FUDaePassStateFogType, EXP); - break; - - case FUDaePassState::FOG_COORD_SRC: - SET_ENUM(0, FUDaePassStateFogCoordinateType, FOG_COORDINATE); - break; - - case FUDaePassState::FRONT_FACE: - SET_ENUM(0, FUDaePassStateFrontFaceType, COUNTER_CLOCKWISE); - break; - - case FUDaePassState::LIGHT_MODEL_COLOR_CONTROL: - SET_ENUM(0, FUDaePassStateLightModelColorControlType, SINGLE_COLOR); - break; - - case FUDaePassState::LOGIC_OP: - SET_ENUM(0, FUDaePassStateLogicOperation, COPY); - break; - - case FUDaePassState::POLYGON_MODE: - SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); - SET_ENUM(4, FUDaePassStatePolygonMode, FILL); - break; - - case FUDaePassState::SHADE_MODEL: - SET_ENUM(0, FUDaePassStateShadeModel, SMOOTH); - break; - - case FUDaePassState::STENCIL_FUNC: - SET_ENUM(0, FUDaePassStateFunction, ALWAYS); - SET_VALUE(4, uint8, 0); - SET_VALUE(5, uint8, 0xFF); - break; - - case FUDaePassState::STENCIL_OP: - SET_ENUM(0, FUDaePassStateStencilOperation, KEEP); - SET_ENUM(4, FUDaePassStateStencilOperation, KEEP); - SET_ENUM(8, FUDaePassStateStencilOperation, KEEP); - break; - - case FUDaePassState::STENCIL_FUNC_SEPARATE: - SET_ENUM(0, FUDaePassStateFunction, ALWAYS); - SET_ENUM(4, FUDaePassStateFunction, ALWAYS); - SET_VALUE(8, uint8, 0); - SET_VALUE(9, uint8, 0xFF); - break; - - case FUDaePassState::STENCIL_OP_SEPARATE: - SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); - SET_ENUM(4, FUDaePassStateStencilOperation, KEEP); - SET_ENUM(8, FUDaePassStateStencilOperation, KEEP); - SET_ENUM(12, FUDaePassStateStencilOperation, KEEP); - break; - - case FUDaePassState::STENCIL_MASK_SEPARATE: - SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); - SET_VALUE(4, uint8, 0xFF); - break; - - case FUDaePassState::LIGHT_ENABLE: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, bool, false); - break; - - case FUDaePassState::LIGHT_AMBIENT: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, FMVector4, FMVector4(0,0,0,1)); - break; - - case FUDaePassState::LIGHT_DIFFUSE: - case FUDaePassState::LIGHT_SPECULAR: - case FUDaePassState::TEXTURE_ENV_COLOR: - case FUDaePassState::CLIP_PLANE: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, FMVector4, FMVector4::Zero); - break; - - case FUDaePassState::LIGHT_POSITION: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, FMVector4, FMVector4(0,0,1,0)); - break; - - case FUDaePassState::LIGHT_CONSTANT_ATTENUATION: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, float, 1.0f); - break; - - case FUDaePassState::LIGHT_LINEAR_ATTENUATION: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, float, 0.0f); - break; - - case FUDaePassState::LIGHT_QUADRATIC_ATTENUATION: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, float, 0.0f); - break; - - case FUDaePassState::LIGHT_SPOT_CUTOFF: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, float, 180.0f); - break; - - case FUDaePassState::LIGHT_SPOT_DIRECTION: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, FMVector3, FMVector3(0,0,-1)); - break; - - case FUDaePassState::LIGHT_SPOT_EXPONENT: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, float, 0.0f); - break; - - case FUDaePassState::TEXTURE1D: - case FUDaePassState::TEXTURE2D: - case FUDaePassState::TEXTURE3D: - case FUDaePassState::TEXTURECUBE: - case FUDaePassState::TEXTURERECT: - case FUDaePassState::TEXTUREDEPTH: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, uint32, 0); - break; - - case FUDaePassState::TEXTURE1D_ENABLE: - case FUDaePassState::TEXTURE2D_ENABLE: - case FUDaePassState::TEXTURE3D_ENABLE: - case FUDaePassState::TEXTURECUBE_ENABLE: - case FUDaePassState::TEXTURERECT_ENABLE: - case FUDaePassState::TEXTUREDEPTH_ENABLE: - case FUDaePassState::CLIP_PLANE_ENABLE: - SET_VALUE(0, uint8, 0); - SET_VALUE(1, bool, false); - break; - - case FUDaePassState::TEXTURE_ENV_MODE: - memset(data, 0, dataSize); - break; - - case FUDaePassState::BLEND_COLOR: - case FUDaePassState::CLEAR_COLOR: - case FUDaePassState::FOG_COLOR: - case FUDaePassState::SCISSOR: - SET_VALUE(0, FMVector4, FMVector4::Zero); - break; - - case FUDaePassState::LIGHT_MODEL_AMBIENT: - case FUDaePassState::MATERIAL_AMBIENT: - SET_VALUE(0, FMVector4, FMVector4(0.2f,0.2f,0.2f,1.0f)); - break; - - case FUDaePassState::MATERIAL_DIFFUSE: - SET_VALUE(0, FMVector4, FMVector4(0.8f,0.8f,0.8f,1.0f)); - break; - - case FUDaePassState::MATERIAL_EMISSION: - case FUDaePassState::MATERIAL_SPECULAR: - SET_VALUE(0, FMVector4, FMVector4(0,0,0,1)); - break; - - case FUDaePassState::POINT_DISTANCE_ATTENUATION: - SET_VALUE(0, FMVector3, FMVector3(1,0,0)); - break; - - case FUDaePassState::DEPTH_BOUNDS: - case FUDaePassState::DEPTH_RANGE: - SET_VALUE(0, FMVector2, FMVector2(0,1)); - break; - - case FUDaePassState::POLYGON_OFFSET: - SET_VALUE(0, FMVector2, FMVector2(0,0)); - break; - - case FUDaePassState::DEPTH_MASK: - SET_VALUE(0, bool, true); - break; - - case FUDaePassState::CLEAR_STENCIL: - SET_VALUE(0, uint32, 0); - break; - - case FUDaePassState::STENCIL_MASK: - SET_VALUE(0, uint32, 0xFFFFFFFF); - break; - - case FUDaePassState::CLEAR_DEPTH: - case FUDaePassState::FOG_DENSITY: - case FUDaePassState::FOG_END: - case FUDaePassState::LINE_WIDTH: - case FUDaePassState::POINT_FADE_THRESHOLD_SIZE: - case FUDaePassState::POINT_SIZE: - case FUDaePassState::POINT_SIZE_MAX: - SET_VALUE(0, float, 1.0f); - break; - - case FUDaePassState::FOG_START: - case FUDaePassState::MATERIAL_SHININESS: - case FUDaePassState::POINT_SIZE_MIN: - SET_VALUE(0, float, 0.0f); - break; - - case FUDaePassState::COLOR_MASK: - SET_VALUE(0, bool, true); - SET_VALUE(1, bool, true); - SET_VALUE(2, bool, true); - SET_VALUE(3, bool, true); - break; - - case FUDaePassState::LINE_STIPPLE: - SET_VALUE(0, uint16, 1); - SET_VALUE(2, uint16, 0xFF); - break; - - case FUDaePassState::MODEL_VIEW_MATRIX: - case FUDaePassState::PROJECTION_MATRIX: - SET_VALUE(0, FMMatrix44, FMMatrix44::Identity); - break; - - case FUDaePassState::LIGHTING_ENABLE: - case FUDaePassState::ALPHA_TEST_ENABLE: - case FUDaePassState::AUTO_NORMAL_ENABLE: - case FUDaePassState::BLEND_ENABLE: - case FUDaePassState::COLOR_LOGIC_OP_ENABLE: - case FUDaePassState::CULL_FACE_ENABLE: - case FUDaePassState::DEPTH_BOUNDS_ENABLE: - case FUDaePassState::DEPTH_CLAMP_ENABLE: - case FUDaePassState::DEPTH_TEST_ENABLE: - case FUDaePassState::DITHER_ENABLE: - case FUDaePassState::FOG_ENABLE: - case FUDaePassState::LIGHT_MODEL_LOCAL_VIEWER_ENABLE: - case FUDaePassState::LIGHT_MODEL_TWO_SIDE_ENABLE: - case FUDaePassState::LINE_SMOOTH_ENABLE: - case FUDaePassState::LINE_STIPPLE_ENABLE: - case FUDaePassState::LOGIC_OP_ENABLE: - case FUDaePassState::MULTISAMPLE_ENABLE: - case FUDaePassState::NORMALIZE_ENABLE: - case FUDaePassState::POINT_SMOOTH_ENABLE: - case FUDaePassState::POLYGON_OFFSET_FILL_ENABLE: - case FUDaePassState::POLYGON_OFFSET_LINE_ENABLE: - case FUDaePassState::POLYGON_OFFSET_POINT_ENABLE: - case FUDaePassState::POLYGON_SMOOTH_ENABLE: - case FUDaePassState::POLYGON_STIPPLE_ENABLE: - case FUDaePassState::RESCALE_NORMAL_ENABLE: - case FUDaePassState::SAMPLE_ALPHA_TO_COVERAGE_ENABLE: - case FUDaePassState::SAMPLE_ALPHA_TO_ONE_ENABLE: - case FUDaePassState::SAMPLE_COVERAGE_ENABLE: - case FUDaePassState::SCISSOR_TEST_ENABLE: - case FUDaePassState::STENCIL_TEST_ENABLE: - SET_VALUE(0, bool, false); - break; - - case FUDaePassState::COLOR_MATERIAL_ENABLE: - SET_VALUE(0, bool, true); - break; - - case FUDaePassState::COUNT: - case FUDaePassState::INVALID: - default: - FUFail(break); - } - -#undef SET_ENUM -#undef SET_VALUE -} - -FCDEffectPassState::~FCDEffectPassState() -{ - SAFE_DELETE_ARRAY(data); - dataSize = 0; - type = FUDaePassState::INVALID; -} - -FCDEffectPassState* FCDEffectPassState::Clone(FCDEffectPassState* clone) const -{ - if (clone == NULL) - { - clone = new FCDEffectPassState(const_cast(GetDocument()), GetType()); - } - - // The clone's data array should have been allocated properly. - FUAssert(dataSize == clone->dataSize, return NULL); - memcpy(clone->data, data, dataSize); - return clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDEffectPassState.h" +//#include "FUtils/FUDaeSyntax.h" + +// +// Translation Tables +// + +static const size_t dataSizeTable[FUDaePassState::COUNT] = +{ + 8, 8, 16, 4, 8, 8, 4, 4, 4, 4, // [ 0- 9] + 4, 4, 4, 8, 4, 6, 12, 10, 16, 5, // [ 10- 19] + 2, 17, 17, 17, 17, 5, 5, 5, 5, 17, 5, // [ 20- 30] + 5, 5, 5, 5, 5, 5, 2, 2, 2, 2, 2, 2, 17, 256, // [ 31- 44] + 17, 2, 16, 16, 4, 4, 4, 8, 1, 8, // [ 45- 54] + 4, 4, 4, 16, 16, 1, 4, 4, // [ 55- 62] + 16, 16, 16, 4, 16, 64, 12, 4, 4, 4, 4, // [ 63- 73] + 8, 64, 16, 4, 1, 1, 1, 1, 1, 1, // [ 74- 83] + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // [ 84- 94] + 1, 1, 1, 1, 1, 1, 1, 1, // [ 95-102] + 1, 1, 1, 1, 1 // [103-107] +}; + +// +// FCDEffectPassState +// + +ImplementObjectType(FCDEffectPassState); + +FCDEffectPassState::FCDEffectPassState(FCDocument* document, FUDaePassState::State renderState) +: FCDObject(document) +, InitializeParameter(type, renderState) +, data(NULL), dataSize(0) +{ + // Use the translation table to figure out the necessary memory to hold the data. + if (renderState >= 0 && renderState < FUDaePassState::COUNT) dataSize = dataSizeTable[type]; + else FUFail(dataSize = 1); + + // Allocate the data array right away and only once. + data = new uint8[dataSize]; + + // Set the render state to its default value(s) + SetDefaultValue(); +} + +void FCDEffectPassState::SetDefaultValue() +{ + +#define SET_VALUE(offset, valueType, actualValue) *((valueType*)(data + offset)) = actualValue; +#define SET_ENUM(offset, nameSpace, actualValue) *((uint32*)(data + offset)) = nameSpace::actualValue; + + switch ((uint32) type) + { + case FUDaePassState::ALPHA_FUNC: + SET_ENUM(0, FUDaePassStateFunction, ALWAYS); + SET_VALUE(4, float, 0.0f); + break; + + case FUDaePassState::BLEND_FUNC: + SET_ENUM(0, FUDaePassStateBlendType, ONE); + SET_ENUM(4, FUDaePassStateBlendType, ZERO); + break; + + case FUDaePassState::BLEND_FUNC_SEPARATE: + SET_ENUM(0, FUDaePassStateBlendType, ONE); + SET_ENUM(4, FUDaePassStateBlendType, ZERO); + SET_ENUM(8, FUDaePassStateBlendType, ONE); + SET_ENUM(12, FUDaePassStateBlendType, ZERO); + break; + + case FUDaePassState::BLEND_EQUATION: + SET_ENUM(0, FUDaePassStateBlendEquation, ADD); + break; + + case FUDaePassState::BLEND_EQUATION_SEPARATE: + SET_ENUM(0, FUDaePassStateBlendEquation, ADD); + SET_ENUM(4, FUDaePassStateBlendEquation, ADD); + break; + + case FUDaePassState::COLOR_MATERIAL: + SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); + SET_ENUM(4, FUDaePassStateMaterialType, AMBIENT_AND_DIFFUSE); + break; + + case FUDaePassState::CULL_FACE: + SET_ENUM(0, FUDaePassStateFaceType, BACK); + break; + + case FUDaePassState::DEPTH_FUNC: + SET_ENUM(0, FUDaePassStateFunction, ALWAYS); + break; + + case FUDaePassState::FOG_MODE: + SET_ENUM(0, FUDaePassStateFogType, EXP); + break; + + case FUDaePassState::FOG_COORD_SRC: + SET_ENUM(0, FUDaePassStateFogCoordinateType, FOG_COORDINATE); + break; + + case FUDaePassState::FRONT_FACE: + SET_ENUM(0, FUDaePassStateFrontFaceType, COUNTER_CLOCKWISE); + break; + + case FUDaePassState::LIGHT_MODEL_COLOR_CONTROL: + SET_ENUM(0, FUDaePassStateLightModelColorControlType, SINGLE_COLOR); + break; + + case FUDaePassState::LOGIC_OP: + SET_ENUM(0, FUDaePassStateLogicOperation, COPY); + break; + + case FUDaePassState::POLYGON_MODE: + SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); + SET_ENUM(4, FUDaePassStatePolygonMode, FILL); + break; + + case FUDaePassState::SHADE_MODEL: + SET_ENUM(0, FUDaePassStateShadeModel, SMOOTH); + break; + + case FUDaePassState::STENCIL_FUNC: + SET_ENUM(0, FUDaePassStateFunction, ALWAYS); + SET_VALUE(4, uint8, 0); + SET_VALUE(5, uint8, 0xFF); + break; + + case FUDaePassState::STENCIL_OP: + SET_ENUM(0, FUDaePassStateStencilOperation, KEEP); + SET_ENUM(4, FUDaePassStateStencilOperation, KEEP); + SET_ENUM(8, FUDaePassStateStencilOperation, KEEP); + break; + + case FUDaePassState::STENCIL_FUNC_SEPARATE: + SET_ENUM(0, FUDaePassStateFunction, ALWAYS); + SET_ENUM(4, FUDaePassStateFunction, ALWAYS); + SET_VALUE(8, uint8, 0); + SET_VALUE(9, uint8, 0xFF); + break; + + case FUDaePassState::STENCIL_OP_SEPARATE: + SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); + SET_ENUM(4, FUDaePassStateStencilOperation, KEEP); + SET_ENUM(8, FUDaePassStateStencilOperation, KEEP); + SET_ENUM(12, FUDaePassStateStencilOperation, KEEP); + break; + + case FUDaePassState::STENCIL_MASK_SEPARATE: + SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); + SET_VALUE(4, uint8, 0xFF); + break; + + case FUDaePassState::LIGHT_ENABLE: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, bool, false); + break; + + case FUDaePassState::LIGHT_AMBIENT: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, FMVector4, FMVector4(0,0,0,1)); + break; + + case FUDaePassState::LIGHT_DIFFUSE: + case FUDaePassState::LIGHT_SPECULAR: + case FUDaePassState::TEXTURE_ENV_COLOR: + case FUDaePassState::CLIP_PLANE: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, FMVector4, FMVector4::Zero); + break; + + case FUDaePassState::LIGHT_POSITION: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, FMVector4, FMVector4(0,0,1,0)); + break; + + case FUDaePassState::LIGHT_CONSTANT_ATTENUATION: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, float, 1.0f); + break; + + case FUDaePassState::LIGHT_LINEAR_ATTENUATION: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, float, 0.0f); + break; + + case FUDaePassState::LIGHT_QUADRATIC_ATTENUATION: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, float, 0.0f); + break; + + case FUDaePassState::LIGHT_SPOT_CUTOFF: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, float, 180.0f); + break; + + case FUDaePassState::LIGHT_SPOT_DIRECTION: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, FMVector3, FMVector3(0,0,-1)); + break; + + case FUDaePassState::LIGHT_SPOT_EXPONENT: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, float, 0.0f); + break; + + case FUDaePassState::TEXTURE1D: + case FUDaePassState::TEXTURE2D: + case FUDaePassState::TEXTURE3D: + case FUDaePassState::TEXTURECUBE: + case FUDaePassState::TEXTURERECT: + case FUDaePassState::TEXTUREDEPTH: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, uint32, 0); + break; + + case FUDaePassState::TEXTURE1D_ENABLE: + case FUDaePassState::TEXTURE2D_ENABLE: + case FUDaePassState::TEXTURE3D_ENABLE: + case FUDaePassState::TEXTURECUBE_ENABLE: + case FUDaePassState::TEXTURERECT_ENABLE: + case FUDaePassState::TEXTUREDEPTH_ENABLE: + case FUDaePassState::CLIP_PLANE_ENABLE: + SET_VALUE(0, uint8, 0); + SET_VALUE(1, bool, false); + break; + + case FUDaePassState::TEXTURE_ENV_MODE: + memset(data, 0, dataSize); + break; + + case FUDaePassState::BLEND_COLOR: + case FUDaePassState::CLEAR_COLOR: + case FUDaePassState::FOG_COLOR: + case FUDaePassState::SCISSOR: + SET_VALUE(0, FMVector4, FMVector4::Zero); + break; + + case FUDaePassState::LIGHT_MODEL_AMBIENT: + case FUDaePassState::MATERIAL_AMBIENT: + SET_VALUE(0, FMVector4, FMVector4(0.2f,0.2f,0.2f,1.0f)); + break; + + case FUDaePassState::MATERIAL_DIFFUSE: + SET_VALUE(0, FMVector4, FMVector4(0.8f,0.8f,0.8f,1.0f)); + break; + + case FUDaePassState::MATERIAL_EMISSION: + case FUDaePassState::MATERIAL_SPECULAR: + SET_VALUE(0, FMVector4, FMVector4(0,0,0,1)); + break; + + case FUDaePassState::POINT_DISTANCE_ATTENUATION: + SET_VALUE(0, FMVector3, FMVector3(1,0,0)); + break; + + case FUDaePassState::DEPTH_BOUNDS: + case FUDaePassState::DEPTH_RANGE: + SET_VALUE(0, FMVector2, FMVector2(0,1)); + break; + + case FUDaePassState::POLYGON_OFFSET: + SET_VALUE(0, FMVector2, FMVector2(0,0)); + break; + + case FUDaePassState::DEPTH_MASK: + SET_VALUE(0, bool, true); + break; + + case FUDaePassState::CLEAR_STENCIL: + SET_VALUE(0, uint32, 0); + break; + + case FUDaePassState::STENCIL_MASK: + SET_VALUE(0, uint32, 0xFFFFFFFF); + break; + + case FUDaePassState::CLEAR_DEPTH: + case FUDaePassState::FOG_DENSITY: + case FUDaePassState::FOG_END: + case FUDaePassState::LINE_WIDTH: + case FUDaePassState::POINT_FADE_THRESHOLD_SIZE: + case FUDaePassState::POINT_SIZE: + case FUDaePassState::POINT_SIZE_MAX: + SET_VALUE(0, float, 1.0f); + break; + + case FUDaePassState::FOG_START: + case FUDaePassState::MATERIAL_SHININESS: + case FUDaePassState::POINT_SIZE_MIN: + SET_VALUE(0, float, 0.0f); + break; + + case FUDaePassState::COLOR_MASK: + SET_VALUE(0, bool, true); + SET_VALUE(1, bool, true); + SET_VALUE(2, bool, true); + SET_VALUE(3, bool, true); + break; + + case FUDaePassState::LINE_STIPPLE: + SET_VALUE(0, uint16, 1); + SET_VALUE(2, uint16, 0xFF); + break; + + case FUDaePassState::MODEL_VIEW_MATRIX: + case FUDaePassState::PROJECTION_MATRIX: + SET_VALUE(0, FMMatrix44, FMMatrix44::Identity); + break; + + case FUDaePassState::LIGHTING_ENABLE: + case FUDaePassState::ALPHA_TEST_ENABLE: + case FUDaePassState::AUTO_NORMAL_ENABLE: + case FUDaePassState::BLEND_ENABLE: + case FUDaePassState::COLOR_LOGIC_OP_ENABLE: + case FUDaePassState::CULL_FACE_ENABLE: + case FUDaePassState::DEPTH_BOUNDS_ENABLE: + case FUDaePassState::DEPTH_CLAMP_ENABLE: + case FUDaePassState::DEPTH_TEST_ENABLE: + case FUDaePassState::DITHER_ENABLE: + case FUDaePassState::FOG_ENABLE: + case FUDaePassState::LIGHT_MODEL_LOCAL_VIEWER_ENABLE: + case FUDaePassState::LIGHT_MODEL_TWO_SIDE_ENABLE: + case FUDaePassState::LINE_SMOOTH_ENABLE: + case FUDaePassState::LINE_STIPPLE_ENABLE: + case FUDaePassState::LOGIC_OP_ENABLE: + case FUDaePassState::MULTISAMPLE_ENABLE: + case FUDaePassState::NORMALIZE_ENABLE: + case FUDaePassState::POINT_SMOOTH_ENABLE: + case FUDaePassState::POLYGON_OFFSET_FILL_ENABLE: + case FUDaePassState::POLYGON_OFFSET_LINE_ENABLE: + case FUDaePassState::POLYGON_OFFSET_POINT_ENABLE: + case FUDaePassState::POLYGON_SMOOTH_ENABLE: + case FUDaePassState::POLYGON_STIPPLE_ENABLE: + case FUDaePassState::RESCALE_NORMAL_ENABLE: + case FUDaePassState::SAMPLE_ALPHA_TO_COVERAGE_ENABLE: + case FUDaePassState::SAMPLE_ALPHA_TO_ONE_ENABLE: + case FUDaePassState::SAMPLE_COVERAGE_ENABLE: + case FUDaePassState::SCISSOR_TEST_ENABLE: + case FUDaePassState::STENCIL_TEST_ENABLE: + SET_VALUE(0, bool, false); + break; + + case FUDaePassState::COLOR_MATERIAL_ENABLE: + SET_VALUE(0, bool, true); + break; + + case FUDaePassState::COUNT: + case FUDaePassState::INVALID: + default: + FUFail(break); + } + +#undef SET_ENUM +#undef SET_VALUE +} + +FCDEffectPassState::~FCDEffectPassState() +{ + SAFE_DELETE_ARRAY(data); + dataSize = 0; + type = FUDaePassState::INVALID; +} + +FCDEffectPassState* FCDEffectPassState::Clone(FCDEffectPassState* clone) const +{ + if (clone == NULL) + { + clone = new FCDEffectPassState(const_cast(GetDocument()), GetType()); + } + + // The clone's data array should have been allocated properly. + FUAssert(dataSize == clone->dataSize, return NULL); + memcpy(clone->data, data, dataSize); + return clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectPassState.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfileFX.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfileFX.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfileFX.cpp (revision 24247) @@ -1,104 +1,104 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffect.h" -#include "FCDocument/FCDEffectCode.h" -#include "FCDocument/FCDEffectProfileFX.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterFactory.h" -#include "FCDocument/FCDEffectTechnique.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDImage.h" - -// -// FCDEffectProfileFX -// - -ImplementObjectType(FCDEffectProfileFX); -ImplementParameterObject(FCDEffectProfileFX, FCDEffectCode, codes, new FCDEffectCode(parent->GetDocument())); -ImplementParameterObject(FCDEffectProfileFX, FCDEffectTechnique, techniques, new FCDEffectTechnique(parent->GetDocument(), parent)); - -FCDEffectProfileFX::FCDEffectProfileFX(FCDocument* document, FCDEffect* _parent) -: FCDEffectProfile(document, _parent) -, InitializeParameter(type, FUDaeProfileType::UNKNOWN) -, InitializeParameterNoArg(platform) -, InitializeParameterNoArg(codes) -, InitializeParameterNoArg(techniques) -{ -} - -FCDEffectProfileFX::~FCDEffectProfileFX() -{ -} - -FCDEffectTechnique* FCDEffectProfileFX::AddTechnique() -{ - FCDEffectTechnique* technique = new FCDEffectTechnique(GetDocument(), this); - techniques.push_back(technique); - SetNewChildFlag(); - return technique; -} - -const FCDEffectCode* FCDEffectProfileFX::FindCode(const char* sid) const -{ - for (const FCDEffectCode** itC = codes.begin(); itC != codes.end(); ++itC) - { - if ((*itC)->GetSubId() == sid) return (*itC); - } - return NULL; -} - -// Adds a new code inclusion to this effect profile. -FCDEffectCode* FCDEffectProfileFX::AddCode() -{ - FCDEffectCode* code = new FCDEffectCode(GetDocument()); - codes.push_back(code); - SetNewChildFlag(); - return code; -} - -// Clone the profile effect and its parameters -FCDEffectProfile* FCDEffectProfileFX::Clone(FCDEffectProfile* _clone) const -{ - FCDEffectProfileFX* clone = NULL; - if (_clone == NULL) { _clone = clone = new FCDEffectProfileFX(const_cast(GetDocument()), const_cast(GetParent())); } - else if (_clone->GetObjectType() == FCDEffectProfileFX::GetClassType()) clone = (FCDEffectProfileFX*) _clone; - - if (_clone != NULL) FCDEffectProfile::Clone(_clone); - if (clone != NULL) - { - clone->type = type; - - // Clone the codes: needs to happen before the techniques are cloned. - clone->codes.reserve(codes.size()); - for (const FCDEffectCode** itC = codes.begin(); itC != codes.end(); ++itC) - { - FCDEffectCode* clonedCode = clone->AddCode(); - (*itC)->Clone(clonedCode); - } - - // Clone the techniques - clone->techniques.reserve(techniques.size()); - for (const FCDEffectTechnique** itT = techniques.begin(); itT != techniques.end(); ++itT) - { - FCDEffectTechnique* clonedTechnique = clone->AddTechnique(); - (*itT)->Clone(clonedTechnique); - } - } - - return _clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffect.h" +#include "FCDocument/FCDEffectCode.h" +#include "FCDocument/FCDEffectProfileFX.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterFactory.h" +#include "FCDocument/FCDEffectTechnique.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDImage.h" + +// +// FCDEffectProfileFX +// + +ImplementObjectType(FCDEffectProfileFX); +ImplementParameterObject(FCDEffectProfileFX, FCDEffectCode, codes, new FCDEffectCode(parent->GetDocument())); +ImplementParameterObject(FCDEffectProfileFX, FCDEffectTechnique, techniques, new FCDEffectTechnique(parent->GetDocument(), parent)); + +FCDEffectProfileFX::FCDEffectProfileFX(FCDocument* document, FCDEffect* _parent) +: FCDEffectProfile(document, _parent) +, InitializeParameter(type, FUDaeProfileType::UNKNOWN) +, InitializeParameterNoArg(platform) +, InitializeParameterNoArg(codes) +, InitializeParameterNoArg(techniques) +{ +} + +FCDEffectProfileFX::~FCDEffectProfileFX() +{ +} + +FCDEffectTechnique* FCDEffectProfileFX::AddTechnique() +{ + FCDEffectTechnique* technique = new FCDEffectTechnique(GetDocument(), this); + techniques.push_back(technique); + SetNewChildFlag(); + return technique; +} + +const FCDEffectCode* FCDEffectProfileFX::FindCode(const char* sid) const +{ + for (const FCDEffectCode** itC = codes.begin(); itC != codes.end(); ++itC) + { + if ((*itC)->GetSubId() == sid) return (*itC); + } + return NULL; +} + +// Adds a new code inclusion to this effect profile. +FCDEffectCode* FCDEffectProfileFX::AddCode() +{ + FCDEffectCode* code = new FCDEffectCode(GetDocument()); + codes.push_back(code); + SetNewChildFlag(); + return code; +} + +// Clone the profile effect and its parameters +FCDEffectProfile* FCDEffectProfileFX::Clone(FCDEffectProfile* _clone) const +{ + FCDEffectProfileFX* clone = NULL; + if (_clone == NULL) { _clone = clone = new FCDEffectProfileFX(const_cast(GetDocument()), const_cast(GetParent())); } + else if (_clone->GetObjectType() == FCDEffectProfileFX::GetClassType()) clone = (FCDEffectProfileFX*) _clone; + + if (_clone != NULL) FCDEffectProfile::Clone(_clone); + if (clone != NULL) + { + clone->type = type; + + // Clone the codes: needs to happen before the techniques are cloned. + clone->codes.reserve(codes.size()); + for (const FCDEffectCode** itC = codes.begin(); itC != codes.end(); ++itC) + { + FCDEffectCode* clonedCode = clone->AddCode(); + (*itC)->Clone(clonedCode); + } + + // Clone the techniques + clone->techniques.reserve(techniques.size()); + for (const FCDEffectTechnique** itT = techniques.begin(); itT != techniques.end(); ++itT) + { + FCDEffectTechnique* clonedTechnique = clone->AddTechnique(); + (*itT)->Clone(clonedTechnique); + } + } + + return _clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectProfileFX.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTechnique.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTechnique.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTechnique.h (revision 24247) @@ -1,158 +1,158 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEffectTechnique.h - This file declares the FCDEffectTechnique class. -*/ - -#ifndef _FCD_EFFECT_TECHNIQUE_H_ -#define _FCD_EFFECT_TECHNIQUE_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -class FCDEffectCode; -class FCDEffectPass; -class FCDEffectParameter; -class FCDEffectProfileFX; - -typedef fm::pvector FCDEffectPassList; /**< A dynamically-sized array of effect passes. */ -typedef fm::pvector FCDEffectCodeList; /**< A dynamically-sized array of effect code inclusions. */ - -/** - A COLLADA effect technique. - - The COLLADA effect technique contains the passes to be used in the rendering of - polygon sets. - - It also contains a list of effect parameters: both generators and overrides - and it is the lowest level of abstraction in which you can access effect parameters. For - flattened materials, this means that all the effect parameters will be accessible at this level. - - It also contains a list of effect code inclusions. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDEffectTechnique : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - FCDEffectProfileFX* parent; - - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name")); - DeclareParameterContainer(FCDEffectCode, codes, FC("Code Inclusions")); - DeclareParameterContainer(FCDEffectPass, passes, FC("Passes")) - DeclareParameterContainer(FCDEffectParameter, parameters, FC("Effect Parameters")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDEffectProfileFX::AddTechnique function. - @param document The FCollada document that owns this technique. - @param parent The effect profile which contains the technique. */ - FCDEffectTechnique(FCDocument* document, FCDEffectProfileFX* parent); - - /** Destructor. */ - virtual ~FCDEffectTechnique(); - - /** Retrieves the effect profile that contains this technique. - @return The parent effect profile. */ - inline FCDEffectProfileFX* GetParent() { return parent; } - inline const FCDEffectProfileFX* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the COLLADA id of the parent effect. - This function is mostly useful as a shortcut for debugging and reporting. - @return The COLLADA id of the parent effect. */ - DEPRECATED(3.05A, GetParent()->GetParent()->GetDaeId) const fm::string& GetDaeId() const { return emptyString; } - - /** Retrieves the sub-id of the technique. - @return The sub-id of the technique. */ - const fstring& GetName() const { return name; } - - /** Sets the sub-id of the technique. - The effect technique must have a valid sub-id that is unique - within its scope. Otherwise, one will be provided on XML export. - @param _name A valid sub-id. */ - void SetName(const fstring& _name) { name = _name; SetDirtyFlag(); } - - /** Retrieves the list of passes. - @return The list of passes. */ - DEPRECATED(3.05A, GetPassCount and GetPass(index)) void GetPassList() {} - - /** Retrieves the number of passes contained within this effect technique. - @return The number of passes. */ - size_t GetPassCount() const { return passes.size(); } - - /** Retrieves a specific pass contained within this effect technique. - @param index The index of the pass. - @return The pass. This pointer will be NULL if the index is out-of-bounds. */ - FCDEffectPass* GetPass(size_t index) { FUAssert(index < GetPassCount(), return NULL); return passes.at(index); } - const FCDEffectPass* GetPass(size_t index) const { FUAssert(index < GetPassCount(), return NULL); return passes.at(index); } /**< See above. */ - - /** Adds a new pass to this effect technique. - @return The new pass. */ - FCDEffectPass* AddPass(); - - /** Retrieves the list of code inclusions. - @return The list of code inclusions. */ - DEPRECATED(3.05A, GetCodeCount and GetCode(index) or FindCode) void GetCodeList() {} - - /** Retrieves the number of code inclusions contained within the effect profile. - @return The number of code inclusions. */ - size_t GetCodeCount() const { return codes.size(); } - - /** Retrieves a code inclusion contained within the effect profile. - @param index The index of the code inclusion. - @return The code inclusion. This pointer will be NULL if the index is out-of-bounds. */ - FCDEffectCode* GetCode(size_t index) { FUAssert(index < GetCodeCount(), return NULL); return codes.at(index); } - const FCDEffectCode* GetCode(size_t index) const { FUAssert(index < GetCodeCount(), return NULL); return codes.at(index); } /**< See above. */ - - /** Retrieves the code inclusion with the given sub-id. - @param sid A COLLADA sub-id. - @return The code inclusion with the given sub-id. This pointer will be NULL, - if there are no code inclusions that match the given sub-id. */ - inline FCDEffectCode* FindCode(const char* sid) { return const_cast(const_cast(this)->FindCode(sid)); } - const FCDEffectCode* FindCode(const char* sid) const; /**< See above. */ - - /** Adds a new code inclusion to this effect profile. - @return The new code inclusion. */ - FCDEffectCode* AddCode(); - - /** Retrieves the number of local effect parameters - @return The number of local effect parameters. */ - inline size_t GetEffectParameterCount() const { return parameters.size(); } - - /** Retrieves a given local effect parameter. - @param index An index. - @return The local effect parameter at the given index. */ - inline FCDEffectParameter* GetEffectParameter(size_t index) { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } - inline const FCDEffectParameter* GetEffectParameter(size_t index) const { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } - - /** Adds a local effect parameter to the local list. - @see FCDEffectParameter::Type - @param type The value type of the effect parameter to create. - @return The new local effect parameter. */ - FCDEffectParameter* AddEffectParameter(uint32 type); - - /** [INTERNAL] Clones the full effect technique. - @param clone The cloned technique. - If this pointer is NULL, a new technique is created and - you will need to release this new techniquetechnique. - @return The cloned technique. This pointer will never be NULL. */ - FCDEffectTechnique* Clone(FCDEffectTechnique* clone = NULL) const; - - /** [INTERNAL] Flattens this effect technique. - Merges the parameter overrides into the parameter generators. */ - DEPRECATED(3.05A, not recommended) void Flatten() {} -}; - -#endif +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEffectTechnique.h + This file declares the FCDEffectTechnique class. +*/ + +#ifndef _FCD_EFFECT_TECHNIQUE_H_ +#define _FCD_EFFECT_TECHNIQUE_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +class FCDEffectCode; +class FCDEffectPass; +class FCDEffectParameter; +class FCDEffectProfileFX; + +typedef fm::pvector FCDEffectPassList; /**< A dynamically-sized array of effect passes. */ +typedef fm::pvector FCDEffectCodeList; /**< A dynamically-sized array of effect code inclusions. */ + +/** + A COLLADA effect technique. + + The COLLADA effect technique contains the passes to be used in the rendering of + polygon sets. + + It also contains a list of effect parameters: both generators and overrides + and it is the lowest level of abstraction in which you can access effect parameters. For + flattened materials, this means that all the effect parameters will be accessible at this level. + + It also contains a list of effect code inclusions. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDEffectTechnique : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + FCDEffectProfileFX* parent; + + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name")); + DeclareParameterContainer(FCDEffectCode, codes, FC("Code Inclusions")); + DeclareParameterContainer(FCDEffectPass, passes, FC("Passes")) + DeclareParameterContainer(FCDEffectParameter, parameters, FC("Effect Parameters")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDEffectProfileFX::AddTechnique function. + @param document The FCollada document that owns this technique. + @param parent The effect profile which contains the technique. */ + FCDEffectTechnique(FCDocument* document, FCDEffectProfileFX* parent); + + /** Destructor. */ + virtual ~FCDEffectTechnique(); + + /** Retrieves the effect profile that contains this technique. + @return The parent effect profile. */ + inline FCDEffectProfileFX* GetParent() { return parent; } + inline const FCDEffectProfileFX* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the COLLADA id of the parent effect. + This function is mostly useful as a shortcut for debugging and reporting. + @return The COLLADA id of the parent effect. */ + DEPRECATED(3.05A, GetParent()->GetParent()->GetDaeId) const fm::string& GetDaeId() const { return emptyString; } + + /** Retrieves the sub-id of the technique. + @return The sub-id of the technique. */ + const fstring& GetName() const { return name; } + + /** Sets the sub-id of the technique. + The effect technique must have a valid sub-id that is unique + within its scope. Otherwise, one will be provided on XML export. + @param _name A valid sub-id. */ + void SetName(const fstring& _name) { name = _name; SetDirtyFlag(); } + + /** Retrieves the list of passes. + @return The list of passes. */ + DEPRECATED(3.05A, GetPassCount and GetPass(index)) void GetPassList() {} + + /** Retrieves the number of passes contained within this effect technique. + @return The number of passes. */ + size_t GetPassCount() const { return passes.size(); } + + /** Retrieves a specific pass contained within this effect technique. + @param index The index of the pass. + @return The pass. This pointer will be NULL if the index is out-of-bounds. */ + FCDEffectPass* GetPass(size_t index) { FUAssert(index < GetPassCount(), return NULL); return passes.at(index); } + const FCDEffectPass* GetPass(size_t index) const { FUAssert(index < GetPassCount(), return NULL); return passes.at(index); } /**< See above. */ + + /** Adds a new pass to this effect technique. + @return The new pass. */ + FCDEffectPass* AddPass(); + + /** Retrieves the list of code inclusions. + @return The list of code inclusions. */ + DEPRECATED(3.05A, GetCodeCount and GetCode(index) or FindCode) void GetCodeList() {} + + /** Retrieves the number of code inclusions contained within the effect profile. + @return The number of code inclusions. */ + size_t GetCodeCount() const { return codes.size(); } + + /** Retrieves a code inclusion contained within the effect profile. + @param index The index of the code inclusion. + @return The code inclusion. This pointer will be NULL if the index is out-of-bounds. */ + FCDEffectCode* GetCode(size_t index) { FUAssert(index < GetCodeCount(), return NULL); return codes.at(index); } + const FCDEffectCode* GetCode(size_t index) const { FUAssert(index < GetCodeCount(), return NULL); return codes.at(index); } /**< See above. */ + + /** Retrieves the code inclusion with the given sub-id. + @param sid A COLLADA sub-id. + @return The code inclusion with the given sub-id. This pointer will be NULL, + if there are no code inclusions that match the given sub-id. */ + inline FCDEffectCode* FindCode(const char* sid) { return const_cast(const_cast(this)->FindCode(sid)); } + const FCDEffectCode* FindCode(const char* sid) const; /**< See above. */ + + /** Adds a new code inclusion to this effect profile. + @return The new code inclusion. */ + FCDEffectCode* AddCode(); + + /** Retrieves the number of local effect parameters + @return The number of local effect parameters. */ + inline size_t GetEffectParameterCount() const { return parameters.size(); } + + /** Retrieves a given local effect parameter. + @param index An index. + @return The local effect parameter at the given index. */ + inline FCDEffectParameter* GetEffectParameter(size_t index) { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } + inline const FCDEffectParameter* GetEffectParameter(size_t index) const { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } + + /** Adds a local effect parameter to the local list. + @see FCDEffectParameter::Type + @param type The value type of the effect parameter to create. + @return The new local effect parameter. */ + FCDEffectParameter* AddEffectParameter(uint32 type); + + /** [INTERNAL] Clones the full effect technique. + @param clone The cloned technique. + If this pointer is NULL, a new technique is created and + you will need to release this new techniquetechnique. + @return The cloned technique. This pointer will never be NULL. */ + FCDEffectTechnique* Clone(FCDEffectTechnique* clone = NULL) const; + + /** [INTERNAL] Flattens this effect technique. + Merges the parameter overrides into the parameter generators. */ + DEPRECATED(3.05A, not recommended) void Flatten() {} +}; + +#endif Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEffectTechnique.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitter.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitter.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitter.h (revision 24247) @@ -1,66 +1,66 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#ifndef _FCD_EMITTER_H_ -#define _FCD_EMITTER_H_ - -/** - @file FCDEmitter.h - This file defines the entity class for emitters in FCollada. -*/ - -/** - @defgroup FCDEmitters COLLADA Particle Emitter Classes -*/ - -class FCDocument; -class FCDExtra; -class FCDEmitterParticle; - - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -/** - A COLLADA generic emitter. - - This class does not belong to the COLLADA COMMON profile. - It is used to define both particle and sound emitters. - - @ingroup FCDEmitters -*/ - -class FCOLLADA_EXPORT FCDEmitter : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - -public: - /** Constructor. Do not use directly, emitters should be created using - the AddEntity function on the FCDEmitterLibrary - @param document The COLLADA document that owns the emitter. */ - FCDEmitter(FCDocument* document); - - /** Destructor. */ - ~FCDEmitter(); - - /** Retrieves the entity class type. - @return The entity class type: EMITTER */ - virtual Type GetType() const { return EMITTER; } - - /** Clones the emitter information. - @param clone The cloned emitter. - If this pointer is NULL, a new emitter is created and - you will need to release it manually. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; -}; - -#endif //_FCD_EMITTER_H +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef _FCD_EMITTER_H_ +#define _FCD_EMITTER_H_ + +/** + @file FCDEmitter.h + This file defines the entity class for emitters in FCollada. +*/ + +/** + @defgroup FCDEmitters COLLADA Particle Emitter Classes +*/ + +class FCDocument; +class FCDExtra; +class FCDEmitterParticle; + + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +/** + A COLLADA generic emitter. + + This class does not belong to the COLLADA COMMON profile. + It is used to define both particle and sound emitters. + + @ingroup FCDEmitters +*/ + +class FCOLLADA_EXPORT FCDEmitter : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + +public: + /** Constructor. Do not use directly, emitters should be created using + the AddEntity function on the FCDEmitterLibrary + @param document The COLLADA document that owns the emitter. */ + FCDEmitter(FCDocument* document); + + /** Destructor. */ + ~FCDEmitter(); + + /** Retrieves the entity class type. + @return The entity class type: EMITTER */ + virtual Type GetType() const { return EMITTER; } + + /** Clones the emitter information. + @param clone The cloned emitter. + If this pointer is NULL, a new emitter is created and + you will need to release it manually. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; +}; + +#endif //_FCD_EMITTER_H Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitter.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterObject.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterObject.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterObject.h (revision 24247) @@ -1,30 +1,30 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEmitterObject.h - This file contains the FCDEmitterObject class, and definitions - for its two children FCDPositionObject and FCDOrienationObject - and their various definitions -*/ - -#ifndef _FCD_EMITTER_OBJECT_H_ -#define _FCD_EMITTER_OBJECT_H_ - -#ifndef _FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // _FCD_OBJECT_H_ -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -class FCDGeometry; -class FCDEntityReference; -class FUUri; - -#endif +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEmitterObject.h + This file contains the FCDEmitterObject class, and definitions + for its two children FCDPositionObject and FCDOrienationObject + and their various definitions +*/ + +#ifndef _FCD_EMITTER_OBJECT_H_ +#define _FCD_EMITTER_OBJECT_H_ + +#ifndef _FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // _FCD_OBJECT_H_ +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +class FCDGeometry; +class FCDEntityReference; +class FUUri; + +#endif Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEmitterObject.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntity.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntity.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntity.h (revision 24247) @@ -1,188 +1,188 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEntity.h - This file contains the FCDEntity class. -*/ - -#ifndef _FCD_ENTITY_H_ -#define _FCD_ENTITY_H_ - -#ifndef __FCD_OBJECT_WITH_ID_H_ -#include "FCDocument/FCDObjectWithId.h" -#endif // __FCD_OBJECT_WITH_ID_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -class FCDocument; -class FCDAsset; -class FCDExtra; - -typedef fm::pvector FCDAssetList; /**< A dynamically-sized array of asset tags. */ -typedef fm::pvector FCDAssetConstList; /**< A dynamically-sized array of asset tags. */ - -/** - A COLLADA entity. - - A COLLADA entity is an object contained within a COLLADA library. - As such, it is based on the FCDObjectWithId class so that it - can be accessed by other entities, such as the scene graph. - - The entity adds to the FCDObjectWithId class: a name, - an extra tree and an optional note, as well as a way - to identity the type of the entity, in order to up-cast it - to its correct class. - - @ingroup FCDocument -*/ - -class FCOLLADA_EXPORT FCDEntity : public FCDObjectWithId -{ -public: - /** The types of entity classes. - Each type corresponds directly to one class that contains the - FCDEntity class as a parent, so you can up-cast FCDEntity pointers. */ - enum Type - { - ENTITY, /**< A generic entity (FCDEntity). Should never be used. */ - ANIMATION, /**< An animation (FCDAnimation). */ - ANIMATION_CLIP, /**< An animation clip (FCDAnimationClip). */ - CAMERA, /**< A camera (FCDCamera). */ - LIGHT, /**< A light (FCDLight). */ - IMAGE, /**< An image (FCDImage). */ - MATERIAL, /**< A visual material definition (FCDMaterial). */ - EFFECT, /**< An effect definition (FCDEffect). */ - GEOMETRY, /**< A geometric object (FCDGeometry). Includes splines and meshes. */ - CONTROLLER, /**< A geometric controller (FCDController). Includes skins and morphers. */ - SCENE_NODE, /**< A visual scene node (FCDSceneNode). */ - PHYSICS_RIGID_CONSTRAINT, /**< A physics rigid constraint (FCDPhysicsRigidConstraint). */ - PHYSICS_MATERIAL, /**< A physics material definiton (FCDPhysicsMaterial). */ - PHYSICS_RIGID_BODY, /**< A physics rigid body (FCDPhysicsRigidBody). */ - PHYSICS_SHAPE, /**< A physics shape (FCDPhysicsShape). */ - PHYSICS_ANALYTICAL_GEOMETRY, /**< A physics analytical geometric object (FCDPhysicsAnalyticalGeometry). */ - PHYSICS_MODEL, /**< A physics model (FCDPhysicsModel). */ - PHYSICS_SCENE_NODE, /**< A physics scene node (FCDPhysicsScene). */ - FORCE_FIELD, /**< A physics force field (FCDForceField). */ - EMITTER, /**< A generic emitter for sound and particles (FCDEmitter) - Premium feature. */ - TYPE_COUNT - }; - -private: - DeclareObjectType(FCDObjectWithId); - - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name")); - DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); - DeclareParameterRef(FCDAsset, asset, FC("Asset Tag")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, note, FC("Note")); // Maya and Max both support custom strings for objects. - -public: - /** Constructor: do not use directly. - Instead, create objects of the up-classes. - @param document The COLLADA document that owns the entity. - @param baseId The prefix COLLADA id to be used if no COLLADA id is provided. */ - FCDEntity(FCDocument* document, const char* baseId = "GenericEntity"); - - /** Destructor. */ - virtual ~FCDEntity(); - - /** Retrieves the entity class type for an entity. - You can use the entity class type of up-cast an entity pointer - to the correct up-class. - This function should be overwritten by all up-classes. - @return The entity class type. */ - virtual Type GetType() const { return ENTITY; } - - /** Retrieves the name of the entity. - This value has no direct use in COLLADA but is useful - to track the user-friendly name of an entity. - @return The name. */ - const fstring& GetName() const { return name; } - - /** Sets the name of the entity. - This value has no direct use in COLLADA but is useful - to track the user-friendly name of an entity. - @param _name The name. */ - void SetName(const fstring& _name); - - /** Retrieves the extra information tree for this entity. - The prefered way to save extra information in FCollada is at - the entity level. Use this extra information tree to store - any information you want exported and imported back. - @return The extra information tree. */ - FCDExtra* GetExtra() { return extra; } - const FCDExtra* GetExtra() const { return extra; } /**< See above. */ - - /** Retrieves the asset information for this entity. - In the non-const version, calling this function will - create an asset structure. If you are interested in a specific asset-type - information, such as up_axis and units, please use the - FCDEntity::GetHierarchicalAssets function. - @return The asset information structure. */ - FCDAsset* GetAsset(); - inline const FCDAsset* GetAsset() const { return asset; } /**< See above. */ - - /** Retrieves the asset information structures that affect - this entity in its hierarchy. - @param assets A list of asset information structures to fill in. */ - inline void GetHierarchicalAssets(FCDAssetList& assets) { GetHierarchicalAssets(*(FCDAssetConstList*) &assets); } - virtual void GetHierarchicalAssets(FCDAssetConstList& assets) const; /**< See above. */ - - /** Retrieves whether the entity has a user-defined note. - This value is a simpler way, than the extra tree, to store - user-defined information that does not belong in COLLADA. - @return Whether the entity has an user-defined note. */ - bool HasNote() const; - - /** Retrieves the user-defined note for this entity. - This value is a simpler way, than the extra tree, to store - user-defined information that does not belong in COLLADA. - @return The user-defined note. */ - const fstring& GetNote() const; - - /** Sets the user-defined note for this entity. - This value is a simpler way, than the extra tree, to store - user-defined information that does not belong in COLLADA. - @param _note The user-defined note. */ - void SetNote(const fstring& _note); - - /** Retrieves the child entity that has the given COLLADA id. - This function is only useful for entities that are hierarchical: - visual/physics scene nodes and animations. - @param daeId A COLLADA id. - @return The child entity with the given id. This pointer will be NULL - if no child entity matches the given id. */ - virtual FCDEntity* FindDaeId(const fm::string& daeId) { return const_cast(const_cast(this)->FindDaeId(daeId)); } - virtual const FCDEntity* FindDaeId(const fm::string& daeId) const; /**< See above. */ - - /** Copies the entity information into a clone. - All the overwriting functions of this function should call this function - to copy the COLLADA id and the other entity-level information. - All the up-classes of this class should implement this function. - The cloned entity may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new entity - will be created and you will need to release the returned pointer manually. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - - /** Cleans illegal characters in from the input char string - @param c The string to clean - @returns the sanitized version */ - static fstring CleanName(const fchar* c); -}; - -#endif // _FCD_ENTITY_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEntity.h + This file contains the FCDEntity class. +*/ + +#ifndef _FCD_ENTITY_H_ +#define _FCD_ENTITY_H_ + +#ifndef __FCD_OBJECT_WITH_ID_H_ +#include "FCDocument/FCDObjectWithId.h" +#endif // __FCD_OBJECT_WITH_ID_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +class FCDocument; +class FCDAsset; +class FCDExtra; + +typedef fm::pvector FCDAssetList; /**< A dynamically-sized array of asset tags. */ +typedef fm::pvector FCDAssetConstList; /**< A dynamically-sized array of asset tags. */ + +/** + A COLLADA entity. + + A COLLADA entity is an object contained within a COLLADA library. + As such, it is based on the FCDObjectWithId class so that it + can be accessed by other entities, such as the scene graph. + + The entity adds to the FCDObjectWithId class: a name, + an extra tree and an optional note, as well as a way + to identity the type of the entity, in order to up-cast it + to its correct class. + + @ingroup FCDocument +*/ + +class FCOLLADA_EXPORT FCDEntity : public FCDObjectWithId +{ +public: + /** The types of entity classes. + Each type corresponds directly to one class that contains the + FCDEntity class as a parent, so you can up-cast FCDEntity pointers. */ + enum Type + { + ENTITY, /**< A generic entity (FCDEntity). Should never be used. */ + ANIMATION, /**< An animation (FCDAnimation). */ + ANIMATION_CLIP, /**< An animation clip (FCDAnimationClip). */ + CAMERA, /**< A camera (FCDCamera). */ + LIGHT, /**< A light (FCDLight). */ + IMAGE, /**< An image (FCDImage). */ + MATERIAL, /**< A visual material definition (FCDMaterial). */ + EFFECT, /**< An effect definition (FCDEffect). */ + GEOMETRY, /**< A geometric object (FCDGeometry). Includes splines and meshes. */ + CONTROLLER, /**< A geometric controller (FCDController). Includes skins and morphers. */ + SCENE_NODE, /**< A visual scene node (FCDSceneNode). */ + PHYSICS_RIGID_CONSTRAINT, /**< A physics rigid constraint (FCDPhysicsRigidConstraint). */ + PHYSICS_MATERIAL, /**< A physics material definiton (FCDPhysicsMaterial). */ + PHYSICS_RIGID_BODY, /**< A physics rigid body (FCDPhysicsRigidBody). */ + PHYSICS_SHAPE, /**< A physics shape (FCDPhysicsShape). */ + PHYSICS_ANALYTICAL_GEOMETRY, /**< A physics analytical geometric object (FCDPhysicsAnalyticalGeometry). */ + PHYSICS_MODEL, /**< A physics model (FCDPhysicsModel). */ + PHYSICS_SCENE_NODE, /**< A physics scene node (FCDPhysicsScene). */ + FORCE_FIELD, /**< A physics force field (FCDForceField). */ + EMITTER, /**< A generic emitter for sound and particles (FCDEmitter) - Premium feature. */ + TYPE_COUNT + }; + +private: + DeclareObjectType(FCDObjectWithId); + + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name")); + DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); + DeclareParameterRef(FCDAsset, asset, FC("Asset Tag")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, note, FC("Note")); // Maya and Max both support custom strings for objects. + +public: + /** Constructor: do not use directly. + Instead, create objects of the up-classes. + @param document The COLLADA document that owns the entity. + @param baseId The prefix COLLADA id to be used if no COLLADA id is provided. */ + FCDEntity(FCDocument* document, const char* baseId = "GenericEntity"); + + /** Destructor. */ + virtual ~FCDEntity(); + + /** Retrieves the entity class type for an entity. + You can use the entity class type of up-cast an entity pointer + to the correct up-class. + This function should be overwritten by all up-classes. + @return The entity class type. */ + virtual Type GetType() const { return ENTITY; } + + /** Retrieves the name of the entity. + This value has no direct use in COLLADA but is useful + to track the user-friendly name of an entity. + @return The name. */ + const fstring& GetName() const { return name; } + + /** Sets the name of the entity. + This value has no direct use in COLLADA but is useful + to track the user-friendly name of an entity. + @param _name The name. */ + void SetName(const fstring& _name); + + /** Retrieves the extra information tree for this entity. + The prefered way to save extra information in FCollada is at + the entity level. Use this extra information tree to store + any information you want exported and imported back. + @return The extra information tree. */ + FCDExtra* GetExtra() { return extra; } + const FCDExtra* GetExtra() const { return extra; } /**< See above. */ + + /** Retrieves the asset information for this entity. + In the non-const version, calling this function will + create an asset structure. If you are interested in a specific asset-type + information, such as up_axis and units, please use the + FCDEntity::GetHierarchicalAssets function. + @return The asset information structure. */ + FCDAsset* GetAsset(); + inline const FCDAsset* GetAsset() const { return asset; } /**< See above. */ + + /** Retrieves the asset information structures that affect + this entity in its hierarchy. + @param assets A list of asset information structures to fill in. */ + inline void GetHierarchicalAssets(FCDAssetList& assets) { GetHierarchicalAssets(*(FCDAssetConstList*) &assets); } + virtual void GetHierarchicalAssets(FCDAssetConstList& assets) const; /**< See above. */ + + /** Retrieves whether the entity has a user-defined note. + This value is a simpler way, than the extra tree, to store + user-defined information that does not belong in COLLADA. + @return Whether the entity has an user-defined note. */ + bool HasNote() const; + + /** Retrieves the user-defined note for this entity. + This value is a simpler way, than the extra tree, to store + user-defined information that does not belong in COLLADA. + @return The user-defined note. */ + const fstring& GetNote() const; + + /** Sets the user-defined note for this entity. + This value is a simpler way, than the extra tree, to store + user-defined information that does not belong in COLLADA. + @param _note The user-defined note. */ + void SetNote(const fstring& _note); + + /** Retrieves the child entity that has the given COLLADA id. + This function is only useful for entities that are hierarchical: + visual/physics scene nodes and animations. + @param daeId A COLLADA id. + @return The child entity with the given id. This pointer will be NULL + if no child entity matches the given id. */ + virtual FCDEntity* FindDaeId(const fm::string& daeId) { return const_cast(const_cast(this)->FindDaeId(daeId)); } + virtual const FCDEntity* FindDaeId(const fm::string& daeId) const; /**< See above. */ + + /** Copies the entity information into a clone. + All the overwriting functions of this function should call this function + to copy the COLLADA id and the other entity-level information. + All the up-classes of this class should implement this function. + The cloned entity may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new entity + will be created and you will need to release the returned pointer manually. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + + /** Cleans illegal characters in from the input char string + @param c The string to clean + @returns the sanitized version */ + static fstring CleanName(const fchar* c); +}; + +#endif // _FCD_ENTITY_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntity.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityReference.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityReference.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityReference.h (revision 24247) @@ -1,154 +1,154 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDEntityReference.h - This file contains the FCDEntityReference class. -*/ - -#ifndef _FCD_ENTITY_REFERENCE_H_ -#define _FCD_ENTITY_REFERENCE_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_URI_H_ -#include "FUtils/FUUri.h" -#endif // _FU_URI_H_ - -class FCDPlaceHolder; -class FCDObjectWithId; - -/** - A COLLADA external reference for an entity instance. - FCollada only exposes external references for entity instances. - Other types of external references: geometry sources, morph targets, etc. - are not supported. - - The entity instance for an external reference cannot be modified - and tracks it, so that if is it released manually, the reference is also released. - - The placeholder and the document referenced by the entity instance can - be modified manually or by the entity instance. - - Also allowing external links by more than just entity instances. Controllers can - reference external geometry targets. - - Renaming this class to FCDEntityReference, as it used for tracking ALL entities. - This lightens the Code load on all classes that track entities. - - TODO: The following are non-compliant on the XRefs: - Animations (instance_animation) <-- TODO QUICK - Morphers (base_geom && morph_targets) - Emitters (force links) - Emitters (object_mesh) <-- TODO LAST - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDEntityReference : public FCDObject, FUTracker -{ -private: - DeclareObjectType(FCDObject); - - FCDEntity* entity; - FCDPlaceHolder* placeHolder; - fm::string entityId; - - // Pointer back to the nearest object with id that references - // us down the hierarchy. This is because the references from the - // actual object with the link are irrelevant in terms of the hierarchy, - // it is only objects with id's (ie FCDEntities) that actually matter in terms - // of object durability etc. - FCDObjectWithId* baseObject; - -public: - /** Constructor. - @param document The FCollada document that owns the reference. - @param baseObject The parent object. */ - FCDEntityReference(FCDocument* document, FCDObjectWithId* parent); - - /** Destructor. */ - virtual ~FCDEntityReference(); - - /** Retrieves the placeholder if this references an entity - from an external COLLADA document. - @return The COLLADA document placeholder. */ - FCDPlaceHolder* GetPlaceHolder() { return placeHolder; } - const FCDPlaceHolder* GetPlaceHolder() const { return placeHolder; } /**< See above. */ - - /** Retrieves the COLLADA id of the entity that is externally referenced. - @return The COLLADA id of the referenced entity. */ - const fm::string& GetEntityId() const { return entityId; } - - /** Retrieves whether this entity reference is an external entity reference. - This function intentionally hides the FCDObject::IsExternal function. - @return Whether the entity reference is an external entity reference. */ - inline bool IsExternal() const { return placeHolder != NULL; } - - /** Retrieves whether this entity reference is a local entity reference. - This function intentionally hides the FCDObject::IsLocal function. - @return Whether the entity reference is a local entity reference. */ - inline bool IsLocal() const { return placeHolder == NULL; } - - /** Sets the COLLADA id of the referenced entity. - @param id The COLLADA id of the referenced entity. */ - void SetEntityId(const fm::string& id) { entityId = id; SetDirtyFlag(); } - - /** Retrieves the full URI of the external reference. - This points to the COLLADA document and the id of the referenced entity. - @return The referenced entity URI. */ - FUUri GetUri() const; - - /** Sets the URI of the external reference. - This points to the COLLADA document and the id of the referenced entity. - @param uri The referenced entity URL. */ - void SetUri(const FUUri& uri); - - /** Get the entity this external reference points to. This may cause the entity to - load if it is not present already! - See the FCollada::GetDereferenceFlag() for more information. - @return the entity */ - FCDEntity* GetEntity() { return const_cast(const_cast(this)->GetEntity()); } - const FCDEntity* GetEntity() const; /**< See above. */ - - /** Get a pointer to the entity that either directly or indirectly - exclusively contains this reference. This is not necessarily the class - that contains the actual pointer, but it is the class that is responsible for - managing the link to the entity referenced (ie, not an FCDEntityInstance, but the - containing FCDEntity). - @return A pointer the object that uses this class to reference an entity */ - inline const FCDObjectWithId* GetClosestObjectWithId() const { return baseObject; } - - /** Set the pointer to the closest entity upstream that contains this reference. - @param obj An object with Id that either directly or indirectly exclusively - contains this reference */ - inline void SetClosestObjectWithId(FCDObjectWithId* obj) { FUAssert(baseObject == NULL,); baseObject = obj; } - - /** Set the entity we are referencing. If this is from an external document, it will - create the appropriate FCDPlaceholder etc. - @entity The new entity to reference */ - void SetEntity(FCDEntity* entity); - -private: - // Attempt to find the entity based on the set URL etc. - // This can cause an external document to load if the reference is external. - void LoadEntity(); - - // Sets the COLLADA document referenced by the entity instance. - // @param document The COLLADA document referenced by the entity instance. - void SetEntityDocument(FCDocument* document); - - // Sets the COLLADA document place holder that replaces the - // external COLLADA document for this reference. - // @param placeHolder The COLLADA document place holder. - void SetPlaceHolder(FCDPlaceHolder* placeHolder); - - virtual void OnObjectReleased(FUTrackable* object); -}; - -#endif // _FCD_ENTITY_REFERENCE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDEntityReference.h + This file contains the FCDEntityReference class. +*/ + +#ifndef _FCD_ENTITY_REFERENCE_H_ +#define _FCD_ENTITY_REFERENCE_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_URI_H_ +#include "FUtils/FUUri.h" +#endif // _FU_URI_H_ + +class FCDPlaceHolder; +class FCDObjectWithId; + +/** + A COLLADA external reference for an entity instance. + FCollada only exposes external references for entity instances. + Other types of external references: geometry sources, morph targets, etc. + are not supported. + + The entity instance for an external reference cannot be modified + and tracks it, so that if is it released manually, the reference is also released. + + The placeholder and the document referenced by the entity instance can + be modified manually or by the entity instance. + + Also allowing external links by more than just entity instances. Controllers can + reference external geometry targets. + + Renaming this class to FCDEntityReference, as it used for tracking ALL entities. + This lightens the Code load on all classes that track entities. + + TODO: The following are non-compliant on the XRefs: + Animations (instance_animation) <-- TODO QUICK + Morphers (base_geom && morph_targets) + Emitters (force links) + Emitters (object_mesh) <-- TODO LAST + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDEntityReference : public FCDObject, FUTracker +{ +private: + DeclareObjectType(FCDObject); + + FCDEntity* entity; + FCDPlaceHolder* placeHolder; + fm::string entityId; + + // Pointer back to the nearest object with id that references + // us down the hierarchy. This is because the references from the + // actual object with the link are irrelevant in terms of the hierarchy, + // it is only objects with id's (ie FCDEntities) that actually matter in terms + // of object durability etc. + FCDObjectWithId* baseObject; + +public: + /** Constructor. + @param document The FCollada document that owns the reference. + @param baseObject The parent object. */ + FCDEntityReference(FCDocument* document, FCDObjectWithId* parent); + + /** Destructor. */ + virtual ~FCDEntityReference(); + + /** Retrieves the placeholder if this references an entity + from an external COLLADA document. + @return The COLLADA document placeholder. */ + FCDPlaceHolder* GetPlaceHolder() { return placeHolder; } + const FCDPlaceHolder* GetPlaceHolder() const { return placeHolder; } /**< See above. */ + + /** Retrieves the COLLADA id of the entity that is externally referenced. + @return The COLLADA id of the referenced entity. */ + const fm::string& GetEntityId() const { return entityId; } + + /** Retrieves whether this entity reference is an external entity reference. + This function intentionally hides the FCDObject::IsExternal function. + @return Whether the entity reference is an external entity reference. */ + inline bool IsExternal() const { return placeHolder != NULL; } + + /** Retrieves whether this entity reference is a local entity reference. + This function intentionally hides the FCDObject::IsLocal function. + @return Whether the entity reference is a local entity reference. */ + inline bool IsLocal() const { return placeHolder == NULL; } + + /** Sets the COLLADA id of the referenced entity. + @param id The COLLADA id of the referenced entity. */ + void SetEntityId(const fm::string& id) { entityId = id; SetDirtyFlag(); } + + /** Retrieves the full URI of the external reference. + This points to the COLLADA document and the id of the referenced entity. + @return The referenced entity URI. */ + FUUri GetUri() const; + + /** Sets the URI of the external reference. + This points to the COLLADA document and the id of the referenced entity. + @param uri The referenced entity URL. */ + void SetUri(const FUUri& uri); + + /** Get the entity this external reference points to. This may cause the entity to + load if it is not present already! + See the FCollada::GetDereferenceFlag() for more information. + @return the entity */ + FCDEntity* GetEntity() { return const_cast(const_cast(this)->GetEntity()); } + const FCDEntity* GetEntity() const; /**< See above. */ + + /** Get a pointer to the entity that either directly or indirectly + exclusively contains this reference. This is not necessarily the class + that contains the actual pointer, but it is the class that is responsible for + managing the link to the entity referenced (ie, not an FCDEntityInstance, but the + containing FCDEntity). + @return A pointer the object that uses this class to reference an entity */ + inline const FCDObjectWithId* GetClosestObjectWithId() const { return baseObject; } + + /** Set the pointer to the closest entity upstream that contains this reference. + @param obj An object with Id that either directly or indirectly exclusively + contains this reference */ + inline void SetClosestObjectWithId(FCDObjectWithId* obj) { FUAssert(baseObject == NULL,); baseObject = obj; } + + /** Set the entity we are referencing. If this is from an external document, it will + create the appropriate FCDPlaceholder etc. + @entity The new entity to reference */ + void SetEntity(FCDEntity* entity); + +private: + // Attempt to find the entity based on the set URL etc. + // This can cause an external document to load if the reference is external. + void LoadEntity(); + + // Sets the COLLADA document referenced by the entity instance. + // @param document The COLLADA document referenced by the entity instance. + void SetEntityDocument(FCDocument* document); + + // Sets the COLLADA document place holder that replaces the + // external COLLADA document for this reference. + // @param placeHolder The COLLADA document place holder. + void SetPlaceHolder(FCDPlaceHolder* placeHolder); + + virtual void OnObjectReleased(FUTrackable* object); +}; + +#endif // _FCD_ENTITY_REFERENCE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDEntityReference.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExtra.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExtra.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExtra.h (revision 24247) @@ -1,526 +1,526 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDExtra.h - This file contains the FCDExtra class and its sub-classes: - FCDENode, FCDETechnique and FCDEAttribute. -*/ - -#ifndef _FCD_EXTRA_H_ -#define _FCD_EXTRA_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -class FCDAnimated; -class FCDAnimatedCustom; -class FCDEAttribute; -class FCDETechnique; -class FCDEType; -class FCDENode; - -typedef fm::pvector FCDENodeList; /**< A dynamically-sized list of extra tree nodes. */ - -/** - A COLLADA extra tree. - - An extra tree contains the user-defined COLLADA information - contained within \ elements. For this, the extra tree - root simply contains a list of techniques. Each technique - belongs to a different application-specific profile. -*/ -class FCOLLADA_EXPORT FCDExtra : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - FUObject* parent; - DeclareParameterContainer(FCDEType, types, FC("Extra Types")); - -public: - /** Constructor. - Only structures that contain extra trees should create them. - @param document The COLLADA document that owns the extra tree. - @param parent The object that contains this extra tree. This parameter - is used only for plug-in support. */ - FCDExtra(FCDocument* document, FUObject* parent); - - /** Destructor. */ - virtual ~FCDExtra(); - - /** Retrieves the parent object for the extra tree. - @return The parent object pointer. */ - inline FUObject* GetParent() { return parent; } - inline const FUObject* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the list of types contained by this extra tree. - @return The list of types. */ - DEPRECATED(3.05A, GetTypeCount and GetType(index)) inline void GetTypes() const {} - - /** Retrieves the number of types contained by this extra tree. - @return The number of types. */ - size_t GetTypeCount() const { return types.size(); } - - /** Retrieves the default extra type. - The default extra type has an empty typename and is always created by default. - The default extra type will NOT be exported if it is empty. - @return The default extra type. */ - inline FCDEType* GetDefaultType() { return const_cast(const_cast(this)->GetDefaultType()); } - inline const FCDEType* GetDefaultType() const { return FindType(""); } /**< See above. */ - - /** Retrieves a specific type contained by this extra tree. - @param index The index of the type. - @return The type. This pointer will be NULL if the index is out-of-bounds. */ - inline FCDEType* GetType(size_t index) { FUAssert(index < types.size(), return NULL); return types.at(index); } - inline const FCDEType* GetType(size_t index) const { FUAssert(index < types.size(), return NULL); return types.at(index); } /**< See above. */ - - /** Adds a new application-specific type to the extra tree. - If the given application-specific type already exists - within the extra tree, the old type will be returned. - @param name The application-specific name. - @return A type for this application-specific name. */ - FCDEType* AddType(const char* name); - inline FCDEType* AddType(const fm::string& name) { return AddType(name.c_str()); } /**< See above. */ - - /** Retrieves a specific type contained by this extra tree. - @param name The application-specific name of the type. - @return The type that matches the name. This pointer may - be NULL if no type matches the name. */ - inline FCDEType* FindType(const char* name) { return const_cast(const_cast(this)->FindType(name)); } - const FCDEType* FindType(const char* name) const; /**< See above. */ - inline FCDEType* FindType(const fm::string& name) { return FindType(name.c_str()); } /**< See above. */ - inline const FCDEType* FindType(const fm::string& name) const { return FindType(name.c_str()); } /**< See above. */ - - /** Determines whether this structure is empty or not. - Basically, if there is an extra type, and that this type contains at - least one extra technique, content exists. - @return True if non-empty, false otherwise.*/ - bool HasContent() const; - - /** [INTERNAL] Clones the extra tree information. - @param clone The extra tree that will take in this extra tree's information. - If this pointer is NULL, a new extra tree will be created and you will - need to release the returned pointer manually. - @return The clone. */ - FCDExtra* Clone(FCDExtra* clone = NULL) const; -}; - -/** - A COLLADA typed extra node. - - The 'type' attribute of the extra nodes allow us to bucket techniques - to allow for different data for the same idea. - - Therefore, a typed extra node contains a type name and a list of techniques. -*/ -class FCOLLADA_EXPORT FCDEType : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - FCDExtra* parent; - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, name, FC("Type name")); - DeclareParameterContainer(FCDETechnique, techniques, FC("Profile-specific Techniques")); - -public: - /** Constructor: do not use directly. - Use the FCDExtra::AddType function instead. - @param document The COLLADA document that owns the extra tree. - @param parent The parent extra tree structure. - @param type The name of the type for this typed extra. */ - FCDEType(FCDocument* document, FCDExtra* parent, const char* type); - - /** Destructor. */ - virtual ~FCDEType(); - - /** Retrieves the extra tree that contains this typed extra. - @return The parent extra tree. */ - inline FCDExtra* GetParent() { return parent; } - inline const FCDExtra* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the name of the type of the typed extra. - @return The name of the type. */ - inline const fm::string& GetName() const { return name; } - - /** Modifies the name of the type of the typed extra. - Be careful when modifying the name of a type. The extra tree - assumes no duplicate type names within its typed extras. - @param _name The new name of the type. */ - inline void SetName(const fm::string& _name) { name = _name; } - - /** Retrieves the list of techniques contained by this extra tree. - @return The list of techniques. */ - DEPRECATED(3.05A, GetTechniqueCount and GetTechnique(index)) inline void GetTechniques() const {} - - /** Retrieves the number of techniques contained by this extra tree. - @return The number of techniques. */ - inline size_t GetTechniqueCount() const { return techniques.size(); } - - /** Retrieves a specific technique contained by this extra tree. - @param index The index of the technique. - @return The technique. This pointer will be NULL if the - index is out-of-bounds. */ - inline FCDETechnique* GetTechnique(size_t index) { FUAssert(index < techniques.size(), return NULL); return techniques.at(index); } - inline const FCDETechnique* GetTechnique(size_t index) const { FUAssert(index < techniques.size(), return NULL); return techniques.at(index); } /**< See above. */ - - /** Adds a new application-specific profile technique to the extra tree. - If the given application-specific profile already exists - within the extra tree, the old technique will be returned. - @param profile The application-specific profile name. - @return A technique for this application-specific profile. */ - FCDETechnique* AddTechnique(const char* profile); - inline FCDETechnique* AddTechnique(const fm::string& profile) { return AddTechnique(profile.c_str()); } /**< See above. */ - - /** Retrieves a specific technique contained by this extra tree. - @param profile The application-specific profile name of the technique. - @return The technique that matches the profile name. This pointer may - be NULL if no technique matches the profile name. */ - FCDETechnique* FindTechnique(const char* profile) { return const_cast(const_cast(this)->FindTechnique(profile)); } - const FCDETechnique* FindTechnique(const char* profile) const; /**< See above. */ - inline FCDETechnique* FindTechnique(const fm::string& profile) { return FindTechnique(profile.c_str()); } /**< See above. */ - inline const FCDETechnique* FindTechnique(const fm::string& profile) const { return FindTechnique(profile.c_str()); } /**< See above. */ - - /** Retrieves the extra tree node that has a given element name. - This function searches for the extra tree node within all the - techniques. - @param name An element name. - @return The extra tree node that matches the element name. This pointer - will be NULL if no extra tree node matches the element name. */ - inline FCDENode* FindRootNode(const char* name) { return const_cast(const_cast(this)->FindRootNode(name)); } - const FCDENode* FindRootNode(const char* name) const; /**< See above. */ - inline FCDENode* FindRootNode(const fm::string& name) { return FindRootNode(name.c_str()); } /**< See above. */ - inline const FCDENode* FindRootNode(const fm::string& name) const { return FindRootNode(name.c_str()); } /**< See above. */ - - /** [INTERNAL] Clones the extra tree information. - @param clone The extra tree that will take in this extra tree's information. - If this pointer is NULL, a new extra tree will be created and you will - need to release the returned pointer manually. - @return The clone. */ - FCDEType* Clone(FCDEType* clone = NULL) const; -}; - -/** - A COLLADA extra tree node. - - The extra tree node is a hierarchical structure that contains child - extra tree nodes as well as attributes. If the extra tree node is a leaf - of the tree, it may contain textual content. - - The extra tree node leaf may be animated, if it has the 'sid' attribute. -*/ -class FCOLLADA_EXPORT FCDENode : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - FCDENode* parent; - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, name, FC("Node name")); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, content, FC("Node content")); - - DeclareParameterContainer(FCDENode, children, FC("Children")); - DeclareParameterContainer(FCDEAttribute, attributes, FC("Attributes")); - - DeclareParameterRef(FCDAnimatedCustom, animated, FC("Custom Animatable")); - -public: - /** Constructor: do not use directly. - Instead, call the FCDENode::AddChild function of the parent within the hierarchy. - @param document The COLLADA document that owns the extra tree node. - @param parent The extra tree node that contains this extra tree node. */ - FCDENode(FCDocument* document, FCDENode* parent); - - /** Destructor. */ - virtual ~FCDENode(); - - /** Retrieves the name of the extra tree node. - The name of the extra tree node is the name of the equivalent XML tree node. - @return The name of the extra tree node. */ - inline const char* GetName() const { return name->c_str(); } - - /** Sets the name of the extra tree node. - The name of the extra tree node is the name of the equivalent XML tree node. - @param _name The name of the extra tree node. */ - inline void SetName(const char* _name) { fm::string n = _name; SetName(n); } - inline void SetName(const fm::string& _name) { fm::string n = _name; SetName(n); } /**< See above. */ - void SetName(fm::string& _name); - - /** Cleans up extra tree node names and extra tree attribute names in order to - always start with an alphabetic character or an underscore, as well as contain - only alphanumeric characters or underscore. - @param n The string to clean. This reference will be updated with the cleaned name. */ - static void CleanName(fm::string& n); - - /** Retrieves the textual content of the extra tree node. - This value is only valid for extra tree node that have no children, - as COLLADA doesn't allow for mixed-content. - @return The textual content of the extra tree node. */ - const fchar* GetContent() const; - - /** Sets the textual content of the extra tree node. - This function will release all the child node of this extra tree node, - as COLLADA doesn't allow for mixed-content. - @param _content The textual content. */ - void SetContent(const fchar* _content); - inline void SetContent(const fstring& _content) { return SetContent(_content.c_str()); } /**< See above. */ - - /** [INTERNAL] Set the content directly. - @param _content The new content to set. - */ - void SetContentDirect(const fstring& _content) { content = _content; } - - /** Retrieves the animated values associated with this extra tree node. - Extra tree node leaves may be animated. If this extra tree node leaf - is animated, this animated value will contain the animation curves. - @return The animated value. */ - FCDAnimatedCustom* GetAnimated() { return animated; } - const FCDAnimatedCustom* GetAnimated() const { return animated; } /**< See above. */ - - /**[INTERNAL] Set the customized animated. The old pointer is released first. - @animatedCustom The new animated. - */ - void SetAnimated(FCDAnimatedCustom* animatedCustom); - - /** Retrieves the parent of an extra tree node. - The hierarchy cannot be changed dynamically. If you to move an extra tree node, - you will need to clone it manually and release the old extra tree node. - @return The parent extra tree node within the hierarchy. This pointer - will be NULL if the extra tree node is a extra tree technique. */ - FCDENode* GetParent() { return parent; } - const FCDENode* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the children of an extra tree node. - @return The list of child extra tree nodes. */ - DEPRECATED(3.05A, GetChildNodeCount and GetChildNode(index)) void GetChildNodes() const {} - - /** Retrieves the number of children of an extra tree node. - @return The number of children. */ - size_t GetChildNodeCount() const { return children.size(); } - - /** Retrieves a specific child extra tree node. - @param index The index of the child extra tree node. - @return The child extra tree node. This pointer will be NULL if the index - is out-of-bounds. */ - FCDENode* GetChildNode(size_t index) { FUAssert(index < children.size(), return NULL); return children.at(index); } - const FCDENode* GetChildNode(size_t index) const { FUAssert(index < children.size(), return NULL); return children.at(index); } /**< See above. */ - - /** Adds a new child extra tree to this extra tree node. - @see AddParameter - @return The new child extra tree node. */ - FCDENode* AddChildNode(); - - /** Adds a new, named, child extra tree to this extra tree node. - @see AddParameter - @param name The name of the child node. - @return The new child extra tree node. */ - FCDENode* AddChildNode(const char* name); - inline FCDENode* AddChildNode(const fm::string& name) { return AddChildNode(name.c_str()); } /**< See above. */ - - /** Retrieves the child extra tree node with the given name. - @param name A name. - @return The child extra tree node that matches the given name. - This pointer will be NULL if no child extra tree node matches - the given name. */ - inline FCDENode* FindChildNode(const char* name) { return const_cast(const_cast(this)->FindChildNode(name)); } - const FCDENode* FindChildNode(const char* name) const; /**< See above. */ - inline FCDENode* FindChildNode(const fm::string& name) { return FindChildNode(name.c_str()); } /**< See above. */ - inline const FCDENode* FindChildNode(const fm::string& name) const { return FindChildNode(name.c_str()); } /**< See above. */ - - /** Retrieves the child extra tree nodes with the given name. - @param name A name. - @param nodes A list of nodes to fill in with the nodes - that match a given name. */ - void FindChildrenNodes(const char* name, FCDENodeList& nodes) const; - inline void FindChildrenNodes(const fm::string& name, FCDENodeList& nodes) const { FindChildrenNodes(name.c_str(), nodes); } /**< See above. */ - - /** Retrieves the child extra tree node with the given name. - A parameter has no child nodes and is described as: \value\. - The first child extra tree node where the name matches 'X' will be returned. - @param name The parameter name. - @return The first child extra tree node holding the wanted parameter within the hierarchy. - This pointer will be NULL to indicate that no parameter matches the given name. */ - const FCDENode* FindParameter(const char* name) const; - inline FCDENode* FindParameter(const char* name) { return const_cast(const_cast(this)->FindParameter(name)); } /**< See above. */ - - /** Retrieves a list of all the parameters contained within the hierarchy. - A parameter has no child nodes and is described as: \value\. - Using this function, The parameter would be returned with the name 'X'. - @param nodes The list of parameters to fill in. This list is not emptied by the function. - @param names The list of names of the parameters. This list is not emptied by the function. */ - void FindParameters(FCDENodeList& nodes, StringList& names); - - /** Retrieves the list of attributes for this extra tree node. - @return The list of attributes. */ - DEPRECATED(3.05A, GetAttributeCount and GetAttribute(index)) void GetAttributes() const {} - - /** Retrieves the number of attributes for this extra tree node. - @return The number of attributes. */ - size_t GetAttributeCount() const { return attributes.size(); } - - /** Retrieves a specific attribute of this extra tree node. - @param index The index. - @return The attribute at this index. This pointer will be NULL - if the index is out-of-bounds. */ - FCDEAttribute* GetAttribute(size_t index) { FUAssert(index < attributes.size(), return NULL); return attributes.at(index); } - const FCDEAttribute* GetAttribute(size_t index) const { FUAssert(index < attributes.size(), return NULL); return attributes.at(index); } /**< See above. */ - - /** Adds a new attribute to this extra tree node. - If an attribute with the same name already exists, this function simply - assigns the new value to the existing attribute and returns the existing attribute. - @param _name The name of the attribute. If this parameter is - a non-constant fm::string reference, it will be updated with the cleaned name. - @param _value The value of the attribute. - @return The new attribute. */ - FCDEAttribute* AddAttribute(fm::string& _name, const fchar* _value); - inline FCDEAttribute* AddAttribute(const char* _name, const fchar* _value) { fm::string n = _name; return AddAttribute(n, _value); } /**< See above. */ - inline FCDEAttribute* AddAttribute(const fm::string& _name, const fchar* _value) { fm::string n = _name; return AddAttribute(n, _value); } /**< See above. */ - inline FCDEAttribute* AddAttribute(const char* _name, const fstring& _value) { fm::string n = _name; return AddAttribute(n, _value.c_str()); } /**< See above. */ - inline FCDEAttribute* AddAttribute(fm::string& _name, const fstring& _value) { return AddAttribute(_name, _value.c_str()); } /**< See above. */ - inline FCDEAttribute* AddAttribute(const fm::string& _name, const fstring& _value) { fm::string n = _name; return AddAttribute(n, _value.c_str()); } /**< See above. */ - template inline FCDEAttribute* AddAttribute(const char* _name, const T& _value) { fm::string n = _name; return AddAttribute(n, TO_FSTRING(_value)); } /**< See above. */ - template inline FCDEAttribute* AddAttribute(fm::string& _name, const T& _value) { return AddAttribute(_name, TO_FSTRING(_value)); } /**< See above. */ - template inline FCDEAttribute* AddAttribute(const fm::string& _name, const T& _value) { fm::string n = _name; return AddAttribute(n, TO_FSTRING(_value)); } /**< See above. */ - - /** Retrieve the attribute of this extra tree node with the given name. - Attribute names are unique within an extra tree node. - @param name The attribute name. - @return The attribute that matches the name. This pointer will be NULL if - there is no attribute with the given name. */ - inline FCDEAttribute* FindAttribute(const char* name) { return const_cast(const_cast(this)->FindAttribute(name)); } - const FCDEAttribute* FindAttribute(const char* name) const; /**< See above. */ - - /** Retrieves the value of an attribute on this extra tree node. - Attributes names are unique within an extra tree node. - @param name The attribute name. - @return The value attached to the attribute with the given name. This value - will be the empty string when no attribute exists with the given name. */ - const fstring& ReadAttribute(const char* name) const; - - /** Adds a parameter as the child node. - A parameter is the simplest child node possible: - with a name and a value, represented as the node's content. - @see AddChildNode - @param name The parameter name. - @param value The parameter value. */ - FCDENode* AddParameter(const char* name, const fchar* value); - inline FCDENode* AddParameter(const fm::string& name, const fchar* value) { return AddParameter(name.c_str(), value); } /**< See above. */ - inline FCDENode* AddParameter(const char* name, const fstring& value) { return AddParameter(name, value.c_str()); } /**< See above. */ - inline FCDENode* AddParameter(const fm::string& name, const fstring& value) { return AddParameter(name.c_str(), value.c_str()); } /**< See above. */ - template - inline FCDENode* AddParameter(const char* name, const T& value) { return AddParameter(name, TO_FSTRING(value)); } /**< See above. */ - template - inline FCDENode* AddParameter(const fm::string& name, const T& value) { return AddParameter(name.c_str(), TO_FSTRING(value)); } /**< See above. */ - - /** Clones the extra tree node. - @param clone The extra tree node that will receive the clone information. - This pointer cannot be NULL. - @return The clone. You will need to release the returned pointer manually. */ - virtual FCDENode* Clone(FCDENode* clone) const; -}; - -/** - A COLLADA extra tree technique. - - For convenience, this extra tree technique is based on top of the FCDENode class. - An extra tree technique is the root of the extra tree specific to - the profile of an application. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDETechnique : public FCDENode -{ -private: - DeclareObjectType(FCDENode); - - FCDEType* parent; - DeclareParameterPtr(FUTrackable, pluginOverride, FC("Plug-in Override Object")); - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, profile, FC("Profile Name")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDEType::AddTechnique function. - @param document The COLLADA document that owns the technique. - @param parent The extra type that contains this technique. - @param profile The application-specific profile name. */ - FCDETechnique(FCDocument* document, FCDEType* parent, const char* profile); - - /** Destructor. */ - virtual ~FCDETechnique(); - - /** Retrieves the name of the application-specific profile of the technique. - @return The name of the application-specific profile. */ - const char* GetProfile() const { return profile->c_str(); } - - /** Sets the name of the application-specific profile of the technique. - Be careful when modifying the application-specific profile name. - There is an assumption that within a typed-extra, all application-specific - profile names are unique. - @param _profile The new name of the application-specific profile. */ - void SetProfile(const fm::string& _profile) { profile = _profile; } - - /** Retrieves the plug-in object that overrides the extra tree for this profile. - The plug-in object should contain all the necessary information and this extra tree - is expected to be empty. - @return The profile-specific plug-in object. */ - FUTrackable* GetPluginObject() { return pluginOverride; } - const FUTrackable* GetPluginObject() const { return pluginOverride; } /**< See above. */ - - /** Sets the plug-in object that overrides the extra tree for this profile.*/ - void SetPluginObject(FUTrackable* plugin) { pluginOverride = plugin; } - - /** Clones the extra tree node. - @param clone The extra tree node that will receive the clone information. - If this pointer is NULL, a new extra tree technique will be created and you will - need to release the returned pointer manually. - @return The clone. */ - virtual FCDENode* Clone(FCDENode* clone) const; -}; - -/** - An extra tree attribute. - Contains a name and a value string. -*/ -class FCDEAttribute : public FUParameterizable -{ -private: - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, name, FC("Attribute Name")); /**< The attribute name. Must be provided. */ - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, value, FC("Attribute Value")); /**< The attribute value. Is optional. */ - -public: - /** Default constructor. - The name and the value string will be blank. */ - FCDEAttribute(); - - /** Constructor. - Sets the attribute name and the attribute value appropriately. - @param name The attribute name. - @param value The attribute value. */ - FCDEAttribute(const char* name, const fchar* value); - - /** Retrieves the name of the attribute. - @return The name of the attribute. */ - inline const fm::string& GetName() const { return name; } - - /** Sets the name of the attribute. - @param _name The new name of the attribute. */ - inline void SetName(const fm::string& _name) { name = _name; } - - /** Retrieves the value of the attribute. - @return The value of the attribute. */ - inline const fstring& GetValue() const { return value; } - - /** Sets the value of the attribute. - @param _value The new value of the attribute. */ - inline void SetValue(const fstring& _value) { value = _value; } -}; - -#endif // _FCD_EXTRA_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDExtra.h + This file contains the FCDExtra class and its sub-classes: + FCDENode, FCDETechnique and FCDEAttribute. +*/ + +#ifndef _FCD_EXTRA_H_ +#define _FCD_EXTRA_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +class FCDAnimated; +class FCDAnimatedCustom; +class FCDEAttribute; +class FCDETechnique; +class FCDEType; +class FCDENode; + +typedef fm::pvector FCDENodeList; /**< A dynamically-sized list of extra tree nodes. */ + +/** + A COLLADA extra tree. + + An extra tree contains the user-defined COLLADA information + contained within \ elements. For this, the extra tree + root simply contains a list of techniques. Each technique + belongs to a different application-specific profile. +*/ +class FCOLLADA_EXPORT FCDExtra : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + FUObject* parent; + DeclareParameterContainer(FCDEType, types, FC("Extra Types")); + +public: + /** Constructor. + Only structures that contain extra trees should create them. + @param document The COLLADA document that owns the extra tree. + @param parent The object that contains this extra tree. This parameter + is used only for plug-in support. */ + FCDExtra(FCDocument* document, FUObject* parent); + + /** Destructor. */ + virtual ~FCDExtra(); + + /** Retrieves the parent object for the extra tree. + @return The parent object pointer. */ + inline FUObject* GetParent() { return parent; } + inline const FUObject* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the list of types contained by this extra tree. + @return The list of types. */ + DEPRECATED(3.05A, GetTypeCount and GetType(index)) inline void GetTypes() const {} + + /** Retrieves the number of types contained by this extra tree. + @return The number of types. */ + size_t GetTypeCount() const { return types.size(); } + + /** Retrieves the default extra type. + The default extra type has an empty typename and is always created by default. + The default extra type will NOT be exported if it is empty. + @return The default extra type. */ + inline FCDEType* GetDefaultType() { return const_cast(const_cast(this)->GetDefaultType()); } + inline const FCDEType* GetDefaultType() const { return FindType(""); } /**< See above. */ + + /** Retrieves a specific type contained by this extra tree. + @param index The index of the type. + @return The type. This pointer will be NULL if the index is out-of-bounds. */ + inline FCDEType* GetType(size_t index) { FUAssert(index < types.size(), return NULL); return types.at(index); } + inline const FCDEType* GetType(size_t index) const { FUAssert(index < types.size(), return NULL); return types.at(index); } /**< See above. */ + + /** Adds a new application-specific type to the extra tree. + If the given application-specific type already exists + within the extra tree, the old type will be returned. + @param name The application-specific name. + @return A type for this application-specific name. */ + FCDEType* AddType(const char* name); + inline FCDEType* AddType(const fm::string& name) { return AddType(name.c_str()); } /**< See above. */ + + /** Retrieves a specific type contained by this extra tree. + @param name The application-specific name of the type. + @return The type that matches the name. This pointer may + be NULL if no type matches the name. */ + inline FCDEType* FindType(const char* name) { return const_cast(const_cast(this)->FindType(name)); } + const FCDEType* FindType(const char* name) const; /**< See above. */ + inline FCDEType* FindType(const fm::string& name) { return FindType(name.c_str()); } /**< See above. */ + inline const FCDEType* FindType(const fm::string& name) const { return FindType(name.c_str()); } /**< See above. */ + + /** Determines whether this structure is empty or not. + Basically, if there is an extra type, and that this type contains at + least one extra technique, content exists. + @return True if non-empty, false otherwise.*/ + bool HasContent() const; + + /** [INTERNAL] Clones the extra tree information. + @param clone The extra tree that will take in this extra tree's information. + If this pointer is NULL, a new extra tree will be created and you will + need to release the returned pointer manually. + @return The clone. */ + FCDExtra* Clone(FCDExtra* clone = NULL) const; +}; + +/** + A COLLADA typed extra node. + + The 'type' attribute of the extra nodes allow us to bucket techniques + to allow for different data for the same idea. + + Therefore, a typed extra node contains a type name and a list of techniques. +*/ +class FCOLLADA_EXPORT FCDEType : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + FCDExtra* parent; + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, name, FC("Type name")); + DeclareParameterContainer(FCDETechnique, techniques, FC("Profile-specific Techniques")); + +public: + /** Constructor: do not use directly. + Use the FCDExtra::AddType function instead. + @param document The COLLADA document that owns the extra tree. + @param parent The parent extra tree structure. + @param type The name of the type for this typed extra. */ + FCDEType(FCDocument* document, FCDExtra* parent, const char* type); + + /** Destructor. */ + virtual ~FCDEType(); + + /** Retrieves the extra tree that contains this typed extra. + @return The parent extra tree. */ + inline FCDExtra* GetParent() { return parent; } + inline const FCDExtra* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the name of the type of the typed extra. + @return The name of the type. */ + inline const fm::string& GetName() const { return name; } + + /** Modifies the name of the type of the typed extra. + Be careful when modifying the name of a type. The extra tree + assumes no duplicate type names within its typed extras. + @param _name The new name of the type. */ + inline void SetName(const fm::string& _name) { name = _name; } + + /** Retrieves the list of techniques contained by this extra tree. + @return The list of techniques. */ + DEPRECATED(3.05A, GetTechniqueCount and GetTechnique(index)) inline void GetTechniques() const {} + + /** Retrieves the number of techniques contained by this extra tree. + @return The number of techniques. */ + inline size_t GetTechniqueCount() const { return techniques.size(); } + + /** Retrieves a specific technique contained by this extra tree. + @param index The index of the technique. + @return The technique. This pointer will be NULL if the + index is out-of-bounds. */ + inline FCDETechnique* GetTechnique(size_t index) { FUAssert(index < techniques.size(), return NULL); return techniques.at(index); } + inline const FCDETechnique* GetTechnique(size_t index) const { FUAssert(index < techniques.size(), return NULL); return techniques.at(index); } /**< See above. */ + + /** Adds a new application-specific profile technique to the extra tree. + If the given application-specific profile already exists + within the extra tree, the old technique will be returned. + @param profile The application-specific profile name. + @return A technique for this application-specific profile. */ + FCDETechnique* AddTechnique(const char* profile); + inline FCDETechnique* AddTechnique(const fm::string& profile) { return AddTechnique(profile.c_str()); } /**< See above. */ + + /** Retrieves a specific technique contained by this extra tree. + @param profile The application-specific profile name of the technique. + @return The technique that matches the profile name. This pointer may + be NULL if no technique matches the profile name. */ + FCDETechnique* FindTechnique(const char* profile) { return const_cast(const_cast(this)->FindTechnique(profile)); } + const FCDETechnique* FindTechnique(const char* profile) const; /**< See above. */ + inline FCDETechnique* FindTechnique(const fm::string& profile) { return FindTechnique(profile.c_str()); } /**< See above. */ + inline const FCDETechnique* FindTechnique(const fm::string& profile) const { return FindTechnique(profile.c_str()); } /**< See above. */ + + /** Retrieves the extra tree node that has a given element name. + This function searches for the extra tree node within all the + techniques. + @param name An element name. + @return The extra tree node that matches the element name. This pointer + will be NULL if no extra tree node matches the element name. */ + inline FCDENode* FindRootNode(const char* name) { return const_cast(const_cast(this)->FindRootNode(name)); } + const FCDENode* FindRootNode(const char* name) const; /**< See above. */ + inline FCDENode* FindRootNode(const fm::string& name) { return FindRootNode(name.c_str()); } /**< See above. */ + inline const FCDENode* FindRootNode(const fm::string& name) const { return FindRootNode(name.c_str()); } /**< See above. */ + + /** [INTERNAL] Clones the extra tree information. + @param clone The extra tree that will take in this extra tree's information. + If this pointer is NULL, a new extra tree will be created and you will + need to release the returned pointer manually. + @return The clone. */ + FCDEType* Clone(FCDEType* clone = NULL) const; +}; + +/** + A COLLADA extra tree node. + + The extra tree node is a hierarchical structure that contains child + extra tree nodes as well as attributes. If the extra tree node is a leaf + of the tree, it may contain textual content. + + The extra tree node leaf may be animated, if it has the 'sid' attribute. +*/ +class FCOLLADA_EXPORT FCDENode : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + FCDENode* parent; + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, name, FC("Node name")); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, content, FC("Node content")); + + DeclareParameterContainer(FCDENode, children, FC("Children")); + DeclareParameterContainer(FCDEAttribute, attributes, FC("Attributes")); + + DeclareParameterRef(FCDAnimatedCustom, animated, FC("Custom Animatable")); + +public: + /** Constructor: do not use directly. + Instead, call the FCDENode::AddChild function of the parent within the hierarchy. + @param document The COLLADA document that owns the extra tree node. + @param parent The extra tree node that contains this extra tree node. */ + FCDENode(FCDocument* document, FCDENode* parent); + + /** Destructor. */ + virtual ~FCDENode(); + + /** Retrieves the name of the extra tree node. + The name of the extra tree node is the name of the equivalent XML tree node. + @return The name of the extra tree node. */ + inline const char* GetName() const { return name->c_str(); } + + /** Sets the name of the extra tree node. + The name of the extra tree node is the name of the equivalent XML tree node. + @param _name The name of the extra tree node. */ + inline void SetName(const char* _name) { fm::string n = _name; SetName(n); } + inline void SetName(const fm::string& _name) { fm::string n = _name; SetName(n); } /**< See above. */ + void SetName(fm::string& _name); + + /** Cleans up extra tree node names and extra tree attribute names in order to + always start with an alphabetic character or an underscore, as well as contain + only alphanumeric characters or underscore. + @param n The string to clean. This reference will be updated with the cleaned name. */ + static void CleanName(fm::string& n); + + /** Retrieves the textual content of the extra tree node. + This value is only valid for extra tree node that have no children, + as COLLADA doesn't allow for mixed-content. + @return The textual content of the extra tree node. */ + const fchar* GetContent() const; + + /** Sets the textual content of the extra tree node. + This function will release all the child node of this extra tree node, + as COLLADA doesn't allow for mixed-content. + @param _content The textual content. */ + void SetContent(const fchar* _content); + inline void SetContent(const fstring& _content) { return SetContent(_content.c_str()); } /**< See above. */ + + /** [INTERNAL] Set the content directly. + @param _content The new content to set. + */ + void SetContentDirect(const fstring& _content) { content = _content; } + + /** Retrieves the animated values associated with this extra tree node. + Extra tree node leaves may be animated. If this extra tree node leaf + is animated, this animated value will contain the animation curves. + @return The animated value. */ + FCDAnimatedCustom* GetAnimated() { return animated; } + const FCDAnimatedCustom* GetAnimated() const { return animated; } /**< See above. */ + + /**[INTERNAL] Set the customized animated. The old pointer is released first. + @animatedCustom The new animated. + */ + void SetAnimated(FCDAnimatedCustom* animatedCustom); + + /** Retrieves the parent of an extra tree node. + The hierarchy cannot be changed dynamically. If you to move an extra tree node, + you will need to clone it manually and release the old extra tree node. + @return The parent extra tree node within the hierarchy. This pointer + will be NULL if the extra tree node is a extra tree technique. */ + FCDENode* GetParent() { return parent; } + const FCDENode* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the children of an extra tree node. + @return The list of child extra tree nodes. */ + DEPRECATED(3.05A, GetChildNodeCount and GetChildNode(index)) void GetChildNodes() const {} + + /** Retrieves the number of children of an extra tree node. + @return The number of children. */ + size_t GetChildNodeCount() const { return children.size(); } + + /** Retrieves a specific child extra tree node. + @param index The index of the child extra tree node. + @return The child extra tree node. This pointer will be NULL if the index + is out-of-bounds. */ + FCDENode* GetChildNode(size_t index) { FUAssert(index < children.size(), return NULL); return children.at(index); } + const FCDENode* GetChildNode(size_t index) const { FUAssert(index < children.size(), return NULL); return children.at(index); } /**< See above. */ + + /** Adds a new child extra tree to this extra tree node. + @see AddParameter + @return The new child extra tree node. */ + FCDENode* AddChildNode(); + + /** Adds a new, named, child extra tree to this extra tree node. + @see AddParameter + @param name The name of the child node. + @return The new child extra tree node. */ + FCDENode* AddChildNode(const char* name); + inline FCDENode* AddChildNode(const fm::string& name) { return AddChildNode(name.c_str()); } /**< See above. */ + + /** Retrieves the child extra tree node with the given name. + @param name A name. + @return The child extra tree node that matches the given name. + This pointer will be NULL if no child extra tree node matches + the given name. */ + inline FCDENode* FindChildNode(const char* name) { return const_cast(const_cast(this)->FindChildNode(name)); } + const FCDENode* FindChildNode(const char* name) const; /**< See above. */ + inline FCDENode* FindChildNode(const fm::string& name) { return FindChildNode(name.c_str()); } /**< See above. */ + inline const FCDENode* FindChildNode(const fm::string& name) const { return FindChildNode(name.c_str()); } /**< See above. */ + + /** Retrieves the child extra tree nodes with the given name. + @param name A name. + @param nodes A list of nodes to fill in with the nodes + that match a given name. */ + void FindChildrenNodes(const char* name, FCDENodeList& nodes) const; + inline void FindChildrenNodes(const fm::string& name, FCDENodeList& nodes) const { FindChildrenNodes(name.c_str(), nodes); } /**< See above. */ + + /** Retrieves the child extra tree node with the given name. + A parameter has no child nodes and is described as: \value\. + The first child extra tree node where the name matches 'X' will be returned. + @param name The parameter name. + @return The first child extra tree node holding the wanted parameter within the hierarchy. + This pointer will be NULL to indicate that no parameter matches the given name. */ + const FCDENode* FindParameter(const char* name) const; + inline FCDENode* FindParameter(const char* name) { return const_cast(const_cast(this)->FindParameter(name)); } /**< See above. */ + + /** Retrieves a list of all the parameters contained within the hierarchy. + A parameter has no child nodes and is described as: \value\. + Using this function, The parameter would be returned with the name 'X'. + @param nodes The list of parameters to fill in. This list is not emptied by the function. + @param names The list of names of the parameters. This list is not emptied by the function. */ + void FindParameters(FCDENodeList& nodes, StringList& names); + + /** Retrieves the list of attributes for this extra tree node. + @return The list of attributes. */ + DEPRECATED(3.05A, GetAttributeCount and GetAttribute(index)) void GetAttributes() const {} + + /** Retrieves the number of attributes for this extra tree node. + @return The number of attributes. */ + size_t GetAttributeCount() const { return attributes.size(); } + + /** Retrieves a specific attribute of this extra tree node. + @param index The index. + @return The attribute at this index. This pointer will be NULL + if the index is out-of-bounds. */ + FCDEAttribute* GetAttribute(size_t index) { FUAssert(index < attributes.size(), return NULL); return attributes.at(index); } + const FCDEAttribute* GetAttribute(size_t index) const { FUAssert(index < attributes.size(), return NULL); return attributes.at(index); } /**< See above. */ + + /** Adds a new attribute to this extra tree node. + If an attribute with the same name already exists, this function simply + assigns the new value to the existing attribute and returns the existing attribute. + @param _name The name of the attribute. If this parameter is + a non-constant fm::string reference, it will be updated with the cleaned name. + @param _value The value of the attribute. + @return The new attribute. */ + FCDEAttribute* AddAttribute(fm::string& _name, const fchar* _value); + inline FCDEAttribute* AddAttribute(const char* _name, const fchar* _value) { fm::string n = _name; return AddAttribute(n, _value); } /**< See above. */ + inline FCDEAttribute* AddAttribute(const fm::string& _name, const fchar* _value) { fm::string n = _name; return AddAttribute(n, _value); } /**< See above. */ + inline FCDEAttribute* AddAttribute(const char* _name, const fstring& _value) { fm::string n = _name; return AddAttribute(n, _value.c_str()); } /**< See above. */ + inline FCDEAttribute* AddAttribute(fm::string& _name, const fstring& _value) { return AddAttribute(_name, _value.c_str()); } /**< See above. */ + inline FCDEAttribute* AddAttribute(const fm::string& _name, const fstring& _value) { fm::string n = _name; return AddAttribute(n, _value.c_str()); } /**< See above. */ + template inline FCDEAttribute* AddAttribute(const char* _name, const T& _value) { fm::string n = _name; return AddAttribute(n, TO_FSTRING(_value)); } /**< See above. */ + template inline FCDEAttribute* AddAttribute(fm::string& _name, const T& _value) { return AddAttribute(_name, TO_FSTRING(_value)); } /**< See above. */ + template inline FCDEAttribute* AddAttribute(const fm::string& _name, const T& _value) { fm::string n = _name; return AddAttribute(n, TO_FSTRING(_value)); } /**< See above. */ + + /** Retrieve the attribute of this extra tree node with the given name. + Attribute names are unique within an extra tree node. + @param name The attribute name. + @return The attribute that matches the name. This pointer will be NULL if + there is no attribute with the given name. */ + inline FCDEAttribute* FindAttribute(const char* name) { return const_cast(const_cast(this)->FindAttribute(name)); } + const FCDEAttribute* FindAttribute(const char* name) const; /**< See above. */ + + /** Retrieves the value of an attribute on this extra tree node. + Attributes names are unique within an extra tree node. + @param name The attribute name. + @return The value attached to the attribute with the given name. This value + will be the empty string when no attribute exists with the given name. */ + const fstring& ReadAttribute(const char* name) const; + + /** Adds a parameter as the child node. + A parameter is the simplest child node possible: + with a name and a value, represented as the node's content. + @see AddChildNode + @param name The parameter name. + @param value The parameter value. */ + FCDENode* AddParameter(const char* name, const fchar* value); + inline FCDENode* AddParameter(const fm::string& name, const fchar* value) { return AddParameter(name.c_str(), value); } /**< See above. */ + inline FCDENode* AddParameter(const char* name, const fstring& value) { return AddParameter(name, value.c_str()); } /**< See above. */ + inline FCDENode* AddParameter(const fm::string& name, const fstring& value) { return AddParameter(name.c_str(), value.c_str()); } /**< See above. */ + template + inline FCDENode* AddParameter(const char* name, const T& value) { return AddParameter(name, TO_FSTRING(value)); } /**< See above. */ + template + inline FCDENode* AddParameter(const fm::string& name, const T& value) { return AddParameter(name.c_str(), TO_FSTRING(value)); } /**< See above. */ + + /** Clones the extra tree node. + @param clone The extra tree node that will receive the clone information. + This pointer cannot be NULL. + @return The clone. You will need to release the returned pointer manually. */ + virtual FCDENode* Clone(FCDENode* clone) const; +}; + +/** + A COLLADA extra tree technique. + + For convenience, this extra tree technique is based on top of the FCDENode class. + An extra tree technique is the root of the extra tree specific to + the profile of an application. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDETechnique : public FCDENode +{ +private: + DeclareObjectType(FCDENode); + + FCDEType* parent; + DeclareParameterPtr(FUTrackable, pluginOverride, FC("Plug-in Override Object")); + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, profile, FC("Profile Name")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDEType::AddTechnique function. + @param document The COLLADA document that owns the technique. + @param parent The extra type that contains this technique. + @param profile The application-specific profile name. */ + FCDETechnique(FCDocument* document, FCDEType* parent, const char* profile); + + /** Destructor. */ + virtual ~FCDETechnique(); + + /** Retrieves the name of the application-specific profile of the technique. + @return The name of the application-specific profile. */ + const char* GetProfile() const { return profile->c_str(); } + + /** Sets the name of the application-specific profile of the technique. + Be careful when modifying the application-specific profile name. + There is an assumption that within a typed-extra, all application-specific + profile names are unique. + @param _profile The new name of the application-specific profile. */ + void SetProfile(const fm::string& _profile) { profile = _profile; } + + /** Retrieves the plug-in object that overrides the extra tree for this profile. + The plug-in object should contain all the necessary information and this extra tree + is expected to be empty. + @return The profile-specific plug-in object. */ + FUTrackable* GetPluginObject() { return pluginOverride; } + const FUTrackable* GetPluginObject() const { return pluginOverride; } /**< See above. */ + + /** Sets the plug-in object that overrides the extra tree for this profile.*/ + void SetPluginObject(FUTrackable* plugin) { pluginOverride = plugin; } + + /** Clones the extra tree node. + @param clone The extra tree node that will receive the clone information. + If this pointer is NULL, a new extra tree technique will be created and you will + need to release the returned pointer manually. + @return The clone. */ + virtual FCDENode* Clone(FCDENode* clone) const; +}; + +/** + An extra tree attribute. + Contains a name and a value string. +*/ +class FCDEAttribute : public FUParameterizable +{ +private: + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, name, FC("Attribute Name")); /**< The attribute name. Must be provided. */ + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, value, FC("Attribute Value")); /**< The attribute value. Is optional. */ + +public: + /** Default constructor. + The name and the value string will be blank. */ + FCDEAttribute(); + + /** Constructor. + Sets the attribute name and the attribute value appropriately. + @param name The attribute name. + @param value The attribute value. */ + FCDEAttribute(const char* name, const fchar* value); + + /** Retrieves the name of the attribute. + @return The name of the attribute. */ + inline const fm::string& GetName() const { return name; } + + /** Sets the name of the attribute. + @param _name The new name of the attribute. */ + inline void SetName(const fm::string& _name) { name = _name; } + + /** Retrieves the value of the attribute. + @return The value of the attribute. */ + inline const fstring& GetValue() const { return value; } + + /** Sets the value of the attribute. + @param _value The new value of the attribute. */ + inline void SetValue(const fstring& _value) { value = _value; } +}; + +#endif // _FCD_EXTRA_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDExtra.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDrag.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDrag.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDrag.h (revision 24247) @@ -1,17 +1,17 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDForceDrag.h - This file contains the FCDForceDrag class. -*/ - -#ifndef _FCD_FORCE_DRAG_H_ -#define _FCD_FORCE_DRAG_H_ - -#endif // _FCD_FORCE_DRAG_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDForceDrag.h + This file contains the FCDForceDrag class. +*/ + +#ifndef _FCD_FORCE_DRAG_H_ +#define _FCD_FORCE_DRAG_H_ + +#endif // _FCD_FORCE_DRAG_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceDrag.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.h (revision 24247) Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceGravity.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceGravity.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceGravity.cpp (revision 24247) @@ -1,13 +1,13 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDForceGravity.h" - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDForceGravity.h" + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceGravity.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceTyped.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceTyped.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceTyped.h (revision 24247) @@ -1,12 +1,12 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#ifndef _FCD_FORCE_TYPED_H_ -#define _FCD_FORCE_TYPED_H_ - -#endif // _FCD_FORCE_TYPED_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef _FCD_FORCE_TYPED_H_ +#define _FCD_FORCE_TYPED_H_ + +#endif // _FCD_FORCE_TYPED_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceTyped.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForcePBomb.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForcePBomb.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForcePBomb.h (revision 24247) @@ -1,17 +1,17 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDForcePBomb.h - This file contains the FCDForcePBomb class. -*/ - -#ifndef _FCD_FORCE_PBOMB_H_ -#define _FCD_FORCE_PBOMB_H_ - -#endif // _FCD_FORCE_PBOMB_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDForcePBomb.h + This file contains the FCDForcePBomb class. +*/ + +#ifndef _FCD_FORCE_PBOMB_H_ +#define _FCD_FORCE_PBOMB_H_ + +#endif // _FCD_FORCE_PBOMB_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForcePBomb.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForcePBomb.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForcePBomb.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForcePBomb.cpp (revision 24247) @@ -1,13 +1,13 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDForcePBomb.h" - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDForcePBomb.h" + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForcePBomb.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceGravity.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceGravity.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceGravity.h (revision 24247) @@ -1,17 +1,17 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDForceGravity.h - This file contains the FCDForceGravity class. -*/ - -#ifndef _FCD_FORCE_GRAVITY_H_ -#define _FCD_FORCE_GRAVITY_H_ - -#endif // _FCD_FORCE_GRAVITY_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDForceGravity.h + This file contains the FCDForceGravity class. +*/ + +#ifndef _FCD_FORCE_GRAVITY_H_ +#define _FCD_FORCE_GRAVITY_H_ + +#endif // _FCD_FORCE_GRAVITY_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceGravity.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceWind.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceWind.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceWind.cpp (revision 24247) @@ -1,13 +1,13 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDForceWind.h" - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDForceWind.h" + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceWind.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometry.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometry.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometry.h (revision 24247) @@ -1,126 +1,126 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDGeometry.h - This file contains the FCDGeometry class. - The FCDGeometry class holds the information for one mesh or spline - entity, within the COLLADA geometry library. -*/ -#ifndef _FCD_GEOMETRY_H_ -#define _FCD_GEOMETRY_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ - -class FCDocument; -class FCDGeometryMesh; -class FCDGeometrySpline; - -/** - @defgroup FCDGeometry COLLADA Document Geometry Entity - @addtogroup FCDocument -*/ - -/** - A COLLADA geometry entity. - There are three types of COLLADA geometry entities: meshes, NURBS surfaces and splines. - *NURBS Surfaces are part of the Premium Build only.* - - Meshes are collections of polygons where the vertices always have a position, - usually have a normal to define smooth or hard edges and may be colored or textured. - - Parameterized surfaces (PSurface) are a list of parameterized patches defined as a sequence of - weighted control points that may be associated with two knot vectors - and possibly trimming curves to define a 3D surface. - - Note: "PSurfaces" are part of the Premium Build only. - - Splines are a sequence of control points used to generate a smooth curve. - - @ingroup FCDGeometry -*/ - -class FCOLLADA_EXPORT FCDGeometry : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - - // Contains only one of the following, in order of importance. - DeclareParameterRef(FCDGeometryMesh, mesh, FC("Mesh")); - DeclareParameterRef(FCDGeometrySpline, spline, FC("Spline")); - -public: - /** Contructor: do not use directly. - Create new geometries using the FCDLibrary::AddEntity function. - @param document The COLLADA document which owns the new geometry entity. */ - FCDGeometry(FCDocument* document); - - /** Destructor. */ - virtual ~FCDGeometry(); - - /** [INTERNAL] Set geometry information. - @param data The specific geometry data structure. - */ - void SetMesh(FCDGeometryMesh* data){ mesh = data; } - void SetSpline(FCDGeometrySpline* data){ spline = data; } /** see above */ - - /** Retrieves the entity class type. - This function is a part of the FCDEntity interface. - @return The entity class type: GEOMETRY. */ - virtual Type GetType() const { return GEOMETRY; } - - /** Retrieves whether the type of this geometry is a mesh. - @return Whether this geometry is a mesh. */ - bool IsMesh() const { return mesh != NULL; } - - /** Retrieves the mesh information structure for this geometry. - Verify that this geometry is a mesh using the IsMesh function prior to calling this function. - @return The mesh information structure. This pointer will be NULL when the geometry is a spline or is undefined. */ - FCDGeometryMesh* GetMesh() { return mesh; } - const FCDGeometryMesh* GetMesh() const { return mesh; } /**< See above. */ - - /** Sets the type of this geometry to mesh and creates an empty mesh structure. - This function will release any mesh or spline structure that the geometry may already contain - @return The mesh information structure. This pointer will always be valid. */ - FCDGeometryMesh* CreateMesh(); - - /** Retrieves whether the type of this geometry is a spline. - @return Whether this geometry is a spline. */ - bool IsSpline() const { return spline != NULL; } - - /** Retrieves the spline information structure for this geometry. - Verify that this geometry is a spline using the IsSpline function prior to calling this function. - @return The spline information structure. This pointer will be NULL when the geometry is a mesh or is undefined. */ - FCDGeometrySpline* GetSpline() { return spline; } - const FCDGeometrySpline* GetSpline() const { return spline; } /**< See above. */ - - /** Sets the type of this geometry to spline and creates an empty spline structure. - This function will release any mesh or spline structure that the geometry may already contain. - @return The spline information structure. This pointer will always be valid. */ - FCDGeometrySpline* CreateSpline(); - - - /** Retrieves whether the type of this geometry is a parameterized surface. - @return Whether this geometry is a parameterized surface. */ - bool IsPSurface() const { return false; } - - /** Copies the geometry entity into a clone. - The clone may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new geometry entity - will be created and you will need to release the returned pointer manually. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; -}; - -#endif // _FCD_GEOMETRY_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDGeometry.h + This file contains the FCDGeometry class. + The FCDGeometry class holds the information for one mesh or spline + entity, within the COLLADA geometry library. +*/ +#ifndef _FCD_GEOMETRY_H_ +#define _FCD_GEOMETRY_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ + +class FCDocument; +class FCDGeometryMesh; +class FCDGeometrySpline; + +/** + @defgroup FCDGeometry COLLADA Document Geometry Entity + @addtogroup FCDocument +*/ + +/** + A COLLADA geometry entity. + There are three types of COLLADA geometry entities: meshes, NURBS surfaces and splines. + *NURBS Surfaces are part of the Premium Build only.* + + Meshes are collections of polygons where the vertices always have a position, + usually have a normal to define smooth or hard edges and may be colored or textured. + + Parameterized surfaces (PSurface) are a list of parameterized patches defined as a sequence of + weighted control points that may be associated with two knot vectors + and possibly trimming curves to define a 3D surface. + + Note: "PSurfaces" are part of the Premium Build only. + + Splines are a sequence of control points used to generate a smooth curve. + + @ingroup FCDGeometry +*/ + +class FCOLLADA_EXPORT FCDGeometry : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + + // Contains only one of the following, in order of importance. + DeclareParameterRef(FCDGeometryMesh, mesh, FC("Mesh")); + DeclareParameterRef(FCDGeometrySpline, spline, FC("Spline")); + +public: + /** Contructor: do not use directly. + Create new geometries using the FCDLibrary::AddEntity function. + @param document The COLLADA document which owns the new geometry entity. */ + FCDGeometry(FCDocument* document); + + /** Destructor. */ + virtual ~FCDGeometry(); + + /** [INTERNAL] Set geometry information. + @param data The specific geometry data structure. + */ + void SetMesh(FCDGeometryMesh* data){ mesh = data; } + void SetSpline(FCDGeometrySpline* data){ spline = data; } /** see above */ + + /** Retrieves the entity class type. + This function is a part of the FCDEntity interface. + @return The entity class type: GEOMETRY. */ + virtual Type GetType() const { return GEOMETRY; } + + /** Retrieves whether the type of this geometry is a mesh. + @return Whether this geometry is a mesh. */ + bool IsMesh() const { return mesh != NULL; } + + /** Retrieves the mesh information structure for this geometry. + Verify that this geometry is a mesh using the IsMesh function prior to calling this function. + @return The mesh information structure. This pointer will be NULL when the geometry is a spline or is undefined. */ + FCDGeometryMesh* GetMesh() { return mesh; } + const FCDGeometryMesh* GetMesh() const { return mesh; } /**< See above. */ + + /** Sets the type of this geometry to mesh and creates an empty mesh structure. + This function will release any mesh or spline structure that the geometry may already contain + @return The mesh information structure. This pointer will always be valid. */ + FCDGeometryMesh* CreateMesh(); + + /** Retrieves whether the type of this geometry is a spline. + @return Whether this geometry is a spline. */ + bool IsSpline() const { return spline != NULL; } + + /** Retrieves the spline information structure for this geometry. + Verify that this geometry is a spline using the IsSpline function prior to calling this function. + @return The spline information structure. This pointer will be NULL when the geometry is a mesh or is undefined. */ + FCDGeometrySpline* GetSpline() { return spline; } + const FCDGeometrySpline* GetSpline() const { return spline; } /**< See above. */ + + /** Sets the type of this geometry to spline and creates an empty spline structure. + This function will release any mesh or spline structure that the geometry may already contain. + @return The spline information structure. This pointer will always be valid. */ + FCDGeometrySpline* CreateSpline(); + + + /** Retrieves whether the type of this geometry is a parameterized surface. + @return Whether this geometry is a parameterized surface. */ + bool IsPSurface() const { return false; } + + /** Copies the geometry entity into a clone. + The clone may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new geometry entity + will be created and you will need to release the returned pointer manually. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; +}; + +#endif // _FCD_GEOMETRY_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometry.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryMesh.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryMesh.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryMesh.h (revision 24247) @@ -1,298 +1,298 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDGeometryMesh.h - This file contains the FCDGeometryMesh class. -*/ - -#ifndef _FCD_GEOMETRY_MESH_H_ -#define _FCD_GEOMETRY_MESH_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ - -class FCDocument; -class FCDGeometry; -class FCDGeometryPolygons; -class FCDGeometrySource; - -typedef fm::pvector FCDGeometrySourceList; /**< A dynamically-sized array of FCDGeometrySource objects. */ -typedef fm::pvector FCDGeometrySourceConstList; /**< A dynamically-sized array of FCDGeometrySource constant objects. */ -typedef fm::pvector FCDGeometryPolygonsList; /**< A dynamically-sized array of geometry polygon sets. */ - -/** - A COLLADA geometric mesh. - A COLLADA geometric mesh is a list of vertices tied together in polygons. - A set of per-vertex data is used to determine the vertices of the mesh. - This data usually includes a single list: of vertex positions, but it may also - contain per-vertex colors, per-vertex normals or per-vertex texture coordinates. - The other data sources declare per-vertex-face data. - - The faces of a mesh may be split across different groups, as they may have - different materials assigned to them. The FCDGeometryPolygons objects contains one such group - of faces. - - @ingroup FCDGeometry -*/ -class FCOLLADA_EXPORT FCDGeometryMesh : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - FCDGeometry* parent; - DeclareParameterContainer(FCDGeometrySource, sources, FC("Data Sources")); - DeclareParameterContainer(FCDGeometryPolygons, polygons, FC("Polygons Sets")); - - DeclareParameterTrackList(FCDGeometrySource, vertexSources, FC("Vertex Sources")); - size_t faceCount, holeCount; - size_t faceVertexCount; - - bool isConvex; //determines if the mesh is defined as a - bool convexify; //determines if the mesh needs to be turned into a convex mesh - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, convexHullOf, FC("Convex Hull of")); - -public: - /** Contructor: do not use directly. Use FCDGeometry::AddMesh instead. - @param document The COLLADA document which owns this mesh. - @param parent The geometry entity which contains this mesh. */ - FCDGeometryMesh(FCDocument* document, FCDGeometry* parent); - - /** Destructor. */ - virtual ~FCDGeometryMesh(); - - /** [INTERNAL] Links a convex mesh to its source geometry (in convexHullOf). - The geometry's mesh is copied into the current one and convexified. - This function is used at the end of the import of a document to verify that the - geometry was found. - @return The status of the linkage. */ - bool Link(); - - /** Retrieve the parent of this geometric spline: the geometry entity. - @return The geometry entity that this spline belongs to. */ - FCDGeometry* GetParent() { return parent; } - const FCDGeometry* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the number of faces within the geometric mesh. - @return The number of faces within the geometric mesh. */ - inline size_t GetFaceCount() const { return faceCount; } - - /** Retrieves the number of holes within the faces of the geometric mesh. - As one face may contain multiple holes, this value may be larger than the number of faces. - @return The number of holes within the faces of the geometric mesh. */ - inline size_t GetHoleCount() const { return holeCount; } - - /** Retrieves the total number of per-face vertices in the mesh. - This function makes no assumption about the uniqueness of the per-face vertices. - @return The total number of per-face vertices in the mesh. */ - inline size_t GetFaceVertexCount() const { return faceVertexCount; } - - /** Retrieves whether the mesh is defined as convex or not. - @return Whether the mesh is defined as convex. */ - inline bool IsConvex() const { return isConvex; } - - /** Sets whether the mesh should be defined as convex. - @param _isConvex Whether the mesh is convex. */ - inline void SetConvex(bool _isConvex) { isConvex = _isConvex; SetDirtyFlag(); } - - /** Retrieves the attribute determining if the mesh needs to be made convex. - @return The flag determining if the mesh needs to be made convex. */ - inline bool GetConvexify() const { return convexify; } - - /** Raise a flag that the mesh needs to be made convex and the host application should - take care of it. In the future, we could compute ourselves the convex hull of the mesh. - A good algorithm could be the "Quickhull". - @param _convexify Whether the mesh needs to be made convex. */ - inline void SetConvexify(bool _convexify) { convexify = _convexify; SetDirtyFlag();} - - /** Retrieves the name of the concave mesh we need to convexify. - @return The name of the geometry containing the mesh to convexify. */ - const fm::string& GetConvexHullOf() const {return convexHullOf;} - - /** Retrieves the convex hull of this mesh. - @return The convex hull geometry created using this mesh. This pointer will be - NULL if no convex hull was created using this mesh. */ - inline FCDGeometryMesh* FindConvexHullOfMesh() { return const_cast(const_cast(this)->FindConvexHullOfMesh()); } - const FCDGeometryMesh* FindConvexHullOfMesh() const; /**< See above. */ - - /** Sets the name of the geometry of which this mesh is the convex hull of. - @param _geom The geometry of which this mesh is the convex hull of.*/ - void SetConvexHullOf(FCDGeometry* _geom); - - /** [INTERNAL] Set the convec hull name directly. - @param id The name id. - */ - void SetConvexHullOf(const fm::string& id){ convexHullOf = id; } - - /** Retrieves the COLLADA id of the mesh. - This is a shortcut to the parent geometry's COLLADA id. - @return The COLLADA id of the mesh. */ - const fm::string& GetDaeId() const; - - /** Retrieves the number of independent polygon groups. - Each polygon group is represented within a FCDGeometryPolygons object. - An independent polygon group is usually created to assign a different material to different parts of the mesh - or to assign partial texture coordinates and texture tangents to different parts of the mesh. - @return The number of independent polygon groups. */ - inline size_t GetPolygonsCount() const { return polygons.size(); } - - /** Retrieves a specific polygon group. - Each polygon group is represented within a FCDGeometryPolygons object. - An independent polygon group is usually created to assign a different material to different parts of the mesh - or to assign partial texture coordinates and texture tangents to different parts of the mesh. - @param index The index of the polygon group. This index should be less than the number - of independent polygon groups returned by the GetPolygonsCount function. - @return The polygon group. This pointer will be NULL if the index is out-of-bounds. */ - inline FCDGeometryPolygons* GetPolygons(size_t index) { FUAssert(index < GetPolygonsCount(), return NULL); return polygons.at(index); } - inline const FCDGeometryPolygons* GetPolygons(size_t index) const { FUAssert(index < GetPolygonsCount(), return NULL); return polygons.at(index); } /**< See above. */ - - /** Creates a new polygon group. - Each polygon group is represented within a FCDGeometryPolygons object. - The new polygon group will be assigned all the existing per-vertex data sources. - No material will be assigned to the new polygon group. - @return The new polygon group. This pointer should never be NULL. */ - FCDGeometryPolygons* AddPolygons(); - - /** Retrieves if the mesh consists of only triangles. - @return The boolean value. */ - bool IsTriangles() const; - - /** Retrieves the polygons sets which use the given material semantic. - Useful when processing material instances. - @param semantic The material semantic to find. - @param sets A list of polygon sets to fill in. - This list is not cleared. */ - void FindPolygonsByMaterial(const fstring& semantic, FCDGeometryPolygonsList& sets); - - /** Retrieves the list of per-vertex data sources. - There should usually be one per-vertex data source that contains positions. - All the sources within this list are also present within the data source list. - @return The list of per-vertex data sources. */ - DEPRECATED(3.05A, GetVertexSourceCount and GetVertexSource(index)) void GetVertexSources() const {} - - /** Retrieves the number of per-vertex data sources. - This number should always be lesser or equal to the number of data sources, as each per-vertex - data source is also included within the list of data sources. - @return The number of per-vertex data sources. */ - inline size_t GetVertexSourceCount() const { return vertexSources.size(); } - - /** Retrieves a specific per-vertex data source. - All the per-vertex data sources are also included in the list of data sources. - @param index The index of the per-vertex data source. This index should be less than the number of - per-vertex data sources returns by the GetVertexSourceCount function. - @return The per-vertex data source. This pointer will be NULL if the index is out-of-bounds. */ - inline FCDGeometrySource* GetVertexSource(size_t index) { FUAssert(index < GetVertexSourceCount(), return NULL); return vertexSources.at(index); } - inline const FCDGeometrySource* GetVertexSource(size_t index) const { FUAssert(index < GetVertexSourceCount(), return NULL); return vertexSources.at(index); } /**< See above. */ - - /** Creates a new per-vertex data source for this geometric mesh. - The per-vertex data source will be added to both the per-vertex data source list and the data source list. - The new per-vertex data source will automatically be added to all the existing polygon groups. - @param type The type of data that will be contained within the source. - Defaults to UNKNOWN, so that you may provide the source type later. - @return The new per-vertex data source. This pointer should never be NULL. */ - FCDGeometrySource* AddVertexSource(FUDaeGeometryInput::Semantic type = FUDaeGeometryInput::UNKNOWN); - - /** Sets a source as per-vertex data. - @param source A source that will now contain per-vertex data. */ - void AddVertexSource(FCDGeometrySource* source); - - /** Transforms a source of per-vertex data into a source of per-vertex-face data. - Note: the offsets of the inputs is not changed and no data is released. - @param source A source that will now contain per-vertex data. */ - void RemoveVertexSource(FCDGeometrySource* source); - - /** Retrieves whether a given geometry source is a per-vertex source of this mesh. - @param source A source contained within this mesh. - @return Whether the source is a per-vertex source of the mesh. */ - inline bool IsVertexSource(const FCDGeometrySource* source) const { return vertexSources.contains(const_cast(source)); } - - /** [INTERNAL] Retrieves the data source that matches the given COLLADA id. - @param id A valid COLLADA id. - @return The data source. This pointer will be NULL if no matching data source was found. */ - FCDGeometrySource* FindSourceById(const fm::string& id) { return const_cast(const_cast(this)->FindSourceById(id)); } - const FCDGeometrySource* FindSourceById(const fm::string& id) const; /**< See above. */ - - /** Retrieves the first data source that matches the given geometry data type. - @param type A geometry data type. - @return The first data source that matches the data type. This pointer will be NULL - if no matching data source was found. */ - FCDGeometrySource* FindSourceByType(FUDaeGeometryInput::Semantic type) { return const_cast(const_cast(this)->FindSourceByType(type)); } - const FCDGeometrySource* FindSourceByType(FUDaeGeometryInput::Semantic type) const; /**< See above. */ - - /** Retrieves the first data source that matches the given name. - @param name A valid COLLADA name. - @return The first data source that matches the name. This pointer will be NULL - if no matching data source was found. */ - FCDGeometrySource* FindSourceByName(const fstring& name) { return const_cast(const_cast(this)->FindSourceByName(name)); } - const FCDGeometrySource* FindSourceByName(const fstring& name) const; /**< See above. */ - - /** Retrieves the list of data sources that matches the given geometry data type. - @param type A geometry data type. - @param sources A list of data sources to fill in with the matching data sources. - This list is not cleared and no check for uniqueness is done. */ - void FindSourcesByType(FUDaeGeometryInput::Semantic type, FCDGeometrySourceList& sources) { FindSourcesByType(type, *(FCDGeometrySourceConstList*) &sources); } - void FindSourcesByType(FUDaeGeometryInput::Semantic type, FCDGeometrySourceConstList& sources) const; /**< See above. */ - - /** Retrieves the per-vertex data that specifically contains the vertex positions. - If there are more than one per-vertex data source that contains vertex positions, the first one is returned. - @deprecated Use FindSourceByType instead. - @return A per-vertex data source that contains vertex positions. This pointer will be NULL - in the unlikely possibility that there are no per-vertex data source that contains vertex positions. */ - FCDGeometrySource* GetPositionSource() { return FindSourceByType(FUDaeGeometryInput::POSITION); } - const FCDGeometrySource* GetPositionSource() const { return FindSourceByType(FUDaeGeometryInput::POSITION); } /**< See above. */ - - /** Retrieves the list of all data sources. - Some of the sources within this list are also present within the vertex data source list. - @return The list of all data sources. */ - DEPRECATED(3.05A, GetSourceCount and GetSource(index)) void GetSources() const {} - - /** Retrieves the number of data sources contained within this geometric mesh. - @return The number of data sources within the mesh. */ - inline size_t GetSourceCount() const { return sources.size(); } - - /** Retrieves a specific data source. - @param index The index of the data source. This index should be less than the number of - data sources returns by the GetSourceCount function. - @return The data source. This pointer will be NULL if the index is out-of-bounds. */ - inline FCDGeometrySource* GetSource(size_t index) { FUAssert(index < GetSourceCount(), return NULL); return sources.at(index); } - inline const FCDGeometrySource* GetSource(size_t index) const { FUAssert(index < GetSourceCount(), return NULL); return sources.at(index); } /**< See above. */ - - /** Creates a new data source for this geometric mesh. - The new data source will not be added to any of the existing polygon groups. - @param type The type of data that will be contained within the source. - Defaults to UNKNOWN, so that you may provide the source type later. - @return The new per-vertex data source. This pointer should never be NULL. */ - FCDGeometrySource* AddSource(FUDaeGeometryInput::Semantic type = FUDaeGeometryInput::UNKNOWN); - - /** Copies the mesh into a clone. - The clone may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new mesh - will be created and you will need to release the returned pointer manually. - @return The clone. */ - FCDGeometryMesh* Clone(FCDGeometryMesh* clone = NULL) const; - - /** [INTERNAL] Forces the recalculation of the hole count, vertex count, face-vertex counts and their offsets. - Since the counts and offsets are buffered at the geometric mesh object level, this function allows the polygon - groups to force the recalculation of the buffered values, when they are modified. */ - void Recalculate(); -}; - -#endif // _FCD_GEOMETRY_MESH_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDGeometryMesh.h + This file contains the FCDGeometryMesh class. +*/ + +#ifndef _FCD_GEOMETRY_MESH_H_ +#define _FCD_GEOMETRY_MESH_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ + +class FCDocument; +class FCDGeometry; +class FCDGeometryPolygons; +class FCDGeometrySource; + +typedef fm::pvector FCDGeometrySourceList; /**< A dynamically-sized array of FCDGeometrySource objects. */ +typedef fm::pvector FCDGeometrySourceConstList; /**< A dynamically-sized array of FCDGeometrySource constant objects. */ +typedef fm::pvector FCDGeometryPolygonsList; /**< A dynamically-sized array of geometry polygon sets. */ + +/** + A COLLADA geometric mesh. + A COLLADA geometric mesh is a list of vertices tied together in polygons. + A set of per-vertex data is used to determine the vertices of the mesh. + This data usually includes a single list: of vertex positions, but it may also + contain per-vertex colors, per-vertex normals or per-vertex texture coordinates. + The other data sources declare per-vertex-face data. + + The faces of a mesh may be split across different groups, as they may have + different materials assigned to them. The FCDGeometryPolygons objects contains one such group + of faces. + + @ingroup FCDGeometry +*/ +class FCOLLADA_EXPORT FCDGeometryMesh : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + FCDGeometry* parent; + DeclareParameterContainer(FCDGeometrySource, sources, FC("Data Sources")); + DeclareParameterContainer(FCDGeometryPolygons, polygons, FC("Polygons Sets")); + + DeclareParameterTrackList(FCDGeometrySource, vertexSources, FC("Vertex Sources")); + size_t faceCount, holeCount; + size_t faceVertexCount; + + bool isConvex; //determines if the mesh is defined as a + bool convexify; //determines if the mesh needs to be turned into a convex mesh + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, convexHullOf, FC("Convex Hull of")); + +public: + /** Contructor: do not use directly. Use FCDGeometry::AddMesh instead. + @param document The COLLADA document which owns this mesh. + @param parent The geometry entity which contains this mesh. */ + FCDGeometryMesh(FCDocument* document, FCDGeometry* parent); + + /** Destructor. */ + virtual ~FCDGeometryMesh(); + + /** [INTERNAL] Links a convex mesh to its source geometry (in convexHullOf). + The geometry's mesh is copied into the current one and convexified. + This function is used at the end of the import of a document to verify that the + geometry was found. + @return The status of the linkage. */ + bool Link(); + + /** Retrieve the parent of this geometric spline: the geometry entity. + @return The geometry entity that this spline belongs to. */ + FCDGeometry* GetParent() { return parent; } + const FCDGeometry* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the number of faces within the geometric mesh. + @return The number of faces within the geometric mesh. */ + inline size_t GetFaceCount() const { return faceCount; } + + /** Retrieves the number of holes within the faces of the geometric mesh. + As one face may contain multiple holes, this value may be larger than the number of faces. + @return The number of holes within the faces of the geometric mesh. */ + inline size_t GetHoleCount() const { return holeCount; } + + /** Retrieves the total number of per-face vertices in the mesh. + This function makes no assumption about the uniqueness of the per-face vertices. + @return The total number of per-face vertices in the mesh. */ + inline size_t GetFaceVertexCount() const { return faceVertexCount; } + + /** Retrieves whether the mesh is defined as convex or not. + @return Whether the mesh is defined as convex. */ + inline bool IsConvex() const { return isConvex; } + + /** Sets whether the mesh should be defined as convex. + @param _isConvex Whether the mesh is convex. */ + inline void SetConvex(bool _isConvex) { isConvex = _isConvex; SetDirtyFlag(); } + + /** Retrieves the attribute determining if the mesh needs to be made convex. + @return The flag determining if the mesh needs to be made convex. */ + inline bool GetConvexify() const { return convexify; } + + /** Raise a flag that the mesh needs to be made convex and the host application should + take care of it. In the future, we could compute ourselves the convex hull of the mesh. + A good algorithm could be the "Quickhull". + @param _convexify Whether the mesh needs to be made convex. */ + inline void SetConvexify(bool _convexify) { convexify = _convexify; SetDirtyFlag();} + + /** Retrieves the name of the concave mesh we need to convexify. + @return The name of the geometry containing the mesh to convexify. */ + const fm::string& GetConvexHullOf() const {return convexHullOf;} + + /** Retrieves the convex hull of this mesh. + @return The convex hull geometry created using this mesh. This pointer will be + NULL if no convex hull was created using this mesh. */ + inline FCDGeometryMesh* FindConvexHullOfMesh() { return const_cast(const_cast(this)->FindConvexHullOfMesh()); } + const FCDGeometryMesh* FindConvexHullOfMesh() const; /**< See above. */ + + /** Sets the name of the geometry of which this mesh is the convex hull of. + @param _geom The geometry of which this mesh is the convex hull of.*/ + void SetConvexHullOf(FCDGeometry* _geom); + + /** [INTERNAL] Set the convec hull name directly. + @param id The name id. + */ + void SetConvexHullOf(const fm::string& id){ convexHullOf = id; } + + /** Retrieves the COLLADA id of the mesh. + This is a shortcut to the parent geometry's COLLADA id. + @return The COLLADA id of the mesh. */ + const fm::string& GetDaeId() const; + + /** Retrieves the number of independent polygon groups. + Each polygon group is represented within a FCDGeometryPolygons object. + An independent polygon group is usually created to assign a different material to different parts of the mesh + or to assign partial texture coordinates and texture tangents to different parts of the mesh. + @return The number of independent polygon groups. */ + inline size_t GetPolygonsCount() const { return polygons.size(); } + + /** Retrieves a specific polygon group. + Each polygon group is represented within a FCDGeometryPolygons object. + An independent polygon group is usually created to assign a different material to different parts of the mesh + or to assign partial texture coordinates and texture tangents to different parts of the mesh. + @param index The index of the polygon group. This index should be less than the number + of independent polygon groups returned by the GetPolygonsCount function. + @return The polygon group. This pointer will be NULL if the index is out-of-bounds. */ + inline FCDGeometryPolygons* GetPolygons(size_t index) { FUAssert(index < GetPolygonsCount(), return NULL); return polygons.at(index); } + inline const FCDGeometryPolygons* GetPolygons(size_t index) const { FUAssert(index < GetPolygonsCount(), return NULL); return polygons.at(index); } /**< See above. */ + + /** Creates a new polygon group. + Each polygon group is represented within a FCDGeometryPolygons object. + The new polygon group will be assigned all the existing per-vertex data sources. + No material will be assigned to the new polygon group. + @return The new polygon group. This pointer should never be NULL. */ + FCDGeometryPolygons* AddPolygons(); + + /** Retrieves if the mesh consists of only triangles. + @return The boolean value. */ + bool IsTriangles() const; + + /** Retrieves the polygons sets which use the given material semantic. + Useful when processing material instances. + @param semantic The material semantic to find. + @param sets A list of polygon sets to fill in. + This list is not cleared. */ + void FindPolygonsByMaterial(const fstring& semantic, FCDGeometryPolygonsList& sets); + + /** Retrieves the list of per-vertex data sources. + There should usually be one per-vertex data source that contains positions. + All the sources within this list are also present within the data source list. + @return The list of per-vertex data sources. */ + DEPRECATED(3.05A, GetVertexSourceCount and GetVertexSource(index)) void GetVertexSources() const {} + + /** Retrieves the number of per-vertex data sources. + This number should always be lesser or equal to the number of data sources, as each per-vertex + data source is also included within the list of data sources. + @return The number of per-vertex data sources. */ + inline size_t GetVertexSourceCount() const { return vertexSources.size(); } + + /** Retrieves a specific per-vertex data source. + All the per-vertex data sources are also included in the list of data sources. + @param index The index of the per-vertex data source. This index should be less than the number of + per-vertex data sources returns by the GetVertexSourceCount function. + @return The per-vertex data source. This pointer will be NULL if the index is out-of-bounds. */ + inline FCDGeometrySource* GetVertexSource(size_t index) { FUAssert(index < GetVertexSourceCount(), return NULL); return vertexSources.at(index); } + inline const FCDGeometrySource* GetVertexSource(size_t index) const { FUAssert(index < GetVertexSourceCount(), return NULL); return vertexSources.at(index); } /**< See above. */ + + /** Creates a new per-vertex data source for this geometric mesh. + The per-vertex data source will be added to both the per-vertex data source list and the data source list. + The new per-vertex data source will automatically be added to all the existing polygon groups. + @param type The type of data that will be contained within the source. + Defaults to UNKNOWN, so that you may provide the source type later. + @return The new per-vertex data source. This pointer should never be NULL. */ + FCDGeometrySource* AddVertexSource(FUDaeGeometryInput::Semantic type = FUDaeGeometryInput::UNKNOWN); + + /** Sets a source as per-vertex data. + @param source A source that will now contain per-vertex data. */ + void AddVertexSource(FCDGeometrySource* source); + + /** Transforms a source of per-vertex data into a source of per-vertex-face data. + Note: the offsets of the inputs is not changed and no data is released. + @param source A source that will now contain per-vertex data. */ + void RemoveVertexSource(FCDGeometrySource* source); + + /** Retrieves whether a given geometry source is a per-vertex source of this mesh. + @param source A source contained within this mesh. + @return Whether the source is a per-vertex source of the mesh. */ + inline bool IsVertexSource(const FCDGeometrySource* source) const { return vertexSources.contains(const_cast(source)); } + + /** [INTERNAL] Retrieves the data source that matches the given COLLADA id. + @param id A valid COLLADA id. + @return The data source. This pointer will be NULL if no matching data source was found. */ + FCDGeometrySource* FindSourceById(const fm::string& id) { return const_cast(const_cast(this)->FindSourceById(id)); } + const FCDGeometrySource* FindSourceById(const fm::string& id) const; /**< See above. */ + + /** Retrieves the first data source that matches the given geometry data type. + @param type A geometry data type. + @return The first data source that matches the data type. This pointer will be NULL + if no matching data source was found. */ + FCDGeometrySource* FindSourceByType(FUDaeGeometryInput::Semantic type) { return const_cast(const_cast(this)->FindSourceByType(type)); } + const FCDGeometrySource* FindSourceByType(FUDaeGeometryInput::Semantic type) const; /**< See above. */ + + /** Retrieves the first data source that matches the given name. + @param name A valid COLLADA name. + @return The first data source that matches the name. This pointer will be NULL + if no matching data source was found. */ + FCDGeometrySource* FindSourceByName(const fstring& name) { return const_cast(const_cast(this)->FindSourceByName(name)); } + const FCDGeometrySource* FindSourceByName(const fstring& name) const; /**< See above. */ + + /** Retrieves the list of data sources that matches the given geometry data type. + @param type A geometry data type. + @param sources A list of data sources to fill in with the matching data sources. + This list is not cleared and no check for uniqueness is done. */ + void FindSourcesByType(FUDaeGeometryInput::Semantic type, FCDGeometrySourceList& sources) { FindSourcesByType(type, *(FCDGeometrySourceConstList*) &sources); } + void FindSourcesByType(FUDaeGeometryInput::Semantic type, FCDGeometrySourceConstList& sources) const; /**< See above. */ + + /** Retrieves the per-vertex data that specifically contains the vertex positions. + If there are more than one per-vertex data source that contains vertex positions, the first one is returned. + @deprecated Use FindSourceByType instead. + @return A per-vertex data source that contains vertex positions. This pointer will be NULL + in the unlikely possibility that there are no per-vertex data source that contains vertex positions. */ + FCDGeometrySource* GetPositionSource() { return FindSourceByType(FUDaeGeometryInput::POSITION); } + const FCDGeometrySource* GetPositionSource() const { return FindSourceByType(FUDaeGeometryInput::POSITION); } /**< See above. */ + + /** Retrieves the list of all data sources. + Some of the sources within this list are also present within the vertex data source list. + @return The list of all data sources. */ + DEPRECATED(3.05A, GetSourceCount and GetSource(index)) void GetSources() const {} + + /** Retrieves the number of data sources contained within this geometric mesh. + @return The number of data sources within the mesh. */ + inline size_t GetSourceCount() const { return sources.size(); } + + /** Retrieves a specific data source. + @param index The index of the data source. This index should be less than the number of + data sources returns by the GetSourceCount function. + @return The data source. This pointer will be NULL if the index is out-of-bounds. */ + inline FCDGeometrySource* GetSource(size_t index) { FUAssert(index < GetSourceCount(), return NULL); return sources.at(index); } + inline const FCDGeometrySource* GetSource(size_t index) const { FUAssert(index < GetSourceCount(), return NULL); return sources.at(index); } /**< See above. */ + + /** Creates a new data source for this geometric mesh. + The new data source will not be added to any of the existing polygon groups. + @param type The type of data that will be contained within the source. + Defaults to UNKNOWN, so that you may provide the source type later. + @return The new per-vertex data source. This pointer should never be NULL. */ + FCDGeometrySource* AddSource(FUDaeGeometryInput::Semantic type = FUDaeGeometryInput::UNKNOWN); + + /** Copies the mesh into a clone. + The clone may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new mesh + will be created and you will need to release the returned pointer manually. + @return The clone. */ + FCDGeometryMesh* Clone(FCDGeometryMesh* clone = NULL) const; + + /** [INTERNAL] Forces the recalculation of the hole count, vertex count, face-vertex counts and their offsets. + Since the counts and offsets are buffered at the geometric mesh object level, this function allows the polygon + groups to force the recalculation of the buffered values, when they are modified. */ + void Recalculate(); +}; + +#endif // _FCD_GEOMETRY_MESH_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryMesh.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygons.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygons.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygons.h (revision 24247) @@ -1,364 +1,364 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDGeometryPolygons.h - This file defines the FCDGeometryPolygons class. -*/ - -#ifndef _FCD_GEOMETRY_POLYGONS_H_ -#define _FCD_GEOMETRY_POLYGONS_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -class FCDocument; -class FCDExtra; -class FCDMaterial; -class FCDGeometryMesh; -class FCDGeometrySource; -class FCDGeometryPolygonsInput; - -typedef fm::pvector FCDGeometryPolygonsInputList; /**< A dynamically-sized array of FCDGeometryPolygonsInput objects. */ -typedef fm::pvector FCDGeometryPolygonsInputConstList; /**< A dynamically-sized array of FCDGeometryPolygonsInput objects. */ -typedef fm::map FCDGeometrySourceCloneMap; /**< A map of old FCDGeometrySource objects to newly cloned FCDGeometrySource objects. */ - -/** - A mesh polygon set. - Each polygon set contains a list of inputs and the tessellation information - to make polygons out of the data and indices of the input. FCollada - supports triangle lists as well as polygon lists and lists of polygons with holes. - This implies that each face has an undeterminate number of vertices. - The tessellation information creates polygons, but may also creates holes within the polygons. - - @ingroup FCDGeometry -*/ -class FCOLLADA_EXPORT FCDGeometryPolygons : public FCDObject -{ -public: - /** The types of primitives. */ - enum PrimitiveType - { - LINES, /**< A list of lines. Only one element is contained in the face-vertex count list. - It represents the total number of line vertices. The total number of lines is - equal to half the total number of line vertices. */ - LINE_STRIPS, /**< A list of continuous lines. Each element in the face-vertex count list - represents the number of consecutive line vertices before restarting. */ - POLYGONS, /**< A list of polygons. All the polygons may be triangles. - This is the most common primitive type. The polygons may have holes. Each element in the - face-vertex count list represent the number of vertices for one polygon. */ - TRIANGLE_FANS, /**< A list of triangle fans. Each element in the face-vertex count list - represents the number of vertices for one fan. A triangle fan is defined by re-using the first - vertex for every triangle. Advancing pairs are then used in order to generate adjacent triangles - such that if there are 5 vertices, then 3 triangles are created: {0,1,2}, {0,2,3} and {0,3,4}. */ - TRIANGLE_STRIPS, /**< A list of continuous triangles. Each element in the face-vertex count list - represents the number of vertices for one strip. A triangle strip is defined by re-using two - advancing vertices from the previous triangle for the next triangle. If there are 5 vertices in - the strip, then 3 triangles are created: {0,1,2}, {1,2,3}, {2,3,4}. Note that vertex winding must - also be taken into consideration and every even triangle in the strip has its vertices swapped - from the above pattern. */ - POINTS /**< A list of Camera-facing sprites. The face-vertex count list will contain one element that - represents the total number of points. Two non-COLLADA geometry sources (POINT_SIZE and POINT_ROTATION) - are specific to this type. */ - }; - -private: - DeclareObjectType(FCDObject); - - FCDGeometryMesh* parent; - DeclareParameterContainer(FCDGeometryPolygonsInput, inputs, FC("Data Inputs")); - DeclareParameterList(UInt32, faceVertexCounts, FC("Per-face Vertex counts")); - DeclareParameterList(UInt32, holeFaces, FC("Hole face indices")); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, primitiveType, FC("Primitive Type")); // PrimitiveType - - // Buffered statistics - size_t faceVertexCount; - size_t faceOffset; - size_t faceVertexOffset; - size_t holeOffset; - - // Material for this set of polygons - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, materialSemantic, FC("Material Semantic")); - - // Extra information tree - DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); - -public: - /** Constructor: do not use directly. Instead, use the FCDGeometryMesh::AddPolygons function - to create new polygon sets. - @param document The COLLADA document which owns this polygon set. - @param parent The geometric mesh which contains this polygon set.*/ - FCDGeometryPolygons(FCDocument* document, FCDGeometryMesh* parent); - - /** Destructor. */ - virtual ~FCDGeometryPolygons(); - - /** Retrieves the geometry that contains this polygons. - @return The parent geometry. */ - inline FCDGeometryMesh* GetParent() { return parent; } - inline const FCDGeometryMesh* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the extra information tree for this entity instance. The - prefered way to save extra information in FCollada is at the entity - level. Use this extra information tree to store any information you - want exported and imported back. - @return The extra information tree. */ - FCDExtra* GetExtra(); - inline const FCDExtra* GetExtra() const { return const_cast(this)->GetExtra(); } /**< See above. */ - - /** Retrieves the primitive type for this polygons set. - @return The primitive type. */ - inline PrimitiveType GetPrimitiveType() const { return (PrimitiveType) *primitiveType; } - - /** Sets the primitive type for this polygons set. - Important note: no attempt is made at fixing up the indices. You should - only do this operation of empty polygons set. - @param type The new primitive type. */ - inline void SetPrimitiveType(PrimitiveType type) { primitiveType = type; SetDirtyFlag(); } - - /** Retrieves the list of face-vertex counts. Each face within the polygon set - has one or more entry within this list, depending on the number of holes within that face. - Each face-vertex count indicates the number of ordered indices - within the polygon set inputs that are used to generate a face or its holes. - To find out if a face-vertex count represents a face or its holes, check - the hole-faces list retrieved using the GetHoleFaces function. - Indirectly, the face-vertex count indicates the degree of the polygon. - @see GetHoleFaces @see GetHoleCount - @return The list of face-vertex counts.*/ - inline const uint32* GetFaceVertexCounts() const { return faceVertexCounts.begin(); } /**< See above. */ - - /** Adds a new count to the face-vertex count list. - This function only modifies the face-vertex count list. - To also add indices to the inputs for the new face, use the AddFace function. - @param count The number of vertices in the new face. */ - void AddFaceVertexCount(uint32 count); - - /** Retrieves the number of face-vertex counts within the polygon set. - This value also represents the total the number of faces and holes within the polygon set. - @return The number of face-vertex counts within the polygon set. */ - inline size_t GetFaceVertexCountCount() const { return faceVertexCounts.size(); } - - /** Sets the number of face-vertex counts within the polygon set. - Any additional face-vertex count will not be initialized and - any removed face-vertex count will not remove the equivalent - indices within the polygon set inputs. - @param count The new number of face-vertex counts within the polygon set. */ - void SetFaceVertexCountCount(size_t count); - - /** [DEPRECATED] - Retrieves if the polygons is a list of polygons (returns false), or a list of triangles - (returns true). - @return The boolean answer. */ - DEPRECATED(3.05, TestPolyType) bool IsTriangles() const; - - /** Tests if the polygon can be aproximated with a constant face count - Returns: 3 if all faces are triangles, 4 if all faces are triangles, else -1 */ - int32 TestPolyType() const; - - /** Retrieves the number of holes within the faces of the polygon set. - @return The number of holes within the faces of the polygon set. */ - inline size_t GetHoleCount() const { return holeFaces.size(); } - - /** Retrieves the number of faces within the polygon set. - @return The number of faces within the polygon set. */ - inline size_t GetFaceCount() const { return faceVertexCounts.size() - GetHoleCount(); } - - /** Retrieves the number of faces which appear before this polygon set within the geometric mesh. - This value is useful when traversing all the faces of a geometric mesh. - @return The number of faces in previous polygon sets. */ - inline size_t GetFaceOffset() const { return faceOffset; } - - /** Retrieves the total number of face-vertex pairs within the polygon set. - This value is the total of all the values within the face-vertex count list. - Do remember that the list of face-vertex pairs includes holes. - @return The total number of face-vertex pairs within the polygon set. */ - inline size_t GetFaceVertexCount() const { return faceVertexCount; } - - /** Retrieves the number of face-vertex pairs for a given face. - This value includes face-vertex pairs that create the polygon and its holes. - @param index A face index. - @return The number of face-vertex pairs for a given face. */ - size_t GetFaceVertexCount(size_t index) const; - - /** Retrieves the total number of face-vertex pairs which appear - before this polygon set within the geometric mesh. - This value is useful when traversing all the face-vertex pairs of a geometric mesh. - @return The number of face-vertex pairs in previous polygon sets. */ - inline size_t GetFaceVertexOffset() const { return faceVertexOffset; } - - /** Retrieves the number of holes which appear before this polygon set. - This value is useful when traversing all the face-vertex pairs of a geometric mesh. */ - inline size_t GetHoleOffset() const { return holeOffset; } - - /** Retrieves the number of face-vertex pairs which appear - before a given face within the polygon set. - This value is useful when doing per-vertex mesh operations within the polygon set. - @param index The index of the face. - @return The number of face-vertex pairs before the given face, within the polygon set. */ - size_t GetFaceVertexOffset(size_t index) const; - - /** [INTERNAL] Sets the number of faces in previous polygon sets. - Used by the FCDGeometryMesh::Recalculate function. - @param offset The number of faces in previous polygon sets. */ - inline void SetFaceOffset(size_t offset) { faceOffset = offset; SetDirtyFlag(); } - - /** [INTERNAL] Sets the number of face-vertex pairs in previous polygon sets. - Used by the FCDGeometryMesh::Recalculate function. - @param offset The number of face-vertex pairs in previous polygon sets. */ - inline void SetFaceVertexOffset(size_t offset) { faceVertexOffset = offset; SetDirtyFlag(); } - - /** [INTERNAL] Sets the number of holes in previous polygon sets. - Used by the FCDGeometryMesh::Recalculate function. - @param offset The number of holes in previous polygon sets. */ - inline void SetHoleOffset(size_t offset) { holeOffset = offset; SetDirtyFlag(); } - - /** Creates a new face. - Enough indices to fill the face will be added to the polygon set inputs: you will - want to overwrite those, as they will all be set to zero. - @param degree The degree of the polygon. This number implies the number of indices - that will be expected, in order, within each of the input index lists. */ - virtual void AddFace(uint32 degree); - - /** Removes a face. - @param index The index of the face to remove. All the indices associated - with this face will also be removed. */ - virtual void RemoveFace(size_t index); - - /** Retrieves the list of polygon set inputs. - @see FCDGeometryPolygonsInput - @return The list of polygon set inputs. */ - DEPRECATED(3.05A, GetInputCount and GetInput(index)) void GetInputs() {} - - /** Retrieves the number of polygon set inputs. - @return The number of polygon set inputs. */ - inline size_t GetInputCount() const { return inputs.size(); } - - /** Retrieves a specific polygon set input. - @param index The index of the polygon set input. This index should - not be greater than or equal to the number of polygon set inputs. - @return The specific polygon set input. This pointer will be NULL if the index is out-of-bounds. */ - inline FCDGeometryPolygonsInput* GetInput(size_t index) { FUAssert(index < GetInputCount(), return NULL); return inputs.at(index); } - inline const FCDGeometryPolygonsInput* GetInput(size_t index) const { FUAssert(index < GetInputCount(), return NULL); return inputs.at(index); } /**< See above. */ - - /** Creates a new polygon set input. - @param source The data source for the polygon set input. - @param offset The tessellation indices offset for the polygon set input. - If this value is new to the list of polygon inputs, you will need to fill in the indices. - Please use the FindIndices function to verify that the offset is new and that indices need - to be provided. The offset of zero is reserved for per-vertex data sources. - @return The new polygon set input. */ - FCDGeometryPolygonsInput* AddInput(FCDGeometrySource* source, uint32 offset); - - /** Retrieves the number of hole entries within the face-vertex count list. - @return The number of hole entries within the face-vertex count list. */ - inline size_t GetHoleFaceCount() const { return holeFaces.size(); } - - /** Sets the number of hole entries within the face-vertex count list. - Any additional hole entries will need to be initialized by the application. - Reducing the number of hole entries without taking special care to remove - these entries from the face-vertex count list will result in new, unwanted, faces. - @param count The number of hole entries within the face-vertex count list. */ - void SetHoleFaceCount(size_t count); - - /** Checks whether a given face-vertex count entries represents a hole. - @param index The index of the face-vertex count entry. - @return Whether this face-vertex count entry is a hole. */ - bool IsHoleFaceHole(size_t index); - - /** Retrieves the list of entries within the face-vertex count list - that are considered holes. COLLADA does not support holes within holes, - so each entry within this list implies a hole within the previous face. - @see GetFaceVertexCounts - @return The list of hole entries within the face-vertex counts. */ - inline const uint32* GetHoleFaces() const { return holeFaces.begin(); } /**< See above. */ - - /** Adds a new hole identifier. - The face-vertex count entry should already exist and the identifier will be place - in increasing order within the current list of entries within the face-vertex count list. - @param index The index of the hole within the face-vertex count list. */ - void AddHole(uint32 index); - - /** Retrieves the number of holes within faces of the polygon set that appear - before the given face index. This value is useful when trying to access - a specific face of a mesh, as holes and faces appear together within the - face-vertex degree list. - @param index A face index. - @return The number of holes within the polygon set that appear - before the given face index. */ - size_t GetHoleCountBefore(size_t index) const; - - /** Retrieves the number of holes within a given face. - @param index A face index. - @return The number of holes within the given face. */ - size_t GetHoleCount(size_t index) const; - - /** Retrieves the first polygon set input found that has the given data type. - @param semantic A type of geometry data. - @return The polygon set input. This pointer will be NULL if - no polygon set input matches the data type. */ - FCDGeometryPolygonsInput* FindInput(FUDaeGeometryInput::Semantic semantic) { return const_cast(const_cast(this)->FindInput(semantic)); } - const FCDGeometryPolygonsInput* FindInput(FUDaeGeometryInput::Semantic semantic) const; /**< See above. */ - - /** Retrieves the polygon set input that points towards a given data source. - @param source A geometry data source. - @return The polygon set input. This pointer will be NULL if - no polygon set input matches the data source. */ - FCDGeometryPolygonsInput* FindInput(const FCDGeometrySource* source) { return const_cast(const_cast(this)->FindInput(source)); } - const FCDGeometryPolygonsInput* FindInput(const FCDGeometrySource* source) const; /**< See above. */ - - /** [INTERNAL] Retrieves the polygon set input that points towards a given data source. - @param sourceId The COLLADA id of a geometry data source. - @return The polygon set input. This pointer will be NULL if - no polygon set input matches the COLLADA id. */ - FCDGeometryPolygonsInput* FindInput(const fm::string& sourceId); - - /** Retrieves all the polygon set inputs that have the given data type. - @param semantic A type of geometry data. - @param inputs A list of polygon set inputs to fill in. This list is not emptied by the function - and may remain untouched, if no polygon set input matches the given data type. */ - inline void FindInputs(FUDaeGeometryInput::Semantic semantic, FCDGeometryPolygonsInputList& inputs) { const_cast(this)->FindInputs(semantic, *(FCDGeometryPolygonsInputConstList*)&inputs); } - void FindInputs(FUDaeGeometryInput::Semantic semantic, FCDGeometryPolygonsInputConstList& inputs) const; /**< See above. */ - - /** Retrieves the symbolic name for the material used on this polygon set. - Match this symbolic name within a FCDGeometryInstance to get the - correct material instance. - @return A symbolic material name. */ - inline const fstring& GetMaterialSemantic() const { return materialSemantic; } - - /** Sets a symbolic name for the material used on this polygon set. - This symbolic name will be matched in the FCDMaterialInstance contained within - a FCDGeometryInstance to assign the correct material. - @param semantic The symbolic material name. */ - inline void SetMaterialSemantic(const fchar* semantic) { materialSemantic = semantic; SetDirtyFlag(); } - inline void SetMaterialSemantic(const fstring& semantic) { materialSemantic = semantic; SetDirtyFlag(); } /**< See above. */ - - /** [INTERNAL] Recalculates the buffered offset and count values for this polygon set. */ - virtual void Recalculate(); - - /** [INTERNAL] Creates a copy of this mesh. - You should use the FCDGeometry::Clone function instead of this function. - @param clone The clone polygon set. - @param cloneMap A match-map of the original geometry sources to the clone geometry sources for the mesh. - @return The clone polygon set. */ - virtual FCDGeometryPolygons* Clone(FCDGeometryPolygons* clone, const FCDGeometrySourceCloneMap& cloneMap) const; -}; - -#endif // _FCD_GEOMETRY_POLYGONS_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDGeometryPolygons.h + This file defines the FCDGeometryPolygons class. +*/ + +#ifndef _FCD_GEOMETRY_POLYGONS_H_ +#define _FCD_GEOMETRY_POLYGONS_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +class FCDocument; +class FCDExtra; +class FCDMaterial; +class FCDGeometryMesh; +class FCDGeometrySource; +class FCDGeometryPolygonsInput; + +typedef fm::pvector FCDGeometryPolygonsInputList; /**< A dynamically-sized array of FCDGeometryPolygonsInput objects. */ +typedef fm::pvector FCDGeometryPolygonsInputConstList; /**< A dynamically-sized array of FCDGeometryPolygonsInput objects. */ +typedef fm::map FCDGeometrySourceCloneMap; /**< A map of old FCDGeometrySource objects to newly cloned FCDGeometrySource objects. */ + +/** + A mesh polygon set. + Each polygon set contains a list of inputs and the tessellation information + to make polygons out of the data and indices of the input. FCollada + supports triangle lists as well as polygon lists and lists of polygons with holes. + This implies that each face has an undeterminate number of vertices. + The tessellation information creates polygons, but may also creates holes within the polygons. + + @ingroup FCDGeometry +*/ +class FCOLLADA_EXPORT FCDGeometryPolygons : public FCDObject +{ +public: + /** The types of primitives. */ + enum PrimitiveType + { + LINES, /**< A list of lines. Only one element is contained in the face-vertex count list. + It represents the total number of line vertices. The total number of lines is + equal to half the total number of line vertices. */ + LINE_STRIPS, /**< A list of continuous lines. Each element in the face-vertex count list + represents the number of consecutive line vertices before restarting. */ + POLYGONS, /**< A list of polygons. All the polygons may be triangles. + This is the most common primitive type. The polygons may have holes. Each element in the + face-vertex count list represent the number of vertices for one polygon. */ + TRIANGLE_FANS, /**< A list of triangle fans. Each element in the face-vertex count list + represents the number of vertices for one fan. A triangle fan is defined by re-using the first + vertex for every triangle. Advancing pairs are then used in order to generate adjacent triangles + such that if there are 5 vertices, then 3 triangles are created: {0,1,2}, {0,2,3} and {0,3,4}. */ + TRIANGLE_STRIPS, /**< A list of continuous triangles. Each element in the face-vertex count list + represents the number of vertices for one strip. A triangle strip is defined by re-using two + advancing vertices from the previous triangle for the next triangle. If there are 5 vertices in + the strip, then 3 triangles are created: {0,1,2}, {1,2,3}, {2,3,4}. Note that vertex winding must + also be taken into consideration and every even triangle in the strip has its vertices swapped + from the above pattern. */ + POINTS /**< A list of Camera-facing sprites. The face-vertex count list will contain one element that + represents the total number of points. Two non-COLLADA geometry sources (POINT_SIZE and POINT_ROTATION) + are specific to this type. */ + }; + +private: + DeclareObjectType(FCDObject); + + FCDGeometryMesh* parent; + DeclareParameterContainer(FCDGeometryPolygonsInput, inputs, FC("Data Inputs")); + DeclareParameterList(UInt32, faceVertexCounts, FC("Per-face Vertex counts")); + DeclareParameterList(UInt32, holeFaces, FC("Hole face indices")); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, primitiveType, FC("Primitive Type")); // PrimitiveType + + // Buffered statistics + size_t faceVertexCount; + size_t faceOffset; + size_t faceVertexOffset; + size_t holeOffset; + + // Material for this set of polygons + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, materialSemantic, FC("Material Semantic")); + + // Extra information tree + DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); + +public: + /** Constructor: do not use directly. Instead, use the FCDGeometryMesh::AddPolygons function + to create new polygon sets. + @param document The COLLADA document which owns this polygon set. + @param parent The geometric mesh which contains this polygon set.*/ + FCDGeometryPolygons(FCDocument* document, FCDGeometryMesh* parent); + + /** Destructor. */ + virtual ~FCDGeometryPolygons(); + + /** Retrieves the geometry that contains this polygons. + @return The parent geometry. */ + inline FCDGeometryMesh* GetParent() { return parent; } + inline const FCDGeometryMesh* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the extra information tree for this entity instance. The + prefered way to save extra information in FCollada is at the entity + level. Use this extra information tree to store any information you + want exported and imported back. + @return The extra information tree. */ + FCDExtra* GetExtra(); + inline const FCDExtra* GetExtra() const { return const_cast(this)->GetExtra(); } /**< See above. */ + + /** Retrieves the primitive type for this polygons set. + @return The primitive type. */ + inline PrimitiveType GetPrimitiveType() const { return (PrimitiveType) *primitiveType; } + + /** Sets the primitive type for this polygons set. + Important note: no attempt is made at fixing up the indices. You should + only do this operation of empty polygons set. + @param type The new primitive type. */ + inline void SetPrimitiveType(PrimitiveType type) { primitiveType = type; SetDirtyFlag(); } + + /** Retrieves the list of face-vertex counts. Each face within the polygon set + has one or more entry within this list, depending on the number of holes within that face. + Each face-vertex count indicates the number of ordered indices + within the polygon set inputs that are used to generate a face or its holes. + To find out if a face-vertex count represents a face or its holes, check + the hole-faces list retrieved using the GetHoleFaces function. + Indirectly, the face-vertex count indicates the degree of the polygon. + @see GetHoleFaces @see GetHoleCount + @return The list of face-vertex counts.*/ + inline const uint32* GetFaceVertexCounts() const { return faceVertexCounts.begin(); } /**< See above. */ + + /** Adds a new count to the face-vertex count list. + This function only modifies the face-vertex count list. + To also add indices to the inputs for the new face, use the AddFace function. + @param count The number of vertices in the new face. */ + void AddFaceVertexCount(uint32 count); + + /** Retrieves the number of face-vertex counts within the polygon set. + This value also represents the total the number of faces and holes within the polygon set. + @return The number of face-vertex counts within the polygon set. */ + inline size_t GetFaceVertexCountCount() const { return faceVertexCounts.size(); } + + /** Sets the number of face-vertex counts within the polygon set. + Any additional face-vertex count will not be initialized and + any removed face-vertex count will not remove the equivalent + indices within the polygon set inputs. + @param count The new number of face-vertex counts within the polygon set. */ + void SetFaceVertexCountCount(size_t count); + + /** [DEPRECATED] + Retrieves if the polygons is a list of polygons (returns false), or a list of triangles + (returns true). + @return The boolean answer. */ + DEPRECATED(3.05, TestPolyType) bool IsTriangles() const; + + /** Tests if the polygon can be aproximated with a constant face count + Returns: 3 if all faces are triangles, 4 if all faces are triangles, else -1 */ + int32 TestPolyType() const; + + /** Retrieves the number of holes within the faces of the polygon set. + @return The number of holes within the faces of the polygon set. */ + inline size_t GetHoleCount() const { return holeFaces.size(); } + + /** Retrieves the number of faces within the polygon set. + @return The number of faces within the polygon set. */ + inline size_t GetFaceCount() const { return faceVertexCounts.size() - GetHoleCount(); } + + /** Retrieves the number of faces which appear before this polygon set within the geometric mesh. + This value is useful when traversing all the faces of a geometric mesh. + @return The number of faces in previous polygon sets. */ + inline size_t GetFaceOffset() const { return faceOffset; } + + /** Retrieves the total number of face-vertex pairs within the polygon set. + This value is the total of all the values within the face-vertex count list. + Do remember that the list of face-vertex pairs includes holes. + @return The total number of face-vertex pairs within the polygon set. */ + inline size_t GetFaceVertexCount() const { return faceVertexCount; } + + /** Retrieves the number of face-vertex pairs for a given face. + This value includes face-vertex pairs that create the polygon and its holes. + @param index A face index. + @return The number of face-vertex pairs for a given face. */ + size_t GetFaceVertexCount(size_t index) const; + + /** Retrieves the total number of face-vertex pairs which appear + before this polygon set within the geometric mesh. + This value is useful when traversing all the face-vertex pairs of a geometric mesh. + @return The number of face-vertex pairs in previous polygon sets. */ + inline size_t GetFaceVertexOffset() const { return faceVertexOffset; } + + /** Retrieves the number of holes which appear before this polygon set. + This value is useful when traversing all the face-vertex pairs of a geometric mesh. */ + inline size_t GetHoleOffset() const { return holeOffset; } + + /** Retrieves the number of face-vertex pairs which appear + before a given face within the polygon set. + This value is useful when doing per-vertex mesh operations within the polygon set. + @param index The index of the face. + @return The number of face-vertex pairs before the given face, within the polygon set. */ + size_t GetFaceVertexOffset(size_t index) const; + + /** [INTERNAL] Sets the number of faces in previous polygon sets. + Used by the FCDGeometryMesh::Recalculate function. + @param offset The number of faces in previous polygon sets. */ + inline void SetFaceOffset(size_t offset) { faceOffset = offset; SetDirtyFlag(); } + + /** [INTERNAL] Sets the number of face-vertex pairs in previous polygon sets. + Used by the FCDGeometryMesh::Recalculate function. + @param offset The number of face-vertex pairs in previous polygon sets. */ + inline void SetFaceVertexOffset(size_t offset) { faceVertexOffset = offset; SetDirtyFlag(); } + + /** [INTERNAL] Sets the number of holes in previous polygon sets. + Used by the FCDGeometryMesh::Recalculate function. + @param offset The number of holes in previous polygon sets. */ + inline void SetHoleOffset(size_t offset) { holeOffset = offset; SetDirtyFlag(); } + + /** Creates a new face. + Enough indices to fill the face will be added to the polygon set inputs: you will + want to overwrite those, as they will all be set to zero. + @param degree The degree of the polygon. This number implies the number of indices + that will be expected, in order, within each of the input index lists. */ + virtual void AddFace(uint32 degree); + + /** Removes a face. + @param index The index of the face to remove. All the indices associated + with this face will also be removed. */ + virtual void RemoveFace(size_t index); + + /** Retrieves the list of polygon set inputs. + @see FCDGeometryPolygonsInput + @return The list of polygon set inputs. */ + DEPRECATED(3.05A, GetInputCount and GetInput(index)) void GetInputs() {} + + /** Retrieves the number of polygon set inputs. + @return The number of polygon set inputs. */ + inline size_t GetInputCount() const { return inputs.size(); } + + /** Retrieves a specific polygon set input. + @param index The index of the polygon set input. This index should + not be greater than or equal to the number of polygon set inputs. + @return The specific polygon set input. This pointer will be NULL if the index is out-of-bounds. */ + inline FCDGeometryPolygonsInput* GetInput(size_t index) { FUAssert(index < GetInputCount(), return NULL); return inputs.at(index); } + inline const FCDGeometryPolygonsInput* GetInput(size_t index) const { FUAssert(index < GetInputCount(), return NULL); return inputs.at(index); } /**< See above. */ + + /** Creates a new polygon set input. + @param source The data source for the polygon set input. + @param offset The tessellation indices offset for the polygon set input. + If this value is new to the list of polygon inputs, you will need to fill in the indices. + Please use the FindIndices function to verify that the offset is new and that indices need + to be provided. The offset of zero is reserved for per-vertex data sources. + @return The new polygon set input. */ + FCDGeometryPolygonsInput* AddInput(FCDGeometrySource* source, uint32 offset); + + /** Retrieves the number of hole entries within the face-vertex count list. + @return The number of hole entries within the face-vertex count list. */ + inline size_t GetHoleFaceCount() const { return holeFaces.size(); } + + /** Sets the number of hole entries within the face-vertex count list. + Any additional hole entries will need to be initialized by the application. + Reducing the number of hole entries without taking special care to remove + these entries from the face-vertex count list will result in new, unwanted, faces. + @param count The number of hole entries within the face-vertex count list. */ + void SetHoleFaceCount(size_t count); + + /** Checks whether a given face-vertex count entries represents a hole. + @param index The index of the face-vertex count entry. + @return Whether this face-vertex count entry is a hole. */ + bool IsHoleFaceHole(size_t index); + + /** Retrieves the list of entries within the face-vertex count list + that are considered holes. COLLADA does not support holes within holes, + so each entry within this list implies a hole within the previous face. + @see GetFaceVertexCounts + @return The list of hole entries within the face-vertex counts. */ + inline const uint32* GetHoleFaces() const { return holeFaces.begin(); } /**< See above. */ + + /** Adds a new hole identifier. + The face-vertex count entry should already exist and the identifier will be place + in increasing order within the current list of entries within the face-vertex count list. + @param index The index of the hole within the face-vertex count list. */ + void AddHole(uint32 index); + + /** Retrieves the number of holes within faces of the polygon set that appear + before the given face index. This value is useful when trying to access + a specific face of a mesh, as holes and faces appear together within the + face-vertex degree list. + @param index A face index. + @return The number of holes within the polygon set that appear + before the given face index. */ + size_t GetHoleCountBefore(size_t index) const; + + /** Retrieves the number of holes within a given face. + @param index A face index. + @return The number of holes within the given face. */ + size_t GetHoleCount(size_t index) const; + + /** Retrieves the first polygon set input found that has the given data type. + @param semantic A type of geometry data. + @return The polygon set input. This pointer will be NULL if + no polygon set input matches the data type. */ + FCDGeometryPolygonsInput* FindInput(FUDaeGeometryInput::Semantic semantic) { return const_cast(const_cast(this)->FindInput(semantic)); } + const FCDGeometryPolygonsInput* FindInput(FUDaeGeometryInput::Semantic semantic) const; /**< See above. */ + + /** Retrieves the polygon set input that points towards a given data source. + @param source A geometry data source. + @return The polygon set input. This pointer will be NULL if + no polygon set input matches the data source. */ + FCDGeometryPolygonsInput* FindInput(const FCDGeometrySource* source) { return const_cast(const_cast(this)->FindInput(source)); } + const FCDGeometryPolygonsInput* FindInput(const FCDGeometrySource* source) const; /**< See above. */ + + /** [INTERNAL] Retrieves the polygon set input that points towards a given data source. + @param sourceId The COLLADA id of a geometry data source. + @return The polygon set input. This pointer will be NULL if + no polygon set input matches the COLLADA id. */ + FCDGeometryPolygonsInput* FindInput(const fm::string& sourceId); + + /** Retrieves all the polygon set inputs that have the given data type. + @param semantic A type of geometry data. + @param inputs A list of polygon set inputs to fill in. This list is not emptied by the function + and may remain untouched, if no polygon set input matches the given data type. */ + inline void FindInputs(FUDaeGeometryInput::Semantic semantic, FCDGeometryPolygonsInputList& inputs) { const_cast(this)->FindInputs(semantic, *(FCDGeometryPolygonsInputConstList*)&inputs); } + void FindInputs(FUDaeGeometryInput::Semantic semantic, FCDGeometryPolygonsInputConstList& inputs) const; /**< See above. */ + + /** Retrieves the symbolic name for the material used on this polygon set. + Match this symbolic name within a FCDGeometryInstance to get the + correct material instance. + @return A symbolic material name. */ + inline const fstring& GetMaterialSemantic() const { return materialSemantic; } + + /** Sets a symbolic name for the material used on this polygon set. + This symbolic name will be matched in the FCDMaterialInstance contained within + a FCDGeometryInstance to assign the correct material. + @param semantic The symbolic material name. */ + inline void SetMaterialSemantic(const fchar* semantic) { materialSemantic = semantic; SetDirtyFlag(); } + inline void SetMaterialSemantic(const fstring& semantic) { materialSemantic = semantic; SetDirtyFlag(); } /**< See above. */ + + /** [INTERNAL] Recalculates the buffered offset and count values for this polygon set. */ + virtual void Recalculate(); + + /** [INTERNAL] Creates a copy of this mesh. + You should use the FCDGeometry::Clone function instead of this function. + @param clone The clone polygon set. + @param cloneMap A match-map of the original geometry sources to the clone geometry sources for the mesh. + @return The clone polygon set. */ + virtual FCDGeometryPolygons* Clone(FCDGeometryPolygons* clone, const FCDGeometrySourceCloneMap& cloneMap) const; +}; + +#endif // _FCD_GEOMETRY_POLYGONS_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygons.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsTools.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsTools.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsTools.h (revision 24247) @@ -1,165 +1,165 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDGeometryPolygonsTools.h - This file defines the FCDGeometryPolygonsTools namespace. -*/ - -#ifndef _FCD_GEOMETRY_POLYGONS_TOOLS_H_ -#define _FCD_GEOMETRY_POLYGONS_TOOLS_H_ - -class FCDGeometryMesh; -class FCDGeometrySource; -class FCDGeometryPolygons; -class FCDGeometryPolygonsInput; - -/** A translation map between old vertex position indices and the new indices. - It is generated in the FCDGeometryPolygonsTools::GenerateUniqueIndices function. */ -typedef fm::map FCDGeometryIndexTranslationMap; -typedef fm::pvector FCDGeometryIndexTranslationMapList; /**< A dynamically-sized array of translation maps. */ -typedef fm::vector FCDNewIndicesList; /**< A dynamically-sized array of index lists. */ - -/** Holds commonly-used transformation functions for meshes and polygons sets. */ -namespace FCDGeometryPolygonsTools -{ - - /** MAX_BUFFER_COUNT is the default value to split by when packing vertices and indices. - It represents the usual upper limit of video cards on buffer submission size*/ - #define MAX_BUFFER_COUNT ((uint16)~0) - - /** Triangulates a mesh. - @param mesh The mesh to triangulate. */ - FCOLLADA_EXPORT void Triangulate(FCDGeometryMesh* mesh); - - /** Triangulates a polygons set. - @param polygons The polygons set to triangulate. - @param recalculate Whether the statistics of the mesh should be recalculated - after the tool has completed. */ - FCOLLADA_EXPORT void Triangulate(FCDGeometryPolygons* polygons, bool recalculate = true); - - /** Generates the texture tangents and binormals for a given source of texture coordinates. - A source of normals and a source of vertex positions will be expected. - @param mesh The mesh that contains the texture coordinate source. - @param texcoordSource The source of texture coordinates that needs its tangents and binormals generated. - @param generateBinormals Whether the binormals should also be generated. - Do note that the binormal is always the cross-product of the tangent and the normal at a vertex-face pair. */ - FCOLLADA_EXPORT void GenerateTextureTangentBasis(FCDGeometryMesh* mesh, FCDGeometrySource* texcoordSource, bool generateBinormals = true); - - /** Prepares the mesh for using its geometry sources in vertex buffers with a unique index buffer. - This is useful for older engines and the applications that only support one index - per face-vertex pair. - @param mesh The mesh to process. - @param polygons The polygons set to isolate and process. If this pointer is NULL, the whole mesh is processed - for one index buffer. - @param translationMap Optional map that returns how to translate old vertex position indices into new indices. - This map is necessary to support skins and morphers. */ - FCOLLADA_EXPORT void GenerateUniqueIndices(FCDGeometryMesh* mesh, FCDGeometryPolygons* polygons = NULL, FCDGeometryIndexTranslationMap* translationMap = NULL); - - /** Prepares the mesh for using its geometry sources in vertex buffers with a unique index buffer. - This is useful for older engines and the applications that only support one index - per face-vertex pair. This version of the GenerateUniqueIndices function fills in the outTranslationMaps, - but does not modify the data in the FCDGeometryPolygon objects. - @param mesh The mesh to process. - @param polygons The polygons set to isolate and process. If this pointer is NULL, the whole mesh is processed - for one index buffer. - @param outIndices The unique index buffer data. - @param outTranslationMaps How the vertex data needs to be relocated in order to use the unique index buffer data. */ - FCOLLADA_EXPORT void GenerateUniqueIndices(FCDGeometryMesh* mesh, FCDGeometryPolygons* polygonsToProcess, FCDNewIndicesList& outIndices, FCDGeometryIndexTranslationMapList& outTranslationMaps); - - /** Applies the translation map onto some vertex data. - Refer to the information within the translation map to pre-cache the necessary amount of vertices. - @param targData The vertex buffer data to be filled-in. - @param srcData The original vertex data. - @param stride The stride within the target vertex buffer data and within the orignal vertex data. - @param translationMap How to relocate the vertex data. */ - FCOLLADA_EXPORT void ApplyUniqueIndices(float* targData, float* srcData, uint32 stride, const FCDGeometryIndexTranslationMap* translationMap); - - /** Applies the translation map onto some vertex data. - Refer to the information within the translation map to pre-cache the necessary amount of vertices. - @param targMesh The mesh object to be modified in-place. - @param baseMesh The original mesh object that contains the original vertex data. - @param newIndices The unique index buffer data. - @param translationMaps How the vertex data needs to be relocated in order to use the unique index buffer data. */ - FCOLLADA_EXPORT void ApplyUniqueIndices(FCDGeometryMesh* targMesh, FCDGeometryMesh* baseMesh, const UInt32List& newIndices, const FCDGeometryIndexTranslationMapList& translationMaps); - - /** Reverts the modifications done when applying the unique index - buffer data translation unto some polygons input. - IMPORTANT: this function is un-tested, DO NOT USE. - @param inSrc ? - @param outSrc ? - @param translationMap ? */ - FCOLLADA_EXPORT void RevertUniqueIndices(const FCDGeometryPolygonsInput& inSrc, FCDGeometryPolygonsInput& outSrc, const FCDGeometryIndexTranslationMap& translationMap); - - /** Used to pack a vertex buffer object with 3D float vertex data. - @param destBuffer The vertex buffer memory. - @param destBufferStride The size of one vertex in the vertex buffer. - @param source The original mesh vertex data. - @param vCount The number of vertex elements in the original mesh vertex data. - @param vtxPackingMap The packing map, generated by GenerateVertexPackingMap, for this vertex data. - @param translationMap The translation map, generated by GenerateUniqueIndices, for this vertex data. */ - FCOLLADA_EXPORT void PackVertexBufferV3(uint8* destBuffer, uint32 destBuffStride, - const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, - const FCDGeometryIndexTranslationMap& translationMap); - - /** Used to pack a vertex buffer object object with 4 bytes color data. - @param destBuffer The vertex buffer memory. - @param destBufferStride The size of one vertex in the vertex buffer. - @param source The original mesh vertex data. - @param vCount The number of vertex elements in the original mesh vertex data. - @param vtxPackingMap The packing map, generated by GenerateVertexPackingMap, for this vertex data. - @param translationMap The translation map, generated by GenerateUniqueIndices, for this vertex data. */ - FCOLLADA_EXPORT void PackVertexBufferColor(uint8* destBuffer, uint32 destBuffStride, - const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, - const FCDGeometryIndexTranslationMap& translationMap); - - /** Used to pack a vertex buffer object object with 2D float vertex data. - @param destBuffer The vertex buffer memory. - @param destBufferStride The size of one vertex in the vertex buffer. - @param source The original mesh vertex data. - @param vCount The number of vertex elements in the original mesh vertex data. - @param vtxPackingMap The packing map, generated by GenerateVertexPackingMap, for this vertex data. - @param translationMap The translation map, generated by GenerateUniqueIndices, for this vertex data. */ - FCOLLADA_EXPORT void PackVertexBufferV2(uint8* destBuffer, uint32 destBuffStride, - const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, - const FCDGeometryIndexTranslationMap& translationMap); - - /** Generates a packing map for a mesh' given vertex data. - @param maxIndex The total number of indices in the input index data. - @param maxIndices The maximum number of indices to include in one packing map. Generally, this number would be 2^16-1. - @param maxVertices The maximum number of vertices to include in one packing map. Generally, this number would also be 2^16-1. - @param inIndices The input unique index data. - @param outIndices The resulting indices. - @param outPackingMap The packing maps. These maps are used to identify - @param outNVertices The number of vertices for each split packing map. - @return The number of indices packed away. */ - FCOLLADA_EXPORT uint16 GenerateVertexPackingMap(size_t maxIndex, size_t maxIndices, size_t maxVertices, const uint32* inIndices, - uint16* outIndices, UInt16List* outPackingMap, uint16* outNVertices=NULL); - - /** Retrieves the largest unique index within a given translation map. - This function is unnecessary expensive and we suggest that you cache its results. - @param translationMap A translation map. - @return The largest unique index within the translation map. */ - FCOLLADA_EXPORT uint32 FindLargestUniqueIndex(const FCDGeometryIndexTranslationMap& translationMap); - - /** Splits the mesh's polygons sets to ensure that none of them have more than a given number of indices within their - index buffers. If you intend of using the GenerateUniqueIndices tool on your meshes, you should run it before this tool. - This function affects only the indices and the number of polygon sets within a mesh and therefore has no impact on - skins or morphers attached to the given mesh. - @param mesh The mesh to process. - @param maximumIndexCount The maximum number of indices to have within each polygons set. */ - FCOLLADA_EXPORT void FitIndexBuffers(FCDGeometryMesh* mesh, size_t maximumIndexCount); - - /** Reverses all the normals of a mesh. - Since they are related to normals, this function also reverses geometric - tangents and binormals as well as texture tangents and binormals. - @param mesh The mesh to process. */ - FCOLLADA_EXPORT void ReverseNormals(FCDGeometryMesh* mesh); -}; - -#endif // _FCD_GEOMETRY_POLYGONS_TOOLS_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDGeometryPolygonsTools.h + This file defines the FCDGeometryPolygonsTools namespace. +*/ + +#ifndef _FCD_GEOMETRY_POLYGONS_TOOLS_H_ +#define _FCD_GEOMETRY_POLYGONS_TOOLS_H_ + +class FCDGeometryMesh; +class FCDGeometrySource; +class FCDGeometryPolygons; +class FCDGeometryPolygonsInput; + +/** A translation map between old vertex position indices and the new indices. + It is generated in the FCDGeometryPolygonsTools::GenerateUniqueIndices function. */ +typedef fm::map FCDGeometryIndexTranslationMap; +typedef fm::pvector FCDGeometryIndexTranslationMapList; /**< A dynamically-sized array of translation maps. */ +typedef fm::vector FCDNewIndicesList; /**< A dynamically-sized array of index lists. */ + +/** Holds commonly-used transformation functions for meshes and polygons sets. */ +namespace FCDGeometryPolygonsTools +{ + + /** MAX_BUFFER_COUNT is the default value to split by when packing vertices and indices. + It represents the usual upper limit of video cards on buffer submission size*/ + #define MAX_BUFFER_COUNT ((uint16)~0) + + /** Triangulates a mesh. + @param mesh The mesh to triangulate. */ + FCOLLADA_EXPORT void Triangulate(FCDGeometryMesh* mesh); + + /** Triangulates a polygons set. + @param polygons The polygons set to triangulate. + @param recalculate Whether the statistics of the mesh should be recalculated + after the tool has completed. */ + FCOLLADA_EXPORT void Triangulate(FCDGeometryPolygons* polygons, bool recalculate = true); + + /** Generates the texture tangents and binormals for a given source of texture coordinates. + A source of normals and a source of vertex positions will be expected. + @param mesh The mesh that contains the texture coordinate source. + @param texcoordSource The source of texture coordinates that needs its tangents and binormals generated. + @param generateBinormals Whether the binormals should also be generated. + Do note that the binormal is always the cross-product of the tangent and the normal at a vertex-face pair. */ + FCOLLADA_EXPORT void GenerateTextureTangentBasis(FCDGeometryMesh* mesh, FCDGeometrySource* texcoordSource, bool generateBinormals = true); + + /** Prepares the mesh for using its geometry sources in vertex buffers with a unique index buffer. + This is useful for older engines and the applications that only support one index + per face-vertex pair. + @param mesh The mesh to process. + @param polygons The polygons set to isolate and process. If this pointer is NULL, the whole mesh is processed + for one index buffer. + @param translationMap Optional map that returns how to translate old vertex position indices into new indices. + This map is necessary to support skins and morphers. */ + FCOLLADA_EXPORT void GenerateUniqueIndices(FCDGeometryMesh* mesh, FCDGeometryPolygons* polygons = NULL, FCDGeometryIndexTranslationMap* translationMap = NULL); + + /** Prepares the mesh for using its geometry sources in vertex buffers with a unique index buffer. + This is useful for older engines and the applications that only support one index + per face-vertex pair. This version of the GenerateUniqueIndices function fills in the outTranslationMaps, + but does not modify the data in the FCDGeometryPolygon objects. + @param mesh The mesh to process. + @param polygons The polygons set to isolate and process. If this pointer is NULL, the whole mesh is processed + for one index buffer. + @param outIndices The unique index buffer data. + @param outTranslationMaps How the vertex data needs to be relocated in order to use the unique index buffer data. */ + FCOLLADA_EXPORT void GenerateUniqueIndices(FCDGeometryMesh* mesh, FCDGeometryPolygons* polygonsToProcess, FCDNewIndicesList& outIndices, FCDGeometryIndexTranslationMapList& outTranslationMaps); + + /** Applies the translation map onto some vertex data. + Refer to the information within the translation map to pre-cache the necessary amount of vertices. + @param targData The vertex buffer data to be filled-in. + @param srcData The original vertex data. + @param stride The stride within the target vertex buffer data and within the orignal vertex data. + @param translationMap How to relocate the vertex data. */ + FCOLLADA_EXPORT void ApplyUniqueIndices(float* targData, float* srcData, uint32 stride, const FCDGeometryIndexTranslationMap* translationMap); + + /** Applies the translation map onto some vertex data. + Refer to the information within the translation map to pre-cache the necessary amount of vertices. + @param targMesh The mesh object to be modified in-place. + @param baseMesh The original mesh object that contains the original vertex data. + @param newIndices The unique index buffer data. + @param translationMaps How the vertex data needs to be relocated in order to use the unique index buffer data. */ + FCOLLADA_EXPORT void ApplyUniqueIndices(FCDGeometryMesh* targMesh, FCDGeometryMesh* baseMesh, const UInt32List& newIndices, const FCDGeometryIndexTranslationMapList& translationMaps); + + /** Reverts the modifications done when applying the unique index + buffer data translation unto some polygons input. + IMPORTANT: this function is un-tested, DO NOT USE. + @param inSrc ? + @param outSrc ? + @param translationMap ? */ + FCOLLADA_EXPORT void RevertUniqueIndices(const FCDGeometryPolygonsInput& inSrc, FCDGeometryPolygonsInput& outSrc, const FCDGeometryIndexTranslationMap& translationMap); + + /** Used to pack a vertex buffer object with 3D float vertex data. + @param destBuffer The vertex buffer memory. + @param destBufferStride The size of one vertex in the vertex buffer. + @param source The original mesh vertex data. + @param vCount The number of vertex elements in the original mesh vertex data. + @param vtxPackingMap The packing map, generated by GenerateVertexPackingMap, for this vertex data. + @param translationMap The translation map, generated by GenerateUniqueIndices, for this vertex data. */ + FCOLLADA_EXPORT void PackVertexBufferV3(uint8* destBuffer, uint32 destBuffStride, + const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, + const FCDGeometryIndexTranslationMap& translationMap); + + /** Used to pack a vertex buffer object object with 4 bytes color data. + @param destBuffer The vertex buffer memory. + @param destBufferStride The size of one vertex in the vertex buffer. + @param source The original mesh vertex data. + @param vCount The number of vertex elements in the original mesh vertex data. + @param vtxPackingMap The packing map, generated by GenerateVertexPackingMap, for this vertex data. + @param translationMap The translation map, generated by GenerateUniqueIndices, for this vertex data. */ + FCOLLADA_EXPORT void PackVertexBufferColor(uint8* destBuffer, uint32 destBuffStride, + const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, + const FCDGeometryIndexTranslationMap& translationMap); + + /** Used to pack a vertex buffer object object with 2D float vertex data. + @param destBuffer The vertex buffer memory. + @param destBufferStride The size of one vertex in the vertex buffer. + @param source The original mesh vertex data. + @param vCount The number of vertex elements in the original mesh vertex data. + @param vtxPackingMap The packing map, generated by GenerateVertexPackingMap, for this vertex data. + @param translationMap The translation map, generated by GenerateUniqueIndices, for this vertex data. */ + FCOLLADA_EXPORT void PackVertexBufferV2(uint8* destBuffer, uint32 destBuffStride, + const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, + const FCDGeometryIndexTranslationMap& translationMap); + + /** Generates a packing map for a mesh' given vertex data. + @param maxIndex The total number of indices in the input index data. + @param maxIndices The maximum number of indices to include in one packing map. Generally, this number would be 2^16-1. + @param maxVertices The maximum number of vertices to include in one packing map. Generally, this number would also be 2^16-1. + @param inIndices The input unique index data. + @param outIndices The resulting indices. + @param outPackingMap The packing maps. These maps are used to identify + @param outNVertices The number of vertices for each split packing map. + @return The number of indices packed away. */ + FCOLLADA_EXPORT uint16 GenerateVertexPackingMap(size_t maxIndex, size_t maxIndices, size_t maxVertices, const uint32* inIndices, + uint16* outIndices, UInt16List* outPackingMap, uint16* outNVertices=NULL); + + /** Retrieves the largest unique index within a given translation map. + This function is unnecessary expensive and we suggest that you cache its results. + @param translationMap A translation map. + @return The largest unique index within the translation map. */ + FCOLLADA_EXPORT uint32 FindLargestUniqueIndex(const FCDGeometryIndexTranslationMap& translationMap); + + /** Splits the mesh's polygons sets to ensure that none of them have more than a given number of indices within their + index buffers. If you intend of using the GenerateUniqueIndices tool on your meshes, you should run it before this tool. + This function affects only the indices and the number of polygon sets within a mesh and therefore has no impact on + skins or morphers attached to the given mesh. + @param mesh The mesh to process. + @param maximumIndexCount The maximum number of indices to have within each polygons set. */ + FCOLLADA_EXPORT void FitIndexBuffers(FCDGeometryMesh* mesh, size_t maximumIndexCount); + + /** Reverses all the normals of a mesh. + Since they are related to normals, this function also reverses geometric + tangents and binormals as well as texture tangents and binormals. + @param mesh The mesh to process. */ + FCOLLADA_EXPORT void ReverseNormals(FCDGeometryMesh* mesh); +}; + +#endif // _FCD_GEOMETRY_POLYGONS_TOOLS_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsTools.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySpline.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySpline.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySpline.h (revision 24247) @@ -1,336 +1,336 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/** - @file FCDGeometrySpline.h - This file contains the FCDGeometrySpline class. - The FCDGeometrySpline class hold the information for one COLLADA geometric spline. -*/ -#ifndef _FCD_GEOMETRY_SPLINE_H_ -#define _FCD_GEOMETRY_SPLINE_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -class FCDocument; -class FCDGeometry; -class FCDBezierSpline; -class FCDNURBSSpline; - -/** Represents a generic spline. - A FCSpline contains a list of control vertices and a closed attribute which defaults to false.*/ -class FCOLLADA_EXPORT FCDSpline : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - FUDaeSplineForm::Form form; - fm::string name; - -protected: - FMVector3List cvs; /**< The list of control vertices. */ - -public: - /** Constructor. - @param document The FCollada document that owns this spline. */ - FCDSpline(FCDocument* document); - - /** Destructor. */ - virtual ~FCDSpline(); - - /** Retrieves the type of the spline. This is the only method of the FCDSpline interface. - @return FUDaeSplineType of the spline.*/ - virtual FUDaeSplineType::Type GetSplineType() const = 0; - - /** Gets the name of the spline. - @return The spline name.*/ - inline fm::string& GetName() { return name; } - inline const fm::string& GetName() const { return name; } /**< See above.*/ - - /** Sets the name of the spline. - @param _name The new name.*/ - inline void SetName(const fm::string& _name) { name = _name; } - - /** Retrieves if the spline is closed or not. - @return The closed boolean value.*/ - inline bool IsClosed() const { return form == FUDaeSplineForm::CLOSED; } - - /** Sets if the spline is closed or not. - @param closed The closed attribute value.*/ - inline void SetClosed(bool closed) { form = (closed) ? FUDaeSplineForm::CLOSED : FUDaeSplineForm::OPEN; } - - /** Retrieves the number of CVs in the spline. - @return The number of control vertices.*/ - inline size_t GetCVCount() const { return cvs.size(); } - - /** Retrieves a pointer to the control vertex specified by the given index. - @param index The index, must be higher or equal to 0 and lower than GetCVCount(). - @return The control vertex.*/ - inline FMVector3* GetCV(size_t index) { FUAssert(index < GetCVCount(), return NULL); return &(cvs.at(index)); } - inline const FMVector3* GetCV(size_t index) const { FUAssert(index < GetCVCount(), return NULL); return &(cvs.at(index)); } /**< See above. */ - - /** Retrieves a reference to the CVs list. - @return The reference to the control vertices. */ - inline FMVector3List& GetCVs() { return cvs; } - inline const FMVector3List& GetCVs() const { return cvs; } /**< See above. */ - - /** Empty the spline's control vertex list. */ - inline void ClearCVs() { cvs.clear(); } - - /** [INTERNAL] Copies the spline into a clone. - The clone may reside in another document. - @param clone The empty clone. This pointer cannot be NULL. - @return The clone. */ - virtual FCDSpline* Clone(FCDSpline* clone) const; -}; - -typedef fm::pvector FCDSplineList; /**< A dynamically-sized array of FCSpline.*/ -typedef FUObjectContainer FCDSplineContainer; /**< A dynamically-sized containment array of FCSpline.*/ -typedef fm::pvector FCDBezierSplineList; /**< A dynamically-sized array of FCDBezierSpline. @ingroup FCDGeometry */ -typedef fm::pvector FCDNURBSSplineList; /**< A dynamically-sized array of FCDNURBSSpline. @ingroup FCDGeometry */ - -/** Represents a Linear spline. - - Linear splines are, like the Bezier splines, represented as an array of - adjacent linear segment. Each segment consisting of 2 control vertices, the - last one being reused as the first vertex of the next segment. If the spline - is closed, the first vertex is also reused for the last vertex of the last segment. -*/ -class FCOLLADA_EXPORT FCDLinearSpline : public FCDSpline -{ -private: - DeclareObjectType(FCDSpline); - -public: - /** Constructor. - @param document The FCollada document that owns this spline. */ - FCDLinearSpline(FCDocument* document); - - /** Destructor. */ - virtual ~FCDLinearSpline(); - - /** FCDSpline method implementation. - @return The LINEAR spline type.*/ - virtual FUDaeSplineType::Type GetSplineType() const { return FUDaeSplineType::LINEAR; } - - /** Adds a CV to a Linear spline - @param cv 3D position of the CV.*/ - bool AddCV(const FMVector3& cv){ cvs.push_back(cv); return true; } - - /** Convert the linear segments contained inside this linear spline into Bezier segments. - @param toFill The Bezier spline to fill with linear information.*/ - void ToBezier(FCDBezierSpline& toFill); - - /** Determines if the spline is valid. - @return True is the spline is valid, false otherwise.*/ - virtual bool IsValid() const; -}; - -/** Represents a Bezier spline. - - The Bezier spline is represented as an array of adjacent cubic Bezier segments. - Each segment consists of 4 control vertices, the last one being reused as the - first vertex of the next segment. If the spline is closed, the first control vertex - is also reused for the last vertex of the last segment. -*/ -class FCOLLADA_EXPORT FCDBezierSpline : public FCDSpline -{ -private: - DeclareObjectType(FCDSpline); - -public: - /** Constructor. - @param document The FCollada document that owns this spline. */ - FCDBezierSpline(FCDocument* document); - - /** Destructor. */ - virtual ~FCDBezierSpline(); - - /** FCDSpline method implementation. - @return The BEZIER spline type.*/ - virtual FUDaeSplineType::Type GetSplineType() const { return FUDaeSplineType::BEZIER; } - - /** Adds a CV to a Bezier spline - @param cv 3D position of the CV.*/ - bool AddCV(const FMVector3& cv){ cvs.push_back(cv); return true; } - - /** Creates one NURB per Bezier segment and appends it to the provided NURB list. - @param toFill The NURB list to fill.*/ - void ToNURBs(FCDNURBSSplineList &toFill) const; - - /** Determines if the spline is valid. - @return True is the spline is valid, false otherwise.*/ - virtual bool IsValid() const; -}; - -/** - Represents a NURBS spline. - - This is a typical NURBS spline. It uses a list of FMVector3 for its control vertices, - along with a list of float to represent each vertex weight. A knot vector (uniform or not, - clamped or not), together with a degree, complete the specification. -*/ -class FCOLLADA_EXPORT FCDNURBSSpline : public FCDSpline -{ -private: - DeclareObjectType(FCDSpline); - - FloatList weights; - FloatList knots; - uint32 degree; - -public: - /** Constructor. - @param document The FCollada document that owns this spline. */ - FCDNURBSSpline(FCDocument* document); - - /** Destructor. */ - virtual ~FCDNURBSSpline(); - - /** FCDSpline method implementation. - @return The NURBS spline type.*/ - virtual FUDaeSplineType::Type GetSplineType() const { return FUDaeSplineType::NURBS; } - - /** Get the degree for this NURBS. - @return The degree.*/ - inline uint32 GetDegree() const { return degree; } - - /** Set the degree for this NURBS. - @param deg The wanted degree.*/ - inline void SetDegree(uint32 deg){ degree = deg; } - - /** Add a control vertex as a 3D position and a weight attribute specific to this CV. - @param cv The 3D position. - @param weight The weight attribute.*/ - bool AddCV(const FMVector3& cv, float weight); - - /** Retrieves a reference to the weight specified by the index. - @param index The index. - @return The address of the weight value, NULL if index is invalid.*/ - inline float* GetWeight(size_t index) { FUAssert(index < GetCVCount(), return NULL); return &(weights.at(index)); } - inline const float* GetWeight(size_t index) const { FUAssert(index < GetCVCount(), return NULL); return &(weights.at(index)); } /**< See above. */ - - /** Retrieves the knot count in this NURB. - @return The knot count.*/ - inline size_t GetKnotCount() const { return knots.size(); } - - /** Add a knot to this NURB. - @param knot The knot value.*/ - inline void AddKnot(float knot) { knots.push_back(knot); } - - /** Retrieves a reference to the knot specified by the index. - @param index The index. - @return The address of the knot value, NULL if index is invalid.*/ - inline float* GetKnot(size_t index) { FUAssert(index < GetKnotCount(), return NULL); return &(knots.at(index));} - inline const float* GetKnot(size_t index) const { FUAssert(index < GetKnotCount(), return NULL); return &(knots.at(index));} /**< See above. */ - - /** Retrieves a const reference to the weight list. - @return The weights' const reference.*/ - inline FloatList& GetWeights() { return weights; } - inline const FloatList& GetWeights() const { return weights; } /**< See above. */ - - /** Retrieves a const reference to the knot list. - @return The knots' const reference.*/ - inline FloatList& GetKnots() { return knots; } - inline const FloatList& GetKnots() const { return knots; } /**< See above. */ - - /** Determines if the spline is valid. - @return True is the spline is valid, false otherwise.*/ - virtual bool IsValid() const; - - /** [INTERNAL] Copies the spline into a clone. - The clone may reside in another document. - @param clone The empty clone. This pointer cannot be NULL. - @return The clone. */ - virtual FCDSpline* Clone(FCDSpline* clone) const; -}; - -/** - A COLLADA geometric spline. - - A COLLADA spline contains an array of FCDSpline of the same type. - - @todo: Insert the mathematical formula to calculate the spline position. - - @ingroup FCDGeometry -*/ -class FCOLLADA_EXPORT FCDGeometrySpline : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - FCDGeometry* parent; - - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, type, FC("Spline Type")); // FUDaeSplineType::Type; - DeclareParameterContainer(FCDSpline, splines, FC("Splines")); - -public: - /** Constructor: do not use directly. Use the FCDGeometry::CreateMesh function instead. - @param document The COLLADA document that owns the new spline. - @param parent The geometry entity that contains the new spline. */ - FCDGeometrySpline(FCDocument* document, FCDGeometry* parent); - - /** Destructor. */ - virtual ~FCDGeometrySpline(); - - /** Retrieves the parent of this geometric spline: the geometry entity. - @return The geometry entity that this spline belongs to. */ - FCDGeometry* GetParent() { return parent; } - const FCDGeometry* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the type of this geometry spline. - @return The type.*/ - FUDaeSplineType::Type GetType() const { return (FUDaeSplineType::Type) *type; } - - /** Sets the spline type for this geometry spline. - Changing the type of a geometry spline that contains sub-splines will clear all its sub-splines. - @param _type The type. */ - bool SetType(FUDaeSplineType::Type _type); - - /** Retrieves the number of splines in this geometry spline. - @return The spline count.*/ - size_t GetSplineCount() const { return splines.size(); } - - /** Retrieves the total amount of control vertices in the spline array. - @return The total CV count.*/ - size_t GetTotalCVCount(); - - /** Retrieves a pointer to the spline specified by the given index. - @param index The index, higher or equal to 0 and lower than GetSplineCount(). - @return The FCDSpline pointer, or NULL if index is invalid.*/ - FCDSpline* GetSpline(size_t index){ FUAssert(index < GetSplineCount(), return NULL); return splines[index]; } - const FCDSpline* GetSpline(size_t index) const { FUAssert(index < GetSplineCount(), return NULL); return splines[index]; }/**< see above */ - - /** Adds a spline to this geometry spline. - @param type The type of spline to create. - Set the type to FUDaeSplineType::UNKNOWN to create a spline that has - the same type as this geometry spline. - @return The new spline. This pointer will be NULL if the requested spline - type is different from existing splines. This pointer will be NULL - if the requested type is FUDaeSplineType::UNKNOWN and this geometry spline - doesn't yet have a type assigned. */ - FCDSpline* AddSpline(FUDaeSplineType::Type type = FUDaeSplineType::UNKNOWN); - - /** Converts the Bezier splines in this geometry to a list of NURBS splines. - @param toFill The list of NURBS to fill. An empty list if the type of this geometry is not BEZIER.*/ - void ConvertBezierToNURBS(FCDNURBSSplineList& toFill); - - /** Copies the spline into a clone. - The clone may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new spline - will be created and you will need to release the returned pointer manually. - @return The clone. */ - FCDGeometrySpline* Clone(FCDGeometrySpline* clone = NULL) const; -}; - -#endif // _FCD_GEOMETRY_SPLINE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/** + @file FCDGeometrySpline.h + This file contains the FCDGeometrySpline class. + The FCDGeometrySpline class hold the information for one COLLADA geometric spline. +*/ +#ifndef _FCD_GEOMETRY_SPLINE_H_ +#define _FCD_GEOMETRY_SPLINE_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +class FCDocument; +class FCDGeometry; +class FCDBezierSpline; +class FCDNURBSSpline; + +/** Represents a generic spline. + A FCSpline contains a list of control vertices and a closed attribute which defaults to false.*/ +class FCOLLADA_EXPORT FCDSpline : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + FUDaeSplineForm::Form form; + fm::string name; + +protected: + FMVector3List cvs; /**< The list of control vertices. */ + +public: + /** Constructor. + @param document The FCollada document that owns this spline. */ + FCDSpline(FCDocument* document); + + /** Destructor. */ + virtual ~FCDSpline(); + + /** Retrieves the type of the spline. This is the only method of the FCDSpline interface. + @return FUDaeSplineType of the spline.*/ + virtual FUDaeSplineType::Type GetSplineType() const = 0; + + /** Gets the name of the spline. + @return The spline name.*/ + inline fm::string& GetName() { return name; } + inline const fm::string& GetName() const { return name; } /**< See above.*/ + + /** Sets the name of the spline. + @param _name The new name.*/ + inline void SetName(const fm::string& _name) { name = _name; } + + /** Retrieves if the spline is closed or not. + @return The closed boolean value.*/ + inline bool IsClosed() const { return form == FUDaeSplineForm::CLOSED; } + + /** Sets if the spline is closed or not. + @param closed The closed attribute value.*/ + inline void SetClosed(bool closed) { form = (closed) ? FUDaeSplineForm::CLOSED : FUDaeSplineForm::OPEN; } + + /** Retrieves the number of CVs in the spline. + @return The number of control vertices.*/ + inline size_t GetCVCount() const { return cvs.size(); } + + /** Retrieves a pointer to the control vertex specified by the given index. + @param index The index, must be higher or equal to 0 and lower than GetCVCount(). + @return The control vertex.*/ + inline FMVector3* GetCV(size_t index) { FUAssert(index < GetCVCount(), return NULL); return &(cvs.at(index)); } + inline const FMVector3* GetCV(size_t index) const { FUAssert(index < GetCVCount(), return NULL); return &(cvs.at(index)); } /**< See above. */ + + /** Retrieves a reference to the CVs list. + @return The reference to the control vertices. */ + inline FMVector3List& GetCVs() { return cvs; } + inline const FMVector3List& GetCVs() const { return cvs; } /**< See above. */ + + /** Empty the spline's control vertex list. */ + inline void ClearCVs() { cvs.clear(); } + + /** [INTERNAL] Copies the spline into a clone. + The clone may reside in another document. + @param clone The empty clone. This pointer cannot be NULL. + @return The clone. */ + virtual FCDSpline* Clone(FCDSpline* clone) const; +}; + +typedef fm::pvector FCDSplineList; /**< A dynamically-sized array of FCSpline.*/ +typedef FUObjectContainer FCDSplineContainer; /**< A dynamically-sized containment array of FCSpline.*/ +typedef fm::pvector FCDBezierSplineList; /**< A dynamically-sized array of FCDBezierSpline. @ingroup FCDGeometry */ +typedef fm::pvector FCDNURBSSplineList; /**< A dynamically-sized array of FCDNURBSSpline. @ingroup FCDGeometry */ + +/** Represents a Linear spline. + + Linear splines are, like the Bezier splines, represented as an array of + adjacent linear segment. Each segment consisting of 2 control vertices, the + last one being reused as the first vertex of the next segment. If the spline + is closed, the first vertex is also reused for the last vertex of the last segment. +*/ +class FCOLLADA_EXPORT FCDLinearSpline : public FCDSpline +{ +private: + DeclareObjectType(FCDSpline); + +public: + /** Constructor. + @param document The FCollada document that owns this spline. */ + FCDLinearSpline(FCDocument* document); + + /** Destructor. */ + virtual ~FCDLinearSpline(); + + /** FCDSpline method implementation. + @return The LINEAR spline type.*/ + virtual FUDaeSplineType::Type GetSplineType() const { return FUDaeSplineType::LINEAR; } + + /** Adds a CV to a Linear spline + @param cv 3D position of the CV.*/ + bool AddCV(const FMVector3& cv){ cvs.push_back(cv); return true; } + + /** Convert the linear segments contained inside this linear spline into Bezier segments. + @param toFill The Bezier spline to fill with linear information.*/ + void ToBezier(FCDBezierSpline& toFill); + + /** Determines if the spline is valid. + @return True is the spline is valid, false otherwise.*/ + virtual bool IsValid() const; +}; + +/** Represents a Bezier spline. + + The Bezier spline is represented as an array of adjacent cubic Bezier segments. + Each segment consists of 4 control vertices, the last one being reused as the + first vertex of the next segment. If the spline is closed, the first control vertex + is also reused for the last vertex of the last segment. +*/ +class FCOLLADA_EXPORT FCDBezierSpline : public FCDSpline +{ +private: + DeclareObjectType(FCDSpline); + +public: + /** Constructor. + @param document The FCollada document that owns this spline. */ + FCDBezierSpline(FCDocument* document); + + /** Destructor. */ + virtual ~FCDBezierSpline(); + + /** FCDSpline method implementation. + @return The BEZIER spline type.*/ + virtual FUDaeSplineType::Type GetSplineType() const { return FUDaeSplineType::BEZIER; } + + /** Adds a CV to a Bezier spline + @param cv 3D position of the CV.*/ + bool AddCV(const FMVector3& cv){ cvs.push_back(cv); return true; } + + /** Creates one NURB per Bezier segment and appends it to the provided NURB list. + @param toFill The NURB list to fill.*/ + void ToNURBs(FCDNURBSSplineList &toFill) const; + + /** Determines if the spline is valid. + @return True is the spline is valid, false otherwise.*/ + virtual bool IsValid() const; +}; + +/** + Represents a NURBS spline. + + This is a typical NURBS spline. It uses a list of FMVector3 for its control vertices, + along with a list of float to represent each vertex weight. A knot vector (uniform or not, + clamped or not), together with a degree, complete the specification. +*/ +class FCOLLADA_EXPORT FCDNURBSSpline : public FCDSpline +{ +private: + DeclareObjectType(FCDSpline); + + FloatList weights; + FloatList knots; + uint32 degree; + +public: + /** Constructor. + @param document The FCollada document that owns this spline. */ + FCDNURBSSpline(FCDocument* document); + + /** Destructor. */ + virtual ~FCDNURBSSpline(); + + /** FCDSpline method implementation. + @return The NURBS spline type.*/ + virtual FUDaeSplineType::Type GetSplineType() const { return FUDaeSplineType::NURBS; } + + /** Get the degree for this NURBS. + @return The degree.*/ + inline uint32 GetDegree() const { return degree; } + + /** Set the degree for this NURBS. + @param deg The wanted degree.*/ + inline void SetDegree(uint32 deg){ degree = deg; } + + /** Add a control vertex as a 3D position and a weight attribute specific to this CV. + @param cv The 3D position. + @param weight The weight attribute.*/ + bool AddCV(const FMVector3& cv, float weight); + + /** Retrieves a reference to the weight specified by the index. + @param index The index. + @return The address of the weight value, NULL if index is invalid.*/ + inline float* GetWeight(size_t index) { FUAssert(index < GetCVCount(), return NULL); return &(weights.at(index)); } + inline const float* GetWeight(size_t index) const { FUAssert(index < GetCVCount(), return NULL); return &(weights.at(index)); } /**< See above. */ + + /** Retrieves the knot count in this NURB. + @return The knot count.*/ + inline size_t GetKnotCount() const { return knots.size(); } + + /** Add a knot to this NURB. + @param knot The knot value.*/ + inline void AddKnot(float knot) { knots.push_back(knot); } + + /** Retrieves a reference to the knot specified by the index. + @param index The index. + @return The address of the knot value, NULL if index is invalid.*/ + inline float* GetKnot(size_t index) { FUAssert(index < GetKnotCount(), return NULL); return &(knots.at(index));} + inline const float* GetKnot(size_t index) const { FUAssert(index < GetKnotCount(), return NULL); return &(knots.at(index));} /**< See above. */ + + /** Retrieves a const reference to the weight list. + @return The weights' const reference.*/ + inline FloatList& GetWeights() { return weights; } + inline const FloatList& GetWeights() const { return weights; } /**< See above. */ + + /** Retrieves a const reference to the knot list. + @return The knots' const reference.*/ + inline FloatList& GetKnots() { return knots; } + inline const FloatList& GetKnots() const { return knots; } /**< See above. */ + + /** Determines if the spline is valid. + @return True is the spline is valid, false otherwise.*/ + virtual bool IsValid() const; + + /** [INTERNAL] Copies the spline into a clone. + The clone may reside in another document. + @param clone The empty clone. This pointer cannot be NULL. + @return The clone. */ + virtual FCDSpline* Clone(FCDSpline* clone) const; +}; + +/** + A COLLADA geometric spline. + + A COLLADA spline contains an array of FCDSpline of the same type. + + @todo: Insert the mathematical formula to calculate the spline position. + + @ingroup FCDGeometry +*/ +class FCOLLADA_EXPORT FCDGeometrySpline : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + FCDGeometry* parent; + + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, type, FC("Spline Type")); // FUDaeSplineType::Type; + DeclareParameterContainer(FCDSpline, splines, FC("Splines")); + +public: + /** Constructor: do not use directly. Use the FCDGeometry::CreateMesh function instead. + @param document The COLLADA document that owns the new spline. + @param parent The geometry entity that contains the new spline. */ + FCDGeometrySpline(FCDocument* document, FCDGeometry* parent); + + /** Destructor. */ + virtual ~FCDGeometrySpline(); + + /** Retrieves the parent of this geometric spline: the geometry entity. + @return The geometry entity that this spline belongs to. */ + FCDGeometry* GetParent() { return parent; } + const FCDGeometry* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the type of this geometry spline. + @return The type.*/ + FUDaeSplineType::Type GetType() const { return (FUDaeSplineType::Type) *type; } + + /** Sets the spline type for this geometry spline. + Changing the type of a geometry spline that contains sub-splines will clear all its sub-splines. + @param _type The type. */ + bool SetType(FUDaeSplineType::Type _type); + + /** Retrieves the number of splines in this geometry spline. + @return The spline count.*/ + size_t GetSplineCount() const { return splines.size(); } + + /** Retrieves the total amount of control vertices in the spline array. + @return The total CV count.*/ + size_t GetTotalCVCount(); + + /** Retrieves a pointer to the spline specified by the given index. + @param index The index, higher or equal to 0 and lower than GetSplineCount(). + @return The FCDSpline pointer, or NULL if index is invalid.*/ + FCDSpline* GetSpline(size_t index){ FUAssert(index < GetSplineCount(), return NULL); return splines[index]; } + const FCDSpline* GetSpline(size_t index) const { FUAssert(index < GetSplineCount(), return NULL); return splines[index]; }/**< see above */ + + /** Adds a spline to this geometry spline. + @param type The type of spline to create. + Set the type to FUDaeSplineType::UNKNOWN to create a spline that has + the same type as this geometry spline. + @return The new spline. This pointer will be NULL if the requested spline + type is different from existing splines. This pointer will be NULL + if the requested type is FUDaeSplineType::UNKNOWN and this geometry spline + doesn't yet have a type assigned. */ + FCDSpline* AddSpline(FUDaeSplineType::Type type = FUDaeSplineType::UNKNOWN); + + /** Converts the Bezier splines in this geometry to a list of NURBS splines. + @param toFill The list of NURBS to fill. An empty list if the type of this geometry is not BEZIER.*/ + void ConvertBezierToNURBS(FCDNURBSSplineList& toFill); + + /** Copies the spline into a clone. + The clone may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new spline + will be created and you will need to release the returned pointer manually. + @return The clone. */ + FCDGeometrySpline* Clone(FCDGeometrySpline* clone = NULL) const; +}; + +#endif // _FCD_GEOMETRY_SPLINE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySpline.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.hpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.hpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.hpp (revision 24247) @@ -1,89 +1,89 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#ifndef _FCD_EXTRA_H_ -#include "FCDocument/FCDExtra.h" -#endif // _FCD_EXTRA_H_ -#ifndef _FCD_ASSET_H_ -#include "FCDocument/FCDAsset.h" -#endif // _FCD_ASSET_H_ -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENITTY_H_ - -template -FCDLibrary::FCDLibrary(FCDocument* document) -: FCDObject(document) -, InitializeParameterNoArg(entities) -, InitializeParameterNoArg(extra) -, InitializeParameterNoArg(asset) -{ - extra = new FCDExtra(document, this); -} - -template -FCDLibrary::~FCDLibrary() -{ - SAFE_RELEASE(extra); - SAFE_RELEASE(asset); -} - -// Create the asset if it isn't already there. -template -FCDAsset* FCDLibrary::GetAsset(bool create) -{ - if (create && asset == NULL) asset = new FCDAsset(GetDocument()); - return asset; -} - -// Search for the entity in this library with a given COLLADA id. -template -const T* FCDLibrary::FindDaeId(const fm::string& daeId) const -{ -#ifdef _DEBUG - // [staylor] June 12 2007 - !!Code change verification check!! - // When fixing up the FCPlugin archive merge, removed SkipPound - // here (Should be obsolete). If you see this code much past this - // date, feel free to remove it. - FUAssert (daeId.empty() || daeId[0] != '#',); -#endif - - size_t entityCount = entities.size(); - for (size_t i = 0; i < entityCount; ++i) - { - const FCDEntity* found = entities[i]->FindDaeId(daeId); - if (found != NULL && found->GetObjectType() == T::GetClassType()) - { - return (T*) found; - } - } - return NULL; -} - -// Search for the entity in this library with a given COLLADA id. -template -T* FCDLibrary::AddEntity() -{ - T* entity = new T(GetDocument()); - entities.push_back(entity); - SetNewChildFlag(); - return entity; -} - - -template -void FCDLibrary::AddEntity(T* entity) -{ - entities.push_back(entity); SetNewChildFlag(); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef _FCD_EXTRA_H_ +#include "FCDocument/FCDExtra.h" +#endif // _FCD_EXTRA_H_ +#ifndef _FCD_ASSET_H_ +#include "FCDocument/FCDAsset.h" +#endif // _FCD_ASSET_H_ +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENITTY_H_ + +template +FCDLibrary::FCDLibrary(FCDocument* document) +: FCDObject(document) +, InitializeParameterNoArg(entities) +, InitializeParameterNoArg(extra) +, InitializeParameterNoArg(asset) +{ + extra = new FCDExtra(document, this); +} + +template +FCDLibrary::~FCDLibrary() +{ + SAFE_RELEASE(extra); + SAFE_RELEASE(asset); +} + +// Create the asset if it isn't already there. +template +FCDAsset* FCDLibrary::GetAsset(bool create) +{ + if (create && asset == NULL) asset = new FCDAsset(GetDocument()); + return asset; +} + +// Search for the entity in this library with a given COLLADA id. +template +const T* FCDLibrary::FindDaeId(const fm::string& daeId) const +{ +#ifdef _DEBUG + // [staylor] June 12 2007 - !!Code change verification check!! + // When fixing up the FCPlugin archive merge, removed SkipPound + // here (Should be obsolete). If you see this code much past this + // date, feel free to remove it. + FUAssert (daeId.empty() || daeId[0] != '#',); +#endif + + size_t entityCount = entities.size(); + for (size_t i = 0; i < entityCount; ++i) + { + const FCDEntity* found = entities[i]->FindDaeId(daeId); + if (found != NULL && found->GetObjectType() == T::GetClassType()) + { + return (T*) found; + } + } + return NULL; +} + +// Search for the entity in this library with a given COLLADA id. +template +T* FCDLibrary::AddEntity() +{ + T* entity = new T(GetDocument()); + entities.push_back(entity); + SetNewChildFlag(); + return entity; +} + + +template +void FCDLibrary::AddEntity(T* entity) +{ + entities.push_back(entity); SetNewChildFlag(); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.hpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLightTools.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLightTools.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLightTools.h (revision 24247) @@ -1,44 +1,44 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDLightTools.h - This file defines the FCDLightTools namespace. -*/ - -#ifndef _FCD_LIGHT_TOOLS_H_ -#define _FCD_LIGHT_TOOLS_H_ - -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -class FCDLight; - -/** Holds commonly-used transformation functions for lights. */ -namespace FCDLightTools -{ - /** Loads the penumbra into the light. - The FCDLight does not contain penumbra information directly, but it - can be represented with appropriate values for the outerAngle and the - fallOffAngle. If the penumbra is positive, then the outerAngle is the - sum of the penumbra value and the fallOffAngle. If the penumbra is - negative, then the outerAngle is the fallOffAngle and the fallOffAngle - is the outerAngle minus the penumbra. This method sets the fallOffAngle - and outerAngle to correspond to the penumbra given. It takes care of - the animations as well. - @param light The light to process. - @param penumbraValue The value of the penumbra. - @param penumbraAnimated The animated helper for the loaded penumbra. - @param createAnimationChannel True to create animation channel for the - falloff angle if needed. False will attach the animation to the - outer angle's channel if needed. */ - void FCOLLADA_EXPORT LoadPenumbra(FCDLight* light, float penumbraValue, FCDAnimated* penumbraAnimated, bool createAnimationChannel=true); -} - -#endif // _FCD_LIGHT_TOOLS_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDLightTools.h + This file defines the FCDLightTools namespace. +*/ + +#ifndef _FCD_LIGHT_TOOLS_H_ +#define _FCD_LIGHT_TOOLS_H_ + +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +class FCDLight; + +/** Holds commonly-used transformation functions for lights. */ +namespace FCDLightTools +{ + /** Loads the penumbra into the light. + The FCDLight does not contain penumbra information directly, but it + can be represented with appropriate values for the outerAngle and the + fallOffAngle. If the penumbra is positive, then the outerAngle is the + sum of the penumbra value and the fallOffAngle. If the penumbra is + negative, then the outerAngle is the fallOffAngle and the fallOffAngle + is the outerAngle minus the penumbra. This method sets the fallOffAngle + and outerAngle to correspond to the penumbra given. It takes care of + the animations as well. + @param light The light to process. + @param penumbraValue The value of the penumbra. + @param penumbraAnimated The animated helper for the loaded penumbra. + @param createAnimationChannel True to create animation channel for the + falloff angle if needed. False will attach the animation to the + outer angle's channel if needed. */ + void FCOLLADA_EXPORT LoadPenumbra(FCDLight* light, float penumbraValue, FCDAnimated* penumbraAnimated, bool createAnimationChannel=true); +} + +#endif // _FCD_LIGHT_TOOLS_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLightTools.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterialInstance.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterialInstance.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterialInstance.h (revision 24247) @@ -1,240 +1,240 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDMaterialInstance.h - This file contains the FCDMaterialInstance and the FCDMaterialInstanceBind classes. -*/ - -#ifndef _FCD_MATERIAL_BIND_H_ -#define _FCD_MATERIAL_BIND_H_ - -#ifndef _FCD_ENTITY_INSTANCE_H_ -#include "FCDocument/FCDEntityInstance.h" -#endif // _FCD_ENTITY_INSTANCE_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ - -class FCDocument; -class FCDGeometryPolygons; - -/** - A ColladaFX per-instance binding. - - This structure is used by the effect to bind its parameters to scene graph values. - Two common examples of this is to bind effect parameters to the position and orientation of the camera. - - @ingroup FCDEffect -*/ -class FCDMaterialInstanceBind : public FUParameterizable -{ -private: - DeclareObjectType(FUParameterizable); - -public: - /** The token used to identify the effect parameter to modify. */ - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, semantic, FC("Semantic")); - - /** The fully-qualified target of the COLLADA element whose value should be bound to the effect parameter. */ - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, target, FC("Target")); - - /** Constructor. */ - FCDMaterialInstanceBind(); - - /** Destructor. */ - virtual ~FCDMaterialInstanceBind(); -}; - -/** - A ColladaFX per-instance vertex input binding. - - This structure is used by the shader to bind its varying inputs - to actual data streams from the polygons sets. A common example of this - is to identify which texture coordinate set to use for a particular TEXCOORDx stream. - - @ingroup FCDEffect -*/ -class FCDMaterialInstanceBindVertexInput : public FUParameterizable -{ -private: - DeclareObjectType(FUParameterizable); - -public: - /** The token used to identify the effect parameter or varying shader input. */ - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, semantic, FC("Bind Semantic")); - - /** The geometry source type of the data source to bind to the effect parameter. - @see FUDaeGeometryInput::Semantic. */ - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, inputSemantic, FC("Input Semantic")); - - /** The set value of the data source to bind to the effect parameter. - A semantic/set pair should always be unique within a polygons set. */ - DeclareParameter(int32, FUParameterQualifiers::SIMPLE, inputSet, FC("Input Set")); - - /** Constructor. */ - FCDMaterialInstanceBindVertexInput(); - - /** Destructor. */ - virtual ~FCDMaterialInstanceBindVertexInput(); - - /** Retrieves the input semantic for this vertex-input binding. - @return The input semantic. */ - FUDaeGeometryInput::Semantic GetInputSemantic() const { return (FUDaeGeometryInput::Semantic) *inputSemantic; } -}; - -/** - A COLLADA material instance. - A material instance is used to given polygon sets with a COLLADA material entity. - It is also used to bind data sources with the inputs of an effect. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDMaterialInstance : public FCDEntityInstance -{ -private: - DeclareObjectType(FCDEntityInstance); - FCDEntityInstance* parent; - - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, semantic, FC("Material Token")); - DeclareParameterContainer(FCDMaterialInstanceBind, bindings, FC("Effect Bindings")); - DeclareParameterContainer(FCDMaterialInstanceBindVertexInput, vertexBindings, FC("Vertex Input Bindings")); - -public: - /** Constructor. - @param parent The entity instance that owns this material instance. */ - FCDMaterialInstance(FCDocument* document, FCDEntityInstance* parent); - - /** Destructor. */ - virtual ~FCDMaterialInstance(); - - /** Retrieves the type of entity instance. - @deprecated Use the following code, instead: - entityInstance->HasType(FCDMaterialInstance::GetClassType()). - @return The type of entity instance. */ - DEPRECATED(3.05A, HasType(FCDMaterialInstance::GetClassType())) virtual Type GetType() const { return MATERIAL; } - - /** Retrieves the parent instance. - @return The parent instance. */ - inline FCDEntityInstance* GetParent() { return parent; } - inline const FCDEntityInstance* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the symbolic name used to link the polygons sets with the material of this instance. - @return The symbolic name of the material instance. */ - inline const fstring& GetSemantic() const { return semantic; } - - /** Sets the symbolic name used to link polygons sets with this instance. - This name should always match against the symbolic name assigned to a polygons set. - @see FCDGeometryPolygons. - @param _semantic The new symbolic name of this instance. */ - inline void SetSemantic(const fchar* _semantic) { semantic = _semantic; SetDirtyFlag(); } - inline void SetSemantic(const fstring& _semantic) { semantic = _semantic; SetDirtyFlag(); } /**< See above. */ - - /** Retrieves the material entity used by this instance. - @return The instanced material. */ - inline FCDMaterial* GetMaterial() { return (FCDMaterial*) GetEntity(); } - inline const FCDMaterial* GetMaterial() const { return (const FCDMaterial*) GetEntity(); } /**< See above. */ - - /** Sets the material entity used by this instance. - @param _material The new instanced material. */ - inline void SetMaterial(FCDMaterial* _material) { SetEntity((FCDEntity*) _material); } - - /** Retrieves the parameter bindings of the instance. - Each material instance may re-define any number of material or effect parameters. - @return The parameter bindings. */ - DEPRECATED(3.05A, GetBindingCount and GetBinding(index)) inline void GetBindings() const {} - - /** Retrieves a given binding. - @param semantic The binding's semantic. - @return The found binding, or NULL if there is no such binding.*/ - const FCDMaterialInstanceBind* FindBinding(const char* semantic); - - /** Retrieves the number of parameter bindings for this instance. - @return The number of parameter bindings. */ - inline size_t GetBindingCount() const { return bindings.size(); } - - /** Retrieves a parameter binding. - @param index The index of the parameter binding. - @return The parameter binding at the given index. */ - inline FCDMaterialInstanceBind* GetBinding(size_t index) { FUAssert(index < bindings.size(), return NULL); return bindings.at(index); } - inline const FCDMaterialInstanceBind* GetBinding(size_t index) const { FUAssert(index < bindings.size(), return NULL); return bindings.at(index); } /**< See above. */ - - /** Retrieves the geometry target that this instance affects. - Note that this function uses the parent geometry instance and searches for the polygon set. - Therefore, the application should buffer the retrieved pointer. */ - FCDObject* GetGeometryTarget(); - - /** Adds a new parameter binding. - @return An empty parameter binding. */ - FCDMaterialInstanceBind* AddBinding(); - - /** Adds a new parameter binding. - @param semantic The token that identifies the material or effect parameter. - @param target The fully-qualified target pointer to the bind scene graph object. - @return The parameter binding. */ - FCDMaterialInstanceBind* AddBinding(const char* semantic, const char* target); - - /** Removes a parameter binding. - @param index The index of the parameter binding to remove. */ - void RemoveBinding(size_t index); - - /** Retrieves the vertex input bindings. - @return The vertex input bindings. */ - DEPRECATED(3.05A, GetVertexInputBindingCount and GetVertexInputBinding(index)) inline void GetVertexInputBindings() {} - - /** Retrieves the number of vertex input bindings. - @return The number of vertex input bindings. */ - inline size_t GetVertexInputBindingCount() const { return vertexBindings.size(); } - - /** Retrieves a vertex input binding. - @param index The index of the vertex input binding. - @return The vertex input binding at the given index. */ - inline FCDMaterialInstanceBindVertexInput* GetVertexInputBinding(size_t index) { FUAssert(index < vertexBindings.size(), return NULL); return vertexBindings.at(index); } - inline const FCDMaterialInstanceBindVertexInput* GetVertexInputBinding(size_t index) const { FUAssert(index < vertexBindings.size(), return NULL); return vertexBindings.at(index); } /**< See above. */ - - /** Retrieves a given vertex input binding. - This is useful when trying to match textures with the texture coordinate sets. - @param semantic A given vertex input binding semantic. - @return The vertex input binding information structure. This pointer will be - NULL if the given semantic is not bound within the material instance. */ - inline FCDMaterialInstanceBindVertexInput* FindVertexInputBinding(const char* semantic) { return const_cast(const_cast(this)->FindVertexInputBinding(semantic)); } - const FCDMaterialInstanceBindVertexInput* FindVertexInputBinding(const char* semantic) const; /**< See above. */ - - /** Adds a new vertex input binding. - @return An empty vertex input binding. */ - FCDMaterialInstanceBindVertexInput* AddVertexInputBinding(); - - /** Adds a new vertex input binding. - Together, the data source type and set should always define a unique data source. - @param semantic The token identify the shader varying input. - @param inputSemantic The polygons set data source type to bind. - @param inputSet The polygons set data source set to bind. - @return The new vertex input binding. */ - FCDMaterialInstanceBindVertexInput* AddVertexInputBinding(const char* semantic, FUDaeGeometryInput::Semantic inputSemantic, int32 inputSet); - - - /** Creates a flattened version of the instantiated material. This is the - preferred way to generate viewer materials from a COLLADA document. - @return The flattened version of the instantiated material. You - will need to delete this pointer manually. This pointer will - be NULL when there is no material attached to this instance. */ - DEPRECATED(3.05A, not recommended) FCDMaterial* FlattenMaterial() { return NULL; } - - /** Clones the material instance. - @param clone The material instance to become the clone. - @return The cloned material instance. */ - virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; -}; - -#endif // _FCD_MATERIAL_BIND_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDMaterialInstance.h + This file contains the FCDMaterialInstance and the FCDMaterialInstanceBind classes. +*/ + +#ifndef _FCD_MATERIAL_BIND_H_ +#define _FCD_MATERIAL_BIND_H_ + +#ifndef _FCD_ENTITY_INSTANCE_H_ +#include "FCDocument/FCDEntityInstance.h" +#endif // _FCD_ENTITY_INSTANCE_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ + +class FCDocument; +class FCDGeometryPolygons; + +/** + A ColladaFX per-instance binding. + + This structure is used by the effect to bind its parameters to scene graph values. + Two common examples of this is to bind effect parameters to the position and orientation of the camera. + + @ingroup FCDEffect +*/ +class FCDMaterialInstanceBind : public FUParameterizable +{ +private: + DeclareObjectType(FUParameterizable); + +public: + /** The token used to identify the effect parameter to modify. */ + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, semantic, FC("Semantic")); + + /** The fully-qualified target of the COLLADA element whose value should be bound to the effect parameter. */ + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, target, FC("Target")); + + /** Constructor. */ + FCDMaterialInstanceBind(); + + /** Destructor. */ + virtual ~FCDMaterialInstanceBind(); +}; + +/** + A ColladaFX per-instance vertex input binding. + + This structure is used by the shader to bind its varying inputs + to actual data streams from the polygons sets. A common example of this + is to identify which texture coordinate set to use for a particular TEXCOORDx stream. + + @ingroup FCDEffect +*/ +class FCDMaterialInstanceBindVertexInput : public FUParameterizable +{ +private: + DeclareObjectType(FUParameterizable); + +public: + /** The token used to identify the effect parameter or varying shader input. */ + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, semantic, FC("Bind Semantic")); + + /** The geometry source type of the data source to bind to the effect parameter. + @see FUDaeGeometryInput::Semantic. */ + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, inputSemantic, FC("Input Semantic")); + + /** The set value of the data source to bind to the effect parameter. + A semantic/set pair should always be unique within a polygons set. */ + DeclareParameter(int32, FUParameterQualifiers::SIMPLE, inputSet, FC("Input Set")); + + /** Constructor. */ + FCDMaterialInstanceBindVertexInput(); + + /** Destructor. */ + virtual ~FCDMaterialInstanceBindVertexInput(); + + /** Retrieves the input semantic for this vertex-input binding. + @return The input semantic. */ + FUDaeGeometryInput::Semantic GetInputSemantic() const { return (FUDaeGeometryInput::Semantic) *inputSemantic; } +}; + +/** + A COLLADA material instance. + A material instance is used to given polygon sets with a COLLADA material entity. + It is also used to bind data sources with the inputs of an effect. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDMaterialInstance : public FCDEntityInstance +{ +private: + DeclareObjectType(FCDEntityInstance); + FCDEntityInstance* parent; + + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, semantic, FC("Material Token")); + DeclareParameterContainer(FCDMaterialInstanceBind, bindings, FC("Effect Bindings")); + DeclareParameterContainer(FCDMaterialInstanceBindVertexInput, vertexBindings, FC("Vertex Input Bindings")); + +public: + /** Constructor. + @param parent The entity instance that owns this material instance. */ + FCDMaterialInstance(FCDocument* document, FCDEntityInstance* parent); + + /** Destructor. */ + virtual ~FCDMaterialInstance(); + + /** Retrieves the type of entity instance. + @deprecated Use the following code, instead: + entityInstance->HasType(FCDMaterialInstance::GetClassType()). + @return The type of entity instance. */ + DEPRECATED(3.05A, HasType(FCDMaterialInstance::GetClassType())) virtual Type GetType() const { return MATERIAL; } + + /** Retrieves the parent instance. + @return The parent instance. */ + inline FCDEntityInstance* GetParent() { return parent; } + inline const FCDEntityInstance* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the symbolic name used to link the polygons sets with the material of this instance. + @return The symbolic name of the material instance. */ + inline const fstring& GetSemantic() const { return semantic; } + + /** Sets the symbolic name used to link polygons sets with this instance. + This name should always match against the symbolic name assigned to a polygons set. + @see FCDGeometryPolygons. + @param _semantic The new symbolic name of this instance. */ + inline void SetSemantic(const fchar* _semantic) { semantic = _semantic; SetDirtyFlag(); } + inline void SetSemantic(const fstring& _semantic) { semantic = _semantic; SetDirtyFlag(); } /**< See above. */ + + /** Retrieves the material entity used by this instance. + @return The instanced material. */ + inline FCDMaterial* GetMaterial() { return (FCDMaterial*) GetEntity(); } + inline const FCDMaterial* GetMaterial() const { return (const FCDMaterial*) GetEntity(); } /**< See above. */ + + /** Sets the material entity used by this instance. + @param _material The new instanced material. */ + inline void SetMaterial(FCDMaterial* _material) { SetEntity((FCDEntity*) _material); } + + /** Retrieves the parameter bindings of the instance. + Each material instance may re-define any number of material or effect parameters. + @return The parameter bindings. */ + DEPRECATED(3.05A, GetBindingCount and GetBinding(index)) inline void GetBindings() const {} + + /** Retrieves a given binding. + @param semantic The binding's semantic. + @return The found binding, or NULL if there is no such binding.*/ + const FCDMaterialInstanceBind* FindBinding(const char* semantic); + + /** Retrieves the number of parameter bindings for this instance. + @return The number of parameter bindings. */ + inline size_t GetBindingCount() const { return bindings.size(); } + + /** Retrieves a parameter binding. + @param index The index of the parameter binding. + @return The parameter binding at the given index. */ + inline FCDMaterialInstanceBind* GetBinding(size_t index) { FUAssert(index < bindings.size(), return NULL); return bindings.at(index); } + inline const FCDMaterialInstanceBind* GetBinding(size_t index) const { FUAssert(index < bindings.size(), return NULL); return bindings.at(index); } /**< See above. */ + + /** Retrieves the geometry target that this instance affects. + Note that this function uses the parent geometry instance and searches for the polygon set. + Therefore, the application should buffer the retrieved pointer. */ + FCDObject* GetGeometryTarget(); + + /** Adds a new parameter binding. + @return An empty parameter binding. */ + FCDMaterialInstanceBind* AddBinding(); + + /** Adds a new parameter binding. + @param semantic The token that identifies the material or effect parameter. + @param target The fully-qualified target pointer to the bind scene graph object. + @return The parameter binding. */ + FCDMaterialInstanceBind* AddBinding(const char* semantic, const char* target); + + /** Removes a parameter binding. + @param index The index of the parameter binding to remove. */ + void RemoveBinding(size_t index); + + /** Retrieves the vertex input bindings. + @return The vertex input bindings. */ + DEPRECATED(3.05A, GetVertexInputBindingCount and GetVertexInputBinding(index)) inline void GetVertexInputBindings() {} + + /** Retrieves the number of vertex input bindings. + @return The number of vertex input bindings. */ + inline size_t GetVertexInputBindingCount() const { return vertexBindings.size(); } + + /** Retrieves a vertex input binding. + @param index The index of the vertex input binding. + @return The vertex input binding at the given index. */ + inline FCDMaterialInstanceBindVertexInput* GetVertexInputBinding(size_t index) { FUAssert(index < vertexBindings.size(), return NULL); return vertexBindings.at(index); } + inline const FCDMaterialInstanceBindVertexInput* GetVertexInputBinding(size_t index) const { FUAssert(index < vertexBindings.size(), return NULL); return vertexBindings.at(index); } /**< See above. */ + + /** Retrieves a given vertex input binding. + This is useful when trying to match textures with the texture coordinate sets. + @param semantic A given vertex input binding semantic. + @return The vertex input binding information structure. This pointer will be + NULL if the given semantic is not bound within the material instance. */ + inline FCDMaterialInstanceBindVertexInput* FindVertexInputBinding(const char* semantic) { return const_cast(const_cast(this)->FindVertexInputBinding(semantic)); } + const FCDMaterialInstanceBindVertexInput* FindVertexInputBinding(const char* semantic) const; /**< See above. */ + + /** Adds a new vertex input binding. + @return An empty vertex input binding. */ + FCDMaterialInstanceBindVertexInput* AddVertexInputBinding(); + + /** Adds a new vertex input binding. + Together, the data source type and set should always define a unique data source. + @param semantic The token identify the shader varying input. + @param inputSemantic The polygons set data source type to bind. + @param inputSet The polygons set data source set to bind. + @return The new vertex input binding. */ + FCDMaterialInstanceBindVertexInput* AddVertexInputBinding(const char* semantic, FUDaeGeometryInput::Semantic inputSemantic, int32 inputSet); + + + /** Creates a flattened version of the instantiated material. This is the + preferred way to generate viewer materials from a COLLADA document. + @return The flattened version of the instantiated material. You + will need to delete this pointer manually. This pointer will + be NULL when there is no material attached to this instance. */ + DEPRECATED(3.05A, not recommended) FCDMaterial* FlattenMaterial() { return NULL; } + + /** Clones the material instance. + @param clone The material instance to become the clone. + @return The cloned material instance. */ + virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; +}; + +#endif // _FCD_MATERIAL_BIND_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterialInstance.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometry.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometry.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometry.cpp (revision 24247) @@ -1,79 +1,79 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometrySpline.h" -#include "FUtils/FUStringConversion.h" - -// -// FCDGeometry -// - -ImplementObjectType(FCDGeometry); -ImplementParameterObject(FCDGeometry, FCDGeometryMesh, mesh, new FCDGeometryMesh(parent->GetDocument(), parent)); -ImplementParameterObject(FCDGeometry, FCDGeometrySpline, spline, new FCDGeometrySpline(parent->GetDocument(), parent)); - -FCDGeometry::FCDGeometry(FCDocument* document) -: FCDEntity(document, "Geometry") -, InitializeParameterNoArg(mesh) -, InitializeParameterNoArg(spline) -{ -} - -FCDGeometry::~FCDGeometry() -{ -} - -// Sets the type of this geometry to mesh and creates an empty mesh structure. -FCDGeometryMesh* FCDGeometry::CreateMesh() -{ - spline = NULL; - mesh = new FCDGeometryMesh(GetDocument(), this); - SetNewChildFlag(); - return mesh; -} - -// Sets the type of this geometry to spline and creates an empty spline structure. -FCDGeometrySpline* FCDGeometry::CreateSpline() -{ - mesh = NULL; - spline = new FCDGeometrySpline(GetDocument(), this); - SetNewChildFlag(); - return spline; -} - - -FCDEntity* FCDGeometry::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDGeometry* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDGeometry(const_cast(GetDocument())); - else if (_clone->HasType(FCDGeometry::GetClassType())) clone = (FCDGeometry*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - // Clone the geometric object - if (IsMesh()) - { - FCDGeometryMesh* clonedMesh = clone->CreateMesh(); - GetMesh()->Clone(clonedMesh); - } - else if (IsSpline()) - { - FCDGeometrySpline* clonedSpline = clone->CreateSpline(); - GetSpline()->Clone(clonedSpline); - } - } - return clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometrySpline.h" +#include "FUtils/FUStringConversion.h" + +// +// FCDGeometry +// + +ImplementObjectType(FCDGeometry); +ImplementParameterObject(FCDGeometry, FCDGeometryMesh, mesh, new FCDGeometryMesh(parent->GetDocument(), parent)); +ImplementParameterObject(FCDGeometry, FCDGeometrySpline, spline, new FCDGeometrySpline(parent->GetDocument(), parent)); + +FCDGeometry::FCDGeometry(FCDocument* document) +: FCDEntity(document, "Geometry") +, InitializeParameterNoArg(mesh) +, InitializeParameterNoArg(spline) +{ +} + +FCDGeometry::~FCDGeometry() +{ +} + +// Sets the type of this geometry to mesh and creates an empty mesh structure. +FCDGeometryMesh* FCDGeometry::CreateMesh() +{ + spline = NULL; + mesh = new FCDGeometryMesh(GetDocument(), this); + SetNewChildFlag(); + return mesh; +} + +// Sets the type of this geometry to spline and creates an empty spline structure. +FCDGeometrySpline* FCDGeometry::CreateSpline() +{ + mesh = NULL; + spline = new FCDGeometrySpline(GetDocument(), this); + SetNewChildFlag(); + return spline; +} + + +FCDEntity* FCDGeometry::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDGeometry* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDGeometry(const_cast(GetDocument())); + else if (_clone->HasType(FCDGeometry::GetClassType())) clone = (FCDGeometry*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + // Clone the geometric object + if (IsMesh()) + { + FCDGeometryMesh* clonedMesh = clone->CreateMesh(); + GetMesh()->Clone(clonedMesh); + } + else if (IsSpline()) + { + FCDGeometrySpline* clonedSpline = clone->CreateSpline(); + GetSpline()->Clone(clonedSpline); + } + } + return clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometry.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryMesh.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryMesh.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryMesh.cpp (revision 24247) @@ -1,265 +1,265 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDGeometryPolygonsInput.h" -#include "FCDocument/FCDGeometrySource.h" -#include "FCDocument/FCDLibrary.h" -#include "FUtils/FUStringConversion.h" - -// -// FCDGeometryMesh -// - -ImplementObjectType(FCDGeometryMesh); -ImplementParameterObject(FCDGeometryMesh, FCDGeometrySource, sources, new FCDGeometrySource(parent->GetDocument())); -ImplementParameterObject(FCDGeometryMesh, FCDGeometryPolygons, polygons, new FCDGeometryPolygons(parent->GetDocument(), parent)); -ImplementParameterObjectNoCtr(FCDGeometryMesh, FCDGeometrySource, vertexSources); - -FCDGeometryMesh::FCDGeometryMesh(FCDocument* document, FCDGeometry* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(sources) -, InitializeParameterNoArg(polygons) -, InitializeParameterNoArg(vertexSources) -, faceCount(0), holeCount(0), faceVertexCount(0) -, isConvex(true), convexify(false) -, InitializeParameterNoArg(convexHullOf) -{ -} - -FCDGeometryMesh::~FCDGeometryMesh() -{ - polygons.clear(); - sources.clear(); - faceVertexCount = faceCount = holeCount = 0; - parent = NULL; -} - -// Retrieve the parent's id -const fm::string& FCDGeometryMesh::GetDaeId() const -{ - return parent->GetDaeId(); -} - -void FCDGeometryMesh::SetConvexHullOf(FCDGeometry* _geom) -{ - convexHullOf = _geom->GetDaeId(); - SetDirtyFlag(); -} - -const FCDGeometryMesh* FCDGeometryMesh::FindConvexHullOfMesh() const -{ - const FCDGeometryMesh* mesh = this; - while ((mesh != NULL) && !mesh->GetConvexHullOf().empty()) - { - const FCDocument* document = mesh->GetDocument(); - const FCDGeometry* geometry = document->GetGeometryLibrary()-> - FindDaeId(mesh->GetConvexHullOf()); - if (geometry == NULL) return NULL; - mesh = geometry->GetMesh(); - } - return mesh; -} - -// Search for a data source in the geometry node -const FCDGeometrySource* FCDGeometryMesh::FindSourceById(const fm::string& id) const -{ - const char* localId = id.c_str(); - if (localId[0] == '#') ++localId; - for (const FCDGeometrySource** it = sources.begin(); it != sources.end(); ++it) - { - if ((*it)->GetDaeId() == localId) return (*it); - } - return NULL; -} - -// Retrieve the source for the given type -const FCDGeometrySource* FCDGeometryMesh::FindSourceByType(FUDaeGeometryInput::Semantic type) const -{ - for (const FCDGeometrySource** itS = sources.begin(); itS != sources.end(); ++itS) - { - if ((*itS)->GetType() == type) return (*itS); - } - return NULL; -} - -void FCDGeometryMesh::FindSourcesByType(FUDaeGeometryInput::Semantic type, FCDGeometrySourceConstList& _sources) const -{ - for (const FCDGeometrySource** itS = sources.begin(); itS != sources.end(); ++itS) - { - if ((*itS)->GetType() == type) _sources.push_back(*itS); - } -} - -const FCDGeometrySource* FCDGeometryMesh::FindSourceByName(const fstring& name) const -{ - for (const FCDGeometrySource** itS = sources.begin(); itS != sources.end(); ++itS) - { - if ((*itS)->GetName() == name) return (*itS); - } - return NULL; -} - -// Creates a new polygon group. -FCDGeometryPolygons* FCDGeometryMesh::AddPolygons() -{ - FCDGeometryPolygons* polys = new FCDGeometryPolygons(GetDocument(), this); - polygons.push_back(polys); - - // Add to this new polygons all the per-vertex sources. - size_t vertexSourceCount = vertexSources.size(); - for (size_t v = 0; v < vertexSourceCount; ++v) - { - polys->AddInput(vertexSources[v], 0); - } - - SetNewChildFlag(); - if (parent != NULL) parent->SetNewChildFlag(); - return polys; -} - -bool FCDGeometryMesh::IsTriangles() const -{ - bool isTriangles = true; - for (size_t i = 0; i < polygons.size() && isTriangles; ++i) - { - isTriangles = (polygons[i]->TestPolyType() == 3); - } - return isTriangles; -} - -// Retrieves the polygon sets that use a given material semantic -void FCDGeometryMesh::FindPolygonsByMaterial(const fstring& semantic, FCDGeometryPolygonsList& sets) -{ - size_t polygonCount = polygons.size(); - for (size_t p = 0; p < polygonCount; ++p) - { - if (polygons[p]->GetMaterialSemantic() == semantic) sets.push_back(polygons[p]); - } -} - -// Creates a new per-vertex data source -FCDGeometrySource* FCDGeometryMesh::AddVertexSource(FUDaeGeometryInput::Semantic type) -{ - FCDGeometrySource* vertexSource = AddSource(type); - vertexSources.push_back(vertexSource); - - // Add this new per-vertex data source to all the existing polygon groups, at offset 0. - size_t polygonsCount = polygons.size(); - for (size_t p = 0; p < polygonsCount; ++p) - { - polygons[p]->AddInput(vertexSource, 0); - } - - SetNewChildFlag(); - return vertexSource; -} - -// Sets a source as per-vertex data. -void FCDGeometryMesh::AddVertexSource(FCDGeometrySource* source) -{ - FUAssert(source != NULL, return); - FUAssert(!vertexSources.contains(source), return); - - // Add the source to the list of per-vertex sources. - vertexSources.push_back(source); - - // Remove any polygon set input that uses the source. - size_t polygonsCount = polygons.size(); - for (size_t p = 0; p < polygonsCount; ++p) - { - FCDGeometryPolygonsInput* input = polygons[p]->FindInput(source); - int32 set = (input != NULL) ? input->GetSet() : -1; - SAFE_RELEASE(input); - input = polygons[p]->AddInput(source, 0); - if (set > -1) input->SetSet(set); - } - - SetNewChildFlag(); -} - -void FCDGeometryMesh::RemoveVertexSource(FCDGeometrySource* source) -{ - FUAssert(source != NULL, return); - if (!vertexSources.contains(source)) return; - - // Add the source to the list of per-vertex sources. - vertexSources.erase(source); - SetDirtyFlag(); -} - -// Creates a new data source -FCDGeometrySource* FCDGeometryMesh::AddSource(FUDaeGeometryInput::Semantic type) -{ - FCDGeometrySource* source = new FCDGeometrySource(GetDocument()); - source->SetType(type); - sources.push_back(source); - SetNewChildFlag(); - return source; -} - -// Recalculates all the hole/vertex/face-vertex counts and offsets within the mesh and its polygons -void FCDGeometryMesh::Recalculate() -{ - faceCount = holeCount = faceVertexCount = 0; - size_t polygonsCount = polygons.size(); - for (size_t p = 0; p < polygonsCount; ++p) - { - FCDGeometryPolygons* polys = polygons[p]; - polys->Recalculate(); - - polys->SetFaceOffset(faceCount); - polys->SetHoleOffset(holeCount); - polys->SetFaceVertexOffset(faceVertexCount); - faceCount += polys->GetFaceCount(); - holeCount += polys->GetHoleCount(); - faceVertexCount += polys->GetFaceVertexCount(); - } - SetDirtyFlag(); -} - -FCDGeometryMesh* FCDGeometryMesh::Clone(FCDGeometryMesh* clone) const -{ - if (clone == NULL) clone = new FCDGeometryMesh(const_cast(GetDocument()), NULL); - - // Copy the miscellaneous information - clone->convexHullOf = convexHullOf; - clone->isConvex = isConvex; - clone->convexify = convexify; - clone->faceCount = faceCount; - clone->holeCount = holeCount; - clone->faceVertexCount = faceVertexCount; - - // Clone the sources - FCDGeometrySourceCloneMap cloneMap; - for (const FCDGeometrySource** itS = sources.begin(); itS != sources.end(); ++itS) - { - FCDGeometrySource* clonedSource = (IsVertexSource(*itS)) ? clone->AddVertexSource() : clone->AddSource(); - (*itS)->Clone(clonedSource); - cloneMap.insert(*itS, clonedSource); - } - - // Clone the polygon sets. - for (const FCDGeometryPolygons** itP = polygons.begin(); itP != polygons.end(); ++itP) - { - FCDGeometryPolygons* clonedPolys = clone->AddPolygons(); - (*itP)->Clone(clonedPolys, cloneMap); - } - - return clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDGeometryPolygonsInput.h" +#include "FCDocument/FCDGeometrySource.h" +#include "FCDocument/FCDLibrary.h" +#include "FUtils/FUStringConversion.h" + +// +// FCDGeometryMesh +// + +ImplementObjectType(FCDGeometryMesh); +ImplementParameterObject(FCDGeometryMesh, FCDGeometrySource, sources, new FCDGeometrySource(parent->GetDocument())); +ImplementParameterObject(FCDGeometryMesh, FCDGeometryPolygons, polygons, new FCDGeometryPolygons(parent->GetDocument(), parent)); +ImplementParameterObjectNoCtr(FCDGeometryMesh, FCDGeometrySource, vertexSources); + +FCDGeometryMesh::FCDGeometryMesh(FCDocument* document, FCDGeometry* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(sources) +, InitializeParameterNoArg(polygons) +, InitializeParameterNoArg(vertexSources) +, faceCount(0), holeCount(0), faceVertexCount(0) +, isConvex(true), convexify(false) +, InitializeParameterNoArg(convexHullOf) +{ +} + +FCDGeometryMesh::~FCDGeometryMesh() +{ + polygons.clear(); + sources.clear(); + faceVertexCount = faceCount = holeCount = 0; + parent = NULL; +} + +// Retrieve the parent's id +const fm::string& FCDGeometryMesh::GetDaeId() const +{ + return parent->GetDaeId(); +} + +void FCDGeometryMesh::SetConvexHullOf(FCDGeometry* _geom) +{ + convexHullOf = _geom->GetDaeId(); + SetDirtyFlag(); +} + +const FCDGeometryMesh* FCDGeometryMesh::FindConvexHullOfMesh() const +{ + const FCDGeometryMesh* mesh = this; + while ((mesh != NULL) && !mesh->GetConvexHullOf().empty()) + { + const FCDocument* document = mesh->GetDocument(); + const FCDGeometry* geometry = document->GetGeometryLibrary()-> + FindDaeId(mesh->GetConvexHullOf()); + if (geometry == NULL) return NULL; + mesh = geometry->GetMesh(); + } + return mesh; +} + +// Search for a data source in the geometry node +const FCDGeometrySource* FCDGeometryMesh::FindSourceById(const fm::string& id) const +{ + const char* localId = id.c_str(); + if (localId[0] == '#') ++localId; + for (const FCDGeometrySource** it = sources.begin(); it != sources.end(); ++it) + { + if ((*it)->GetDaeId() == localId) return (*it); + } + return NULL; +} + +// Retrieve the source for the given type +const FCDGeometrySource* FCDGeometryMesh::FindSourceByType(FUDaeGeometryInput::Semantic type) const +{ + for (const FCDGeometrySource** itS = sources.begin(); itS != sources.end(); ++itS) + { + if ((*itS)->GetType() == type) return (*itS); + } + return NULL; +} + +void FCDGeometryMesh::FindSourcesByType(FUDaeGeometryInput::Semantic type, FCDGeometrySourceConstList& _sources) const +{ + for (const FCDGeometrySource** itS = sources.begin(); itS != sources.end(); ++itS) + { + if ((*itS)->GetType() == type) _sources.push_back(*itS); + } +} + +const FCDGeometrySource* FCDGeometryMesh::FindSourceByName(const fstring& name) const +{ + for (const FCDGeometrySource** itS = sources.begin(); itS != sources.end(); ++itS) + { + if ((*itS)->GetName() == name) return (*itS); + } + return NULL; +} + +// Creates a new polygon group. +FCDGeometryPolygons* FCDGeometryMesh::AddPolygons() +{ + FCDGeometryPolygons* polys = new FCDGeometryPolygons(GetDocument(), this); + polygons.push_back(polys); + + // Add to this new polygons all the per-vertex sources. + size_t vertexSourceCount = vertexSources.size(); + for (size_t v = 0; v < vertexSourceCount; ++v) + { + polys->AddInput(vertexSources[v], 0); + } + + SetNewChildFlag(); + if (parent != NULL) parent->SetNewChildFlag(); + return polys; +} + +bool FCDGeometryMesh::IsTriangles() const +{ + bool isTriangles = true; + for (size_t i = 0; i < polygons.size() && isTriangles; ++i) + { + isTriangles = (polygons[i]->TestPolyType() == 3); + } + return isTriangles; +} + +// Retrieves the polygon sets that use a given material semantic +void FCDGeometryMesh::FindPolygonsByMaterial(const fstring& semantic, FCDGeometryPolygonsList& sets) +{ + size_t polygonCount = polygons.size(); + for (size_t p = 0; p < polygonCount; ++p) + { + if (polygons[p]->GetMaterialSemantic() == semantic) sets.push_back(polygons[p]); + } +} + +// Creates a new per-vertex data source +FCDGeometrySource* FCDGeometryMesh::AddVertexSource(FUDaeGeometryInput::Semantic type) +{ + FCDGeometrySource* vertexSource = AddSource(type); + vertexSources.push_back(vertexSource); + + // Add this new per-vertex data source to all the existing polygon groups, at offset 0. + size_t polygonsCount = polygons.size(); + for (size_t p = 0; p < polygonsCount; ++p) + { + polygons[p]->AddInput(vertexSource, 0); + } + + SetNewChildFlag(); + return vertexSource; +} + +// Sets a source as per-vertex data. +void FCDGeometryMesh::AddVertexSource(FCDGeometrySource* source) +{ + FUAssert(source != NULL, return); + FUAssert(!vertexSources.contains(source), return); + + // Add the source to the list of per-vertex sources. + vertexSources.push_back(source); + + // Remove any polygon set input that uses the source. + size_t polygonsCount = polygons.size(); + for (size_t p = 0; p < polygonsCount; ++p) + { + FCDGeometryPolygonsInput* input = polygons[p]->FindInput(source); + int32 set = (input != NULL) ? input->GetSet() : -1; + SAFE_RELEASE(input); + input = polygons[p]->AddInput(source, 0); + if (set > -1) input->SetSet(set); + } + + SetNewChildFlag(); +} + +void FCDGeometryMesh::RemoveVertexSource(FCDGeometrySource* source) +{ + FUAssert(source != NULL, return); + if (!vertexSources.contains(source)) return; + + // Add the source to the list of per-vertex sources. + vertexSources.erase(source); + SetDirtyFlag(); +} + +// Creates a new data source +FCDGeometrySource* FCDGeometryMesh::AddSource(FUDaeGeometryInput::Semantic type) +{ + FCDGeometrySource* source = new FCDGeometrySource(GetDocument()); + source->SetType(type); + sources.push_back(source); + SetNewChildFlag(); + return source; +} + +// Recalculates all the hole/vertex/face-vertex counts and offsets within the mesh and its polygons +void FCDGeometryMesh::Recalculate() +{ + faceCount = holeCount = faceVertexCount = 0; + size_t polygonsCount = polygons.size(); + for (size_t p = 0; p < polygonsCount; ++p) + { + FCDGeometryPolygons* polys = polygons[p]; + polys->Recalculate(); + + polys->SetFaceOffset(faceCount); + polys->SetHoleOffset(holeCount); + polys->SetFaceVertexOffset(faceVertexCount); + faceCount += polys->GetFaceCount(); + holeCount += polys->GetHoleCount(); + faceVertexCount += polys->GetFaceVertexCount(); + } + SetDirtyFlag(); +} + +FCDGeometryMesh* FCDGeometryMesh::Clone(FCDGeometryMesh* clone) const +{ + if (clone == NULL) clone = new FCDGeometryMesh(const_cast(GetDocument()), NULL); + + // Copy the miscellaneous information + clone->convexHullOf = convexHullOf; + clone->isConvex = isConvex; + clone->convexify = convexify; + clone->faceCount = faceCount; + clone->holeCount = holeCount; + clone->faceVertexCount = faceVertexCount; + + // Clone the sources + FCDGeometrySourceCloneMap cloneMap; + for (const FCDGeometrySource** itS = sources.begin(); itS != sources.end(); ++itS) + { + FCDGeometrySource* clonedSource = (IsVertexSource(*itS)) ? clone->AddVertexSource() : clone->AddSource(); + (*itS)->Clone(clonedSource); + cloneMap.insert(*itS, clonedSource); + } + + // Clone the polygon sets. + for (const FCDGeometryPolygons** itP = polygons.begin(); itP != polygons.end(); ++itP) + { + FCDGeometryPolygons* clonedPolys = clone->AddPolygons(); + (*itP)->Clone(clonedPolys, cloneMap); + } + + return clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryMesh.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygons.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygons.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygons.cpp (revision 24247) @@ -1,337 +1,337 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDGeometryPolygonsInput.h" -#include "FCDocument/FCDGeometrySource.h" - -// -// FCDGeometryPolygons -// - -ImplementObjectType(FCDGeometryPolygons); -ImplementParameterObject(FCDGeometryPolygons, FCDGeometryPolygonsInput, inputs, new FCDGeometryPolygonsInput(parent->GetDocument(), parent)); -ImplementParameterObject(FCDGeometryPolygons, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); - -FCDGeometryPolygons::FCDGeometryPolygons(FCDocument* document, FCDGeometryMesh* _parent) -: FCDObject(document) -, parent(_parent) -, InitializeParameterNoArg(inputs) -, InitializeParameterNoArg(faceVertexCounts) -, InitializeParameterNoArg(holeFaces) -, InitializeParameter(primitiveType, POLYGONS) -, faceVertexCount(0), faceOffset(0), faceVertexOffset(0), holeOffset(0) -, InitializeParameterNoArg(materialSemantic) -, InitializeParameterNoArg(extra) -{ - // Pre-buffer the face-vertex counts so that AddFaceVertexCount won't be extremely costly. - faceVertexCounts.reserve(32); -} - -FCDGeometryPolygons::~FCDGeometryPolygons() -{ - holeFaces.clear(); - parent = NULL; -} - -FCDExtra* FCDGeometryPolygons::GetExtra() -{ - return (extra != NULL) ? extra : (extra = new FCDExtra(GetDocument(), this)); -} - -// Creates a new face. -void FCDGeometryPolygons::AddFace(uint32 degree) -{ - bool newPolygonSet = faceVertexCounts.empty(); - faceVertexCounts.push_back(degree); - - // Inserts empty indices - size_t inputCount = inputs.size(); - for (size_t i = 0; i < inputCount; ++i) - { - FCDGeometryPolygonsInput* input = inputs[i]; - if (!newPolygonSet && input->OwnsIndices()) input->SetIndexCount(input->GetIndexCount() + degree); - else if (newPolygonSet && input->GetIndexCount() == 0) - { - // Declare this input as the owner! - input->SetIndexCount(degree); - } - } - - parent->Recalculate(); - SetDirtyFlag(); -} - -// Removes a face -void FCDGeometryPolygons::RemoveFace(size_t index) -{ - FUAssert(index < GetFaceCount(), return); - - // Remove the associated indices, if they exist. - size_t offset = GetFaceVertexOffset(index); - size_t indexCount = GetFaceVertexCount(index); - size_t inputCount = inputs.size(); - for (size_t i = 0; i < inputCount; ++i) - { - FCDGeometryPolygonsInput* input = inputs[i]; - if (!input->OwnsIndices()) continue; - - size_t inputIndexCount = input->GetIndexCount(); - if (offset < inputIndexCount) - { - // Move the indices backwards. - uint32* indices = input->GetIndices(); - for (size_t o = offset; o < inputIndexCount - indexCount; ++o) - { - indices[o] = indices[o + indexCount]; - } - input->SetIndexCount(max(offset, inputIndexCount - indexCount)); - } - } - - // Remove the face and its holes - size_t holeBefore = GetHoleCountBefore(index); - size_t holeCount = GetHoleCount(index); - faceVertexCounts.erase(index + holeBefore, holeCount + 1); // +1 in order to remove the polygon as well as the holes. - - parent->Recalculate(); - SetDirtyFlag(); -} - -// Calculates the offset of face-vertex pairs before the given face index within the polygon set. -size_t FCDGeometryPolygons::GetFaceVertexOffset(size_t index) const -{ - size_t offset = 0; - - // We'll need to skip over the holes - size_t holeCount = GetHoleCountBefore(index); - if (index + holeCount < faceVertexCounts.size()) - { - // Sum up the wanted offset - UInt32List::const_iterator end = faceVertexCounts.begin() + index + holeCount; - for (UInt32List::const_iterator it = faceVertexCounts.begin(); it != end; ++it) - { - offset += (*it); - } - } - return offset; -} - -// Calculates the number of holes within the polygon set that appear before the given face index. -size_t FCDGeometryPolygons::GetHoleCountBefore(size_t index) const -{ - size_t holeCount = 0; - for (UInt32List::const_iterator it = holeFaces.begin(); it != holeFaces.end(); ++it) - { - if ((*it) <= index) { ++holeCount; ++index; } - } - return holeCount; -} - -// Retrieves the number of holes within a given face. -size_t FCDGeometryPolygons::GetHoleCount(size_t index) const -{ - size_t holeCount = 0; - for (size_t i = index + GetHoleCountBefore(index) + 1; i < faceVertexCounts.size(); ++i) - { - bool isHoled = holeFaces.find((uint32) i) != holeFaces.end(); - if (!isHoled) break; - else ++holeCount; - } - return holeCount; -} - -// The number of face-vertex pairs for a given face. -size_t FCDGeometryPolygons::GetFaceVertexCount(size_t index) const -{ - size_t count = 0; - if (index < GetFaceCount()) - { - size_t holeCount = GetHoleCount(index); - UInt32List::const_iterator it = faceVertexCounts.begin() + index + GetHoleCountBefore(index); - UInt32List::const_iterator end = it + holeCount + 1; // +1 in order to sum the face-vertex pairs of the polygon as its holes. - for (; it != end; ++it) count += (*it); - } - return count; -} - -FCDGeometryPolygonsInput* FCDGeometryPolygons::AddInput(FCDGeometrySource* source, uint32 offset) -{ - FCDGeometryPolygonsInput* input = new FCDGeometryPolygonsInput(GetDocument(), this); - inputs.push_back(input); - input->SetOffset(offset); - input->SetSource(source); - SetNewChildFlag(); - return input; -} - -void FCDGeometryPolygons::SetHoleFaceCount(size_t count) -{ - holeFaces.resize(count); - SetDirtyFlag(); -} - -bool FCDGeometryPolygons::IsHoleFaceHole(size_t index) -{ - return holeFaces.find((uint32) index) != holeFaces.end(); -} - -void FCDGeometryPolygons::AddHole(uint32 index) -{ - FUAssert(!IsHoleFaceHole(index), return); - - // Ordered insert - const uint32* it = holeFaces.begin(); - for (; it != holeFaces.end(); ++it) - { - if (index < (*it)) break; - } - holeFaces.insert(it - holeFaces.begin(), index); -} - -void FCDGeometryPolygons::AddFaceVertexCount(uint32 count) -{ - faceVertexCounts.push_back(count); -} - -void FCDGeometryPolygons::SetFaceVertexCountCount(size_t count) -{ - faceVertexCounts.resize(count); -} - -const FCDGeometryPolygonsInput* FCDGeometryPolygons::FindInput(FUDaeGeometryInput::Semantic semantic) const -{ - for (const FCDGeometryPolygonsInput** it = inputs.begin(); it != inputs.end(); ++it) - { - if ((*it)->GetSemantic() == semantic) return (*it); - } - return NULL; -} - -const FCDGeometryPolygonsInput* FCDGeometryPolygons::FindInput(const FCDGeometrySource* source) const -{ - for (const FCDGeometryPolygonsInput** it = inputs.begin(); it != inputs.end(); ++it) - { - if ((*it)->GetSource() == source) return (*it); - } - return NULL; -} - -FCDGeometryPolygonsInput* FCDGeometryPolygons::FindInput(const fm::string& sourceId) -{ - const char* s = sourceId.c_str(); - if (*s == '#') ++s; - size_t inputCount = inputs.size(); - for (size_t i = 0; i < inputCount; ++i) - { - FCDGeometryPolygonsInput* input = inputs[i]; - if (input->GetSource()->GetDaeId() == s) return input; - } - return NULL; -} - -void FCDGeometryPolygons::FindInputs(FUDaeGeometryInput::Semantic semantic, FCDGeometryPolygonsInputConstList& _inputs) const -{ - for (const FCDGeometryPolygonsInput** it = inputs.begin(); it != inputs.end(); ++it) - { - if ((*it)->GetSemantic() == semantic) _inputs.push_back(*it); - } -} - -// Recalculates the face-vertex count within the polygons -void FCDGeometryPolygons::Recalculate() -{ - faceVertexCount = 0; - for (const uint32* itC = faceVertexCounts.begin(); itC != faceVertexCounts.end(); ++itC) - { - faceVertexCount += (*itC); - } - SetDirtyFlag(); -} - -// [DEPRECATED] -bool FCDGeometryPolygons::IsTriangles() const -{ - UInt32List::const_iterator itC; - for (itC = faceVertexCounts.begin(); itC != faceVertexCounts.end() && (*itC) == 3; ++itC) {} - return (itC == faceVertexCounts.end()); -} - -int32 FCDGeometryPolygons::TestPolyType() const -{ - UInt32List::const_iterator itC = faceVertexCounts.begin(); - if (!faceVertexCounts.empty()) - { - uint32 fCount = *itC; - for (; itC != faceVertexCounts.end() && *itC == fCount; ++itC) {} - if (itC == faceVertexCounts.end()) return fCount; - } - return -1; -} - -// Clone this list of polygons -FCDGeometryPolygons* FCDGeometryPolygons::Clone(FCDGeometryPolygons* clone, const FCDGeometrySourceCloneMap& cloneMap) const -{ - if (clone == NULL) return NULL; - - // Clone the miscellaneous information. - clone->materialSemantic = materialSemantic; - clone->faceVertexCounts = faceVertexCounts; - clone->faceOffset = faceOffset; - clone->faceVertexCount = faceVertexCount; - clone->faceVertexOffset = faceVertexOffset; - clone->holeOffset = holeOffset; - clone->holeFaces = holeFaces; - - // Clone the geometry inputs - // Note that the vertex source inputs are usually created by default. - size_t inputCount = inputs.size(); - clone->inputs.reserve(inputCount); - for (size_t i = 0; i < inputCount; ++i) - { - // Find the cloned source that correspond to the original input. - FCDGeometrySource* cloneSource = NULL; - FCDGeometrySourceCloneMap::const_iterator it = cloneMap.find(inputs[i]->GetSource()); - if (it == cloneMap.end()) - { - // Attempt to match by ID instead. - const fm::string& id = inputs[i]->GetSource()->GetDaeId(); - cloneSource = clone->GetParent()->FindSourceById(id); - } - else - { - cloneSource = (*it).second; - } - - // Retrieve or create the input to clone. - FCDGeometryPolygonsInput* input = clone->FindInput(cloneSource); - if (input == NULL) - { - input = clone->AddInput(cloneSource, inputs[i]->GetOffset()); - } - - // Clone the input information. - if (inputs[i]->OwnsIndices()) - { - input->SetIndices(inputs[i]->GetIndices(), inputs[i]->GetIndexCount()); - } - input->SetSet(inputs[i]->GetSet()); - } - - return clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDGeometryPolygonsInput.h" +#include "FCDocument/FCDGeometrySource.h" + +// +// FCDGeometryPolygons +// + +ImplementObjectType(FCDGeometryPolygons); +ImplementParameterObject(FCDGeometryPolygons, FCDGeometryPolygonsInput, inputs, new FCDGeometryPolygonsInput(parent->GetDocument(), parent)); +ImplementParameterObject(FCDGeometryPolygons, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); + +FCDGeometryPolygons::FCDGeometryPolygons(FCDocument* document, FCDGeometryMesh* _parent) +: FCDObject(document) +, parent(_parent) +, InitializeParameterNoArg(inputs) +, InitializeParameterNoArg(faceVertexCounts) +, InitializeParameterNoArg(holeFaces) +, InitializeParameter(primitiveType, POLYGONS) +, faceVertexCount(0), faceOffset(0), faceVertexOffset(0), holeOffset(0) +, InitializeParameterNoArg(materialSemantic) +, InitializeParameterNoArg(extra) +{ + // Pre-buffer the face-vertex counts so that AddFaceVertexCount won't be extremely costly. + faceVertexCounts.reserve(32); +} + +FCDGeometryPolygons::~FCDGeometryPolygons() +{ + holeFaces.clear(); + parent = NULL; +} + +FCDExtra* FCDGeometryPolygons::GetExtra() +{ + return (extra != NULL) ? extra : (extra = new FCDExtra(GetDocument(), this)); +} + +// Creates a new face. +void FCDGeometryPolygons::AddFace(uint32 degree) +{ + bool newPolygonSet = faceVertexCounts.empty(); + faceVertexCounts.push_back(degree); + + // Inserts empty indices + size_t inputCount = inputs.size(); + for (size_t i = 0; i < inputCount; ++i) + { + FCDGeometryPolygonsInput* input = inputs[i]; + if (!newPolygonSet && input->OwnsIndices()) input->SetIndexCount(input->GetIndexCount() + degree); + else if (newPolygonSet && input->GetIndexCount() == 0) + { + // Declare this input as the owner! + input->SetIndexCount(degree); + } + } + + parent->Recalculate(); + SetDirtyFlag(); +} + +// Removes a face +void FCDGeometryPolygons::RemoveFace(size_t index) +{ + FUAssert(index < GetFaceCount(), return); + + // Remove the associated indices, if they exist. + size_t offset = GetFaceVertexOffset(index); + size_t indexCount = GetFaceVertexCount(index); + size_t inputCount = inputs.size(); + for (size_t i = 0; i < inputCount; ++i) + { + FCDGeometryPolygonsInput* input = inputs[i]; + if (!input->OwnsIndices()) continue; + + size_t inputIndexCount = input->GetIndexCount(); + if (offset < inputIndexCount) + { + // Move the indices backwards. + uint32* indices = input->GetIndices(); + for (size_t o = offset; o < inputIndexCount - indexCount; ++o) + { + indices[o] = indices[o + indexCount]; + } + input->SetIndexCount(max(offset, inputIndexCount - indexCount)); + } + } + + // Remove the face and its holes + size_t holeBefore = GetHoleCountBefore(index); + size_t holeCount = GetHoleCount(index); + faceVertexCounts.erase(index + holeBefore, holeCount + 1); // +1 in order to remove the polygon as well as the holes. + + parent->Recalculate(); + SetDirtyFlag(); +} + +// Calculates the offset of face-vertex pairs before the given face index within the polygon set. +size_t FCDGeometryPolygons::GetFaceVertexOffset(size_t index) const +{ + size_t offset = 0; + + // We'll need to skip over the holes + size_t holeCount = GetHoleCountBefore(index); + if (index + holeCount < faceVertexCounts.size()) + { + // Sum up the wanted offset + UInt32List::const_iterator end = faceVertexCounts.begin() + index + holeCount; + for (UInt32List::const_iterator it = faceVertexCounts.begin(); it != end; ++it) + { + offset += (*it); + } + } + return offset; +} + +// Calculates the number of holes within the polygon set that appear before the given face index. +size_t FCDGeometryPolygons::GetHoleCountBefore(size_t index) const +{ + size_t holeCount = 0; + for (UInt32List::const_iterator it = holeFaces.begin(); it != holeFaces.end(); ++it) + { + if ((*it) <= index) { ++holeCount; ++index; } + } + return holeCount; +} + +// Retrieves the number of holes within a given face. +size_t FCDGeometryPolygons::GetHoleCount(size_t index) const +{ + size_t holeCount = 0; + for (size_t i = index + GetHoleCountBefore(index) + 1; i < faceVertexCounts.size(); ++i) + { + bool isHoled = holeFaces.find((uint32) i) != holeFaces.end(); + if (!isHoled) break; + else ++holeCount; + } + return holeCount; +} + +// The number of face-vertex pairs for a given face. +size_t FCDGeometryPolygons::GetFaceVertexCount(size_t index) const +{ + size_t count = 0; + if (index < GetFaceCount()) + { + size_t holeCount = GetHoleCount(index); + UInt32List::const_iterator it = faceVertexCounts.begin() + index + GetHoleCountBefore(index); + UInt32List::const_iterator end = it + holeCount + 1; // +1 in order to sum the face-vertex pairs of the polygon as its holes. + for (; it != end; ++it) count += (*it); + } + return count; +} + +FCDGeometryPolygonsInput* FCDGeometryPolygons::AddInput(FCDGeometrySource* source, uint32 offset) +{ + FCDGeometryPolygonsInput* input = new FCDGeometryPolygonsInput(GetDocument(), this); + inputs.push_back(input); + input->SetOffset(offset); + input->SetSource(source); + SetNewChildFlag(); + return input; +} + +void FCDGeometryPolygons::SetHoleFaceCount(size_t count) +{ + holeFaces.resize(count); + SetDirtyFlag(); +} + +bool FCDGeometryPolygons::IsHoleFaceHole(size_t index) +{ + return holeFaces.find((uint32) index) != holeFaces.end(); +} + +void FCDGeometryPolygons::AddHole(uint32 index) +{ + FUAssert(!IsHoleFaceHole(index), return); + + // Ordered insert + const uint32* it = holeFaces.begin(); + for (; it != holeFaces.end(); ++it) + { + if (index < (*it)) break; + } + holeFaces.insert(it - holeFaces.begin(), index); +} + +void FCDGeometryPolygons::AddFaceVertexCount(uint32 count) +{ + faceVertexCounts.push_back(count); +} + +void FCDGeometryPolygons::SetFaceVertexCountCount(size_t count) +{ + faceVertexCounts.resize(count); +} + +const FCDGeometryPolygonsInput* FCDGeometryPolygons::FindInput(FUDaeGeometryInput::Semantic semantic) const +{ + for (const FCDGeometryPolygonsInput** it = inputs.begin(); it != inputs.end(); ++it) + { + if ((*it)->GetSemantic() == semantic) return (*it); + } + return NULL; +} + +const FCDGeometryPolygonsInput* FCDGeometryPolygons::FindInput(const FCDGeometrySource* source) const +{ + for (const FCDGeometryPolygonsInput** it = inputs.begin(); it != inputs.end(); ++it) + { + if ((*it)->GetSource() == source) return (*it); + } + return NULL; +} + +FCDGeometryPolygonsInput* FCDGeometryPolygons::FindInput(const fm::string& sourceId) +{ + const char* s = sourceId.c_str(); + if (*s == '#') ++s; + size_t inputCount = inputs.size(); + for (size_t i = 0; i < inputCount; ++i) + { + FCDGeometryPolygonsInput* input = inputs[i]; + if (input->GetSource()->GetDaeId() == s) return input; + } + return NULL; +} + +void FCDGeometryPolygons::FindInputs(FUDaeGeometryInput::Semantic semantic, FCDGeometryPolygonsInputConstList& _inputs) const +{ + for (const FCDGeometryPolygonsInput** it = inputs.begin(); it != inputs.end(); ++it) + { + if ((*it)->GetSemantic() == semantic) _inputs.push_back(*it); + } +} + +// Recalculates the face-vertex count within the polygons +void FCDGeometryPolygons::Recalculate() +{ + faceVertexCount = 0; + for (const uint32* itC = faceVertexCounts.begin(); itC != faceVertexCounts.end(); ++itC) + { + faceVertexCount += (*itC); + } + SetDirtyFlag(); +} + +// [DEPRECATED] +bool FCDGeometryPolygons::IsTriangles() const +{ + UInt32List::const_iterator itC; + for (itC = faceVertexCounts.begin(); itC != faceVertexCounts.end() && (*itC) == 3; ++itC) {} + return (itC == faceVertexCounts.end()); +} + +int32 FCDGeometryPolygons::TestPolyType() const +{ + UInt32List::const_iterator itC = faceVertexCounts.begin(); + if (!faceVertexCounts.empty()) + { + uint32 fCount = *itC; + for (; itC != faceVertexCounts.end() && *itC == fCount; ++itC) {} + if (itC == faceVertexCounts.end()) return fCount; + } + return -1; +} + +// Clone this list of polygons +FCDGeometryPolygons* FCDGeometryPolygons::Clone(FCDGeometryPolygons* clone, const FCDGeometrySourceCloneMap& cloneMap) const +{ + if (clone == NULL) return NULL; + + // Clone the miscellaneous information. + clone->materialSemantic = materialSemantic; + clone->faceVertexCounts = faceVertexCounts; + clone->faceOffset = faceOffset; + clone->faceVertexCount = faceVertexCount; + clone->faceVertexOffset = faceVertexOffset; + clone->holeOffset = holeOffset; + clone->holeFaces = holeFaces; + + // Clone the geometry inputs + // Note that the vertex source inputs are usually created by default. + size_t inputCount = inputs.size(); + clone->inputs.reserve(inputCount); + for (size_t i = 0; i < inputCount; ++i) + { + // Find the cloned source that correspond to the original input. + FCDGeometrySource* cloneSource = NULL; + FCDGeometrySourceCloneMap::const_iterator it = cloneMap.find(inputs[i]->GetSource()); + if (it == cloneMap.end()) + { + // Attempt to match by ID instead. + const fm::string& id = inputs[i]->GetSource()->GetDaeId(); + cloneSource = clone->GetParent()->FindSourceById(id); + } + else + { + cloneSource = (*it).second; + } + + // Retrieve or create the input to clone. + FCDGeometryPolygonsInput* input = clone->FindInput(cloneSource); + if (input == NULL) + { + input = clone->AddInput(cloneSource, inputs[i]->GetOffset()); + } + + // Clone the input information. + if (inputs[i]->OwnsIndices()) + { + input->SetIndices(inputs[i]->GetIndices(), inputs[i]->GetIndexCount()); + } + input->SetSet(inputs[i]->GetSet()); + } + + return clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygons.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsTools.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsTools.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsTools.cpp (revision 24247) @@ -1,1203 +1,1203 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDGeometryPolygonsInput.h" -#include "FCDocument/FCDGeometryPolygonsTools.h" -#include "FCDocument/FCDGeometrySource.h" -#include "FCDocument/FCDAnimated.h" - -namespace FCDGeometryPolygonsTools -{ - // Triangulates a mesh. - void Triangulate(FCDGeometryMesh* mesh) - { - if (mesh == NULL) return; - - size_t polygonsCount = mesh->GetPolygonsCount(); - for (size_t i = 0; i < polygonsCount; ++i) - { - Triangulate(mesh->GetPolygons(i), false); - } - - // Recalculate the mesh/polygons statistics - mesh->Recalculate(); - } - - // Triangulates a polygons set. - void Triangulate(FCDGeometryPolygons* polygons, bool recalculate) - { - if (polygons == NULL) return; - if (polygons->GetPrimitiveType() == FCDGeometryPolygons::LINE_STRIPS || polygons->GetPrimitiveType() == FCDGeometryPolygons::LINES || polygons->GetPrimitiveType() == FCDGeometryPolygons::POINTS) return; - - // Pre-allocate and ready the end index/count buffers - size_t oldFaceCount = polygons->GetFaceVertexCountCount(); - UInt32List oldFaceVertexCounts(polygons->GetFaceVertexCounts(), oldFaceCount); - polygons->SetFaceVertexCountCount(0); - fm::pvector indicesOwners; - fm::vector oldDataIndices; - size_t inputCount = polygons->GetInputCount(); - for (size_t i = 0; i < inputCount; ++i) - { - FCDGeometryPolygonsInput* input = polygons->GetInput(i); - if (input->GetIndexCount() == 0) continue; - uint32* indices = input->GetIndices(); - size_t oldIndexCount = input->GetIndexCount(); - oldDataIndices.push_back(UInt32List(indices, oldIndexCount)); - indicesOwners.push_back(input); - input->SetIndexCount(0); - input->ReserveIndexCount(oldIndexCount); - } - size_t dataIndicesCount = oldDataIndices.size(); - - // Rebuild the index/count buffers. - // Drop holes and polygons with less than three vertices. - size_t oldOffset = 0; - for (size_t oldFaceIndex = 0; oldFaceIndex < oldFaceCount; ++oldFaceIndex) - { - size_t oldFaceVertexCount = oldFaceVertexCounts[oldFaceIndex]; - bool isHole = polygons->IsHoleFaceHole((uint32) oldFaceIndex); - if (!isHole && oldFaceVertexCount >= 3) - { - if (polygons->GetPrimitiveType() == FCDGeometryPolygons::POLYGONS || polygons->GetPrimitiveType() == FCDGeometryPolygons::TRIANGLE_FANS) - { - // Fan-triangulation: works well on convex polygons. - size_t triangleCount = oldFaceVertexCount - 2; - for (size_t triangleIndex = 0; triangleIndex < triangleCount; ++triangleIndex) - { - for (size_t j = 0; j < dataIndicesCount; ++j) - { - UInt32List& oldData = oldDataIndices[j]; - FCDGeometryPolygonsInput* input = indicesOwners[j]; - input->AddIndex(oldData[oldOffset]); - input->AddIndex(oldData[oldOffset + triangleIndex + 1]); - input->AddIndex(oldData[oldOffset + triangleIndex + 2]); - } - polygons->AddFaceVertexCount(3); - } - } - else if (polygons->GetPrimitiveType() == FCDGeometryPolygons::TRIANGLE_STRIPS) - { - // Fan-triangulation: works well on convex polygons. - size_t triangleCount = oldFaceVertexCount - 2; - for (size_t triangleIndex = 0; triangleIndex < triangleCount; ++triangleIndex) - { - for (size_t j = 0; j < dataIndicesCount; ++j) - { - UInt32List& oldData = oldDataIndices[j]; - FCDGeometryPolygonsInput* input = indicesOwners[j]; - if ((triangleIndex & 0x1) == 0x0) - { - input->AddIndex(oldData[oldOffset + triangleIndex + 0]); - input->AddIndex(oldData[oldOffset + triangleIndex + 1]); - input->AddIndex(oldData[oldOffset + triangleIndex + 2]); - } - else - { - // Flip the winding of every second triangle in the strip. - input->AddIndex(oldData[oldOffset + triangleIndex + 0]); - input->AddIndex(oldData[oldOffset + triangleIndex + 2]); - input->AddIndex(oldData[oldOffset + triangleIndex + 1]); - } - } - polygons->AddFaceVertexCount(3); - } - } - } - oldOffset += oldFaceVertexCount; - } - - polygons->SetPrimitiveType(FCDGeometryPolygons::POLYGONS); - polygons->SetHoleFaceCount(0); - - if (recalculate) polygons->Recalculate(); - } - - static uint32 CompressSortedVector(FMVector3& toInsert, FloatList& insertedList, UInt32List& compressIndexReferences) - { - // Look for this vector within the already inserted list. - size_t start = 0, end = compressIndexReferences.size(), mid; - for (mid = (start + end) / 2; start < end; mid = (start + end) / 2) - { - uint32 index = compressIndexReferences[mid]; - if (toInsert.x == insertedList[3 * index]) break; - else if (toInsert.x < insertedList[3 * index]) end = mid; - else start = mid + 1; - } - - // Look for the tolerable range within the binary-sorted dimension. - size_t rangeStart, rangeEnd; - for (rangeStart = mid; rangeStart > 0; --rangeStart) - { - uint32 index = compressIndexReferences[rangeStart - 1]; - if (!IsEquivalent(insertedList[3 * index], toInsert.x)) break; - } - for (rangeEnd = min(mid + 1, compressIndexReferences.size()); rangeEnd < compressIndexReferences.size(); ++rangeEnd) - { - uint32 index = compressIndexReferences[rangeEnd]; - if (!IsEquivalent(insertedList[3 * index], toInsert.x)) break; - } - FUAssert(rangeStart < rangeEnd || (rangeStart == rangeEnd && rangeEnd == compressIndexReferences.size()), return 0); - - // Look for an equivalent vector within the tolerable range - for (size_t g = rangeStart; g < rangeEnd; ++g) - { - uint32 index = compressIndexReferences[g]; - if (IsEquivalent(toInsert, *(const FMVector3*) &insertedList[3 * index])) return index; - } - - // Insert this new vector in the list and add the index reference at the correct position. - uint32 compressIndex = (uint32) (insertedList.size() / 3); - compressIndexReferences.insert(compressIndexReferences.begin() + mid, compressIndex); - insertedList.push_back(toInsert.x); - insertedList.push_back(toInsert.y); - insertedList.push_back(toInsert.z); - return compressIndex; - } - - struct TangentialVertex - { - float* normalPointer; - float* texCoordPointer; - FMVector3 tangent; - uint32 count; - uint32 tangentId; - uint32 binormalId; - }; - typedef fm::vector TangentialVertexList; - - // Generates the texture tangents and binormals for a given source of texture coordinates. - void GenerateTextureTangentBasis(FCDGeometryMesh* mesh, FCDGeometrySource* texcoordSource, bool generateBinormals) - { - if (texcoordSource == NULL || mesh == NULL) return; - - // First count the positions. - FCDGeometrySource* positionSource = mesh->FindSourceByType(FUDaeGeometryInput::POSITION); - if (positionSource == NULL) return; - size_t globalVertexCount = positionSource->GetValueCount(); - - // Allocate the tangential vertices. - // This temporary buffer is necessary to ensure we have smooth tangents/binormals. - TangentialVertexList* globalVertices = new TangentialVertexList[globalVertexCount]; - memset(globalVertices, 0, sizeof(TangentialVertexList) * globalVertexCount); - - // This operation is done on the tessellation: fill in the list of tangential vertices. - size_t polygonsCount = mesh->GetPolygonsCount(); - for (size_t i = 0; i < polygonsCount; ++i) - { - FCDGeometryPolygons* polygons = mesh->GetPolygons(i); - - // Verify that this polygons set uses the given texture coordinate source. - FCDGeometryPolygonsInput* texcoordInput = polygons->FindInput(texcoordSource); - if (texcoordInput == NULL) continue; - - // Retrieve the data and index buffer of positions/normals/texcoords for this polygons set. - FCDGeometryPolygonsInput* positionInput = polygons->FindInput(FUDaeGeometryInput::POSITION); - FCDGeometryPolygonsInput* normalsInput = polygons->FindInput(FUDaeGeometryInput::NORMAL); - if (positionInput == NULL || normalsInput == NULL) continue; - FCDGeometrySource* positionSource = positionInput->GetSource(); - FCDGeometrySource* normalsSource = normalsInput->GetSource(); - FCDGeometrySource* texcoordSource = texcoordInput->GetSource(); - if (positionSource == NULL || normalsSource == NULL || texcoordSource == NULL) continue; - uint32 positionStride = positionSource->GetStride(); - uint32 normalsStride = normalsSource->GetStride(); - uint32 texcoordStride = texcoordSource->GetStride(); - if (positionStride < 3 || normalsStride < 3 || texcoordStride < 2) continue; - uint32* positionIndices = positionInput->GetIndices(); - uint32* normalsIndices = normalsInput->GetIndices(); - uint32* texcoordIndices = texcoordInput->GetIndices(); - size_t indexCount = positionInput->GetIndexCount(); - if (positionIndices == NULL || normalsIndices == NULL || texcoordIndices == NULL) continue; - if (indexCount == 0 || indexCount != normalsInput->GetIndexCount() || indexCount != texcoordInput->GetIndexCount()) continue; - float* positionData = positionSource->GetData(); - float* normalsData = normalsSource->GetData(); - float* texcoordData = texcoordSource->GetData(); - size_t positionDataLength = positionSource->GetDataCount(); - size_t normalsDataLength = normalsSource->GetDataCount(); - size_t texcoordDataLength = texcoordSource->GetDataCount(); - if (positionDataLength == 0 || normalsDataLength == 0 || texcoordDataLength == 0) continue; - - // Iterate of the faces of the polygons set. This includes holes. - size_t faceCount = polygons->GetFaceVertexCountCount(); - size_t faceVertexOffset = 0; - for (size_t faceIndex = 0; faceIndex < faceCount; ++faceIndex) - { - size_t faceVertexCount = polygons->GetFaceVertexCounts()[faceIndex]; - for (size_t vertexIndex = 0; vertexIndex < faceVertexCount; ++vertexIndex) - { - // For each face-vertex pair, retrieve the current/previous/next vertex position/normal/texcoord. - size_t previousVertexIndex = (vertexIndex > 0) ? vertexIndex - 1 : faceVertexCount - 1; - size_t nextVertexIndex = (vertexIndex < faceVertexCount - 1) ? vertexIndex + 1 : 0; - FMVector3& previousPosition = *(FMVector3*)&positionData[positionIndices[faceVertexOffset + previousVertexIndex] * positionStride]; - FMVector2& previousTexcoord = *(FMVector2*)&texcoordData[texcoordIndices[faceVertexOffset + previousVertexIndex] * texcoordStride]; - FMVector3& currentPosition = *(FMVector3*)&positionData[positionIndices[faceVertexOffset + vertexIndex] * positionStride]; - float* texcoordPtr = &texcoordData[texcoordIndices[faceVertexOffset + vertexIndex] * texcoordStride]; - FMVector2& currentTexcoord = *(FMVector2*)texcoordPtr; - FMVector3& nextPosition = *(FMVector3*)&positionData[positionIndices[faceVertexOffset + nextVertexIndex] * positionStride]; - FMVector2& nextTexcoord = *(FMVector2*)&texcoordData[texcoordIndices[faceVertexOffset + nextVertexIndex] * texcoordStride]; - float* normalPtr = &normalsData[normalsIndices[faceVertexOffset + vertexIndex] * normalsStride]; - FMVector3& normal = *(FMVector3*)normalPtr; - - // The formulae to calculate the tangent-space basis vectors is taken from Maya 7.0 API documentation: - // "Appendix A: Tangent and binormal vectors". - - // Prepare the edge vectors. - FMVector3 previousEdge(0.0f, previousTexcoord.x - currentTexcoord.x, previousTexcoord.y - currentTexcoord.y); - FMVector3 nextEdge(0.0f, nextTexcoord.x - currentTexcoord.x, nextTexcoord.y - currentTexcoord.y); - FMVector3 previousDisplacement = (previousPosition - currentPosition); - FMVector3 nextDisplacement = (nextPosition - currentPosition); - FMVector3 tangent; - - // Calculate the X-coordinate of the tangent vector. - previousEdge.x = previousDisplacement.x; - nextEdge.x = nextDisplacement.x; - FMVector3 crossEdge = nextEdge ^ previousEdge; - if (IsEquivalent(crossEdge.x, 0.0f)) crossEdge.x = 1.0f; // degenerate - tangent.x = crossEdge.y / crossEdge.x; - - // Calculate the Y-coordinate of the tangent vector. - previousEdge.x = previousDisplacement.y; - nextEdge.x = nextDisplacement.y; - crossEdge = nextEdge ^ previousEdge; - if (IsEquivalent(crossEdge.x, 0.0f)) crossEdge.x = 1.0f; // degenerate - tangent.y = crossEdge.y / crossEdge.x; - - // Calculate the Z-coordinate of the tangent vector. - previousEdge.x = previousDisplacement.z; - nextEdge.x = nextDisplacement.z; - crossEdge = nextEdge ^ previousEdge; - if (IsEquivalent(crossEdge.x, 0.0f)) crossEdge.x = 1.0f; // degenerate - tangent.z = crossEdge.y / crossEdge.x; - - // Take the normal vector at this face-vertex pair, out of the calculated tangent vector - tangent = tangent - normal * (tangent * normal); - tangent.NormalizeIt(); - - // Add this tangent to our tangential vertex. - FUAssert(positionIndices[faceVertexOffset + vertexIndex] < globalVertexCount, continue); - TangentialVertexList& list = globalVertices[positionIndices[faceVertexOffset + vertexIndex]]; - size_t vertexCount = list.size(); - bool found = false; - for (size_t v = 0; v < vertexCount; ++v) - { - if ((normalPtr == list[v].normalPointer) && (texcoordPtr == list[v].texCoordPointer)) - { - list[v].tangent += tangent; - list[v].count++; - found = true; - } - } - if (!found) - { - TangentialVertex v; - v.normalPointer = normalPtr; - v.texCoordPointer = texcoordPtr; - v.count = 1; v.tangent = tangent; - v.tangentId = v.binormalId = ~(uint32)0; - list.push_back(v); - } - } - faceVertexOffset += faceVertexCount; - } - } - - FCDGeometrySource* tangentSource = NULL; - FCDGeometrySource* binormalSource = NULL; - FloatList tangentData; - FloatList binormalData; - UInt32List tangentCompressionIndices; - UInt32List binormalCompressionIndices; - - // Iterate over the polygons again: this time create the source/inputs for the tangents and binormals. - for (size_t i = 0; i < polygonsCount; ++i) - { - FCDGeometryPolygons* polygons = mesh->GetPolygons(i); - - // Verify that this polygons set uses the given texture coordinate source. - FCDGeometryPolygonsInput* texcoordInput = polygons->FindInput(texcoordSource); - if (texcoordInput == NULL) continue; - - // Retrieve the data and index buffer of positions/normals/texcoords for this polygons set. - FCDGeometryPolygonsInput* positionInput = polygons->FindInput(FUDaeGeometryInput::POSITION); - FCDGeometryPolygonsInput* normalsInput = polygons->FindInput(FUDaeGeometryInput::NORMAL); - if (positionInput == NULL || normalsInput == NULL) continue; - FCDGeometrySource* normalsSource = normalsInput->GetSource(); - FCDGeometrySource* texcoordSource = texcoordInput->GetSource(); - if (normalsSource == NULL || texcoordSource == NULL) continue; - uint32 normalsStride = normalsSource->GetStride(); - uint32 texcoordStride = texcoordSource->GetStride(); - if (normalsStride < 3 || texcoordStride < 2) continue; - uint32* positionIndices = positionInput->GetIndices(); - uint32* normalsIndices = normalsInput->GetIndices(); - uint32* texcoordIndices = texcoordInput->GetIndices(); - size_t indexCount = positionInput->GetIndexCount(); - if (positionIndices == NULL || normalsIndices == NULL || texcoordIndices == NULL) continue; - if (indexCount == 0 || indexCount != normalsInput->GetIndexCount() || indexCount != texcoordInput->GetIndexCount()) continue; - float* normalsData = normalsSource->GetData(); - float* texcoordData = texcoordSource->GetData(); - size_t normalsDataLength = normalsSource->GetDataCount(); - size_t texcoordDataLength = texcoordSource->GetDataCount(); - if (normalsDataLength == 0 || texcoordDataLength == 0) continue; - - // Create the texture tangents/binormals sources - if (tangentSource == NULL) - { - tangentSource = mesh->AddSource(FUDaeGeometryInput::TEXTANGENT); - tangentSource->SetDaeId(texcoordSource->GetDaeId() + "-tangents"); - tangentData.reserve(texcoordSource->GetDataCount()); - if (generateBinormals) - { - binormalSource = mesh->AddSource(FUDaeGeometryInput::TEXBINORMAL); - binormalSource->SetDaeId(texcoordSource->GetDaeId() + "-binormals"); - binormalData.reserve(tangentSource->GetDataCount()); - } - } - - // Calculate the next available offset - uint32 inputOffset = 0; - size_t inputCount = polygons->GetInputCount(); - for (size_t j = 0; j < inputCount; ++j) - { - inputOffset = max(inputOffset, polygons->GetInput(j)->GetOffset()); - } - - // Create the polygons set input for both the tangents and binormals - FCDGeometryPolygonsInput* tangentInput = polygons->AddInput(tangentSource, inputOffset + 1); - tangentInput->SetSet(texcoordInput->GetSet()); - tangentInput->ReserveIndexCount(indexCount); - FCDGeometryPolygonsInput* binormalInput = NULL; - if (binormalSource != NULL) - { - binormalInput = polygons->AddInput(binormalSource, inputOffset + 2); - binormalInput->SetSet(tangentInput->GetSet()); - binormalInput->ReserveIndexCount(indexCount); - } - - // Iterate of the faces of the polygons set. This includes holes. - size_t vertexCount = positionInput->GetIndexCount(); - size_t faceVertexOffset = 0; - for (size_t vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex) - { - // For each face-vertex pair retrieve the current vertex normal&texcoord. - float* normalPtr = &normalsData[normalsIndices[faceVertexOffset + vertexIndex] * normalsStride]; - float* texcoordPtr = - &texcoordData[texcoordIndices[faceVertexOffset + vertexIndex] * texcoordStride]; - - FUAssert(positionIndices[faceVertexOffset + vertexIndex] < globalVertexCount, continue); - TangentialVertexList& list = globalVertices[positionIndices[faceVertexOffset + vertexIndex]]; - size_t vertexCount = list.size(); - for (size_t v = 0; v < vertexCount; ++v) - { - if ((list[v].normalPointer == normalPtr) && (list[v].texCoordPointer == texcoordPtr)) - { - if (list[v].tangentId == ~(uint32)0) - { - list[v].tangent /= (float) list[v].count; // Average the tangent. - list[v].tangent.Normalize(); - list[v].tangentId = CompressSortedVector(list[v].tangent, tangentData, tangentCompressionIndices); - } - tangentInput->AddIndex(list[v].tangentId); - - if (binormalInput != NULL) - { - if (list[v].binormalId == ~(uint32)0) - { - // Calculate and store the binormal. - FMVector3 binormal = (*(FMVector3*)normalPtr ^ list[v].tangent).Normalize(); - uint32 compressedIndex = CompressSortedVector(binormal, binormalData, binormalCompressionIndices); - list[v].binormalId = compressedIndex; - } - binormalInput->AddIndex(list[v].binormalId); - } - } - } - } - } - - if (tangentSource != NULL) tangentSource->SetData(tangentData, 3); - if (binormalSource != NULL) binormalSource->SetData(binormalData, 3); - } - - struct HashIndexMapItem { UInt32List allValues; UInt32List newIndex; }; - typedef fm::vector UInt32ListList; - typedef fm::pvector InputList; - typedef fm::map HashIndexMap; - typedef fm::pvector FCDGeometryIndexTranslationMapList; - - void GenerateUniqueIndices(FCDGeometryMesh* mesh, FCDGeometryPolygons* polygonsToProcess, FCDNewIndicesList& outIndices, FCDGeometryIndexTranslationMapList& outTranslationMaps) - { - // Prepare a list of unique index buffers. - size_t polygonsCount = mesh->GetPolygonsCount(); - if (polygonsCount == 0) return; - size_t totalVertexCount = 0; - - size_t outIndicesMinSize = (polygonsToProcess == NULL) ? polygonsCount : 1; - if (outIndices.size() < outIndicesMinSize) outIndices.resize(outIndicesMinSize); - - // Fill in the index buffers for each polygons set. - for (size_t p = 0; p < polygonsCount; ++p) - { - FCDGeometryPolygons* polygons = mesh->GetPolygons(p); - // DO NOT -EVER- TOUCH MY INDICES - (Says Psuedo-FCDGeometryPoints) - // Way to much code assumes (and carefully guards) the existing sorted structure - if (polygons->GetPrimitiveType() == FCDGeometryPolygons::POINTS) return; - if (polygonsToProcess != NULL && polygons != polygonsToProcess) continue; - - // Find the list we are going to pump our new indices into - UInt32List& outPolyIndices = (polygonsToProcess == NULL) ? outIndices[p] : outIndices.front(); - - // Find all the indices list to determine the hash size. - InputList idxOwners; - size_t inputCount = polygons->GetInputCount(); - for (size_t i = 0; i < inputCount; ++i) - { - if (polygons->GetInput(i)->OwnsIndices()) - { - // Drop index lists with the wrong number of values and avoid repeats - FUAssert(idxOwners.empty() || idxOwners.front()->GetIndexCount() == polygons->GetInput(i)->GetIndexCount(), continue); - if (idxOwners.find(polygons->GetInput(i)) == idxOwners.end()) - { - idxOwners.push_back(polygons->GetInput(i)); - } - } - } - size_t listCount = idxOwners.size(); - if (listCount == 0) continue; // no inputs? - - // Set-up a simple hashing function. - UInt32List hashingFunction; - uint32 hashSize = (uint32) listCount; - hashingFunction.reserve(hashSize); - for (uint32 h = 0; h < hashSize; ++h) hashingFunction.push_back(32 * h / hashSize); - - // Iterate over the index lists, hashing/merging the indices. - HashIndexMap hashMap; - size_t originalIndexCount = idxOwners.front()->GetIndexCount(); - outPolyIndices.reserve(originalIndexCount); - - // optimization: cache the indices - uint32** indices = new uint32*[listCount]; - for (size_t l = 0; l < listCount; ++l) - { - indices[l] = idxOwners[l]->GetIndices(); - } - for (size_t i = 0; i < originalIndexCount; ++i) - { - // Generate the hash value for this vertex-face pair. - uint32 hashValue = 0; - for (size_t l = 0; l < listCount; ++l) - { - hashValue ^= (indices[l][i]) << hashingFunction[l]; - } - - // Look for this value in the already-collected ones. - HashIndexMap::iterator it = hashMap.find(hashValue); - HashIndexMapItem* hashItem; - uint32 newIndex = (uint32) totalVertexCount; - if (it != hashMap.end()) - { - hashItem = &((*it).second); - size_t repeatCount = hashItem->allValues.size() / listCount; - for (size_t r = 0; r < repeatCount && newIndex == totalVertexCount; ++r) - { - size_t l; - for (l = 0; l < listCount; ++l) - { - if (indices[l][i] != hashItem->allValues[r * listCount + l]) break; - } - if (l == listCount) - { - // We have a match: re-use this index. - newIndex = hashItem->newIndex[r]; - } - } - } - else - { - HashIndexMap::iterator k = hashMap.insert(hashValue, HashIndexMapItem()); - hashItem = &k->second; - - // optimization: since we will be adding the indices to allValues, know there will be listCount - hashItem->allValues.reserve(listCount); - } - - if (newIndex == totalVertexCount) - { - // Append this new value/index to the hash map item and to the index buffer. - for (size_t l = 0; l < listCount; ++l) - { - hashItem->allValues.push_back(indices[l][i]); - } - hashItem->newIndex.push_back(newIndex); - totalVertexCount++; - } - outPolyIndices.push_back(newIndex); - } - SAFE_DELETE_ARRAY(indices); - } - - // We now have lists of new indices. Create maps so we can quickly - // map the old data to match the new stuff. - size_t meshSourceCount = mesh->GetSourceCount(); - if (outTranslationMaps.size() < meshSourceCount) outTranslationMaps.resize(meshSourceCount); - for (size_t d = 0; d < meshSourceCount; ++d) - { - FCDGeometrySource* oldSource = mesh->GetSource(d); - FCDGeometryIndexTranslationMap* thisMap = new FCDGeometryIndexTranslationMap(); - outTranslationMaps[d] = thisMap; - - // When processing just one polygons set, duplicate the source - // so that the other polygons set can correctly point to the original source. - for (size_t p = 0; p < polygonsCount; ++p) - { - FCDGeometryPolygons* polygons = mesh->GetPolygons(p); - if (polygonsToProcess != NULL && polygonsToProcess != polygons) continue; - const UInt32List& outPolyIndices = (polygonsToProcess == NULL) ? outIndices[p] : outIndices.front(); - FCDGeometryPolygonsInput* oldInput = polygons->FindInput(oldSource); - if (oldInput == NULL) continue; - - // Retrieve the old list of indices and de-reference the data values. - uint32* oldIndexList = oldInput->GetIndices(); - size_t oldIndexCount = oldInput->GetIndexCount(); - if (oldIndexList == NULL || oldIndexCount == 0) continue; - - size_t indexCount = min(oldIndexCount, outPolyIndices.size()); - for (size_t i = 0; i < indexCount; ++i) - { - uint32 newIndex = outPolyIndices[i]; - uint32 oldIndex = oldIndexList[i]; - if (oldIndex >= oldSource->GetValueCount()) continue; - - // Add this value to the translation map. - FCDGeometryIndexTranslationMap::iterator itU = thisMap->find(oldIndex); - if (itU == thisMap->end()) { itU = thisMap->insert(oldIndex, UInt32List()); } - UInt32List::iterator itF = itU->second.find(newIndex); - if (itF == itU->second.end()) itU->second.push_back(newIndex); - } - } - } - } - - void GenerateUniqueIndices(FCDGeometryMesh* mesh, FCDGeometryPolygons* polygonsToProcess, FCDGeometryIndexTranslationMap* translationMap) - { - // Prepare a list of unique index buffers. - size_t polygonsCount = mesh->GetPolygonsCount(); - if (polygonsCount == 0) return; - UInt32ListList indexBuffers; indexBuffers.resize(polygonsCount); - size_t totalVertexCount = 0; - - // Fill in the index buffers for each polygons set. - for (size_t p = 0; p < polygonsCount; ++p) - { - UInt32List& indexBuffer = indexBuffers[p]; - FCDGeometryPolygons* polygons = mesh->GetPolygons(p); - // DO NOT -EVER- TOUCH MY INDICES - (Says Psuedo-FCDGeometryPoints) - // Way to much code assumes (and carefully guards) the existing sorted structure - if (polygons->GetPrimitiveType() == FCDGeometryPolygons::POINTS) return; - if (polygonsToProcess != NULL && polygons != polygonsToProcess) continue; - - // Find all the indices list to determine the hash size. - InputList idxOwners; - size_t inputCount = polygons->GetInputCount(); - for (size_t i = 0; i < inputCount; ++i) - { - FCDGeometryPolygonsInput* input = polygons->GetInput(i); - if (input->OwnsIndices()) - { - // Drop index lists with the wrong number of values and avoid repeats - FUAssert(idxOwners.empty() || idxOwners.front()->GetIndexCount() == input->GetIndexCount(), continue); - if (idxOwners.find(input) == idxOwners.end()) idxOwners.push_back(input); - } - } - size_t listCount = idxOwners.size(); - if (listCount == 0) continue; // no inputs? - - // Set-up a simple hashing function. - UInt32List hashingFunction; - uint32 hashSize = (uint32) listCount; - hashingFunction.reserve(hashSize); - for (uint32 h = 0; h < hashSize; ++h) hashingFunction.push_back(32 * h / hashSize); - - // Iterate over the index lists, hashing/merging the indices. - HashIndexMap hashMap; - size_t originalIndexCount = idxOwners.front()->GetIndexCount(); - indexBuffer.reserve(originalIndexCount); - - // optimization: cache the indices - uint32** indices = new uint32*[listCount]; - for (size_t l = 0; l < listCount; ++l) - { - indices[l] = idxOwners[l]->GetIndices(); - } - for (size_t i = 0; i < originalIndexCount; ++i) - { - // Generate the hash value for this vertex-face pair. - uint32 hashValue = 0; - for (size_t l = 0; l < listCount; ++l) - { - hashValue ^= (indices[l][i]) << hashingFunction[l]; - } - - // Look for this value in the already-collected ones. - HashIndexMap::iterator it = hashMap.find(hashValue); - HashIndexMapItem* hashItem; - uint32 newIndex = (uint32) totalVertexCount; - if (it != hashMap.end()) - { - hashItem = &((*it).second); - size_t repeatCount = hashItem->allValues.size() / listCount; - for (size_t r = 0; r < repeatCount && newIndex == totalVertexCount; ++r) - { - size_t l; - for (l = 0; l < listCount; ++l) - { - if (indices[l][i] != hashItem->allValues[r * listCount + l]) break; - } - if (l == listCount) - { - // We have a match: re-use this index. - newIndex = hashItem->newIndex[r]; - } - } - } - else - { - HashIndexMap::iterator k = hashMap.insert(hashValue, HashIndexMapItem()); - hashItem = &k->second; - - // optimization: since we will be adding the indices to allValues, know there will be listCount - hashItem->allValues.reserve(listCount); - } - - if (newIndex == totalVertexCount) - { - // Append this new value/index to the hash map item and to the index buffer. - for (size_t l = 0; l < listCount; ++l) - { - hashItem->allValues.push_back(indices[l][i]); - } - hashItem->newIndex.push_back(newIndex); - totalVertexCount++; - } - indexBuffer.push_back(newIndex); - } - SAFE_DELETE_ARRAY(indices); - } - - // De-reference the source data so that all the vertex data match the new indices. - size_t meshSourceCount = mesh->GetSourceCount(); - for (size_t d = 0; d < meshSourceCount; ++d) - { - FCDGeometrySource* oldSource = mesh->GetSource(d); - uint32 stride = oldSource->GetStride(); - const float* oldVertexData = oldSource->GetData(); - bool isPositionSource = oldSource->GetType() == FUDaeGeometryInput::POSITION && translationMap != NULL; - FloatList vertexBuffer; - vertexBuffer.resize(stride * totalVertexCount, 0.0f); - - // When processing just one polygons set, duplicate the source - // so that the other polygons set can correctly point to the original source. - FCDGeometrySource* newSource = (polygonsToProcess != NULL) ? mesh->AddSource(oldSource->GetType()) : oldSource; - - FCDAnimatedList newAnimatedList; - newAnimatedList.clear(); - for (size_t p = 0; p < polygonsCount; ++p) - { - const UInt32List& indexBuffer = indexBuffers[p]; - FCDGeometryPolygons* polygons = mesh->GetPolygons(p); - if (polygonsToProcess != NULL && polygonsToProcess != polygons) continue; - FCDGeometryPolygonsInput* oldInput = polygons->FindInput(oldSource); - if (oldInput == NULL) continue; - - // Retrieve the old list of indices and de-reference the data values. - uint32* oldIndexList = oldInput->GetIndices(); - size_t oldIndexCount = oldInput->GetIndexCount(); - if (oldIndexList == NULL || oldIndexCount == 0) continue; - - size_t indexCount = min(oldIndexCount, indexBuffer.size()); - for (size_t i = 0; i < indexCount; ++i) - { - uint32 newIndex = indexBuffer[i]; - uint32 oldIndex = oldIndexList[i]; - if (oldIndex >= oldSource->GetValueCount()) continue; - - FUObjectContainer& animatedValues = oldSource->GetAnimatedValues(); - FCDAnimated* oldAnimated = NULL; - for (size_t j = 0; j < animatedValues.size(); j++) - { - FCDAnimated* animated = animatedValues[j]; - if (animated->GetValue(0) == &(oldVertexData[stride * oldIndex])) - { - oldAnimated = animated; - break; - } - } - if (oldAnimated != NULL) - { - FCDAnimated* newAnimated = oldAnimated->Clone(oldAnimated->GetDocument()); - newAnimated->SetArrayElement(newIndex); - newAnimatedList.push_back(newAnimated); - } - - // [GLaforte - 12-10-2006] Potential performance optimization: this may copy the same data over itself many times. - for (uint32 s = 0; s < stride; ++s) - { - vertexBuffer[stride * newIndex + s] = oldVertexData[stride * oldIndex + s]; - } - - // Add this value to the vertex position translation map. - if (isPositionSource) - { - FCDGeometryIndexTranslationMap::iterator itU = translationMap->find(oldIndex); - if (itU == translationMap->end()) { itU = translationMap->insert(oldIndex, UInt32List()); } - UInt32List::iterator itF = itU->second.find(newIndex); - if (itF == itU->second.end()) itU->second.push_back(newIndex); - } - } - - if (polygonsToProcess != NULL) - { - // Change the relevant input, if it exists, to point towards the new source. - uint32 set = oldInput->GetSet(); - SAFE_RELEASE(oldInput); - FCDGeometryPolygonsInput* newInput = polygons->AddInput(newSource, 0); - newInput->SetSet(set); - } - } - - // Set the compiled data in the source. - // [ewhittom] In some occasions we have no indices and yet - // vertices (for example in incomplete meshes). In these cases we do - // not want to clear the vertices. - if (!(vertexBuffer.empty() && newSource->GetDataCount() != 0)) - { - newSource->SetData(vertexBuffer, stride); - } - FUObjectContainer& animatedList = newSource->GetAnimatedValues(); - animatedList.clear(); - for (FCDAnimatedList::iterator it = newAnimatedList.begin(); - it != newAnimatedList.end(); it++) - { - animatedList.push_back(*it); - } - } - - if (polygonsToProcess == NULL) - { - // Next, make all the sources per-vertex. - size_t _sourceCount = mesh->GetSourceCount(); - for (size_t s = 0; s < _sourceCount; ++s) - { - FCDGeometrySource* it = mesh->GetSource(s); - if (!mesh->IsVertexSource(it)) - { - mesh->AddVertexSource(it); - } - } - } - - // Enforce the index buffers. - for (size_t p = 0; p < polygonsCount; ++p) - { - const UInt32List& indexBuffer = indexBuffers[p]; - FCDGeometryPolygons* polygons = mesh->GetPolygons(p); - if (polygonsToProcess != NULL && polygons != polygonsToProcess) continue; - - size_t inputCount = polygons->GetInputCount(); - for (size_t i = 0; i < inputCount; i++) - { - FCDGeometryPolygonsInput* anyInput = polygons->GetInput(i); - if (anyInput->GetSource()->GetDataCount() == 0) continue; - // [ewhittom] Allow empty index buffers with non-empty vertex buffers - if (indexBuffer.empty()) continue; - - anyInput->SetIndices(&indexBuffer.front(), indexBuffer.size()); - } - } - } - - - - void ApplyUniqueIndices(float* targData, float* srcData, uint32 stride, const FCDGeometryIndexTranslationMap* translationMap) - { - for (FCDGeometryIndexTranslationMap::const_iterator it = translationMap->begin(), itEnd = translationMap->end(); it != itEnd; ++it) - { - const UInt32List& curList = it->second; - for (UInt32List::const_iterator uit = curList.begin(); uit != curList.end(); ++uit) - { - for (uint32 s = 0; s < stride; ++s) - { - targData[stride * (*uit) + s] = srcData[stride * it->first + s]; - } - } - } - } - - void ApplyUniqueIndices(FCDGeometrySource* targSource, uint32 nValues, const FCDGeometryIndexTranslationMap* translationMap) - { - size_t tmSize = translationMap->size(); - FUAssert(targSource->GetValueCount() == tmSize, return); - - uint32 stride = targSource->GetStride(); - FloatList oldData(targSource->GetData(), targSource->GetDataCount()); - - targSource->SetDataCount(nValues * stride); - float* targData = targSource->GetData(); - - ApplyUniqueIndices(targData, oldData.begin(), stride, translationMap); - } - - void ApplyUniqueIndices(FCDGeometryMesh* targMesh, FCDGeometryMesh* baseMesh, const UInt32List& newIndices, const FCDGeometryIndexTranslationMapList& translationMaps) - { - uint32 largest = 0; - const FCDGeometryIndexTranslationMap* aMap = translationMaps[0]; - for (FCDGeometryIndexTranslationMap::const_iterator it = aMap->begin(), itEnd = aMap->end(); it != itEnd; ++it) - { - const UInt32List& curList = it->second; - for (UInt32List::const_iterator uit = curList.begin(); uit != curList.end(); ++uit) - { - largest = max(largest, *uit); - } - } - - uint32 newBufferLen = largest + 1; - - for (size_t i = 0; i < targMesh->GetSourceCount(); i++) - { - FCDGeometrySource* targSource = targMesh->GetSource(i); - for (size_t j = 0; j < baseMesh->GetSourceCount(); j++) - { - // it is possible the sources are out of order. make sure we - // are using the correct ones. - FCDGeometrySource* baseSource = baseMesh->GetSource(j); - if (baseSource->GetType() == targSource->GetType()) - { - const FCDGeometryIndexTranslationMap* translationMap = translationMaps[j]; - ApplyUniqueIndices(targSource, newBufferLen, translationMap); - } - } - // Set the source to be per-vertex... this means it has data for every vertex? - targMesh->AddVertexSource(targSource); - } - - // Reset the indices. The indices in newIndices are all polygon indices combined - const uint32* newIdxPtr = newIndices.begin(); - size_t nNewIndices = newIndices.size(); - for (size_t p = 0; p < targMesh->GetPolygonsCount(); p++) - { - FCDGeometryPolygons* polygons = targMesh->GetPolygons(p); - FCDGeometryPolygonsInput* anInput = polygons->GetInput(0); - size_t nIndices = anInput->GetIndexCount(); - // Check if we are valid, if not, the best we can do is not crash - FUAssert(nIndices >= nNewIndices, nIndices = nNewIndices); - anInput->SetIndices(newIdxPtr, nIndices); - - newIdxPtr += nIndices; - nNewIndices -= nIndices; - } - } - -#if _MSC_VER -# pragma warning(push) -# pragma warning(disable : 4127) // conditional expression constant -# pragma warning(disable : 4244) // conversion from 'const float' to 'uint8' -#endif - -#define INVALID_VTX_IDX (uint16(~0)) // This value is the default (invalid) value in the vtx data map - - template - void PackVertexBuffers(uint8* destBuffer, uint32 destBuffStride, - const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, - const FCDGeometryIndexTranslationMap& translationMap) - { - const float* srcBuffer = source->GetData(); - const uint32 srcBufferStride = source->GetStride(); - - // Special case for missing Alpha channel - if (isColor) if (srcBufferStride == 3) vCount = 3; - FUAssert(srcBufferStride >= vCount, return); - - for (FCDGeometryIndexTranslationMap::const_iterator tmitr = translationMap.begin(); - tmitr != translationMap.end(); ++tmitr) - { - const UInt32List& newIdxList = tmitr->second; - for (UInt32List::const_iterator ditr = newIdxList.begin(); ditr != newIdxList.end(); ++ditr) - { - uint32 newIdx = *ditr; - if (vtxPackingMap[newIdx] != INVALID_VTX_IDX) - { - const float* srcData = srcBuffer + tmitr->first * srcBufferStride; - VAL& setValue = *(VAL*)(destBuffer + vtxPackingMap[newIdx] * destBuffStride); - if (isColor) - { - for (uint32 i = 0; i < vCount; ++i) - { - setValue[i] = (uint8)(srcData[i] * 255); - } - if (vCount == 3) setValue[3] = 255; - } - else - { - for (uint32 i = 0; i < vCount; ++i) - { - setValue[i] = srcData[i]; - } - } - } - } - } - } - -#if _MSC_VER -# pragma warning(pop) -#endif - - void PackVertexBufferV3(uint8* destBuffer, uint32 destBuffStride, - const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, - const FCDGeometryIndexTranslationMap& translationMap) - { - PackVertexBuffers(destBuffer, destBuffStride, source, vCount, vtxPackingMap, translationMap); - } - - void PackVertexBufferColor(uint8* destBuffer, uint32 destBuffStride, - const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, - const FCDGeometryIndexTranslationMap& translationMap) - { - PackVertexBuffers(destBuffer, destBuffStride, source, vCount, vtxPackingMap, translationMap); - } - - void PackVertexBufferV2(uint8* destBuffer, uint32 destBuffStride, - const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, - const FCDGeometryIndexTranslationMap& translationMap) - { - PackVertexBuffers(destBuffer, destBuffStride, source, vCount, vtxPackingMap, translationMap); - } - - // Iterate over the indices, remapping them using the provided map until we have consumed - // either max indices or max vertices, whichever is first - // return the number of indices actually consumed. - uint16 GenerateVertexPackingMap(size_t maxIndex, size_t maxIndices, size_t maxVertices, const uint32* inIndices, uint16* outIndices, UInt16List* outPackingMap, uint16* outNVertices/*=NULL*/) - { - FUAssert(inIndices != NULL && outPackingMap != NULL, return 0); - FUAssert(maxIndices < INVALID_VTX_IDX, maxIndices = INVALID_VTX_IDX - 1); - outPackingMap->resize(maxIndex + 1, INVALID_VTX_IDX); - uint16 nIndices, nVertices = 0; - for (nIndices = 0; nIndices < maxIndices; ++nIndices) - { - if (outPackingMap->at(*inIndices) == INVALID_VTX_IDX) // New vtx - { - // map this index to the next available vtx space - outPackingMap->at(*inIndices) = nVertices; - // Optimization - dont compare this more often - // than absolutely necessary. So if we need to - // force a break using the maxIndices instead - if (++nVertices >= maxVertices) maxIndices = nIndices; - } - if (outIndices != NULL) - { - *outIndices = outPackingMap->at(*inIndices); - ++outIndices; - } - ++inIndices; - } - // Sanity check - FUAssert(nVertices <= nIndices, nVertices = nIndices); - // Extra requested return - if (outNVertices != NULL) *outNVertices = nVertices; - return nIndices; - } - - uint32 FindLargestUniqueIndex(const FCDGeometryIndexTranslationMap& aMap) - { - uint32 largestIdx = 0; - FCDGeometryIndexTranslationMap::const_iterator it, itEnd = aMap.end(); - for (it = aMap.begin(); it != itEnd; ++it) - { - const UInt32List& curList = it->second; - for (UInt32List::const_iterator uit = curList.begin(); uit != curList.end(); ++uit) - { - largestIdx = max(largestIdx, *uit); - } - } - return largestIdx; - } - - void RevertUniqueIndices(const FCDGeometryPolygonsInput& inPInput, FCDGeometryPolygonsInput& outPInput, const FCDGeometryIndexTranslationMap& translationMap) - { - FUFail(;) // NOT_TESTED - size_t tmSize = translationMap.size(); - uint32 largest = 0; - for (FCDGeometryIndexTranslationMap::const_iterator it = translationMap.begin(), itEnd = translationMap.end(); it != itEnd; ++it) - { - const UInt32List& curList = it->second; - for (UInt32List::const_iterator uit = curList.begin(); uit != curList.end(); ++uit) - { - largest = max(largest, *uit); - } - } - - uint32 oldBufferLen = largest + 1; - - const FCDGeometrySource* inSrc = inPInput.GetSource(); - FCDGeometrySource* outSrc = outPInput.GetSource(); - - FUAssert(inSrc->GetValueCount() == oldBufferLen, return); - - uint32 stride = inSrc->GetStride(); - - outSrc->SetStride(stride); - outSrc->SetValueCount(tmSize); - - const float* inData = inSrc->GetData(); - float* outData = outSrc->GetData(); - - const uint32* inIndices = inPInput.GetIndices(); - FUAssert(inIndices != NULL, return); - UInt32List indices(inIndices, inPInput.GetIndexCount()); - - for (FCDGeometryIndexTranslationMap::const_iterator it = translationMap.begin(), itEnd = translationMap.end(); it != itEnd; ++it) - { - const UInt32List& curList = it->second; - FUAssert(!curList.empty(), continue); - - for (uint32 s = 0; s < stride; ++s) - { - //data[stride * (*uit) + s] = oldData[stride * + s]; - outData[stride * it->first + s] = inData[stride * curList.front() + s]; - } - - for (UInt32List::const_iterator uit = curList.begin(); uit != curList.end(); ++uit) - { - indices.replace(*uit, it->first); - } - } - - outPInput.SetIndices(indices.begin(), indices.size()); - } - - // Splits the mesh's polygons sets to ensure that none of them have - // more than a given number of indices within their index buffers. - void FitIndexBuffers(FCDGeometryMesh* mesh, size_t maximumIndexCount) - { - // Iterate over the original polygons sets, looking for ones that are too big. - // When a polygon set is too big, a new polygon set will be added, but at the end of the list. - size_t originalPolygonCount = mesh->GetPolygonsCount(); - for (size_t i = 0; i < originalPolygonCount; ++i) - { - // Iterate a over the face-vertex counts of the polygons set in order - // to find at which face to break this polygons set. - FCDGeometryPolygons* polygons = mesh->GetPolygons(i); - if (polygons->GetPrimitiveType() == FCDGeometryPolygons::POINTS) continue; - - size_t faceCount = polygons->GetFaceVertexCountCount(); - if (faceCount == 0) continue; - UInt32List faceVertexCounts(polygons->GetFaceVertexCounts(), faceCount); - size_t inputCount = polygons->GetInputCount(); - - UInt32List::iterator splitIt = faceVertexCounts.end(); - uint32 faceVertexCount = 0; - for (splitIt = faceVertexCounts.begin(); splitIt != faceVertexCounts.end(); ++splitIt) - { - if (faceVertexCount + (*splitIt) > maximumIndexCount) break; - faceVertexCount += (*splitIt); - } - if (splitIt == faceVertexCounts.end()) continue; // Polygons sets fit correctly. - size_t splitIndexCount = (size_t) faceVertexCount; - size_t splitFaceCount = splitIt - faceVertexCounts.begin(); - - size_t faceCopyStart = splitFaceCount; - size_t faceCopyEnd = faceCopyStart; - size_t faceVertexCopyStart = splitIndexCount; - size_t faceVertexCopyEnd = faceVertexCopyStart; - while (faceCopyEnd < faceCount) - { - // Create a new polygons set and copy the basic information from the first polygons set. - FCDGeometryPolygons* polygonsCopy = mesh->AddPolygons(); - polygonsCopy->SetMaterialSemantic(polygons->GetMaterialSemantic()); - - // Figure out which faces will be moved to this polygons set. - faceVertexCount = 0; - for (; faceCopyEnd < faceCount; ++faceCopyEnd) - { - uint32 localCount = faceVertexCounts[faceCopyEnd]; - if (faceVertexCount + localCount > maximumIndexCount) break; - faceVertexCount += localCount; - } - faceVertexCopyEnd += faceVertexCount; - - FUAssert(faceVertexCopyEnd > faceVertexCopyStart, continue); - FUAssert(faceCopyEnd > faceCopyStart, continue); - - // Create the inputs and their indices over in the new polygons set. - for (size_t j = 0; j < inputCount; ++j) - { - FCDGeometryPolygonsInput* input = polygons->GetInput(j); - FCDGeometrySource* source = input->GetSource(); - FCDGeometryPolygonsInput* inputCopy; - if (!mesh->IsVertexSource(source)) inputCopy = polygonsCopy->AddInput(source, input->GetOffset()); - else inputCopy = polygonsCopy->FindInput(source); - FUAssert(inputCopy != NULL, continue); - - // For owners, copy the indices over. - size_t indexCopyCount = inputCopy->GetIndexCount(); - if (indexCopyCount == 0) - { - uint32* indices = input->GetIndices(); - inputCopy->SetIndices(indices + faceVertexCopyStart, faceVertexCopyEnd - faceVertexCopyStart); - } - } - - // Copy the face-vertex counts over to the new polygons set - // And increment the copy counters. - size_t faceCopyCount = faceCopyEnd - faceCopyStart; - polygonsCopy->SetFaceVertexCountCount(faceCopyCount); - memcpy((void*) polygonsCopy->GetFaceVertexCounts(), &(*(faceVertexCounts.begin() + faceCopyStart)), faceCopyCount * sizeof(uint32)); - faceCopyStart = faceCopyEnd; - faceVertexCopyStart = faceVertexCopyEnd; - } - - // Remove the faces that were split away and their indices. - for (size_t j = 0; j < inputCount; ++j) - { - FCDGeometryPolygonsInput* input = polygons->GetInput(j); - if (input->OwnsIndices()) - { - input->SetIndexCount(splitIndexCount); - } - } - polygons->SetFaceVertexCountCount(splitFaceCount); - } - - mesh->Recalculate(); - } - - // Reverses all the normals of a mesh. - void ReverseNormals(FCDGeometryMesh* mesh) - { - size_t sourceCount = mesh->GetSourceCount(); - for (size_t i = 0; i < sourceCount; ++i) - { - FCDGeometrySource* source = mesh->GetSource(i); - if (source->GetType() == FUDaeGeometryInput::NORMAL || source->GetType() == FUDaeGeometryInput::GEOTANGENT - || source->GetType() == FUDaeGeometryInput::GEOBINORMAL || source->GetType() == FUDaeGeometryInput::TEXTANGENT - || source->GetType() == FUDaeGeometryInput::TEXBINORMAL) - { - float* v = source->GetData(); - size_t dataCount = source->GetDataCount(); - for (size_t it = 0; it < dataCount; ++it) - { - *(v++) *= -1.0f; - } - } - } - } - -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDGeometryPolygonsInput.h" +#include "FCDocument/FCDGeometryPolygonsTools.h" +#include "FCDocument/FCDGeometrySource.h" +#include "FCDocument/FCDAnimated.h" + +namespace FCDGeometryPolygonsTools +{ + // Triangulates a mesh. + void Triangulate(FCDGeometryMesh* mesh) + { + if (mesh == NULL) return; + + size_t polygonsCount = mesh->GetPolygonsCount(); + for (size_t i = 0; i < polygonsCount; ++i) + { + Triangulate(mesh->GetPolygons(i), false); + } + + // Recalculate the mesh/polygons statistics + mesh->Recalculate(); + } + + // Triangulates a polygons set. + void Triangulate(FCDGeometryPolygons* polygons, bool recalculate) + { + if (polygons == NULL) return; + if (polygons->GetPrimitiveType() == FCDGeometryPolygons::LINE_STRIPS || polygons->GetPrimitiveType() == FCDGeometryPolygons::LINES || polygons->GetPrimitiveType() == FCDGeometryPolygons::POINTS) return; + + // Pre-allocate and ready the end index/count buffers + size_t oldFaceCount = polygons->GetFaceVertexCountCount(); + UInt32List oldFaceVertexCounts(polygons->GetFaceVertexCounts(), oldFaceCount); + polygons->SetFaceVertexCountCount(0); + fm::pvector indicesOwners; + fm::vector oldDataIndices; + size_t inputCount = polygons->GetInputCount(); + for (size_t i = 0; i < inputCount; ++i) + { + FCDGeometryPolygonsInput* input = polygons->GetInput(i); + if (input->GetIndexCount() == 0) continue; + uint32* indices = input->GetIndices(); + size_t oldIndexCount = input->GetIndexCount(); + oldDataIndices.push_back(UInt32List(indices, oldIndexCount)); + indicesOwners.push_back(input); + input->SetIndexCount(0); + input->ReserveIndexCount(oldIndexCount); + } + size_t dataIndicesCount = oldDataIndices.size(); + + // Rebuild the index/count buffers. + // Drop holes and polygons with less than three vertices. + size_t oldOffset = 0; + for (size_t oldFaceIndex = 0; oldFaceIndex < oldFaceCount; ++oldFaceIndex) + { + size_t oldFaceVertexCount = oldFaceVertexCounts[oldFaceIndex]; + bool isHole = polygons->IsHoleFaceHole((uint32) oldFaceIndex); + if (!isHole && oldFaceVertexCount >= 3) + { + if (polygons->GetPrimitiveType() == FCDGeometryPolygons::POLYGONS || polygons->GetPrimitiveType() == FCDGeometryPolygons::TRIANGLE_FANS) + { + // Fan-triangulation: works well on convex polygons. + size_t triangleCount = oldFaceVertexCount - 2; + for (size_t triangleIndex = 0; triangleIndex < triangleCount; ++triangleIndex) + { + for (size_t j = 0; j < dataIndicesCount; ++j) + { + UInt32List& oldData = oldDataIndices[j]; + FCDGeometryPolygonsInput* input = indicesOwners[j]; + input->AddIndex(oldData[oldOffset]); + input->AddIndex(oldData[oldOffset + triangleIndex + 1]); + input->AddIndex(oldData[oldOffset + triangleIndex + 2]); + } + polygons->AddFaceVertexCount(3); + } + } + else if (polygons->GetPrimitiveType() == FCDGeometryPolygons::TRIANGLE_STRIPS) + { + // Fan-triangulation: works well on convex polygons. + size_t triangleCount = oldFaceVertexCount - 2; + for (size_t triangleIndex = 0; triangleIndex < triangleCount; ++triangleIndex) + { + for (size_t j = 0; j < dataIndicesCount; ++j) + { + UInt32List& oldData = oldDataIndices[j]; + FCDGeometryPolygonsInput* input = indicesOwners[j]; + if ((triangleIndex & 0x1) == 0x0) + { + input->AddIndex(oldData[oldOffset + triangleIndex + 0]); + input->AddIndex(oldData[oldOffset + triangleIndex + 1]); + input->AddIndex(oldData[oldOffset + triangleIndex + 2]); + } + else + { + // Flip the winding of every second triangle in the strip. + input->AddIndex(oldData[oldOffset + triangleIndex + 0]); + input->AddIndex(oldData[oldOffset + triangleIndex + 2]); + input->AddIndex(oldData[oldOffset + triangleIndex + 1]); + } + } + polygons->AddFaceVertexCount(3); + } + } + } + oldOffset += oldFaceVertexCount; + } + + polygons->SetPrimitiveType(FCDGeometryPolygons::POLYGONS); + polygons->SetHoleFaceCount(0); + + if (recalculate) polygons->Recalculate(); + } + + static uint32 CompressSortedVector(FMVector3& toInsert, FloatList& insertedList, UInt32List& compressIndexReferences) + { + // Look for this vector within the already inserted list. + size_t start = 0, end = compressIndexReferences.size(), mid; + for (mid = (start + end) / 2; start < end; mid = (start + end) / 2) + { + uint32 index = compressIndexReferences[mid]; + if (toInsert.x == insertedList[3 * index]) break; + else if (toInsert.x < insertedList[3 * index]) end = mid; + else start = mid + 1; + } + + // Look for the tolerable range within the binary-sorted dimension. + size_t rangeStart, rangeEnd; + for (rangeStart = mid; rangeStart > 0; --rangeStart) + { + uint32 index = compressIndexReferences[rangeStart - 1]; + if (!IsEquivalent(insertedList[3 * index], toInsert.x)) break; + } + for (rangeEnd = min(mid + 1, compressIndexReferences.size()); rangeEnd < compressIndexReferences.size(); ++rangeEnd) + { + uint32 index = compressIndexReferences[rangeEnd]; + if (!IsEquivalent(insertedList[3 * index], toInsert.x)) break; + } + FUAssert(rangeStart < rangeEnd || (rangeStart == rangeEnd && rangeEnd == compressIndexReferences.size()), return 0); + + // Look for an equivalent vector within the tolerable range + for (size_t g = rangeStart; g < rangeEnd; ++g) + { + uint32 index = compressIndexReferences[g]; + if (IsEquivalent(toInsert, *(const FMVector3*) &insertedList[3 * index])) return index; + } + + // Insert this new vector in the list and add the index reference at the correct position. + uint32 compressIndex = (uint32) (insertedList.size() / 3); + compressIndexReferences.insert(compressIndexReferences.begin() + mid, compressIndex); + insertedList.push_back(toInsert.x); + insertedList.push_back(toInsert.y); + insertedList.push_back(toInsert.z); + return compressIndex; + } + + struct TangentialVertex + { + float* normalPointer; + float* texCoordPointer; + FMVector3 tangent; + uint32 count; + uint32 tangentId; + uint32 binormalId; + }; + typedef fm::vector TangentialVertexList; + + // Generates the texture tangents and binormals for a given source of texture coordinates. + void GenerateTextureTangentBasis(FCDGeometryMesh* mesh, FCDGeometrySource* texcoordSource, bool generateBinormals) + { + if (texcoordSource == NULL || mesh == NULL) return; + + // First count the positions. + FCDGeometrySource* positionSource = mesh->FindSourceByType(FUDaeGeometryInput::POSITION); + if (positionSource == NULL) return; + size_t globalVertexCount = positionSource->GetValueCount(); + + // Allocate the tangential vertices. + // This temporary buffer is necessary to ensure we have smooth tangents/binormals. + TangentialVertexList* globalVertices = new TangentialVertexList[globalVertexCount]; + memset(globalVertices, 0, sizeof(TangentialVertexList) * globalVertexCount); + + // This operation is done on the tessellation: fill in the list of tangential vertices. + size_t polygonsCount = mesh->GetPolygonsCount(); + for (size_t i = 0; i < polygonsCount; ++i) + { + FCDGeometryPolygons* polygons = mesh->GetPolygons(i); + + // Verify that this polygons set uses the given texture coordinate source. + FCDGeometryPolygonsInput* texcoordInput = polygons->FindInput(texcoordSource); + if (texcoordInput == NULL) continue; + + // Retrieve the data and index buffer of positions/normals/texcoords for this polygons set. + FCDGeometryPolygonsInput* positionInput = polygons->FindInput(FUDaeGeometryInput::POSITION); + FCDGeometryPolygonsInput* normalsInput = polygons->FindInput(FUDaeGeometryInput::NORMAL); + if (positionInput == NULL || normalsInput == NULL) continue; + FCDGeometrySource* positionSource = positionInput->GetSource(); + FCDGeometrySource* normalsSource = normalsInput->GetSource(); + FCDGeometrySource* texcoordSource = texcoordInput->GetSource(); + if (positionSource == NULL || normalsSource == NULL || texcoordSource == NULL) continue; + uint32 positionStride = positionSource->GetStride(); + uint32 normalsStride = normalsSource->GetStride(); + uint32 texcoordStride = texcoordSource->GetStride(); + if (positionStride < 3 || normalsStride < 3 || texcoordStride < 2) continue; + uint32* positionIndices = positionInput->GetIndices(); + uint32* normalsIndices = normalsInput->GetIndices(); + uint32* texcoordIndices = texcoordInput->GetIndices(); + size_t indexCount = positionInput->GetIndexCount(); + if (positionIndices == NULL || normalsIndices == NULL || texcoordIndices == NULL) continue; + if (indexCount == 0 || indexCount != normalsInput->GetIndexCount() || indexCount != texcoordInput->GetIndexCount()) continue; + float* positionData = positionSource->GetData(); + float* normalsData = normalsSource->GetData(); + float* texcoordData = texcoordSource->GetData(); + size_t positionDataLength = positionSource->GetDataCount(); + size_t normalsDataLength = normalsSource->GetDataCount(); + size_t texcoordDataLength = texcoordSource->GetDataCount(); + if (positionDataLength == 0 || normalsDataLength == 0 || texcoordDataLength == 0) continue; + + // Iterate of the faces of the polygons set. This includes holes. + size_t faceCount = polygons->GetFaceVertexCountCount(); + size_t faceVertexOffset = 0; + for (size_t faceIndex = 0; faceIndex < faceCount; ++faceIndex) + { + size_t faceVertexCount = polygons->GetFaceVertexCounts()[faceIndex]; + for (size_t vertexIndex = 0; vertexIndex < faceVertexCount; ++vertexIndex) + { + // For each face-vertex pair, retrieve the current/previous/next vertex position/normal/texcoord. + size_t previousVertexIndex = (vertexIndex > 0) ? vertexIndex - 1 : faceVertexCount - 1; + size_t nextVertexIndex = (vertexIndex < faceVertexCount - 1) ? vertexIndex + 1 : 0; + FMVector3& previousPosition = *(FMVector3*)&positionData[positionIndices[faceVertexOffset + previousVertexIndex] * positionStride]; + FMVector2& previousTexcoord = *(FMVector2*)&texcoordData[texcoordIndices[faceVertexOffset + previousVertexIndex] * texcoordStride]; + FMVector3& currentPosition = *(FMVector3*)&positionData[positionIndices[faceVertexOffset + vertexIndex] * positionStride]; + float* texcoordPtr = &texcoordData[texcoordIndices[faceVertexOffset + vertexIndex] * texcoordStride]; + FMVector2& currentTexcoord = *(FMVector2*)texcoordPtr; + FMVector3& nextPosition = *(FMVector3*)&positionData[positionIndices[faceVertexOffset + nextVertexIndex] * positionStride]; + FMVector2& nextTexcoord = *(FMVector2*)&texcoordData[texcoordIndices[faceVertexOffset + nextVertexIndex] * texcoordStride]; + float* normalPtr = &normalsData[normalsIndices[faceVertexOffset + vertexIndex] * normalsStride]; + FMVector3& normal = *(FMVector3*)normalPtr; + + // The formulae to calculate the tangent-space basis vectors is taken from Maya 7.0 API documentation: + // "Appendix A: Tangent and binormal vectors". + + // Prepare the edge vectors. + FMVector3 previousEdge(0.0f, previousTexcoord.x - currentTexcoord.x, previousTexcoord.y - currentTexcoord.y); + FMVector3 nextEdge(0.0f, nextTexcoord.x - currentTexcoord.x, nextTexcoord.y - currentTexcoord.y); + FMVector3 previousDisplacement = (previousPosition - currentPosition); + FMVector3 nextDisplacement = (nextPosition - currentPosition); + FMVector3 tangent; + + // Calculate the X-coordinate of the tangent vector. + previousEdge.x = previousDisplacement.x; + nextEdge.x = nextDisplacement.x; + FMVector3 crossEdge = nextEdge ^ previousEdge; + if (IsEquivalent(crossEdge.x, 0.0f)) crossEdge.x = 1.0f; // degenerate + tangent.x = crossEdge.y / crossEdge.x; + + // Calculate the Y-coordinate of the tangent vector. + previousEdge.x = previousDisplacement.y; + nextEdge.x = nextDisplacement.y; + crossEdge = nextEdge ^ previousEdge; + if (IsEquivalent(crossEdge.x, 0.0f)) crossEdge.x = 1.0f; // degenerate + tangent.y = crossEdge.y / crossEdge.x; + + // Calculate the Z-coordinate of the tangent vector. + previousEdge.x = previousDisplacement.z; + nextEdge.x = nextDisplacement.z; + crossEdge = nextEdge ^ previousEdge; + if (IsEquivalent(crossEdge.x, 0.0f)) crossEdge.x = 1.0f; // degenerate + tangent.z = crossEdge.y / crossEdge.x; + + // Take the normal vector at this face-vertex pair, out of the calculated tangent vector + tangent = tangent - normal * (tangent * normal); + tangent.NormalizeIt(); + + // Add this tangent to our tangential vertex. + FUAssert(positionIndices[faceVertexOffset + vertexIndex] < globalVertexCount, continue); + TangentialVertexList& list = globalVertices[positionIndices[faceVertexOffset + vertexIndex]]; + size_t vertexCount = list.size(); + bool found = false; + for (size_t v = 0; v < vertexCount; ++v) + { + if ((normalPtr == list[v].normalPointer) && (texcoordPtr == list[v].texCoordPointer)) + { + list[v].tangent += tangent; + list[v].count++; + found = true; + } + } + if (!found) + { + TangentialVertex v; + v.normalPointer = normalPtr; + v.texCoordPointer = texcoordPtr; + v.count = 1; v.tangent = tangent; + v.tangentId = v.binormalId = ~(uint32)0; + list.push_back(v); + } + } + faceVertexOffset += faceVertexCount; + } + } + + FCDGeometrySource* tangentSource = NULL; + FCDGeometrySource* binormalSource = NULL; + FloatList tangentData; + FloatList binormalData; + UInt32List tangentCompressionIndices; + UInt32List binormalCompressionIndices; + + // Iterate over the polygons again: this time create the source/inputs for the tangents and binormals. + for (size_t i = 0; i < polygonsCount; ++i) + { + FCDGeometryPolygons* polygons = mesh->GetPolygons(i); + + // Verify that this polygons set uses the given texture coordinate source. + FCDGeometryPolygonsInput* texcoordInput = polygons->FindInput(texcoordSource); + if (texcoordInput == NULL) continue; + + // Retrieve the data and index buffer of positions/normals/texcoords for this polygons set. + FCDGeometryPolygonsInput* positionInput = polygons->FindInput(FUDaeGeometryInput::POSITION); + FCDGeometryPolygonsInput* normalsInput = polygons->FindInput(FUDaeGeometryInput::NORMAL); + if (positionInput == NULL || normalsInput == NULL) continue; + FCDGeometrySource* normalsSource = normalsInput->GetSource(); + FCDGeometrySource* texcoordSource = texcoordInput->GetSource(); + if (normalsSource == NULL || texcoordSource == NULL) continue; + uint32 normalsStride = normalsSource->GetStride(); + uint32 texcoordStride = texcoordSource->GetStride(); + if (normalsStride < 3 || texcoordStride < 2) continue; + uint32* positionIndices = positionInput->GetIndices(); + uint32* normalsIndices = normalsInput->GetIndices(); + uint32* texcoordIndices = texcoordInput->GetIndices(); + size_t indexCount = positionInput->GetIndexCount(); + if (positionIndices == NULL || normalsIndices == NULL || texcoordIndices == NULL) continue; + if (indexCount == 0 || indexCount != normalsInput->GetIndexCount() || indexCount != texcoordInput->GetIndexCount()) continue; + float* normalsData = normalsSource->GetData(); + float* texcoordData = texcoordSource->GetData(); + size_t normalsDataLength = normalsSource->GetDataCount(); + size_t texcoordDataLength = texcoordSource->GetDataCount(); + if (normalsDataLength == 0 || texcoordDataLength == 0) continue; + + // Create the texture tangents/binormals sources + if (tangentSource == NULL) + { + tangentSource = mesh->AddSource(FUDaeGeometryInput::TEXTANGENT); + tangentSource->SetDaeId(texcoordSource->GetDaeId() + "-tangents"); + tangentData.reserve(texcoordSource->GetDataCount()); + if (generateBinormals) + { + binormalSource = mesh->AddSource(FUDaeGeometryInput::TEXBINORMAL); + binormalSource->SetDaeId(texcoordSource->GetDaeId() + "-binormals"); + binormalData.reserve(tangentSource->GetDataCount()); + } + } + + // Calculate the next available offset + uint32 inputOffset = 0; + size_t inputCount = polygons->GetInputCount(); + for (size_t j = 0; j < inputCount; ++j) + { + inputOffset = max(inputOffset, polygons->GetInput(j)->GetOffset()); + } + + // Create the polygons set input for both the tangents and binormals + FCDGeometryPolygonsInput* tangentInput = polygons->AddInput(tangentSource, inputOffset + 1); + tangentInput->SetSet(texcoordInput->GetSet()); + tangentInput->ReserveIndexCount(indexCount); + FCDGeometryPolygonsInput* binormalInput = NULL; + if (binormalSource != NULL) + { + binormalInput = polygons->AddInput(binormalSource, inputOffset + 2); + binormalInput->SetSet(tangentInput->GetSet()); + binormalInput->ReserveIndexCount(indexCount); + } + + // Iterate of the faces of the polygons set. This includes holes. + size_t vertexCount = positionInput->GetIndexCount(); + size_t faceVertexOffset = 0; + for (size_t vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex) + { + // For each face-vertex pair retrieve the current vertex normal&texcoord. + float* normalPtr = &normalsData[normalsIndices[faceVertexOffset + vertexIndex] * normalsStride]; + float* texcoordPtr = + &texcoordData[texcoordIndices[faceVertexOffset + vertexIndex] * texcoordStride]; + + FUAssert(positionIndices[faceVertexOffset + vertexIndex] < globalVertexCount, continue); + TangentialVertexList& list = globalVertices[positionIndices[faceVertexOffset + vertexIndex]]; + size_t vertexCount = list.size(); + for (size_t v = 0; v < vertexCount; ++v) + { + if ((list[v].normalPointer == normalPtr) && (list[v].texCoordPointer == texcoordPtr)) + { + if (list[v].tangentId == ~(uint32)0) + { + list[v].tangent /= (float) list[v].count; // Average the tangent. + list[v].tangent.Normalize(); + list[v].tangentId = CompressSortedVector(list[v].tangent, tangentData, tangentCompressionIndices); + } + tangentInput->AddIndex(list[v].tangentId); + + if (binormalInput != NULL) + { + if (list[v].binormalId == ~(uint32)0) + { + // Calculate and store the binormal. + FMVector3 binormal = (*(FMVector3*)normalPtr ^ list[v].tangent).Normalize(); + uint32 compressedIndex = CompressSortedVector(binormal, binormalData, binormalCompressionIndices); + list[v].binormalId = compressedIndex; + } + binormalInput->AddIndex(list[v].binormalId); + } + } + } + } + } + + if (tangentSource != NULL) tangentSource->SetData(tangentData, 3); + if (binormalSource != NULL) binormalSource->SetData(binormalData, 3); + } + + struct HashIndexMapItem { UInt32List allValues; UInt32List newIndex; }; + typedef fm::vector UInt32ListList; + typedef fm::pvector InputList; + typedef fm::map HashIndexMap; + typedef fm::pvector FCDGeometryIndexTranslationMapList; + + void GenerateUniqueIndices(FCDGeometryMesh* mesh, FCDGeometryPolygons* polygonsToProcess, FCDNewIndicesList& outIndices, FCDGeometryIndexTranslationMapList& outTranslationMaps) + { + // Prepare a list of unique index buffers. + size_t polygonsCount = mesh->GetPolygonsCount(); + if (polygonsCount == 0) return; + size_t totalVertexCount = 0; + + size_t outIndicesMinSize = (polygonsToProcess == NULL) ? polygonsCount : 1; + if (outIndices.size() < outIndicesMinSize) outIndices.resize(outIndicesMinSize); + + // Fill in the index buffers for each polygons set. + for (size_t p = 0; p < polygonsCount; ++p) + { + FCDGeometryPolygons* polygons = mesh->GetPolygons(p); + // DO NOT -EVER- TOUCH MY INDICES - (Says Psuedo-FCDGeometryPoints) + // Way to much code assumes (and carefully guards) the existing sorted structure + if (polygons->GetPrimitiveType() == FCDGeometryPolygons::POINTS) return; + if (polygonsToProcess != NULL && polygons != polygonsToProcess) continue; + + // Find the list we are going to pump our new indices into + UInt32List& outPolyIndices = (polygonsToProcess == NULL) ? outIndices[p] : outIndices.front(); + + // Find all the indices list to determine the hash size. + InputList idxOwners; + size_t inputCount = polygons->GetInputCount(); + for (size_t i = 0; i < inputCount; ++i) + { + if (polygons->GetInput(i)->OwnsIndices()) + { + // Drop index lists with the wrong number of values and avoid repeats + FUAssert(idxOwners.empty() || idxOwners.front()->GetIndexCount() == polygons->GetInput(i)->GetIndexCount(), continue); + if (idxOwners.find(polygons->GetInput(i)) == idxOwners.end()) + { + idxOwners.push_back(polygons->GetInput(i)); + } + } + } + size_t listCount = idxOwners.size(); + if (listCount == 0) continue; // no inputs? + + // Set-up a simple hashing function. + UInt32List hashingFunction; + uint32 hashSize = (uint32) listCount; + hashingFunction.reserve(hashSize); + for (uint32 h = 0; h < hashSize; ++h) hashingFunction.push_back(32 * h / hashSize); + + // Iterate over the index lists, hashing/merging the indices. + HashIndexMap hashMap; + size_t originalIndexCount = idxOwners.front()->GetIndexCount(); + outPolyIndices.reserve(originalIndexCount); + + // optimization: cache the indices + uint32** indices = new uint32*[listCount]; + for (size_t l = 0; l < listCount; ++l) + { + indices[l] = idxOwners[l]->GetIndices(); + } + for (size_t i = 0; i < originalIndexCount; ++i) + { + // Generate the hash value for this vertex-face pair. + uint32 hashValue = 0; + for (size_t l = 0; l < listCount; ++l) + { + hashValue ^= (indices[l][i]) << hashingFunction[l]; + } + + // Look for this value in the already-collected ones. + HashIndexMap::iterator it = hashMap.find(hashValue); + HashIndexMapItem* hashItem; + uint32 newIndex = (uint32) totalVertexCount; + if (it != hashMap.end()) + { + hashItem = &((*it).second); + size_t repeatCount = hashItem->allValues.size() / listCount; + for (size_t r = 0; r < repeatCount && newIndex == totalVertexCount; ++r) + { + size_t l; + for (l = 0; l < listCount; ++l) + { + if (indices[l][i] != hashItem->allValues[r * listCount + l]) break; + } + if (l == listCount) + { + // We have a match: re-use this index. + newIndex = hashItem->newIndex[r]; + } + } + } + else + { + HashIndexMap::iterator k = hashMap.insert(hashValue, HashIndexMapItem()); + hashItem = &k->second; + + // optimization: since we will be adding the indices to allValues, know there will be listCount + hashItem->allValues.reserve(listCount); + } + + if (newIndex == totalVertexCount) + { + // Append this new value/index to the hash map item and to the index buffer. + for (size_t l = 0; l < listCount; ++l) + { + hashItem->allValues.push_back(indices[l][i]); + } + hashItem->newIndex.push_back(newIndex); + totalVertexCount++; + } + outPolyIndices.push_back(newIndex); + } + SAFE_DELETE_ARRAY(indices); + } + + // We now have lists of new indices. Create maps so we can quickly + // map the old data to match the new stuff. + size_t meshSourceCount = mesh->GetSourceCount(); + if (outTranslationMaps.size() < meshSourceCount) outTranslationMaps.resize(meshSourceCount); + for (size_t d = 0; d < meshSourceCount; ++d) + { + FCDGeometrySource* oldSource = mesh->GetSource(d); + FCDGeometryIndexTranslationMap* thisMap = new FCDGeometryIndexTranslationMap(); + outTranslationMaps[d] = thisMap; + + // When processing just one polygons set, duplicate the source + // so that the other polygons set can correctly point to the original source. + for (size_t p = 0; p < polygonsCount; ++p) + { + FCDGeometryPolygons* polygons = mesh->GetPolygons(p); + if (polygonsToProcess != NULL && polygonsToProcess != polygons) continue; + const UInt32List& outPolyIndices = (polygonsToProcess == NULL) ? outIndices[p] : outIndices.front(); + FCDGeometryPolygonsInput* oldInput = polygons->FindInput(oldSource); + if (oldInput == NULL) continue; + + // Retrieve the old list of indices and de-reference the data values. + uint32* oldIndexList = oldInput->GetIndices(); + size_t oldIndexCount = oldInput->GetIndexCount(); + if (oldIndexList == NULL || oldIndexCount == 0) continue; + + size_t indexCount = min(oldIndexCount, outPolyIndices.size()); + for (size_t i = 0; i < indexCount; ++i) + { + uint32 newIndex = outPolyIndices[i]; + uint32 oldIndex = oldIndexList[i]; + if (oldIndex >= oldSource->GetValueCount()) continue; + + // Add this value to the translation map. + FCDGeometryIndexTranslationMap::iterator itU = thisMap->find(oldIndex); + if (itU == thisMap->end()) { itU = thisMap->insert(oldIndex, UInt32List()); } + UInt32List::iterator itF = itU->second.find(newIndex); + if (itF == itU->second.end()) itU->second.push_back(newIndex); + } + } + } + } + + void GenerateUniqueIndices(FCDGeometryMesh* mesh, FCDGeometryPolygons* polygonsToProcess, FCDGeometryIndexTranslationMap* translationMap) + { + // Prepare a list of unique index buffers. + size_t polygonsCount = mesh->GetPolygonsCount(); + if (polygonsCount == 0) return; + UInt32ListList indexBuffers; indexBuffers.resize(polygonsCount); + size_t totalVertexCount = 0; + + // Fill in the index buffers for each polygons set. + for (size_t p = 0; p < polygonsCount; ++p) + { + UInt32List& indexBuffer = indexBuffers[p]; + FCDGeometryPolygons* polygons = mesh->GetPolygons(p); + // DO NOT -EVER- TOUCH MY INDICES - (Says Psuedo-FCDGeometryPoints) + // Way to much code assumes (and carefully guards) the existing sorted structure + if (polygons->GetPrimitiveType() == FCDGeometryPolygons::POINTS) return; + if (polygonsToProcess != NULL && polygons != polygonsToProcess) continue; + + // Find all the indices list to determine the hash size. + InputList idxOwners; + size_t inputCount = polygons->GetInputCount(); + for (size_t i = 0; i < inputCount; ++i) + { + FCDGeometryPolygonsInput* input = polygons->GetInput(i); + if (input->OwnsIndices()) + { + // Drop index lists with the wrong number of values and avoid repeats + FUAssert(idxOwners.empty() || idxOwners.front()->GetIndexCount() == input->GetIndexCount(), continue); + if (idxOwners.find(input) == idxOwners.end()) idxOwners.push_back(input); + } + } + size_t listCount = idxOwners.size(); + if (listCount == 0) continue; // no inputs? + + // Set-up a simple hashing function. + UInt32List hashingFunction; + uint32 hashSize = (uint32) listCount; + hashingFunction.reserve(hashSize); + for (uint32 h = 0; h < hashSize; ++h) hashingFunction.push_back(32 * h / hashSize); + + // Iterate over the index lists, hashing/merging the indices. + HashIndexMap hashMap; + size_t originalIndexCount = idxOwners.front()->GetIndexCount(); + indexBuffer.reserve(originalIndexCount); + + // optimization: cache the indices + uint32** indices = new uint32*[listCount]; + for (size_t l = 0; l < listCount; ++l) + { + indices[l] = idxOwners[l]->GetIndices(); + } + for (size_t i = 0; i < originalIndexCount; ++i) + { + // Generate the hash value for this vertex-face pair. + uint32 hashValue = 0; + for (size_t l = 0; l < listCount; ++l) + { + hashValue ^= (indices[l][i]) << hashingFunction[l]; + } + + // Look for this value in the already-collected ones. + HashIndexMap::iterator it = hashMap.find(hashValue); + HashIndexMapItem* hashItem; + uint32 newIndex = (uint32) totalVertexCount; + if (it != hashMap.end()) + { + hashItem = &((*it).second); + size_t repeatCount = hashItem->allValues.size() / listCount; + for (size_t r = 0; r < repeatCount && newIndex == totalVertexCount; ++r) + { + size_t l; + for (l = 0; l < listCount; ++l) + { + if (indices[l][i] != hashItem->allValues[r * listCount + l]) break; + } + if (l == listCount) + { + // We have a match: re-use this index. + newIndex = hashItem->newIndex[r]; + } + } + } + else + { + HashIndexMap::iterator k = hashMap.insert(hashValue, HashIndexMapItem()); + hashItem = &k->second; + + // optimization: since we will be adding the indices to allValues, know there will be listCount + hashItem->allValues.reserve(listCount); + } + + if (newIndex == totalVertexCount) + { + // Append this new value/index to the hash map item and to the index buffer. + for (size_t l = 0; l < listCount; ++l) + { + hashItem->allValues.push_back(indices[l][i]); + } + hashItem->newIndex.push_back(newIndex); + totalVertexCount++; + } + indexBuffer.push_back(newIndex); + } + SAFE_DELETE_ARRAY(indices); + } + + // De-reference the source data so that all the vertex data match the new indices. + size_t meshSourceCount = mesh->GetSourceCount(); + for (size_t d = 0; d < meshSourceCount; ++d) + { + FCDGeometrySource* oldSource = mesh->GetSource(d); + uint32 stride = oldSource->GetStride(); + const float* oldVertexData = oldSource->GetData(); + bool isPositionSource = oldSource->GetType() == FUDaeGeometryInput::POSITION && translationMap != NULL; + FloatList vertexBuffer; + vertexBuffer.resize(stride * totalVertexCount, 0.0f); + + // When processing just one polygons set, duplicate the source + // so that the other polygons set can correctly point to the original source. + FCDGeometrySource* newSource = (polygonsToProcess != NULL) ? mesh->AddSource(oldSource->GetType()) : oldSource; + + FCDAnimatedList newAnimatedList; + newAnimatedList.clear(); + for (size_t p = 0; p < polygonsCount; ++p) + { + const UInt32List& indexBuffer = indexBuffers[p]; + FCDGeometryPolygons* polygons = mesh->GetPolygons(p); + if (polygonsToProcess != NULL && polygonsToProcess != polygons) continue; + FCDGeometryPolygonsInput* oldInput = polygons->FindInput(oldSource); + if (oldInput == NULL) continue; + + // Retrieve the old list of indices and de-reference the data values. + uint32* oldIndexList = oldInput->GetIndices(); + size_t oldIndexCount = oldInput->GetIndexCount(); + if (oldIndexList == NULL || oldIndexCount == 0) continue; + + size_t indexCount = min(oldIndexCount, indexBuffer.size()); + for (size_t i = 0; i < indexCount; ++i) + { + uint32 newIndex = indexBuffer[i]; + uint32 oldIndex = oldIndexList[i]; + if (oldIndex >= oldSource->GetValueCount()) continue; + + FUObjectContainer& animatedValues = oldSource->GetAnimatedValues(); + FCDAnimated* oldAnimated = NULL; + for (size_t j = 0; j < animatedValues.size(); j++) + { + FCDAnimated* animated = animatedValues[j]; + if (animated->GetValue(0) == &(oldVertexData[stride * oldIndex])) + { + oldAnimated = animated; + break; + } + } + if (oldAnimated != NULL) + { + FCDAnimated* newAnimated = oldAnimated->Clone(oldAnimated->GetDocument()); + newAnimated->SetArrayElement(newIndex); + newAnimatedList.push_back(newAnimated); + } + + // [GLaforte - 12-10-2006] Potential performance optimization: this may copy the same data over itself many times. + for (uint32 s = 0; s < stride; ++s) + { + vertexBuffer[stride * newIndex + s] = oldVertexData[stride * oldIndex + s]; + } + + // Add this value to the vertex position translation map. + if (isPositionSource) + { + FCDGeometryIndexTranslationMap::iterator itU = translationMap->find(oldIndex); + if (itU == translationMap->end()) { itU = translationMap->insert(oldIndex, UInt32List()); } + UInt32List::iterator itF = itU->second.find(newIndex); + if (itF == itU->second.end()) itU->second.push_back(newIndex); + } + } + + if (polygonsToProcess != NULL) + { + // Change the relevant input, if it exists, to point towards the new source. + uint32 set = oldInput->GetSet(); + SAFE_RELEASE(oldInput); + FCDGeometryPolygonsInput* newInput = polygons->AddInput(newSource, 0); + newInput->SetSet(set); + } + } + + // Set the compiled data in the source. + // [ewhittom] In some occasions we have no indices and yet + // vertices (for example in incomplete meshes). In these cases we do + // not want to clear the vertices. + if (!(vertexBuffer.empty() && newSource->GetDataCount() != 0)) + { + newSource->SetData(vertexBuffer, stride); + } + FUObjectContainer& animatedList = newSource->GetAnimatedValues(); + animatedList.clear(); + for (FCDAnimatedList::iterator it = newAnimatedList.begin(); + it != newAnimatedList.end(); it++) + { + animatedList.push_back(*it); + } + } + + if (polygonsToProcess == NULL) + { + // Next, make all the sources per-vertex. + size_t _sourceCount = mesh->GetSourceCount(); + for (size_t s = 0; s < _sourceCount; ++s) + { + FCDGeometrySource* it = mesh->GetSource(s); + if (!mesh->IsVertexSource(it)) + { + mesh->AddVertexSource(it); + } + } + } + + // Enforce the index buffers. + for (size_t p = 0; p < polygonsCount; ++p) + { + const UInt32List& indexBuffer = indexBuffers[p]; + FCDGeometryPolygons* polygons = mesh->GetPolygons(p); + if (polygonsToProcess != NULL && polygons != polygonsToProcess) continue; + + size_t inputCount = polygons->GetInputCount(); + for (size_t i = 0; i < inputCount; i++) + { + FCDGeometryPolygonsInput* anyInput = polygons->GetInput(i); + if (anyInput->GetSource()->GetDataCount() == 0) continue; + // [ewhittom] Allow empty index buffers with non-empty vertex buffers + if (indexBuffer.empty()) continue; + + anyInput->SetIndices(&indexBuffer.front(), indexBuffer.size()); + } + } + } + + + + void ApplyUniqueIndices(float* targData, float* srcData, uint32 stride, const FCDGeometryIndexTranslationMap* translationMap) + { + for (FCDGeometryIndexTranslationMap::const_iterator it = translationMap->begin(), itEnd = translationMap->end(); it != itEnd; ++it) + { + const UInt32List& curList = it->second; + for (UInt32List::const_iterator uit = curList.begin(); uit != curList.end(); ++uit) + { + for (uint32 s = 0; s < stride; ++s) + { + targData[stride * (*uit) + s] = srcData[stride * it->first + s]; + } + } + } + } + + void ApplyUniqueIndices(FCDGeometrySource* targSource, uint32 nValues, const FCDGeometryIndexTranslationMap* translationMap) + { + size_t tmSize = translationMap->size(); + FUAssert(targSource->GetValueCount() == tmSize, return); + + uint32 stride = targSource->GetStride(); + FloatList oldData(targSource->GetData(), targSource->GetDataCount()); + + targSource->SetDataCount(nValues * stride); + float* targData = targSource->GetData(); + + ApplyUniqueIndices(targData, oldData.begin(), stride, translationMap); + } + + void ApplyUniqueIndices(FCDGeometryMesh* targMesh, FCDGeometryMesh* baseMesh, const UInt32List& newIndices, const FCDGeometryIndexTranslationMapList& translationMaps) + { + uint32 largest = 0; + const FCDGeometryIndexTranslationMap* aMap = translationMaps[0]; + for (FCDGeometryIndexTranslationMap::const_iterator it = aMap->begin(), itEnd = aMap->end(); it != itEnd; ++it) + { + const UInt32List& curList = it->second; + for (UInt32List::const_iterator uit = curList.begin(); uit != curList.end(); ++uit) + { + largest = max(largest, *uit); + } + } + + uint32 newBufferLen = largest + 1; + + for (size_t i = 0; i < targMesh->GetSourceCount(); i++) + { + FCDGeometrySource* targSource = targMesh->GetSource(i); + for (size_t j = 0; j < baseMesh->GetSourceCount(); j++) + { + // it is possible the sources are out of order. make sure we + // are using the correct ones. + FCDGeometrySource* baseSource = baseMesh->GetSource(j); + if (baseSource->GetType() == targSource->GetType()) + { + const FCDGeometryIndexTranslationMap* translationMap = translationMaps[j]; + ApplyUniqueIndices(targSource, newBufferLen, translationMap); + } + } + // Set the source to be per-vertex... this means it has data for every vertex? + targMesh->AddVertexSource(targSource); + } + + // Reset the indices. The indices in newIndices are all polygon indices combined + const uint32* newIdxPtr = newIndices.begin(); + size_t nNewIndices = newIndices.size(); + for (size_t p = 0; p < targMesh->GetPolygonsCount(); p++) + { + FCDGeometryPolygons* polygons = targMesh->GetPolygons(p); + FCDGeometryPolygonsInput* anInput = polygons->GetInput(0); + size_t nIndices = anInput->GetIndexCount(); + // Check if we are valid, if not, the best we can do is not crash + FUAssert(nIndices >= nNewIndices, nIndices = nNewIndices); + anInput->SetIndices(newIdxPtr, nIndices); + + newIdxPtr += nIndices; + nNewIndices -= nIndices; + } + } + +#if _MSC_VER +# pragma warning(push) +# pragma warning(disable : 4127) // conditional expression constant +# pragma warning(disable : 4244) // conversion from 'const float' to 'uint8' +#endif + +#define INVALID_VTX_IDX (uint16(~0)) // This value is the default (invalid) value in the vtx data map + + template + void PackVertexBuffers(uint8* destBuffer, uint32 destBuffStride, + const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, + const FCDGeometryIndexTranslationMap& translationMap) + { + const float* srcBuffer = source->GetData(); + const uint32 srcBufferStride = source->GetStride(); + + // Special case for missing Alpha channel + if (isColor) if (srcBufferStride == 3) vCount = 3; + FUAssert(srcBufferStride >= vCount, return); + + for (FCDGeometryIndexTranslationMap::const_iterator tmitr = translationMap.begin(); + tmitr != translationMap.end(); ++tmitr) + { + const UInt32List& newIdxList = tmitr->second; + for (UInt32List::const_iterator ditr = newIdxList.begin(); ditr != newIdxList.end(); ++ditr) + { + uint32 newIdx = *ditr; + if (vtxPackingMap[newIdx] != INVALID_VTX_IDX) + { + const float* srcData = srcBuffer + tmitr->first * srcBufferStride; + VAL& setValue = *(VAL*)(destBuffer + vtxPackingMap[newIdx] * destBuffStride); + if (isColor) + { + for (uint32 i = 0; i < vCount; ++i) + { + setValue[i] = (uint8)(srcData[i] * 255); + } + if (vCount == 3) setValue[3] = 255; + } + else + { + for (uint32 i = 0; i < vCount; ++i) + { + setValue[i] = srcData[i]; + } + } + } + } + } + } + +#if _MSC_VER +# pragma warning(pop) +#endif + + void PackVertexBufferV3(uint8* destBuffer, uint32 destBuffStride, + const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, + const FCDGeometryIndexTranslationMap& translationMap) + { + PackVertexBuffers(destBuffer, destBuffStride, source, vCount, vtxPackingMap, translationMap); + } + + void PackVertexBufferColor(uint8* destBuffer, uint32 destBuffStride, + const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, + const FCDGeometryIndexTranslationMap& translationMap) + { + PackVertexBuffers(destBuffer, destBuffStride, source, vCount, vtxPackingMap, translationMap); + } + + void PackVertexBufferV2(uint8* destBuffer, uint32 destBuffStride, + const FCDGeometrySource* source, uint32 vCount, uint16* vtxPackingMap, + const FCDGeometryIndexTranslationMap& translationMap) + { + PackVertexBuffers(destBuffer, destBuffStride, source, vCount, vtxPackingMap, translationMap); + } + + // Iterate over the indices, remapping them using the provided map until we have consumed + // either max indices or max vertices, whichever is first + // return the number of indices actually consumed. + uint16 GenerateVertexPackingMap(size_t maxIndex, size_t maxIndices, size_t maxVertices, const uint32* inIndices, uint16* outIndices, UInt16List* outPackingMap, uint16* outNVertices/*=NULL*/) + { + FUAssert(inIndices != NULL && outPackingMap != NULL, return 0); + FUAssert(maxIndices < INVALID_VTX_IDX, maxIndices = INVALID_VTX_IDX - 1); + outPackingMap->resize(maxIndex + 1, INVALID_VTX_IDX); + uint16 nIndices, nVertices = 0; + for (nIndices = 0; nIndices < maxIndices; ++nIndices) + { + if (outPackingMap->at(*inIndices) == INVALID_VTX_IDX) // New vtx + { + // map this index to the next available vtx space + outPackingMap->at(*inIndices) = nVertices; + // Optimization - dont compare this more often + // than absolutely necessary. So if we need to + // force a break using the maxIndices instead + if (++nVertices >= maxVertices) maxIndices = nIndices; + } + if (outIndices != NULL) + { + *outIndices = outPackingMap->at(*inIndices); + ++outIndices; + } + ++inIndices; + } + // Sanity check + FUAssert(nVertices <= nIndices, nVertices = nIndices); + // Extra requested return + if (outNVertices != NULL) *outNVertices = nVertices; + return nIndices; + } + + uint32 FindLargestUniqueIndex(const FCDGeometryIndexTranslationMap& aMap) + { + uint32 largestIdx = 0; + FCDGeometryIndexTranslationMap::const_iterator it, itEnd = aMap.end(); + for (it = aMap.begin(); it != itEnd; ++it) + { + const UInt32List& curList = it->second; + for (UInt32List::const_iterator uit = curList.begin(); uit != curList.end(); ++uit) + { + largestIdx = max(largestIdx, *uit); + } + } + return largestIdx; + } + + void RevertUniqueIndices(const FCDGeometryPolygonsInput& inPInput, FCDGeometryPolygonsInput& outPInput, const FCDGeometryIndexTranslationMap& translationMap) + { + FUFail(;) // NOT_TESTED + size_t tmSize = translationMap.size(); + uint32 largest = 0; + for (FCDGeometryIndexTranslationMap::const_iterator it = translationMap.begin(), itEnd = translationMap.end(); it != itEnd; ++it) + { + const UInt32List& curList = it->second; + for (UInt32List::const_iterator uit = curList.begin(); uit != curList.end(); ++uit) + { + largest = max(largest, *uit); + } + } + + uint32 oldBufferLen = largest + 1; + + const FCDGeometrySource* inSrc = inPInput.GetSource(); + FCDGeometrySource* outSrc = outPInput.GetSource(); + + FUAssert(inSrc->GetValueCount() == oldBufferLen, return); + + uint32 stride = inSrc->GetStride(); + + outSrc->SetStride(stride); + outSrc->SetValueCount(tmSize); + + const float* inData = inSrc->GetData(); + float* outData = outSrc->GetData(); + + const uint32* inIndices = inPInput.GetIndices(); + FUAssert(inIndices != NULL, return); + UInt32List indices(inIndices, inPInput.GetIndexCount()); + + for (FCDGeometryIndexTranslationMap::const_iterator it = translationMap.begin(), itEnd = translationMap.end(); it != itEnd; ++it) + { + const UInt32List& curList = it->second; + FUAssert(!curList.empty(), continue); + + for (uint32 s = 0; s < stride; ++s) + { + //data[stride * (*uit) + s] = oldData[stride * + s]; + outData[stride * it->first + s] = inData[stride * curList.front() + s]; + } + + for (UInt32List::const_iterator uit = curList.begin(); uit != curList.end(); ++uit) + { + indices.replace(*uit, it->first); + } + } + + outPInput.SetIndices(indices.begin(), indices.size()); + } + + // Splits the mesh's polygons sets to ensure that none of them have + // more than a given number of indices within their index buffers. + void FitIndexBuffers(FCDGeometryMesh* mesh, size_t maximumIndexCount) + { + // Iterate over the original polygons sets, looking for ones that are too big. + // When a polygon set is too big, a new polygon set will be added, but at the end of the list. + size_t originalPolygonCount = mesh->GetPolygonsCount(); + for (size_t i = 0; i < originalPolygonCount; ++i) + { + // Iterate a over the face-vertex counts of the polygons set in order + // to find at which face to break this polygons set. + FCDGeometryPolygons* polygons = mesh->GetPolygons(i); + if (polygons->GetPrimitiveType() == FCDGeometryPolygons::POINTS) continue; + + size_t faceCount = polygons->GetFaceVertexCountCount(); + if (faceCount == 0) continue; + UInt32List faceVertexCounts(polygons->GetFaceVertexCounts(), faceCount); + size_t inputCount = polygons->GetInputCount(); + + UInt32List::iterator splitIt = faceVertexCounts.end(); + uint32 faceVertexCount = 0; + for (splitIt = faceVertexCounts.begin(); splitIt != faceVertexCounts.end(); ++splitIt) + { + if (faceVertexCount + (*splitIt) > maximumIndexCount) break; + faceVertexCount += (*splitIt); + } + if (splitIt == faceVertexCounts.end()) continue; // Polygons sets fit correctly. + size_t splitIndexCount = (size_t) faceVertexCount; + size_t splitFaceCount = splitIt - faceVertexCounts.begin(); + + size_t faceCopyStart = splitFaceCount; + size_t faceCopyEnd = faceCopyStart; + size_t faceVertexCopyStart = splitIndexCount; + size_t faceVertexCopyEnd = faceVertexCopyStart; + while (faceCopyEnd < faceCount) + { + // Create a new polygons set and copy the basic information from the first polygons set. + FCDGeometryPolygons* polygonsCopy = mesh->AddPolygons(); + polygonsCopy->SetMaterialSemantic(polygons->GetMaterialSemantic()); + + // Figure out which faces will be moved to this polygons set. + faceVertexCount = 0; + for (; faceCopyEnd < faceCount; ++faceCopyEnd) + { + uint32 localCount = faceVertexCounts[faceCopyEnd]; + if (faceVertexCount + localCount > maximumIndexCount) break; + faceVertexCount += localCount; + } + faceVertexCopyEnd += faceVertexCount; + + FUAssert(faceVertexCopyEnd > faceVertexCopyStart, continue); + FUAssert(faceCopyEnd > faceCopyStart, continue); + + // Create the inputs and their indices over in the new polygons set. + for (size_t j = 0; j < inputCount; ++j) + { + FCDGeometryPolygonsInput* input = polygons->GetInput(j); + FCDGeometrySource* source = input->GetSource(); + FCDGeometryPolygonsInput* inputCopy; + if (!mesh->IsVertexSource(source)) inputCopy = polygonsCopy->AddInput(source, input->GetOffset()); + else inputCopy = polygonsCopy->FindInput(source); + FUAssert(inputCopy != NULL, continue); + + // For owners, copy the indices over. + size_t indexCopyCount = inputCopy->GetIndexCount(); + if (indexCopyCount == 0) + { + uint32* indices = input->GetIndices(); + inputCopy->SetIndices(indices + faceVertexCopyStart, faceVertexCopyEnd - faceVertexCopyStart); + } + } + + // Copy the face-vertex counts over to the new polygons set + // And increment the copy counters. + size_t faceCopyCount = faceCopyEnd - faceCopyStart; + polygonsCopy->SetFaceVertexCountCount(faceCopyCount); + memcpy((void*) polygonsCopy->GetFaceVertexCounts(), &(*(faceVertexCounts.begin() + faceCopyStart)), faceCopyCount * sizeof(uint32)); + faceCopyStart = faceCopyEnd; + faceVertexCopyStart = faceVertexCopyEnd; + } + + // Remove the faces that were split away and their indices. + for (size_t j = 0; j < inputCount; ++j) + { + FCDGeometryPolygonsInput* input = polygons->GetInput(j); + if (input->OwnsIndices()) + { + input->SetIndexCount(splitIndexCount); + } + } + polygons->SetFaceVertexCountCount(splitFaceCount); + } + + mesh->Recalculate(); + } + + // Reverses all the normals of a mesh. + void ReverseNormals(FCDGeometryMesh* mesh) + { + size_t sourceCount = mesh->GetSourceCount(); + for (size_t i = 0; i < sourceCount; ++i) + { + FCDGeometrySource* source = mesh->GetSource(i); + if (source->GetType() == FUDaeGeometryInput::NORMAL || source->GetType() == FUDaeGeometryInput::GEOTANGENT + || source->GetType() == FUDaeGeometryInput::GEOBINORMAL || source->GetType() == FUDaeGeometryInput::TEXTANGENT + || source->GetType() == FUDaeGeometryInput::TEXBINORMAL) + { + float* v = source->GetData(); + size_t dataCount = source->GetDataCount(); + for (size_t it = 0; it < dataCount; ++it) + { + *(v++) *= -1.0f; + } + } + } + } + +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsTools.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySpline.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySpline.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySpline.cpp (revision 24247) @@ -1,340 +1,340 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDGeometrySource.h" -#include "FCDocument/FCDGeometrySpline.h" -#include "FUtils/FUStringConversion.h" - -// -// FCDSpline -// - -ImplementObjectType(FCDSpline); - -FCDSpline::FCDSpline(FCDocument* document) -: FCDObject(document) -{ - form = FUDaeSplineForm::OPEN; -} - -FCDSpline::~FCDSpline() -{ - cvs.clear(); -} - -FCDSpline* FCDSpline::Clone(FCDSpline* clone) const -{ - if (clone == NULL) return NULL; - - clone->cvs = cvs; - clone->name = name; - clone->form = form; - - return clone; -} - -// -// FCDLinearSpline -// - -ImplementObjectType(FCDLinearSpline); - -FCDLinearSpline::FCDLinearSpline(FCDocument* document) -: FCDSpline(document) -{ -} - -FCDLinearSpline::~FCDLinearSpline() -{ -} - -void FCDLinearSpline::ToBezier(FCDBezierSpline& bezier) -{ - if (!IsValid()) return; - - // clear the given spline - bezier.ClearCVs(); - - size_t count = cvs.size(); - bool closed = IsClosed(); - - if (closed) - { - bezier.SetClosed(true); - } - - for (size_t i = 0; i < count; i++) - { - FMVector3& cv = cvs[i]; - if (!closed && (i == 0 || i == count - 1)) - { - // first and last CV on an open spline, 2 times - bezier.AddCV(cv); - bezier.AddCV(cv); - } - else - { - // in between CVs, three times - bezier.AddCV(cv); - bezier.AddCV(cv); - bezier.AddCV(cv); - } - } -} - -bool FCDLinearSpline::IsValid() const -{ - return cvs.size() >= 2; -} - -// -// FCDBezierSpline -// - -ImplementObjectType(FCDBezierSpline); - -FCDBezierSpline::FCDBezierSpline(FCDocument* document) -: FCDSpline(document) -{ -} - -FCDBezierSpline::~FCDBezierSpline() -{ -} - -void FCDBezierSpline::ToNURBs(FCDNURBSSplineList &toFill) const -{ - // calculate the number of nurb segments - bool closed = IsClosed(); - int cvsCount = (int)cvs.size(); - int nurbCount = (!closed) ? ((cvsCount - 1) / 3) : (cvsCount / 3); - - // if the spline is closed, ignore the first CV as it is the in-tangent of the first knot - size_t curCV = (!closed) ? 0 : 1; - int lastNurb = (!closed) ? nurbCount : (nurbCount - 1); - - for (int i = 0; i < lastNurb; i++) - { - FCDNURBSSpline* nurb = new FCDNURBSSpline(const_cast(GetDocument())); - nurb->SetDegree(3); - - // add (degree + 1) CVs to the nurb - for (size_t i = 0; i < (3+1); i++) - { - nurb->AddCV(cvs[curCV++], 1.0f); - } - - // the last CVs will be the starting point of the next nurb segment - curCV--; - - // add (degree+1) knots on each side of the knot vector - for (size_t i = 0; i < (3+1); i++) nurb->AddKnot(0.0f); - for (size_t i = 0; i < (3+1); i++) nurb->AddKnot(1.0f); - - // nurbs created this way are never closed - nurb->SetClosed(false); - - // add the nurb - toFill.push_back(nurb); - } - - if (closed) - { - // we still have one NURB to create - FCDNURBSSpline* nurb = new FCDNURBSSpline(const_cast(GetDocument())); - nurb->SetDegree(3); - - nurb->AddCV(cvs[cvsCount - 2], 1.0f); // the last knot position - nurb->AddCV(cvs[cvsCount - 1], 1.0f); // the last knot out-tangent - nurb->AddCV(cvs[0 ], 1.0f); // the first knot in-tangent - nurb->AddCV(cvs[1 ], 1.0f); // the first knot position - - // add (degree+1) knots on each side of the knot vector - for (size_t i = 0; i < (3+1); i++) nurb->AddKnot(0.0f); - for (size_t i = 0; i < (3+1); i++) nurb->AddKnot(1.0f); - - // nurbs created this way are never closed - nurb->SetClosed(false); - - // add the nurb - toFill.push_back(nurb); - } -} - -bool FCDBezierSpline::IsValid() const -{ - bool s = true; - if (cvs.size() == 0) - { - s = !FUError::Error(FUError::WARNING_LEVEL, FUError::WARNING_SPLINE_CONTROL_INPUT_MISSING); - } - return s; -} - -// -// FCDNURBSSpline -// - -ImplementObjectType(FCDNURBSSpline); - -FCDNURBSSpline::FCDNURBSSpline(FCDocument* document) -: FCDSpline(document) -{ -} - -FCDNURBSSpline::~FCDNURBSSpline() -{ - weights.clear(); - knots.clear(); -} - -FCDSpline* FCDNURBSSpline::Clone(FCDSpline* _clone) const -{ - FCDNURBSSpline* clone = NULL; - if (_clone == NULL) return NULL; - else if (_clone->HasType(FCDNURBSSpline::GetClassType())) clone = (FCDNURBSSpline*) _clone; - - Parent::Clone(_clone); - - if (clone != NULL) - { - // Clone the NURBS-specific spline data - clone->degree = degree; - clone->weights = weights; - clone->knots = knots; - } - - return _clone; -} - -bool FCDNURBSSpline::AddCV(const FMVector3& cv, float weight) -{ - if (weight < 0.0f) return false; - - cvs.push_back(cv); - weights.push_back(weight); - return true; -} - -bool FCDNURBSSpline::IsValid() const -{ - bool s = true; - if (cvs.size() == 0) - { - FUError::Error(FUError::WARNING_LEVEL, FUError::WARNING_SPLINE_CONTROL_INPUT_MISSING); - s = false; - } - - if (cvs.size() != weights.size()) - { - FUError::Error(FUError::ERROR_LEVEL, FUError::ERROR_INVALID_CVS_WEIGHTS); - s = false; - } - - if (cvs.size() != knots.size() - degree - 1) - { - FUError::Error(FUError::ERROR_LEVEL, FUError::ERROR_INVALID_SPLINE); - s = false; - } - - return s; -} - -// -// FCDGeometrySpline -// - -ImplementObjectType(FCDGeometrySpline); -ImplementParameterObjectNoCtr(FCDGeometrySpline, FCDSpline, splines); - -FCDGeometrySpline::FCDGeometrySpline(FCDocument* document, FCDGeometry* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameter(type, FUDaeSplineType::UNKNOWN) -, InitializeParameterNoArg(splines) -{ -} - -FCDGeometrySpline::~FCDGeometrySpline() -{ - parent = NULL; -} - -FCDGeometrySpline* FCDGeometrySpline::Clone(FCDGeometrySpline* clone) const -{ - if (clone == NULL) clone = new FCDGeometrySpline(const_cast(GetDocument()), NULL); - clone->type = type; - - // Clone the spline set. - for (FCDSplineContainer::const_iterator it = splines.begin(); it != splines.end(); ++it) - { - FCDSpline* cloneSpline = clone->AddSpline(); - (*it)->Clone(cloneSpline); - } - - return clone; -} - -bool FCDGeometrySpline::SetType(FUDaeSplineType::Type _type) -{ - while (!splines.empty()) splines.back()->Release(); - type = _type; - SetDirtyFlag(); - return true; -} - -FCDSpline* FCDGeometrySpline::AddSpline(FUDaeSplineType::Type type) -{ - // Retrieve the correct spline type to create. - if (type == FUDaeSplineType::UNKNOWN) type = GetType(); - else if (type != GetType()) return NULL; - - // Create the correctly-type spline - FCDSpline* newSpline = NULL; - switch (type) - { - case FUDaeSplineType::LINEAR: newSpline = new FCDLinearSpline(GetDocument()); break; - case FUDaeSplineType::BEZIER: newSpline = new FCDBezierSpline(GetDocument()); break; - case FUDaeSplineType::NURBS: newSpline = new FCDNURBSSpline(GetDocument()); break; - - case FUDaeSplineType::UNKNOWN: - default: return NULL; - } - - splines.push_back(newSpline); - SetDirtyFlag(); - return newSpline; -} - -size_t FCDGeometrySpline::GetTotalCVCount() -{ - size_t count = 0; - for (size_t i = 0; i < splines.size(); i++) - { - count += splines[i]->GetCVCount(); - } - return count; -} - -void FCDGeometrySpline::ConvertBezierToNURBS(FCDNURBSSplineList &toFill) -{ - if (type != FUDaeSplineType::BEZIER) - { - return; - } - - for (size_t i = 0; i < splines.size(); i++) - { - FCDBezierSpline* bez = static_cast(splines[i]); - bez->ToNURBs(toFill); - } - SetDirtyFlag(); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDGeometrySource.h" +#include "FCDocument/FCDGeometrySpline.h" +#include "FUtils/FUStringConversion.h" + +// +// FCDSpline +// + +ImplementObjectType(FCDSpline); + +FCDSpline::FCDSpline(FCDocument* document) +: FCDObject(document) +{ + form = FUDaeSplineForm::OPEN; +} + +FCDSpline::~FCDSpline() +{ + cvs.clear(); +} + +FCDSpline* FCDSpline::Clone(FCDSpline* clone) const +{ + if (clone == NULL) return NULL; + + clone->cvs = cvs; + clone->name = name; + clone->form = form; + + return clone; +} + +// +// FCDLinearSpline +// + +ImplementObjectType(FCDLinearSpline); + +FCDLinearSpline::FCDLinearSpline(FCDocument* document) +: FCDSpline(document) +{ +} + +FCDLinearSpline::~FCDLinearSpline() +{ +} + +void FCDLinearSpline::ToBezier(FCDBezierSpline& bezier) +{ + if (!IsValid()) return; + + // clear the given spline + bezier.ClearCVs(); + + size_t count = cvs.size(); + bool closed = IsClosed(); + + if (closed) + { + bezier.SetClosed(true); + } + + for (size_t i = 0; i < count; i++) + { + FMVector3& cv = cvs[i]; + if (!closed && (i == 0 || i == count - 1)) + { + // first and last CV on an open spline, 2 times + bezier.AddCV(cv); + bezier.AddCV(cv); + } + else + { + // in between CVs, three times + bezier.AddCV(cv); + bezier.AddCV(cv); + bezier.AddCV(cv); + } + } +} + +bool FCDLinearSpline::IsValid() const +{ + return cvs.size() >= 2; +} + +// +// FCDBezierSpline +// + +ImplementObjectType(FCDBezierSpline); + +FCDBezierSpline::FCDBezierSpline(FCDocument* document) +: FCDSpline(document) +{ +} + +FCDBezierSpline::~FCDBezierSpline() +{ +} + +void FCDBezierSpline::ToNURBs(FCDNURBSSplineList &toFill) const +{ + // calculate the number of nurb segments + bool closed = IsClosed(); + int cvsCount = (int)cvs.size(); + int nurbCount = (!closed) ? ((cvsCount - 1) / 3) : (cvsCount / 3); + + // if the spline is closed, ignore the first CV as it is the in-tangent of the first knot + size_t curCV = (!closed) ? 0 : 1; + int lastNurb = (!closed) ? nurbCount : (nurbCount - 1); + + for (int i = 0; i < lastNurb; i++) + { + FCDNURBSSpline* nurb = new FCDNURBSSpline(const_cast(GetDocument())); + nurb->SetDegree(3); + + // add (degree + 1) CVs to the nurb + for (size_t i = 0; i < (3+1); i++) + { + nurb->AddCV(cvs[curCV++], 1.0f); + } + + // the last CVs will be the starting point of the next nurb segment + curCV--; + + // add (degree+1) knots on each side of the knot vector + for (size_t i = 0; i < (3+1); i++) nurb->AddKnot(0.0f); + for (size_t i = 0; i < (3+1); i++) nurb->AddKnot(1.0f); + + // nurbs created this way are never closed + nurb->SetClosed(false); + + // add the nurb + toFill.push_back(nurb); + } + + if (closed) + { + // we still have one NURB to create + FCDNURBSSpline* nurb = new FCDNURBSSpline(const_cast(GetDocument())); + nurb->SetDegree(3); + + nurb->AddCV(cvs[cvsCount - 2], 1.0f); // the last knot position + nurb->AddCV(cvs[cvsCount - 1], 1.0f); // the last knot out-tangent + nurb->AddCV(cvs[0 ], 1.0f); // the first knot in-tangent + nurb->AddCV(cvs[1 ], 1.0f); // the first knot position + + // add (degree+1) knots on each side of the knot vector + for (size_t i = 0; i < (3+1); i++) nurb->AddKnot(0.0f); + for (size_t i = 0; i < (3+1); i++) nurb->AddKnot(1.0f); + + // nurbs created this way are never closed + nurb->SetClosed(false); + + // add the nurb + toFill.push_back(nurb); + } +} + +bool FCDBezierSpline::IsValid() const +{ + bool s = true; + if (cvs.size() == 0) + { + s = !FUError::Error(FUError::WARNING_LEVEL, FUError::WARNING_SPLINE_CONTROL_INPUT_MISSING); + } + return s; +} + +// +// FCDNURBSSpline +// + +ImplementObjectType(FCDNURBSSpline); + +FCDNURBSSpline::FCDNURBSSpline(FCDocument* document) +: FCDSpline(document) +{ +} + +FCDNURBSSpline::~FCDNURBSSpline() +{ + weights.clear(); + knots.clear(); +} + +FCDSpline* FCDNURBSSpline::Clone(FCDSpline* _clone) const +{ + FCDNURBSSpline* clone = NULL; + if (_clone == NULL) return NULL; + else if (_clone->HasType(FCDNURBSSpline::GetClassType())) clone = (FCDNURBSSpline*) _clone; + + Parent::Clone(_clone); + + if (clone != NULL) + { + // Clone the NURBS-specific spline data + clone->degree = degree; + clone->weights = weights; + clone->knots = knots; + } + + return _clone; +} + +bool FCDNURBSSpline::AddCV(const FMVector3& cv, float weight) +{ + if (weight < 0.0f) return false; + + cvs.push_back(cv); + weights.push_back(weight); + return true; +} + +bool FCDNURBSSpline::IsValid() const +{ + bool s = true; + if (cvs.size() == 0) + { + FUError::Error(FUError::WARNING_LEVEL, FUError::WARNING_SPLINE_CONTROL_INPUT_MISSING); + s = false; + } + + if (cvs.size() != weights.size()) + { + FUError::Error(FUError::ERROR_LEVEL, FUError::ERROR_INVALID_CVS_WEIGHTS); + s = false; + } + + if (cvs.size() != knots.size() - degree - 1) + { + FUError::Error(FUError::ERROR_LEVEL, FUError::ERROR_INVALID_SPLINE); + s = false; + } + + return s; +} + +// +// FCDGeometrySpline +// + +ImplementObjectType(FCDGeometrySpline); +ImplementParameterObjectNoCtr(FCDGeometrySpline, FCDSpline, splines); + +FCDGeometrySpline::FCDGeometrySpline(FCDocument* document, FCDGeometry* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameter(type, FUDaeSplineType::UNKNOWN) +, InitializeParameterNoArg(splines) +{ +} + +FCDGeometrySpline::~FCDGeometrySpline() +{ + parent = NULL; +} + +FCDGeometrySpline* FCDGeometrySpline::Clone(FCDGeometrySpline* clone) const +{ + if (clone == NULL) clone = new FCDGeometrySpline(const_cast(GetDocument()), NULL); + clone->type = type; + + // Clone the spline set. + for (FCDSplineContainer::const_iterator it = splines.begin(); it != splines.end(); ++it) + { + FCDSpline* cloneSpline = clone->AddSpline(); + (*it)->Clone(cloneSpline); + } + + return clone; +} + +bool FCDGeometrySpline::SetType(FUDaeSplineType::Type _type) +{ + while (!splines.empty()) splines.back()->Release(); + type = _type; + SetDirtyFlag(); + return true; +} + +FCDSpline* FCDGeometrySpline::AddSpline(FUDaeSplineType::Type type) +{ + // Retrieve the correct spline type to create. + if (type == FUDaeSplineType::UNKNOWN) type = GetType(); + else if (type != GetType()) return NULL; + + // Create the correctly-type spline + FCDSpline* newSpline = NULL; + switch (type) + { + case FUDaeSplineType::LINEAR: newSpline = new FCDLinearSpline(GetDocument()); break; + case FUDaeSplineType::BEZIER: newSpline = new FCDBezierSpline(GetDocument()); break; + case FUDaeSplineType::NURBS: newSpline = new FCDNURBSSpline(GetDocument()); break; + + case FUDaeSplineType::UNKNOWN: + default: return NULL; + } + + splines.push_back(newSpline); + SetDirtyFlag(); + return newSpline; +} + +size_t FCDGeometrySpline::GetTotalCVCount() +{ + size_t count = 0; + for (size_t i = 0; i < splines.size(); i++) + { + count += splines[i]->GetCVCount(); + } + return count; +} + +void FCDGeometrySpline::ConvertBezierToNURBS(FCDNURBSSplineList &toFill) +{ + if (type != FUDaeSplineType::BEZIER) + { + return; + } + + for (size_t i = 0; i < splines.size(); i++) + { + FCDBezierSpline* bez = static_cast(splines[i]); + bez->ToNURBs(toFill); + } + SetDirtyFlag(); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySpline.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.cpp (revision 24247) @@ -1,164 +1,164 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDAnimation.h" -#include "FCDocument/FCDAnimationClip.h" -#include "FCDocument/FCDAsset.h" -#include "FCDocument/FCDCamera.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDEffect.h" -#include "FCDocument/FCDEmitter.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDForceField.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDImage.h" -#include "FCDocument/FCDLight.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDMaterial.h" -#include "FCDocument/FCDPhysicsMaterial.h" -#include "FCDocument/FCDPhysicsModel.h" -#include "FCDocument/FCDPhysicsScene.h" -#include "FCDocument/FCDSceneNode.h" -#ifndef __APPLE__ -#include "FCDocument/FCDLibrary.hpp" -#endif // __APPLE__ - -// -// FCDLibrary -// - -typedef FCDLibrary FCDAnimationLibrary; -typedef FCDLibrary FCDAnimationClipLibrary; -typedef FCDLibrary FCDCameraLibrary; -typedef FCDLibrary FCDControllerLibrary; -typedef FCDLibrary FCDEffectLibrary; -typedef FCDLibrary FCDEmitterLibrary; -typedef FCDLibrary FCDForceFieldLibrary; -typedef FCDLibrary FCDGeometryLibrary; -typedef FCDLibrary FCDImageLibrary; -typedef FCDLibrary FCDLightLibrary; -typedef FCDLibrary FCDMaterialLibrary; -typedef FCDLibrary FCDSceneNodeLibrary; -typedef FCDLibrary FCDPhysicsModelLibrary; -typedef FCDLibrary FCDPhysicsMaterialLibrary; -typedef FCDLibrary FCDPhysicsSceneLibrary; - -ImplementObjectTypeT(FCDAnimationLibrary); -ImplementObjectTypeT(FCDAnimationClipLibrary); -ImplementObjectTypeT(FCDCameraLibrary); -ImplementObjectTypeT(FCDControllerLibrary); -ImplementObjectTypeT(FCDEffectLibrary); -ImplementObjectTypeT(FCDEmitterLibrary); -ImplementObjectTypeT(FCDForceFieldLibrary); -ImplementObjectTypeT(FCDGeometryLibrary); -ImplementObjectTypeT(FCDImageLibrary); -ImplementObjectTypeT(FCDLightLibrary); -ImplementObjectTypeT(FCDMaterialLibrary); -ImplementObjectTypeT(FCDSceneNodeLibrary); -ImplementObjectTypeT(FCDPhysicsModelLibrary); -ImplementObjectTypeT(FCDPhysicsMaterialLibrary); -ImplementObjectTypeT(FCDPhysicsSceneLibrary); - -ImplementParameterObjectT(FCDAnimationLibrary, FCDAnimation, entities, new FCDAnimation(parent->GetDocument())); -ImplementParameterObjectT(FCDAnimationClipLibrary, FCDAnimationClip, entities, new FCDAnimationClip(parent->GetDocument())); -ImplementParameterObjectT(FCDCameraLibrary, FCDCamera, entities, new FCDCamera(parent->GetDocument())); -ImplementParameterObjectT(FCDControllerLibrary, FCDController, entities, new FCDController(parent->GetDocument())); -ImplementParameterObjectT(FCDEffectLibrary, FCDEffect, entities, new FCDEffect(parent->GetDocument())); -ImplementParameterObjectT(FCDEmitterLibrary, FCDEmitter, entities, new FCDEmitter(parent->GetDocument())); -ImplementParameterObjectT(FCDForceFieldLibrary, FCDForceField, entities, new FCDForceField(parent->GetDocument())); -ImplementParameterObjectT(FCDGeometryLibrary, FCDGeometry, entities, new FCDGeometry(parent->GetDocument())); -ImplementParameterObjectT(FCDImageLibrary, FCDImage, entities, new FCDImage(parent->GetDocument())); -ImplementParameterObjectT(FCDLightLibrary, FCDLight, entities, new FCDLight(parent->GetDocument())); -ImplementParameterObjectT(FCDMaterialLibrary, FCDMaterial, entities, new FCDMaterial(parent->GetDocument())); -ImplementParameterObjectT(FCDSceneNodeLibrary, FCDSceneNode, entities, new FCDSceneNode(parent->GetDocument())); -ImplementParameterObjectT(FCDPhysicsModelLibrary, FCDPhysicsModel, entities, new FCDPhysicsModel(parent->GetDocument())); -ImplementParameterObjectT(FCDPhysicsMaterialLibrary, FCDPhysicsMaterial, entities, new FCDPhysicsMaterial(parent->GetDocument())); -ImplementParameterObjectT(FCDPhysicsSceneLibrary, FCDPhysicsScene, entities, new FCDPhysicsScene(parent->GetDocument())); - -ImplementParameterObjectT(FCDAnimationLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDAnimationClipLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDCameraLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDControllerLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDEffectLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDEmitterLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDForceFieldLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDGeometryLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDImageLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDLightLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDMaterialLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDSceneNodeLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDPhysicsModelLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDPhysicsMaterialLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObjectT(FCDPhysicsSceneLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); - -ImplementParameterObjectT(FCDAnimationLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDAnimationClipLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDCameraLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDControllerLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDEffectLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDEmitterLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDForceFieldLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDGeometryLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDImageLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDLightLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDMaterialLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDSceneNodeLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDPhysicsModelLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDPhysicsMaterialLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObjectT(FCDPhysicsSceneLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); - -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; -template class FCDLibrary; - -template -inline void LibraryExport() -{ - FCDLibrary* l1 = new FCDLibrary(NULL); - T* ptr = l1->AddEntity(); - l1->AddEntity(ptr); - bool b = l1->IsEmpty(); - if (b) { ptr = l1->FindDaeId(emptyCharString); } - ptr = l1->GetEntity(23); - const T* cptr = ((const FCDLibrary*)l1)->GetEntity(0); - cptr = ptr; - FCDAsset* asset = l1->GetAsset(); - asset->SetFlag(11); -} - -FCOLLADA_EXPORT void TrickLinkerFCDLibrary() -{ - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); - LibraryExport(); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDAnimation.h" +#include "FCDocument/FCDAnimationClip.h" +#include "FCDocument/FCDAsset.h" +#include "FCDocument/FCDCamera.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDEffect.h" +#include "FCDocument/FCDEmitter.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDForceField.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDImage.h" +#include "FCDocument/FCDLight.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDMaterial.h" +#include "FCDocument/FCDPhysicsMaterial.h" +#include "FCDocument/FCDPhysicsModel.h" +#include "FCDocument/FCDPhysicsScene.h" +#include "FCDocument/FCDSceneNode.h" +#ifndef __APPLE__ +#include "FCDocument/FCDLibrary.hpp" +#endif // __APPLE__ + +// +// FCDLibrary +// + +typedef FCDLibrary FCDAnimationLibrary; +typedef FCDLibrary FCDAnimationClipLibrary; +typedef FCDLibrary FCDCameraLibrary; +typedef FCDLibrary FCDControllerLibrary; +typedef FCDLibrary FCDEffectLibrary; +typedef FCDLibrary FCDEmitterLibrary; +typedef FCDLibrary FCDForceFieldLibrary; +typedef FCDLibrary FCDGeometryLibrary; +typedef FCDLibrary FCDImageLibrary; +typedef FCDLibrary FCDLightLibrary; +typedef FCDLibrary FCDMaterialLibrary; +typedef FCDLibrary FCDSceneNodeLibrary; +typedef FCDLibrary FCDPhysicsModelLibrary; +typedef FCDLibrary FCDPhysicsMaterialLibrary; +typedef FCDLibrary FCDPhysicsSceneLibrary; + +ImplementObjectTypeT(FCDAnimationLibrary); +ImplementObjectTypeT(FCDAnimationClipLibrary); +ImplementObjectTypeT(FCDCameraLibrary); +ImplementObjectTypeT(FCDControllerLibrary); +ImplementObjectTypeT(FCDEffectLibrary); +ImplementObjectTypeT(FCDEmitterLibrary); +ImplementObjectTypeT(FCDForceFieldLibrary); +ImplementObjectTypeT(FCDGeometryLibrary); +ImplementObjectTypeT(FCDImageLibrary); +ImplementObjectTypeT(FCDLightLibrary); +ImplementObjectTypeT(FCDMaterialLibrary); +ImplementObjectTypeT(FCDSceneNodeLibrary); +ImplementObjectTypeT(FCDPhysicsModelLibrary); +ImplementObjectTypeT(FCDPhysicsMaterialLibrary); +ImplementObjectTypeT(FCDPhysicsSceneLibrary); + +ImplementParameterObjectT(FCDAnimationLibrary, FCDAnimation, entities, new FCDAnimation(parent->GetDocument())); +ImplementParameterObjectT(FCDAnimationClipLibrary, FCDAnimationClip, entities, new FCDAnimationClip(parent->GetDocument())); +ImplementParameterObjectT(FCDCameraLibrary, FCDCamera, entities, new FCDCamera(parent->GetDocument())); +ImplementParameterObjectT(FCDControllerLibrary, FCDController, entities, new FCDController(parent->GetDocument())); +ImplementParameterObjectT(FCDEffectLibrary, FCDEffect, entities, new FCDEffect(parent->GetDocument())); +ImplementParameterObjectT(FCDEmitterLibrary, FCDEmitter, entities, new FCDEmitter(parent->GetDocument())); +ImplementParameterObjectT(FCDForceFieldLibrary, FCDForceField, entities, new FCDForceField(parent->GetDocument())); +ImplementParameterObjectT(FCDGeometryLibrary, FCDGeometry, entities, new FCDGeometry(parent->GetDocument())); +ImplementParameterObjectT(FCDImageLibrary, FCDImage, entities, new FCDImage(parent->GetDocument())); +ImplementParameterObjectT(FCDLightLibrary, FCDLight, entities, new FCDLight(parent->GetDocument())); +ImplementParameterObjectT(FCDMaterialLibrary, FCDMaterial, entities, new FCDMaterial(parent->GetDocument())); +ImplementParameterObjectT(FCDSceneNodeLibrary, FCDSceneNode, entities, new FCDSceneNode(parent->GetDocument())); +ImplementParameterObjectT(FCDPhysicsModelLibrary, FCDPhysicsModel, entities, new FCDPhysicsModel(parent->GetDocument())); +ImplementParameterObjectT(FCDPhysicsMaterialLibrary, FCDPhysicsMaterial, entities, new FCDPhysicsMaterial(parent->GetDocument())); +ImplementParameterObjectT(FCDPhysicsSceneLibrary, FCDPhysicsScene, entities, new FCDPhysicsScene(parent->GetDocument())); + +ImplementParameterObjectT(FCDAnimationLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDAnimationClipLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDCameraLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDControllerLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDEffectLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDEmitterLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDForceFieldLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDGeometryLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDImageLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDLightLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDMaterialLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDSceneNodeLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDPhysicsModelLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDPhysicsMaterialLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObjectT(FCDPhysicsSceneLibrary, FCDAsset, asset, new FCDAsset(parent->GetDocument())); + +ImplementParameterObjectT(FCDAnimationLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDAnimationClipLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDCameraLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDControllerLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDEffectLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDEmitterLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDForceFieldLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDGeometryLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDImageLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDLightLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDMaterialLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDSceneNodeLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDPhysicsModelLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDPhysicsMaterialLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObjectT(FCDPhysicsSceneLibrary, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); + +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; +template class FCDLibrary; + +template +inline void LibraryExport() +{ + FCDLibrary* l1 = new FCDLibrary(NULL); + T* ptr = l1->AddEntity(); + l1->AddEntity(ptr); + bool b = l1->IsEmpty(); + if (b) { ptr = l1->FindDaeId(emptyCharString); } + ptr = l1->GetEntity(23); + const T* cptr = ((const FCDLibrary*)l1)->GetEntity(0); + cptr = ptr; + FCDAsset* asset = l1->GetAsset(); + asset->SetFlag(11); +} + +FCOLLADA_EXPORT void TrickLinkerFCDLibrary() +{ + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); + LibraryExport(); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLibrary.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLightTools.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLightTools.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLightTools.cpp (revision 24247) @@ -1,416 +1,416 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDLightTools.h" -#include "FCDocument/FCDLight.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDAnimation.h" -#include "FCDocument/FCDAnimationCurve.h" -#include "FCDocument/FCDAnimationCurveTools.h" -#include "FCDocument/FCDAnimationKey.h" -#include "FCDocument/FCDAnimationMultiCurve.h" -#include "FCDocument/FCDAnimationChannel.h" -#include "FCDocument/FCDLibrary.h" - -namespace FCDLightTools -{ - void LoadPenumbra(FCDLight* light, float penumbraValue, FCDAnimated* penumbraAnimated, bool createAnimationChannel) - { - bool fallOffIsOuter = false; - - // Take care of the default non-animated values - - float fallOffAngle = light->GetFallOffAngle(); - if (penumbraValue < 0) - { - penumbraValue = -penumbraValue; - - fallOffAngle -= 2*penumbraValue; - light->SetFallOffAngle(fallOffAngle); - fallOffIsOuter = true; - } - - float outerAngle = fallOffAngle + 2*penumbraValue; - light->SetOuterAngle(outerAngle); - - // Take care of the animated values - FCDParameterAnimatableFloat& outerAngleValue = light->GetOuterAngle(); - FCDAnimated* outerAngleAnimated = outerAngleValue.GetAnimated(); - if (penumbraAnimated->HasCurve() && penumbraAnimated != outerAngleAnimated) - { - penumbraAnimated->Clone(outerAngleAnimated); - } - - FCDParameterAnimatableFloat& fallOffAngleValue = light->GetFallOffAngle(); - FCDAnimated* fallOffAngleAnimated = fallOffAngleValue.GetAnimated(); - - FCDAnimationCurve* outerAngleCurve = outerAngleAnimated->GetCurve(0); - FCDAnimationCurve* fallOffAngleCurve = fallOffAngleAnimated->GetCurve(0); - - // no animations on the penumbra nor the fallOffAngle, so no animation needed - if (outerAngleCurve == NULL && fallOffAngleCurve == NULL) return; - - // there's animation on the fallOffAngle only, so just need to copy the animation to the outterAngle as well - if (outerAngleCurve == NULL) - { - fallOffAngleAnimated->Clone(outerAngleAnimated); - FUAssert(outerAngleAnimated != NULL, return); // should not be null because we know fallOffAngle is animated - outerAngleAnimated->SetTargetObject(light); - - // if we penumbra was negative, fallOffAngle needs to be lowered, else outerAngle needs to be raised - float offset = 0.0f; - FCDAnimated* animated = NULL; - if (fallOffIsOuter) - { - offset = -2 * penumbraValue; - animated = fallOffAngleAnimated; - } - else - { - offset = 2 * penumbraValue; - animated = outerAngleAnimated; - } - - // now the outerAngle has the penumbra on it too, so have to update the keys - - // add twice the penumbra to the fallOffAngle to get the OuterAngle - FCDConversionOffsetFunctor offsetFunctor(offset); - FCDAnimationCurveTrackList& curves = animated->GetCurves()[0]; - size_t curvesCount = curves.size(); - for (size_t curvesCounter = 0; curvesCounter < curvesCount; curvesCounter++) - { - curves.at(curvesCounter)->ConvertValues(&offsetFunctor, &offsetFunctor); - } - return; - } - - outerAngleAnimated->SetTargetObject(light); // at this point, outerAngleAnimated != NULL - - // FIXME: [aleung] This is not necessarily true, but close enough for now - size_t outerAngleKeysCount = outerAngleCurve->GetKeyCount(); - FCDAnimationKey** outerAngleKeys = outerAngleCurve->GetKeys(); - bool hasNegPenumbra = fallOffIsOuter; - if (!hasNegPenumbra) - { - for (size_t i = 0; i < outerAngleKeysCount; i++) - { - if (outerAngleKeys[i]->output < 0) - { - hasNegPenumbra = true; - break; - } - } - } - - // there's animation on the penumbra only and there's no negative values, so we just need to animate the outerAngle - if ((fallOffAngleCurve == NULL) && !hasNegPenumbra) - { - FCDAnimationCurveListList& curvesList = outerAngleAnimated->GetCurves(); - - // fall off is not animated, easy case - FCDConversionScaleFunctor scaleFunctor(2); - FCDConversionOffsetFunctor offsetFunctor(fallOffAngleValue); - - FCDAnimationCurveTrackList& curves = curvesList[0]; - size_t curvesCount = curves.size(); - for (size_t curvesCounter = 0; curvesCounter < curvesCount; curvesCounter++) - { - curves.at(curvesCounter)->ConvertValues(&scaleFunctor, &scaleFunctor); - curves.at(curvesCounter)->ConvertValues(&offsetFunctor, &offsetFunctor); - } - return; - } - - // at this point, we need curves for both fallOffAngle and outerAngle! - if (fallOffAngleCurve == NULL) - { - if (createAnimationChannel) - { - outerAngleValue.GetAnimated()->Clone(fallOffAngleAnimated); - } - FUAssert(fallOffAngleAnimated != NULL, return); // should not be null because outerAngle is animated - fallOffAngleAnimated->SetTargetObject(light); - fallOffAngleCurve = fallOffAngleAnimated->GetCurve(0); - - if (fallOffAngleCurve == NULL) - { - FUAssert(createAnimationChannel, ;); // should only happen if we created new animated - fallOffAngleAnimated->RemoveCurve(0); - FCDAnimation* animation = light->GetDocument()->GetAnimationLibrary()->AddEntity(); - animation->SetDaeId("compensate_falloff_for_penumbra"); - FCDAnimationChannel* channel = animation->AddChannel(); - fallOffAngleCurve = channel->AddCurve(); - outerAngleCurve->Clone(fallOffAngleCurve); - fallOffAngleAnimated->AddCurve(0, fallOffAngleCurve); - } - - // remove the keys - FCDAnimationCurveTrackList& curves = fallOffAngleAnimated->GetCurves()[0]; - - size_t curvesCount = curves.size(); - for (size_t i = 0; i < curvesCount; i++) - { - curves.at(i)->SetKeyCount(0, FUDaeInterpolation::BEZIER); - - // add keys at the beginning and end with constant pre/post infinity - // the output value should be outerAngle if fallOffIsOuter, otherwise, it should be fallOffAngle - curves.at(i)->SetPreInfinity(FUDaeInfinity::CONSTANT); - curves.at(i)->SetPostInfinity(FUDaeInfinity::CONSTANT); - - FCDAnimationKey* firstKey = curves.at(i)->AddKey(FUDaeInterpolation::LINEAR); - firstKey->input = outerAngleKeys[0]->input; - firstKey->output = (fallOffIsOuter)? light->GetOuterAngle() : light->GetFallOffAngle(); - - FCDAnimationKey* lastKey = curves.at(i)->AddKey(FUDaeInterpolation::LINEAR); - lastKey->input = outerAngleKeys[(outerAngleKeysCount > 1)? outerAngleKeysCount - 1 : 0]->input; - lastKey->output = (fallOffIsOuter)? light->GetOuterAngle() : light->GetFallOffAngle(); - } - } - - - - - // now we have both penumbra and fallOffAngle animated, have to create missing keys by merging the curves - - - FloatList multiCurveValues(2, 0.0f); - FCDAnimationCurveConstList multiCurveCurves(2); - multiCurveValues[0] = fallOffAngleValue; - multiCurveValues[1] = outerAngleValue; - multiCurveCurves[0] = fallOffAngleCurve; - multiCurveCurves[1] = outerAngleCurve; - - FCDAnimationMultiCurve* multiCurve = FCDAnimationCurveTools::MergeCurves(multiCurveCurves, multiCurveValues); - size_t dimension = multiCurve->GetDimension(); - FUAssert(dimension == 2, return); - - // go through the keys to see if there's any switches in signs. If so, we need to insert intermediate keys to the - // outerAngleCurve (penumbra) at the penumbra = 0 point to get desired result - { - size_t multiKeyCount = multiCurve->GetKeyCount(); - FUAssert(multiKeyCount > 0, return); // should not have no keys - FCDAnimationMKey** multiKeys = multiCurve->GetKeys(); - - size_t additionalKeys = 0; - bool isNegative = multiKeys[0]->output[1] < 0; - bool wasZero = IsEquivalent(multiKeys[0]->output[1], 0.0f); - bool hasFlip = false; - for (size_t i = 1; i < multiKeyCount; i++) // start from 1 since we won't add key before the first key - { - FCDAnimationMKey* key = multiKeys[i]; - if (IsEquivalent(key->output[1], 0.0f)) - { - i++; - if (i < multiKeyCount) - { - isNegative = multiKeys[i]->output[1] < 0; - wasZero = IsEquivalent(multiKeys[i]->output[1], 0.0f); - } - continue; - } - else - { - if (wasZero) - { - isNegative = key->output[1] < 0; - wasZero = false; - continue; - } - wasZero = false; - } - - if ((isNegative && (key->output[1] > 0)) || (!isNegative && (key->output[1] < 0))) - { - hasFlip = true; - isNegative = !isNegative; - - // flip in sign, find out where to add the additional key using binary search - float higherTime = key->input; - float lowerTime = multiKeys[i-1]->input; // will not fail since the first sign is taken - float output[2]; - float currentTime = (higherTime + lowerTime) / 2.0f; - - multiCurve->Evaluate(currentTime, output); - while (!IsEquivalent(output[1], 0.0f)) // while penumbra output != 0 - { - if ((isNegative && (output[1] < 0)) || (!isNegative && (output[1] > 0))) - { - higherTime = currentTime; - } - else - { - lowerTime = currentTime; - } - currentTime = (higherTime + lowerTime) / 2.0f; - multiCurve->Evaluate(currentTime, output); - } - - size_t index = i + additionalKeys; - FCDAnimationKey* newKey = - outerAngleCurve->AddKey((FUDaeInterpolation::Interpolation)multiKeys[i-1]->interpolation, - currentTime, index); - additionalKeys++; - newKey->input = currentTime; - newKey->output = 0.0f; - if (key->interpolation == FUDaeInterpolation::BEZIER) - { - FCDAnimationKeyBezier* newBkey = (FCDAnimationKeyBezier*)newKey; - - float previousInput = multiKeys[i-1]->input; - float nextInput = multiKeys[i]->input; - newBkey->inTangent.x = (previousInput + 2.0f * newBkey->input) / 3.0f; - newBkey->outTangent.x = (nextInput + 2.0f * newBkey->input) / 3.0f; - - // calculate estimate inTangents - float prevDistance = newBkey->input - newBkey->inTangent.x; - float prevDelta = prevDistance / 1000; // small enough to get an estimate - multiCurve->Evaluate(currentTime - prevDelta, output); - float slope = output[1] / prevDelta; - newBkey->inTangent.y = prevDistance * slope; - - // calculate estimate outTangents - float nextDistance = newBkey->outTangent.x - newBkey->input; - float nextDelta = nextDistance / 1000; // small enough to get an estimate - multiCurve->Evaluate(currentTime + nextDelta, output); - slope = output[1] / nextDelta; - newBkey->outTangent.y = nextDistance * slope; - } - } - } - - if (hasFlip) - { - // recompute the multiCurve with the intermediate values - multiCurve = FCDAnimationCurveTools::MergeCurves(multiCurveCurves, multiCurveValues); - dimension = multiCurve->GetDimension(); - FUAssert(dimension == 2, return); - } - } - - - // erase the current keys - fallOffAngleCurve->SetKeyCount(0, FUDaeInterpolation::BEZIER); - outerAngleCurve->SetKeyCount(0, FUDaeInterpolation::BEZIER); - - // add the new keys and set their input and output values - FCDAnimationMKey** keys = multiCurve->GetKeys(); - size_t keyCount = multiCurve->GetKeyCount(); - for (size_t i = 0; i < keyCount; i++) - { - FCDAnimationMKey* key = keys[i]; - - FCDAnimationKey* fallOffAngleKey = - fallOffAngleCurve->AddKey((FUDaeInterpolation::Interpolation)key->interpolation); - FCDAnimationKey* outerAngleKey = - outerAngleCurve->AddKey((FUDaeInterpolation::Interpolation)key->interpolation); - - fallOffAngleKey->input = key->input; - outerAngleKey->input = key->input; - - float offset = key->output[0]; - fallOffAngleKey->output = offset; - outerAngleKey->output = offset + 2*key->output[1]; - - if (key->interpolation == FUDaeInterpolation::BEZIER) - { - FCDAnimationMKeyBezier* bkey = (FCDAnimationMKeyBezier*)key; - - FCDAnimationKeyBezier* fallOffAngleBkey = (FCDAnimationKeyBezier*) fallOffAngleKey; - FCDAnimationKeyBezier* outerAngleBkey = (FCDAnimationKeyBezier*) outerAngleKey; - - fallOffAngleBkey->inTangent = bkey->inTangent[0]; - fallOffAngleBkey->outTangent = bkey->outTangent[0]; - - outerAngleBkey->inTangent = bkey->inTangent[1]; - outerAngleBkey->outTangent = bkey->outTangent[1]; - outerAngleBkey->inTangent.v = 2*outerAngleBkey->inTangent.v; // deal with the offset in next pass - outerAngleBkey->outTangent.v = 2*outerAngleBkey->outTangent.v; // deal with the offset in next pass - - float inTangentsOffset = (fallOffAngleBkey->inTangent.y - fallOffAngleBkey->output) / - (fallOffAngleBkey->inTangent.x - fallOffAngleBkey->input); - float outTangentsOffset = (fallOffAngleBkey->outTangent.y - fallOffAngleBkey->output) / - (fallOffAngleBkey->outTangent.x - fallOffAngleBkey->input); - - outerAngleBkey->outTangent.y += - offset + outTangentsOffset * (outerAngleBkey->outTangent.x - outerAngleBkey->input); - outerAngleBkey->inTangent.y += - offset + inTangentsOffset * (outerAngleBkey->inTangent.x - outerAngleBkey->input); - } - } - - // flip the keys (and their tangents) if necessary - FCDAnimationKey** finalFallOffAngleKeys = fallOffAngleCurve->GetKeys(); - FCDAnimationKey** finalOuterAngleKeys = outerAngleCurve->GetKeys(); - bool previousFlipKeys = false; - FCDAnimationKeyBezier* previousFallOffAngleBkey = NULL; - FCDAnimationKeyBezier* previousOuterAngleBkey = NULL; - for (size_t i = 0; i < keyCount; i++) - { - FCDAnimationKey* fallOffAngleKey = finalFallOffAngleKeys[i]; - FCDAnimationKey* outerAngleKey = finalOuterAngleKeys[i]; - - // FIXME: [aleung] this is not necessarily enough, but close enough for now - bool flipKeys = false; - if (outerAngleKey->output < fallOffAngleKey->output) - { - float temp = fallOffAngleKey->output; - fallOffAngleKey->output = outerAngleKey->output; - outerAngleKey->output = temp; - flipKeys = true; - } - - if (fallOffAngleKey->interpolation == FUDaeInterpolation::BEZIER) // both same interpolation - { - FCDAnimationKeyBezier* fallOffAngleBkey = (FCDAnimationKeyBezier*) fallOffAngleKey; - FCDAnimationKeyBezier* outerAngleBkey = (FCDAnimationKeyBezier*) outerAngleKey; - - if (flipKeys) - { - // flip outTangents - FMVector2 temp = outerAngleBkey->outTangent; - outerAngleBkey->outTangent = fallOffAngleBkey->outTangent; - fallOffAngleBkey->outTangent = temp; - - temp = outerAngleBkey->inTangent; - outerAngleBkey->inTangent = fallOffAngleBkey->inTangent; - fallOffAngleBkey->inTangent = temp; - - if ((!previousFlipKeys) && (i != 0)) - { - // have to flip their outTangents - if (previousFallOffAngleBkey != NULL) - { - temp = previousOuterAngleBkey->outTangent; - previousOuterAngleBkey->outTangent = previousFallOffAngleBkey->outTangent; - previousFallOffAngleBkey->outTangent = temp; - } - } - } - else if (previousFlipKeys) // we need to flip our inTangents even though we did not flip - { - // flip inTangents - FMVector2 temp = outerAngleBkey->inTangent; - outerAngleBkey->inTangent = fallOffAngleBkey->inTangent; - fallOffAngleBkey->inTangent = temp; - } - - previousFallOffAngleBkey = fallOffAngleBkey; - previousOuterAngleBkey = outerAngleBkey; - } - else - { - previousFallOffAngleBkey = NULL; - previousOuterAngleBkey = NULL; - } - previousFlipKeys = flipKeys; - } - } -} - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDLightTools.h" +#include "FCDocument/FCDLight.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDAnimation.h" +#include "FCDocument/FCDAnimationCurve.h" +#include "FCDocument/FCDAnimationCurveTools.h" +#include "FCDocument/FCDAnimationKey.h" +#include "FCDocument/FCDAnimationMultiCurve.h" +#include "FCDocument/FCDAnimationChannel.h" +#include "FCDocument/FCDLibrary.h" + +namespace FCDLightTools +{ + void LoadPenumbra(FCDLight* light, float penumbraValue, FCDAnimated* penumbraAnimated, bool createAnimationChannel) + { + bool fallOffIsOuter = false; + + // Take care of the default non-animated values + + float fallOffAngle = light->GetFallOffAngle(); + if (penumbraValue < 0) + { + penumbraValue = -penumbraValue; + + fallOffAngle -= 2*penumbraValue; + light->SetFallOffAngle(fallOffAngle); + fallOffIsOuter = true; + } + + float outerAngle = fallOffAngle + 2*penumbraValue; + light->SetOuterAngle(outerAngle); + + // Take care of the animated values + FCDParameterAnimatableFloat& outerAngleValue = light->GetOuterAngle(); + FCDAnimated* outerAngleAnimated = outerAngleValue.GetAnimated(); + if (penumbraAnimated->HasCurve() && penumbraAnimated != outerAngleAnimated) + { + penumbraAnimated->Clone(outerAngleAnimated); + } + + FCDParameterAnimatableFloat& fallOffAngleValue = light->GetFallOffAngle(); + FCDAnimated* fallOffAngleAnimated = fallOffAngleValue.GetAnimated(); + + FCDAnimationCurve* outerAngleCurve = outerAngleAnimated->GetCurve(0); + FCDAnimationCurve* fallOffAngleCurve = fallOffAngleAnimated->GetCurve(0); + + // no animations on the penumbra nor the fallOffAngle, so no animation needed + if (outerAngleCurve == NULL && fallOffAngleCurve == NULL) return; + + // there's animation on the fallOffAngle only, so just need to copy the animation to the outterAngle as well + if (outerAngleCurve == NULL) + { + fallOffAngleAnimated->Clone(outerAngleAnimated); + FUAssert(outerAngleAnimated != NULL, return); // should not be null because we know fallOffAngle is animated + outerAngleAnimated->SetTargetObject(light); + + // if we penumbra was negative, fallOffAngle needs to be lowered, else outerAngle needs to be raised + float offset = 0.0f; + FCDAnimated* animated = NULL; + if (fallOffIsOuter) + { + offset = -2 * penumbraValue; + animated = fallOffAngleAnimated; + } + else + { + offset = 2 * penumbraValue; + animated = outerAngleAnimated; + } + + // now the outerAngle has the penumbra on it too, so have to update the keys + + // add twice the penumbra to the fallOffAngle to get the OuterAngle + FCDConversionOffsetFunctor offsetFunctor(offset); + FCDAnimationCurveTrackList& curves = animated->GetCurves()[0]; + size_t curvesCount = curves.size(); + for (size_t curvesCounter = 0; curvesCounter < curvesCount; curvesCounter++) + { + curves.at(curvesCounter)->ConvertValues(&offsetFunctor, &offsetFunctor); + } + return; + } + + outerAngleAnimated->SetTargetObject(light); // at this point, outerAngleAnimated != NULL + + // FIXME: [aleung] This is not necessarily true, but close enough for now + size_t outerAngleKeysCount = outerAngleCurve->GetKeyCount(); + FCDAnimationKey** outerAngleKeys = outerAngleCurve->GetKeys(); + bool hasNegPenumbra = fallOffIsOuter; + if (!hasNegPenumbra) + { + for (size_t i = 0; i < outerAngleKeysCount; i++) + { + if (outerAngleKeys[i]->output < 0) + { + hasNegPenumbra = true; + break; + } + } + } + + // there's animation on the penumbra only and there's no negative values, so we just need to animate the outerAngle + if ((fallOffAngleCurve == NULL) && !hasNegPenumbra) + { + FCDAnimationCurveListList& curvesList = outerAngleAnimated->GetCurves(); + + // fall off is not animated, easy case + FCDConversionScaleFunctor scaleFunctor(2); + FCDConversionOffsetFunctor offsetFunctor(fallOffAngleValue); + + FCDAnimationCurveTrackList& curves = curvesList[0]; + size_t curvesCount = curves.size(); + for (size_t curvesCounter = 0; curvesCounter < curvesCount; curvesCounter++) + { + curves.at(curvesCounter)->ConvertValues(&scaleFunctor, &scaleFunctor); + curves.at(curvesCounter)->ConvertValues(&offsetFunctor, &offsetFunctor); + } + return; + } + + // at this point, we need curves for both fallOffAngle and outerAngle! + if (fallOffAngleCurve == NULL) + { + if (createAnimationChannel) + { + outerAngleValue.GetAnimated()->Clone(fallOffAngleAnimated); + } + FUAssert(fallOffAngleAnimated != NULL, return); // should not be null because outerAngle is animated + fallOffAngleAnimated->SetTargetObject(light); + fallOffAngleCurve = fallOffAngleAnimated->GetCurve(0); + + if (fallOffAngleCurve == NULL) + { + FUAssert(createAnimationChannel, ;); // should only happen if we created new animated + fallOffAngleAnimated->RemoveCurve(0); + FCDAnimation* animation = light->GetDocument()->GetAnimationLibrary()->AddEntity(); + animation->SetDaeId("compensate_falloff_for_penumbra"); + FCDAnimationChannel* channel = animation->AddChannel(); + fallOffAngleCurve = channel->AddCurve(); + outerAngleCurve->Clone(fallOffAngleCurve); + fallOffAngleAnimated->AddCurve(0, fallOffAngleCurve); + } + + // remove the keys + FCDAnimationCurveTrackList& curves = fallOffAngleAnimated->GetCurves()[0]; + + size_t curvesCount = curves.size(); + for (size_t i = 0; i < curvesCount; i++) + { + curves.at(i)->SetKeyCount(0, FUDaeInterpolation::BEZIER); + + // add keys at the beginning and end with constant pre/post infinity + // the output value should be outerAngle if fallOffIsOuter, otherwise, it should be fallOffAngle + curves.at(i)->SetPreInfinity(FUDaeInfinity::CONSTANT); + curves.at(i)->SetPostInfinity(FUDaeInfinity::CONSTANT); + + FCDAnimationKey* firstKey = curves.at(i)->AddKey(FUDaeInterpolation::LINEAR); + firstKey->input = outerAngleKeys[0]->input; + firstKey->output = (fallOffIsOuter)? light->GetOuterAngle() : light->GetFallOffAngle(); + + FCDAnimationKey* lastKey = curves.at(i)->AddKey(FUDaeInterpolation::LINEAR); + lastKey->input = outerAngleKeys[(outerAngleKeysCount > 1)? outerAngleKeysCount - 1 : 0]->input; + lastKey->output = (fallOffIsOuter)? light->GetOuterAngle() : light->GetFallOffAngle(); + } + } + + + + + // now we have both penumbra and fallOffAngle animated, have to create missing keys by merging the curves + + + FloatList multiCurveValues(2, 0.0f); + FCDAnimationCurveConstList multiCurveCurves(2); + multiCurveValues[0] = fallOffAngleValue; + multiCurveValues[1] = outerAngleValue; + multiCurveCurves[0] = fallOffAngleCurve; + multiCurveCurves[1] = outerAngleCurve; + + FCDAnimationMultiCurve* multiCurve = FCDAnimationCurveTools::MergeCurves(multiCurveCurves, multiCurveValues); + size_t dimension = multiCurve->GetDimension(); + FUAssert(dimension == 2, return); + + // go through the keys to see if there's any switches in signs. If so, we need to insert intermediate keys to the + // outerAngleCurve (penumbra) at the penumbra = 0 point to get desired result + { + size_t multiKeyCount = multiCurve->GetKeyCount(); + FUAssert(multiKeyCount > 0, return); // should not have no keys + FCDAnimationMKey** multiKeys = multiCurve->GetKeys(); + + size_t additionalKeys = 0; + bool isNegative = multiKeys[0]->output[1] < 0; + bool wasZero = IsEquivalent(multiKeys[0]->output[1], 0.0f); + bool hasFlip = false; + for (size_t i = 1; i < multiKeyCount; i++) // start from 1 since we won't add key before the first key + { + FCDAnimationMKey* key = multiKeys[i]; + if (IsEquivalent(key->output[1], 0.0f)) + { + i++; + if (i < multiKeyCount) + { + isNegative = multiKeys[i]->output[1] < 0; + wasZero = IsEquivalent(multiKeys[i]->output[1], 0.0f); + } + continue; + } + else + { + if (wasZero) + { + isNegative = key->output[1] < 0; + wasZero = false; + continue; + } + wasZero = false; + } + + if ((isNegative && (key->output[1] > 0)) || (!isNegative && (key->output[1] < 0))) + { + hasFlip = true; + isNegative = !isNegative; + + // flip in sign, find out where to add the additional key using binary search + float higherTime = key->input; + float lowerTime = multiKeys[i-1]->input; // will not fail since the first sign is taken + float output[2]; + float currentTime = (higherTime + lowerTime) / 2.0f; + + multiCurve->Evaluate(currentTime, output); + while (!IsEquivalent(output[1], 0.0f)) // while penumbra output != 0 + { + if ((isNegative && (output[1] < 0)) || (!isNegative && (output[1] > 0))) + { + higherTime = currentTime; + } + else + { + lowerTime = currentTime; + } + currentTime = (higherTime + lowerTime) / 2.0f; + multiCurve->Evaluate(currentTime, output); + } + + size_t index = i + additionalKeys; + FCDAnimationKey* newKey = + outerAngleCurve->AddKey((FUDaeInterpolation::Interpolation)multiKeys[i-1]->interpolation, + currentTime, index); + additionalKeys++; + newKey->input = currentTime; + newKey->output = 0.0f; + if (key->interpolation == FUDaeInterpolation::BEZIER) + { + FCDAnimationKeyBezier* newBkey = (FCDAnimationKeyBezier*)newKey; + + float previousInput = multiKeys[i-1]->input; + float nextInput = multiKeys[i]->input; + newBkey->inTangent.x = (previousInput + 2.0f * newBkey->input) / 3.0f; + newBkey->outTangent.x = (nextInput + 2.0f * newBkey->input) / 3.0f; + + // calculate estimate inTangents + float prevDistance = newBkey->input - newBkey->inTangent.x; + float prevDelta = prevDistance / 1000; // small enough to get an estimate + multiCurve->Evaluate(currentTime - prevDelta, output); + float slope = output[1] / prevDelta; + newBkey->inTangent.y = prevDistance * slope; + + // calculate estimate outTangents + float nextDistance = newBkey->outTangent.x - newBkey->input; + float nextDelta = nextDistance / 1000; // small enough to get an estimate + multiCurve->Evaluate(currentTime + nextDelta, output); + slope = output[1] / nextDelta; + newBkey->outTangent.y = nextDistance * slope; + } + } + } + + if (hasFlip) + { + // recompute the multiCurve with the intermediate values + multiCurve = FCDAnimationCurveTools::MergeCurves(multiCurveCurves, multiCurveValues); + dimension = multiCurve->GetDimension(); + FUAssert(dimension == 2, return); + } + } + + + // erase the current keys + fallOffAngleCurve->SetKeyCount(0, FUDaeInterpolation::BEZIER); + outerAngleCurve->SetKeyCount(0, FUDaeInterpolation::BEZIER); + + // add the new keys and set their input and output values + FCDAnimationMKey** keys = multiCurve->GetKeys(); + size_t keyCount = multiCurve->GetKeyCount(); + for (size_t i = 0; i < keyCount; i++) + { + FCDAnimationMKey* key = keys[i]; + + FCDAnimationKey* fallOffAngleKey = + fallOffAngleCurve->AddKey((FUDaeInterpolation::Interpolation)key->interpolation); + FCDAnimationKey* outerAngleKey = + outerAngleCurve->AddKey((FUDaeInterpolation::Interpolation)key->interpolation); + + fallOffAngleKey->input = key->input; + outerAngleKey->input = key->input; + + float offset = key->output[0]; + fallOffAngleKey->output = offset; + outerAngleKey->output = offset + 2*key->output[1]; + + if (key->interpolation == FUDaeInterpolation::BEZIER) + { + FCDAnimationMKeyBezier* bkey = (FCDAnimationMKeyBezier*)key; + + FCDAnimationKeyBezier* fallOffAngleBkey = (FCDAnimationKeyBezier*) fallOffAngleKey; + FCDAnimationKeyBezier* outerAngleBkey = (FCDAnimationKeyBezier*) outerAngleKey; + + fallOffAngleBkey->inTangent = bkey->inTangent[0]; + fallOffAngleBkey->outTangent = bkey->outTangent[0]; + + outerAngleBkey->inTangent = bkey->inTangent[1]; + outerAngleBkey->outTangent = bkey->outTangent[1]; + outerAngleBkey->inTangent.v = 2*outerAngleBkey->inTangent.v; // deal with the offset in next pass + outerAngleBkey->outTangent.v = 2*outerAngleBkey->outTangent.v; // deal with the offset in next pass + + float inTangentsOffset = (fallOffAngleBkey->inTangent.y - fallOffAngleBkey->output) / + (fallOffAngleBkey->inTangent.x - fallOffAngleBkey->input); + float outTangentsOffset = (fallOffAngleBkey->outTangent.y - fallOffAngleBkey->output) / + (fallOffAngleBkey->outTangent.x - fallOffAngleBkey->input); + + outerAngleBkey->outTangent.y += + offset + outTangentsOffset * (outerAngleBkey->outTangent.x - outerAngleBkey->input); + outerAngleBkey->inTangent.y += + offset + inTangentsOffset * (outerAngleBkey->inTangent.x - outerAngleBkey->input); + } + } + + // flip the keys (and their tangents) if necessary + FCDAnimationKey** finalFallOffAngleKeys = fallOffAngleCurve->GetKeys(); + FCDAnimationKey** finalOuterAngleKeys = outerAngleCurve->GetKeys(); + bool previousFlipKeys = false; + FCDAnimationKeyBezier* previousFallOffAngleBkey = NULL; + FCDAnimationKeyBezier* previousOuterAngleBkey = NULL; + for (size_t i = 0; i < keyCount; i++) + { + FCDAnimationKey* fallOffAngleKey = finalFallOffAngleKeys[i]; + FCDAnimationKey* outerAngleKey = finalOuterAngleKeys[i]; + + // FIXME: [aleung] this is not necessarily enough, but close enough for now + bool flipKeys = false; + if (outerAngleKey->output < fallOffAngleKey->output) + { + float temp = fallOffAngleKey->output; + fallOffAngleKey->output = outerAngleKey->output; + outerAngleKey->output = temp; + flipKeys = true; + } + + if (fallOffAngleKey->interpolation == FUDaeInterpolation::BEZIER) // both same interpolation + { + FCDAnimationKeyBezier* fallOffAngleBkey = (FCDAnimationKeyBezier*) fallOffAngleKey; + FCDAnimationKeyBezier* outerAngleBkey = (FCDAnimationKeyBezier*) outerAngleKey; + + if (flipKeys) + { + // flip outTangents + FMVector2 temp = outerAngleBkey->outTangent; + outerAngleBkey->outTangent = fallOffAngleBkey->outTangent; + fallOffAngleBkey->outTangent = temp; + + temp = outerAngleBkey->inTangent; + outerAngleBkey->inTangent = fallOffAngleBkey->inTangent; + fallOffAngleBkey->inTangent = temp; + + if ((!previousFlipKeys) && (i != 0)) + { + // have to flip their outTangents + if (previousFallOffAngleBkey != NULL) + { + temp = previousOuterAngleBkey->outTangent; + previousOuterAngleBkey->outTangent = previousFallOffAngleBkey->outTangent; + previousFallOffAngleBkey->outTangent = temp; + } + } + } + else if (previousFlipKeys) // we need to flip our inTangents even though we did not flip + { + // flip inTangents + FMVector2 temp = outerAngleBkey->inTangent; + outerAngleBkey->inTangent = fallOffAngleBkey->inTangent; + fallOffAngleBkey->inTangent = temp; + } + + previousFallOffAngleBkey = fallOffAngleBkey; + previousOuterAngleBkey = outerAngleBkey; + } + else + { + previousFallOffAngleBkey = NULL; + previousOuterAngleBkey = NULL; + } + previousFlipKeys = flipKeys; + } + } +} + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLightTools.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterialInstance.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterialInstance.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterialInstance.cpp (revision 24247) @@ -1,198 +1,198 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterFactory.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDMaterial.h" -#include "FCDocument/FCDMaterialInstance.h" - -// -// FCDMaterialInstanceBind -// - -ImplementObjectType(FCDMaterialInstanceBind); - -FCDMaterialInstanceBind::FCDMaterialInstanceBind() -: FUParameterizable() -, InitializeParameterNoArg(semantic) -, InitializeParameterNoArg(target) -{ -} - -FCDMaterialInstanceBind::~FCDMaterialInstanceBind() -{ -} - -// -// FCDMaterialInstanceBindVertexInput -// - -ImplementObjectType(FCDMaterialInstanceBindVertexInput); - -FCDMaterialInstanceBindVertexInput::FCDMaterialInstanceBindVertexInput() -: FUParameterizable() -, InitializeParameterNoArg(semantic) -, InitializeParameter(inputSemantic, FUDaeGeometryInput::TEXCOORD) -, InitializeParameter(inputSet, 0) -{ -} - -FCDMaterialInstanceBindVertexInput::~FCDMaterialInstanceBindVertexInput() -{ -} - -// -// FCDMaterialInstance -// - -ImplementObjectType(FCDMaterialInstance); -ImplementParameterObjectNoArg(FCDMaterialInstance, FCDMaterialInstanceBind, bindings) -ImplementParameterObjectNoArg(FCDMaterialInstance, FCDMaterialInstanceBindVertexInput, vertexBindings) -ImplementParameterObjectNoArg(FCDMaterialInstance, FCDMaterialInstanceBindTextureSurface, texSurfBindings) - -FCDMaterialInstance::FCDMaterialInstance(FCDocument* document, FCDEntityInstance* _parent) -: FCDEntityInstance(document, _parent->GetParent(), FCDEntity::MATERIAL), parent(_parent) -, InitializeParameterNoArg(semantic) -, InitializeParameterNoArg(bindings) -, InitializeParameterNoArg(vertexBindings) -{ -} - -FCDMaterialInstance::~FCDMaterialInstance() -{ - parent = NULL; -} - -FCDObject* FCDMaterialInstance::GetGeometryTarget() -{ - if (parent != NULL && parent->GetEntity() != NULL) - { - FCDEntity* e = parent->GetEntity(); - if (e->HasType(FCDController::GetClassType())) - { - e = ((FCDController*) e)->GetBaseGeometry(); - } - if (e->HasType(FCDGeometry::GetClassType())) - { - FCDGeometry* geometry = (FCDGeometry*) e; - if (geometry->IsMesh()) - { - FCDGeometryMesh* mesh = geometry->GetMesh(); - size_t polygonsCount = mesh->GetPolygonsCount(); - for (size_t i = 0; i < polygonsCount; ++i) - { - FCDGeometryPolygons* polygons = mesh->GetPolygons(i); - if (IsEquivalent(polygons->GetMaterialSemantic(), semantic)) - { - return polygons; - } - } - } - } - } - return NULL; -} - - -const FCDMaterialInstanceBind* FCDMaterialInstance::FindBinding(const char* semantic) -{ - for (const FCDMaterialInstanceBind** it = (const FCDMaterialInstanceBind**) bindings.begin(); it != bindings.end(); ++it) - { - if (IsEquivalent((*it)->semantic, semantic)) return (*it); - } - return NULL; -} - -FCDMaterialInstanceBindVertexInput* FCDMaterialInstance::AddVertexInputBinding() -{ - FCDMaterialInstanceBindVertexInput* out = new FCDMaterialInstanceBindVertexInput(); - vertexBindings.push_back(out); - SetNewChildFlag(); - return vertexBindings.back(); -} - -FCDMaterialInstanceBindVertexInput* FCDMaterialInstance::AddVertexInputBinding(const char* semantic, FUDaeGeometryInput::Semantic inputSemantic, int32 inputSet) -{ - FCDMaterialInstanceBindVertexInput* vbinding = AddVertexInputBinding(); - vbinding->semantic = semantic; - vbinding->inputSemantic = inputSemantic; - vbinding->inputSet = inputSet; - return vbinding; -} - -const FCDMaterialInstanceBindVertexInput* FCDMaterialInstance::FindVertexInputBinding(const char* semantic) const -{ - for (const FCDMaterialInstanceBindVertexInput** it = vertexBindings.begin(); it != vertexBindings.end(); ++it) - { - if (IsEquivalent((*it)->semantic, semantic)) return (*it); - } - return NULL; -} - -FCDMaterialInstanceBind* FCDMaterialInstance::AddBinding() -{ - FCDMaterialInstanceBind* out = new FCDMaterialInstanceBind(); - bindings.push_back(out); - SetNewChildFlag(); - return bindings.back(); -} - -FCDMaterialInstanceBind* FCDMaterialInstance::AddBinding(const char* semantic, const char* target) -{ - FCDMaterialInstanceBind* binding = AddBinding(); - binding->semantic = semantic; - binding->target = target; - return binding; -} - -void FCDMaterialInstance::RemoveBinding(size_t index) -{ - FUAssert(index < bindings.size(), return); - bindings.erase(index); -} - -FCDEntityInstance* FCDMaterialInstance::Clone(FCDEntityInstance* _clone) const -{ - FCDMaterialInstance* clone = NULL; - if (_clone == NULL) clone = new FCDMaterialInstance(const_cast(GetDocument()), NULL); - else if (!_clone->HasType(FCDMaterialInstance::GetClassType())) return Parent::Clone(_clone); - else clone = (FCDMaterialInstance*) _clone; - - Parent::Clone(clone); - - // Clone the bindings and the semantic information. - clone->semantic = semantic; - size_t bindingCount = bindings.size(); - for (size_t b = 0; b < bindingCount; ++b) - { - const FCDMaterialInstanceBind* bind = bindings[b]; - clone->AddBinding(*bind->semantic, *bind->target); - } - bindingCount = vertexBindings.size(); - for (size_t b = 0; b < bindingCount; ++b) - { - const FCDMaterialInstanceBindVertexInput* bind = vertexBindings[b]; - clone->AddVertexInputBinding(*bind->semantic, (FUDaeGeometryInput::Semantic) *bind->inputSemantic, *bind->inputSet); - } - return clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterFactory.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDMaterial.h" +#include "FCDocument/FCDMaterialInstance.h" + +// +// FCDMaterialInstanceBind +// + +ImplementObjectType(FCDMaterialInstanceBind); + +FCDMaterialInstanceBind::FCDMaterialInstanceBind() +: FUParameterizable() +, InitializeParameterNoArg(semantic) +, InitializeParameterNoArg(target) +{ +} + +FCDMaterialInstanceBind::~FCDMaterialInstanceBind() +{ +} + +// +// FCDMaterialInstanceBindVertexInput +// + +ImplementObjectType(FCDMaterialInstanceBindVertexInput); + +FCDMaterialInstanceBindVertexInput::FCDMaterialInstanceBindVertexInput() +: FUParameterizable() +, InitializeParameterNoArg(semantic) +, InitializeParameter(inputSemantic, FUDaeGeometryInput::TEXCOORD) +, InitializeParameter(inputSet, 0) +{ +} + +FCDMaterialInstanceBindVertexInput::~FCDMaterialInstanceBindVertexInput() +{ +} + +// +// FCDMaterialInstance +// + +ImplementObjectType(FCDMaterialInstance); +ImplementParameterObjectNoArg(FCDMaterialInstance, FCDMaterialInstanceBind, bindings) +ImplementParameterObjectNoArg(FCDMaterialInstance, FCDMaterialInstanceBindVertexInput, vertexBindings) +ImplementParameterObjectNoArg(FCDMaterialInstance, FCDMaterialInstanceBindTextureSurface, texSurfBindings) + +FCDMaterialInstance::FCDMaterialInstance(FCDocument* document, FCDEntityInstance* _parent) +: FCDEntityInstance(document, _parent->GetParent(), FCDEntity::MATERIAL), parent(_parent) +, InitializeParameterNoArg(semantic) +, InitializeParameterNoArg(bindings) +, InitializeParameterNoArg(vertexBindings) +{ +} + +FCDMaterialInstance::~FCDMaterialInstance() +{ + parent = NULL; +} + +FCDObject* FCDMaterialInstance::GetGeometryTarget() +{ + if (parent != NULL && parent->GetEntity() != NULL) + { + FCDEntity* e = parent->GetEntity(); + if (e->HasType(FCDController::GetClassType())) + { + e = ((FCDController*) e)->GetBaseGeometry(); + } + if (e->HasType(FCDGeometry::GetClassType())) + { + FCDGeometry* geometry = (FCDGeometry*) e; + if (geometry->IsMesh()) + { + FCDGeometryMesh* mesh = geometry->GetMesh(); + size_t polygonsCount = mesh->GetPolygonsCount(); + for (size_t i = 0; i < polygonsCount; ++i) + { + FCDGeometryPolygons* polygons = mesh->GetPolygons(i); + if (IsEquivalent(polygons->GetMaterialSemantic(), semantic)) + { + return polygons; + } + } + } + } + } + return NULL; +} + + +const FCDMaterialInstanceBind* FCDMaterialInstance::FindBinding(const char* semantic) +{ + for (const FCDMaterialInstanceBind** it = (const FCDMaterialInstanceBind**) bindings.begin(); it != bindings.end(); ++it) + { + if (IsEquivalent((*it)->semantic, semantic)) return (*it); + } + return NULL; +} + +FCDMaterialInstanceBindVertexInput* FCDMaterialInstance::AddVertexInputBinding() +{ + FCDMaterialInstanceBindVertexInput* out = new FCDMaterialInstanceBindVertexInput(); + vertexBindings.push_back(out); + SetNewChildFlag(); + return vertexBindings.back(); +} + +FCDMaterialInstanceBindVertexInput* FCDMaterialInstance::AddVertexInputBinding(const char* semantic, FUDaeGeometryInput::Semantic inputSemantic, int32 inputSet) +{ + FCDMaterialInstanceBindVertexInput* vbinding = AddVertexInputBinding(); + vbinding->semantic = semantic; + vbinding->inputSemantic = inputSemantic; + vbinding->inputSet = inputSet; + return vbinding; +} + +const FCDMaterialInstanceBindVertexInput* FCDMaterialInstance::FindVertexInputBinding(const char* semantic) const +{ + for (const FCDMaterialInstanceBindVertexInput** it = vertexBindings.begin(); it != vertexBindings.end(); ++it) + { + if (IsEquivalent((*it)->semantic, semantic)) return (*it); + } + return NULL; +} + +FCDMaterialInstanceBind* FCDMaterialInstance::AddBinding() +{ + FCDMaterialInstanceBind* out = new FCDMaterialInstanceBind(); + bindings.push_back(out); + SetNewChildFlag(); + return bindings.back(); +} + +FCDMaterialInstanceBind* FCDMaterialInstance::AddBinding(const char* semantic, const char* target) +{ + FCDMaterialInstanceBind* binding = AddBinding(); + binding->semantic = semantic; + binding->target = target; + return binding; +} + +void FCDMaterialInstance::RemoveBinding(size_t index) +{ + FUAssert(index < bindings.size(), return); + bindings.erase(index); +} + +FCDEntityInstance* FCDMaterialInstance::Clone(FCDEntityInstance* _clone) const +{ + FCDMaterialInstance* clone = NULL; + if (_clone == NULL) clone = new FCDMaterialInstance(const_cast(GetDocument()), NULL); + else if (!_clone->HasType(FCDMaterialInstance::GetClassType())) return Parent::Clone(_clone); + else clone = (FCDMaterialInstance*) _clone; + + Parent::Clone(clone); + + // Clone the bindings and the semantic information. + clone->semantic = semantic; + size_t bindingCount = bindings.size(); + for (size_t b = 0; b < bindingCount; ++b) + { + const FCDMaterialInstanceBind* bind = bindings[b]; + clone->AddBinding(*bind->semantic, *bind->target); + } + bindingCount = vertexBindings.size(); + for (size_t b = 0; b < bindingCount; ++b) + { + const FCDMaterialInstanceBindVertexInput* bind = vertexBindings[b]; + clone->AddVertexInputBinding(*bind->semantic, (FUDaeGeometryInput::Semantic) *bind->inputSemantic, *bind->inputSet); + } + return clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterialInstance.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObject.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObject.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObject.cpp (revision 24247) @@ -1,29 +1,29 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDObject.h" - -// -// FCDObject -// - -ImplementObjectType(FCDObject); - -FCDObject::FCDObject(FCDocument* _document) -: FUParameterizable(), document(_document) -, userHandle(NULL) -{ - SetDirtyFlag(); -} - -FCDObject::~FCDObject() -{ -} - - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDObject.h" + +// +// FCDObject +// + +ImplementObjectType(FCDObject); + +FCDObject::FCDObject(FCDocument* _document) +: FUParameterizable(), document(_document) +, userHandle(NULL) +{ + SetDirtyFlag(); +} + +FCDObject::~FCDObject() +{ +} + + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObject.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceWind.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceWind.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceWind.h (revision 24247) @@ -1,17 +1,17 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDForceWind.h - This file contains the FCDForceWind class. -*/ - -#ifndef _FCD_FORCE_WIND_H_ -#define _FCD_FORCE_WIND_H_ - -#endif // _FCD_FORCE_WIND_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDForceWind.h + This file contains the FCDForceWind class. +*/ + +#ifndef _FCD_FORCE_WIND_H_ +#define _FCD_FORCE_WIND_H_ + +#endif // _FCD_FORCE_WIND_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDForceWind.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryInstance.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryInstance.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryInstance.h (revision 24247) @@ -1,141 +1,141 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDGeometryInstance.h - This file contains the FCDGeometryInstance class. -*/ -#ifndef _FCD_GEOMETRY_ENTITY_H_ -#define _FCD_GEOMETRY_ENTITY_H_ - -#ifndef _FCD_ENTITY_INSTANCE_H_ -#include "FCDocument/FCDEntityInstance.h" -#endif // _FCD_ENTITY_INSTANCE_H_ - -class FCDocument; -class FCDMaterial; -class FCDMaterialInstance; -class FCDGeometryPolygons; -class FCDEffectParameter; - -/** - A COLLADA geometry instance. - It is during the instantiation of geometries that the mesh polygons - are attached to actual materials. -*/ -class FCOLLADA_EXPORT FCDGeometryInstance : public FCDEntityInstance -{ -private: - DeclareObjectType(FCDEntityInstance); - DeclareParameterContainer(FCDMaterialInstance, materials, FC("Materials Bound")); - DeclareParameterContainer(FCDEffectParameter, parameters, FC("Effect Parameters")); - - friend class FCDEntityInstanceFactory; - -protected: - /** Constructor. - @param document The FCollada document that owns this instance. - @param parent The visual scene node that contains this instance. This pointer will be NULL for - instances that are not directly under a visual scene node. - @param entityType The type of entity to instantiate. */ - FCDGeometryInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType = FCDEntity::GEOMETRY); - -public: - /** Destructor. */ - virtual ~FCDGeometryInstance(); - - /** Retrieves the entity instance class type. - This is used to determine the up-class for the entity instance object. - @deprecated Instead use: FCDEntityInstance::HasType(FCDGeometryInstance::GetClassType()) - @return The class type: GEOMETRY. */ - virtual Type GetType() const { return GEOMETRY; } - - /** Retrieves the number of local effect parameters - @return The number of local effect parameters. */ - inline size_t GetEffectParameterCount() const { return parameters.size(); } - - /** Retrieves a given local effect parameter. - @param index An index. - @return The local effect parameter at the given index. */ - inline FCDEffectParameter* GetEffectParameter(size_t index) { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } - inline const FCDEffectParameter* GetEffectParameter(size_t index) const { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } - - /** Adds a local effect parameter to the local list. - @see FCDEffectParameter::Type - @param type The value type of the effect parameter to create. - @return The new local effect parameter. */ - FCDEffectParameter* AddEffectParameter(uint32 type); - - /** Retrieves a material instance bound to the given material semantic. - @param semantic A material semantic. - @return The material instance bound to the given material semantic. - This pointer will be NULL if the material semantic has no material - instance binding to it. */ - inline FCDMaterialInstance* FindMaterialInstance(const fchar* semantic) { return const_cast(const_cast(this)->FindMaterialInstance(semantic)); } - inline FCDMaterialInstance* FindMaterialInstance(const fstring& semantic) { return FindMaterialInstance(semantic.c_str()); } /**< See above. */ - const FCDMaterialInstance* FindMaterialInstance(const fchar* semantic) const; /**< See above. */ - inline const FCDMaterialInstance* FindMaterialInstance(const fstring& semantic) const { return FindMaterialInstance(semantic.c_str()); } /**< See above. */ - - /** Retrieves the number of material instances. - @return The number of material instances. */ - inline size_t GetMaterialInstanceCount() const { return materials.size(); } - - /** Retrieves a material instance. - @param index The index of the material instance. - @return The material instance at the given index. */ - inline FCDMaterialInstance* GetMaterialInstance(size_t index) { FUAssert(index < materials.size(), return NULL); return materials.at(index); } - inline const FCDMaterialInstance* GetMaterialInstance(size_t index) const { FUAssert(index < materials.size(), return NULL); return materials.at(index); } /**< See above. */ - - /** Retrieves the material instances. - @return The list of material instances. */ - DEPRECATED(3.05A, GetMaterialInstance) inline FCDMaterialInstance** GetMaterialInstances() { return const_cast(materials.begin()); } - DEPRECATED(3.05A, GetMaterialInstance) inline const FCDMaterialInstance** GetMaterialInstances() const { return materials.begin(); } /**< See above. */ - - /** Adds an empty material instance to the geometry. - This new material instance will be unbound. - @return The empty material instance. */ - FCDMaterialInstance* AddMaterialInstance(); - - /** Binds a material with a polygons set for this geometry instance. - No verification is done to ensure that the polygons set is not - already bound to another material. - @param material A material. - @param polygons A polygons set that belongs to the instanced geometry. - @return The new material instance. */ - FCDMaterialInstance* AddMaterialInstance(FCDMaterial* material, FCDGeometryPolygons* polygons); - - - /** Binds a material to a material semantic token. - No verification is done to ensure that the material semantic token - is used within the instanced geometry or that a material is not already bound - to this token. - @param material A material. - @param semantic A material semantic token. - @return The new material instance. */ - FCDMaterialInstance* AddMaterialInstance(FCDMaterial* material, const fchar* semantic); - inline FCDMaterialInstance* AddMaterialInstance(FCDMaterial* material, const fstring& semantic) { return AddMaterialInstance(material, semantic.c_str()); } /**< See above. */ - - /** Clones the geometry instance. - @param clone The geometry instance to become the clone. If this pointer - is NULL, a new geometry instance will be created. - @return The cloned geometry instance. */ - virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; - - /** [INTERNAL] Cleans up the sub identifiers. - The sub identifiers must be unique with respect to its parent. This method corrects the sub ids if there are conflicts. - @param parentStringMap The string map from the parent of this instance in which the sub ids must be unique. */ - virtual void CleanSubId(FUSUniqueStringMap* parentStringMap); -}; - -#endif // _FCD_GEOMETRY_ENTITY_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDGeometryInstance.h + This file contains the FCDGeometryInstance class. +*/ +#ifndef _FCD_GEOMETRY_ENTITY_H_ +#define _FCD_GEOMETRY_ENTITY_H_ + +#ifndef _FCD_ENTITY_INSTANCE_H_ +#include "FCDocument/FCDEntityInstance.h" +#endif // _FCD_ENTITY_INSTANCE_H_ + +class FCDocument; +class FCDMaterial; +class FCDMaterialInstance; +class FCDGeometryPolygons; +class FCDEffectParameter; + +/** + A COLLADA geometry instance. + It is during the instantiation of geometries that the mesh polygons + are attached to actual materials. +*/ +class FCOLLADA_EXPORT FCDGeometryInstance : public FCDEntityInstance +{ +private: + DeclareObjectType(FCDEntityInstance); + DeclareParameterContainer(FCDMaterialInstance, materials, FC("Materials Bound")); + DeclareParameterContainer(FCDEffectParameter, parameters, FC("Effect Parameters")); + + friend class FCDEntityInstanceFactory; + +protected: + /** Constructor. + @param document The FCollada document that owns this instance. + @param parent The visual scene node that contains this instance. This pointer will be NULL for + instances that are not directly under a visual scene node. + @param entityType The type of entity to instantiate. */ + FCDGeometryInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType = FCDEntity::GEOMETRY); + +public: + /** Destructor. */ + virtual ~FCDGeometryInstance(); + + /** Retrieves the entity instance class type. + This is used to determine the up-class for the entity instance object. + @deprecated Instead use: FCDEntityInstance::HasType(FCDGeometryInstance::GetClassType()) + @return The class type: GEOMETRY. */ + virtual Type GetType() const { return GEOMETRY; } + + /** Retrieves the number of local effect parameters + @return The number of local effect parameters. */ + inline size_t GetEffectParameterCount() const { return parameters.size(); } + + /** Retrieves a given local effect parameter. + @param index An index. + @return The local effect parameter at the given index. */ + inline FCDEffectParameter* GetEffectParameter(size_t index) { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } + inline const FCDEffectParameter* GetEffectParameter(size_t index) const { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } + + /** Adds a local effect parameter to the local list. + @see FCDEffectParameter::Type + @param type The value type of the effect parameter to create. + @return The new local effect parameter. */ + FCDEffectParameter* AddEffectParameter(uint32 type); + + /** Retrieves a material instance bound to the given material semantic. + @param semantic A material semantic. + @return The material instance bound to the given material semantic. + This pointer will be NULL if the material semantic has no material + instance binding to it. */ + inline FCDMaterialInstance* FindMaterialInstance(const fchar* semantic) { return const_cast(const_cast(this)->FindMaterialInstance(semantic)); } + inline FCDMaterialInstance* FindMaterialInstance(const fstring& semantic) { return FindMaterialInstance(semantic.c_str()); } /**< See above. */ + const FCDMaterialInstance* FindMaterialInstance(const fchar* semantic) const; /**< See above. */ + inline const FCDMaterialInstance* FindMaterialInstance(const fstring& semantic) const { return FindMaterialInstance(semantic.c_str()); } /**< See above. */ + + /** Retrieves the number of material instances. + @return The number of material instances. */ + inline size_t GetMaterialInstanceCount() const { return materials.size(); } + + /** Retrieves a material instance. + @param index The index of the material instance. + @return The material instance at the given index. */ + inline FCDMaterialInstance* GetMaterialInstance(size_t index) { FUAssert(index < materials.size(), return NULL); return materials.at(index); } + inline const FCDMaterialInstance* GetMaterialInstance(size_t index) const { FUAssert(index < materials.size(), return NULL); return materials.at(index); } /**< See above. */ + + /** Retrieves the material instances. + @return The list of material instances. */ + DEPRECATED(3.05A, GetMaterialInstance) inline FCDMaterialInstance** GetMaterialInstances() { return const_cast(materials.begin()); } + DEPRECATED(3.05A, GetMaterialInstance) inline const FCDMaterialInstance** GetMaterialInstances() const { return materials.begin(); } /**< See above. */ + + /** Adds an empty material instance to the geometry. + This new material instance will be unbound. + @return The empty material instance. */ + FCDMaterialInstance* AddMaterialInstance(); + + /** Binds a material with a polygons set for this geometry instance. + No verification is done to ensure that the polygons set is not + already bound to another material. + @param material A material. + @param polygons A polygons set that belongs to the instanced geometry. + @return The new material instance. */ + FCDMaterialInstance* AddMaterialInstance(FCDMaterial* material, FCDGeometryPolygons* polygons); + + + /** Binds a material to a material semantic token. + No verification is done to ensure that the material semantic token + is used within the instanced geometry or that a material is not already bound + to this token. + @param material A material. + @param semantic A material semantic token. + @return The new material instance. */ + FCDMaterialInstance* AddMaterialInstance(FCDMaterial* material, const fchar* semantic); + inline FCDMaterialInstance* AddMaterialInstance(FCDMaterial* material, const fstring& semantic) { return AddMaterialInstance(material, semantic.c_str()); } /**< See above. */ + + /** Clones the geometry instance. + @param clone The geometry instance to become the clone. If this pointer + is NULL, a new geometry instance will be created. + @return The cloned geometry instance. */ + virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; + + /** [INTERNAL] Cleans up the sub identifiers. + The sub identifiers must be unique with respect to its parent. This method corrects the sub ids if there are conflicts. + @param parentStringMap The string map from the parent of this instance in which the sub ids must be unique. */ + virtual void CleanSubId(FUSUniqueStringMap* parentStringMap); +}; + +#endif // _FCD_GEOMETRY_ENTITY_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryInstance.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryNURBSSurface.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryNURBSSurface.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryNURBSSurface.h (revision 24247) @@ -1,15 +1,15 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/** - @file FCDGeometryNURBSSurface.h - This file contains the FCDGeometryNURBSSurface class. - The FCDGeometryNURBSSurface class hold the information for one COLLADA NURBS surface. - - Note: The NURBS surfaces are part of the Premium Build only. -*/ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/** + @file FCDGeometryNURBSSurface.h + This file contains the FCDGeometryNURBSSurface class. + The FCDGeometryNURBSSurface class hold the information for one COLLADA NURBS surface. + + Note: The NURBS surfaces are part of the Premium Build only. +*/ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryNURBSSurface.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsInput.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsInput.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsInput.h (revision 24247) @@ -1,161 +1,161 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDGeometryPolygonsInput.h - This file defines FCDGeometryPolygonsInput class. -*/ - -#ifndef _FCD_GEOMETRY_POLYGONS_INPUT_H_ -#define _FCD_GEOMETRY_POLYGONS_INPUT_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -class FCDGeometrySource; -class FCDGeometryPolygons; - -/** - An input data source for one mesh polygons set. - This structure knows the type of input data in the data source - as well as the set and offset for the data. It also contains a - pointer to the mesh data source. - - Many polygon set inputs may have the same offset (or 'idx' in older versions) when multiple - data sources are compressed together within the COLLADA document. - In this case, one and only one of the polygon set input should contain - indices. To find the indices of any polygon set input, - it is recommended that you use the FCDGeometryPolygons::FindIndicesForIdx function. - - @ingroup FCDGeometry -*/ -class FCOLLADA_EXPORT FCDGeometryPolygonsInput : public FCDObject, FUTracker -{ -private: - DeclareObjectType(FCDObject); - - FCDGeometryPolygons* parent; - DeclareParameterPtr(FCDGeometrySource, source, FC("Data Source")); - DeclareParameter(int32, FUParameterQualifiers::SIMPLE, set, FC("Input Set")); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, offset, FC("Stream Offset")); - DeclareParameterList(UInt32, indices, FC("Data Indices")); - -public: - /** Constructor. - @param parent The polygons sets that contains the input. - @param offset The offset for the indices of this input - within the interlaced tesselation information. */ - FCDGeometryPolygonsInput(FCDocument* document, FCDGeometryPolygons* parent); - - /** Destructor. */ - ~FCDGeometryPolygonsInput(); - - /** Retrieves the type of data to input. - FCollada doesn't support data sources which are interpreted - differently depending on the input. Therefore, this information - is retrieved from the source. - @return The source data type. */ - FUDaeGeometryInput::Semantic GetSemantic() const; - - /** Retrieves the data source references by this polygon set input. - This is the data source into which the indices are indexing. - You need to take the data source stride into consideration - when un-indexing the data. - @return The data source. */ - FCDGeometrySource* GetSource() { return source; } - const FCDGeometrySource* GetSource() const { return source; } /**< See above. */ - - /** Sets the data source referenced by this polygon set input. - @param source The data source referenced by the input indices. */ - void SetSource(FCDGeometrySource* source); - - /** Retrieves the offset within the interlaced COLLADA indices for this input's indices. - Changing this value after the input's construction is not recommended. - @param _offset The offset within the interlaced COLLADA indices for this input's indices. */ - inline void SetOffset(uint32 _offset) { offset = _offset; } - - /** Retrieves the offset within the interlaced COLLADA indices for this input's indices. - @return The interlaced indices offset. */ - inline uint32 GetOffset() const { return offset; } - - /** Retrieves the input set. - The input set is used to group together the texture coordinates with the texture tangents and binormals. - In ColladaMax, this value should also represent the map channel index for texture coordinates - and vertex color channels. - @return The input set. */ - inline int32 GetSet() const { return set; } - - /** Sets the input set. - The input set is used to group together the texture coordinates with the texture tangents and binormals. - In ColladaMax, this value should also represent the map channel index for texture coordinates - and vertex color channels. - @param _set The new input set. If the given value is -1, this input does not belong to any set.*/ - inline void SetSet(int32 _set) { set = _set; } - - /** Checks whether this polygon set input owns the local indices for its offset. - Since an offset may be shared, only one polygon set input will own the local indices. - @return Whether this polygon set owns the local indices. */ - inline bool OwnsIndices() const { return !indices.empty(); } - - /** Sets the local indices for the input's offset. - This function may fail if another input already owns the indices for this offset. - @param indices A static list of indices. - @param count The number of indices in the given list. */ - void SetIndices(const uint32* indices, size_t count); - - /** Sets the number of indices in this input's index list. - Any additional indices allocated will not be initialized. - @param count The number of indices in this input's index list. */ - void SetIndexCount(size_t count); - - /** Reserves memory for a given number of indices. - This is useful for performance reasons, since AddIndex can be extremely costly otherwise. - @param count The total number of indices to prepare memory for. */ - void ReserveIndexCount(size_t count); - - /** Adds an index to the indices of this input. - Be careful when adding indices directly to multiple inputs: if - multiple inputs share an index list, you may be adding unwanted indices. - @param index The index to add. */ - void AddIndex(uint32 index); - - /** Adds a batch of indices to the end of the index list of this input. - Be careful when adding indices directly to multiple inputs: if - multiple inputs share an index list, you may be adding unwanted indices. - @param indices The indices to add. */ - void AddIndices(const UInt32List& indices); - - /** Retrieves the list of indices for this input. - @return The list of indices for this input. */ - uint32* GetIndices() { return const_cast(const_cast(this)->GetIndices()); } - const uint32* GetIndices() const; /**< See above. */ - - /** Retrieves the number of indices for this input. - @return The number of indices for this input. */ - size_t GetIndexCount() const; - -private: - // FUTracker interface. - virtual void OnObjectReleased(FUTrackable* object); - - // Finds the index buffer for this list. - FUParameterUInt32List& FindIndices() { return const_cast(const_cast(this)->FindIndices()); } - const FUParameterUInt32List& FindIndices() const; -}; - -#endif // _FCD_GEOMETRY_POLYGONS_INPUT_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDGeometryPolygonsInput.h + This file defines FCDGeometryPolygonsInput class. +*/ + +#ifndef _FCD_GEOMETRY_POLYGONS_INPUT_H_ +#define _FCD_GEOMETRY_POLYGONS_INPUT_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +class FCDGeometrySource; +class FCDGeometryPolygons; + +/** + An input data source for one mesh polygons set. + This structure knows the type of input data in the data source + as well as the set and offset for the data. It also contains a + pointer to the mesh data source. + + Many polygon set inputs may have the same offset (or 'idx' in older versions) when multiple + data sources are compressed together within the COLLADA document. + In this case, one and only one of the polygon set input should contain + indices. To find the indices of any polygon set input, + it is recommended that you use the FCDGeometryPolygons::FindIndicesForIdx function. + + @ingroup FCDGeometry +*/ +class FCOLLADA_EXPORT FCDGeometryPolygonsInput : public FCDObject, FUTracker +{ +private: + DeclareObjectType(FCDObject); + + FCDGeometryPolygons* parent; + DeclareParameterPtr(FCDGeometrySource, source, FC("Data Source")); + DeclareParameter(int32, FUParameterQualifiers::SIMPLE, set, FC("Input Set")); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, offset, FC("Stream Offset")); + DeclareParameterList(UInt32, indices, FC("Data Indices")); + +public: + /** Constructor. + @param parent The polygons sets that contains the input. + @param offset The offset for the indices of this input + within the interlaced tesselation information. */ + FCDGeometryPolygonsInput(FCDocument* document, FCDGeometryPolygons* parent); + + /** Destructor. */ + ~FCDGeometryPolygonsInput(); + + /** Retrieves the type of data to input. + FCollada doesn't support data sources which are interpreted + differently depending on the input. Therefore, this information + is retrieved from the source. + @return The source data type. */ + FUDaeGeometryInput::Semantic GetSemantic() const; + + /** Retrieves the data source references by this polygon set input. + This is the data source into which the indices are indexing. + You need to take the data source stride into consideration + when un-indexing the data. + @return The data source. */ + FCDGeometrySource* GetSource() { return source; } + const FCDGeometrySource* GetSource() const { return source; } /**< See above. */ + + /** Sets the data source referenced by this polygon set input. + @param source The data source referenced by the input indices. */ + void SetSource(FCDGeometrySource* source); + + /** Retrieves the offset within the interlaced COLLADA indices for this input's indices. + Changing this value after the input's construction is not recommended. + @param _offset The offset within the interlaced COLLADA indices for this input's indices. */ + inline void SetOffset(uint32 _offset) { offset = _offset; } + + /** Retrieves the offset within the interlaced COLLADA indices for this input's indices. + @return The interlaced indices offset. */ + inline uint32 GetOffset() const { return offset; } + + /** Retrieves the input set. + The input set is used to group together the texture coordinates with the texture tangents and binormals. + In ColladaMax, this value should also represent the map channel index for texture coordinates + and vertex color channels. + @return The input set. */ + inline int32 GetSet() const { return set; } + + /** Sets the input set. + The input set is used to group together the texture coordinates with the texture tangents and binormals. + In ColladaMax, this value should also represent the map channel index for texture coordinates + and vertex color channels. + @param _set The new input set. If the given value is -1, this input does not belong to any set.*/ + inline void SetSet(int32 _set) { set = _set; } + + /** Checks whether this polygon set input owns the local indices for its offset. + Since an offset may be shared, only one polygon set input will own the local indices. + @return Whether this polygon set owns the local indices. */ + inline bool OwnsIndices() const { return !indices.empty(); } + + /** Sets the local indices for the input's offset. + This function may fail if another input already owns the indices for this offset. + @param indices A static list of indices. + @param count The number of indices in the given list. */ + void SetIndices(const uint32* indices, size_t count); + + /** Sets the number of indices in this input's index list. + Any additional indices allocated will not be initialized. + @param count The number of indices in this input's index list. */ + void SetIndexCount(size_t count); + + /** Reserves memory for a given number of indices. + This is useful for performance reasons, since AddIndex can be extremely costly otherwise. + @param count The total number of indices to prepare memory for. */ + void ReserveIndexCount(size_t count); + + /** Adds an index to the indices of this input. + Be careful when adding indices directly to multiple inputs: if + multiple inputs share an index list, you may be adding unwanted indices. + @param index The index to add. */ + void AddIndex(uint32 index); + + /** Adds a batch of indices to the end of the index list of this input. + Be careful when adding indices directly to multiple inputs: if + multiple inputs share an index list, you may be adding unwanted indices. + @param indices The indices to add. */ + void AddIndices(const UInt32List& indices); + + /** Retrieves the list of indices for this input. + @return The list of indices for this input. */ + uint32* GetIndices() { return const_cast(const_cast(this)->GetIndices()); } + const uint32* GetIndices() const; /**< See above. */ + + /** Retrieves the number of indices for this input. + @return The number of indices for this input. */ + size_t GetIndexCount() const; + +private: + // FUTracker interface. + virtual void OnObjectReleased(FUTrackable* object); + + // Finds the index buffer for this list. + FUParameterUInt32List& FindIndices() { return const_cast(const_cast(this)->FindIndices()); } + const FUParameterUInt32List& FindIndices() const; +}; + +#endif // _FCD_GEOMETRY_POLYGONS_INPUT_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsInput.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySource.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySource.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySource.h (revision 24247) @@ -1,188 +1,188 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDGeometrySource.h - This file contains the FCDGeometrySource class. -*/ - -#ifndef _FCD_GEOMETRY_SOURCE_H_ -#define _FCD_GEOMETRY_SOURCE_H_ - -#ifndef __FCD_OBJECT_WITH_ID_H_ -#include "FCDocument/FCDObjectWithId.h" -#endif // __FCD_OBJECT_WITH_ID_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -class FCDExtra; - -/** - A COLLADA data source for geometric meshes. - - A COLLADA data source for geometric meshes contains a list of floating-point values and the information - to parse these floating-point values into meaningful content: the stride of the list and the type of data - that the floating-point values represent. When the floating-point values are split according to the stride, - you get the individual source values of the given type. A data source may also have a user-generated name to - identify the data within. The name is optional and is used to keep - around the user-friendly name for texture coordinate sets or color sets. - - Each source values of the COLLADA data source may be animated individually, or together: as an element. - - @ingroup FCDGeometry -*/ -class FCOLLADA_EXPORT FCDGeometrySource : public FCDObjectWithId -{ -private: - DeclareObjectType(FCDObjectWithId); - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name")); - DeclareParameterListAnimatable(float, FUParameterQualifiers::SIMPLE, sourceData, FC("Data")) - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, stride, FC("Stride")); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, sourceType, FC("Value Type")); // FUDaeGeometryInput::Semantic sourceType; - DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); - -public: - /** Constructor: do not use directly. - Use FCDGeometryMesh::AddSource or FCDGeometryMesh::AddValueSource instead. - @param document The COLLADA document which owns the data source. */ - FCDGeometrySource(FCDocument* document); - - /** Destructor. */ - virtual ~FCDGeometrySource(); - - /** Copies the data source into a clone. - The clone may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new data source - will be created and you will need to release the returned pointer manually. - @return The clone. */ - FCDGeometrySource* Clone(FCDGeometrySource* clone = NULL) const; - - /** Retrieves the name of the data source. The name is optional and is used to - keep around a user-friendly name for texture coordinate sets or color sets. - @return The name of the data source. */ - inline const fstring& GetName() const { return name; } - - /** Retrieves the pure data of the data source. This is a dynamically-sized array of - floating-point values that contains all the data of the source. - @return The pure data of the data source. */ - inline float* GetData() { return !sourceData.empty() ? &sourceData.front() : NULL; } - inline const float* GetData() const { return !sourceData.empty() ? &sourceData.front() : NULL; } /**< See above. */ - - /** [INTERNAL] Retrieve the reference to the source data. - @return The reference to the source data. - */ - inline FCDParameterListAnimatableFloat& GetSourceData(){ return sourceData; } - inline const FCDParameterListAnimatableFloat& GetSourceData() const { return sourceData; } - - /** Retrieves a ptr to the data of the data source. This allows external objects to - store pointers to our data even when the data memory is reallocated - @return The ptr to the pure data of the data source. */ - inline float** GetDataPtr() { return (float**) sourceData.GetDataPtr(); } - inline const float** GetDataPtr() const { return (const float**) sourceData.GetDataPtr(); } /**< See above. */ - - /** Retrieves the amount of data inside the source. - @return The number of data entries in the source. */ - inline size_t GetDataCount() const { return sourceData.size(); } - - /** Sets the amount of data contained inside the source. - It is preferable to set the stride and to use SetValueCount. - No initialization of new values is done. - @param count The amount of data for the source to contain. */ - void SetDataCount(size_t count); - - /** Retrieves the stride of the data within the source. - There is no guarantee that the number of data values within the source is a multiple of the stride, - yet you should always verify that the stride is at least the wanted dimension. For example, there is - no guarantee that your vertex position data source has a stride of 3. 3dsMax is known to always - export 3D texture coordinate positions. - @return The stride of the data. */ - inline uint32 GetStride() const { return stride; } - - /** Retrieves the number of individual source values contained in the source. - @return The number of source values. */ - inline size_t GetValueCount() const { return sourceData.size() / stride; } - - /** Retrieves the max number of values this input can handle before memory is reallocated. - @return The number of source values. */ - inline size_t GetValueReserved() const { return sourceData.capacity() / stride; } - - /** Sets the number of individual source values contained in the source. - No initialization of new values is done. - @param count The number of individual source values to contain in this source. */ - inline void SetValueCount(size_t count) { FUAssert(stride > 0, return); SetDataCount(count * stride); } - - /** Retrieves one source value out of this source. - @param index The index of the source value. - @return The source value. */ - inline const float* GetValue(size_t index) const { FUAssert(index < GetValueCount(), return NULL); return &sourceData.at(index * stride); } /**< See above. */ - - /** Sets one source value out of this source. - @param index The index of the source value. - @param value The new value. */ - inline void SetValue(size_t index, const float* value) { FUAssert(index < GetValueCount(), return); for (size_t i = 0; i < stride; ++i) sourceData.set(stride * index + i, value[i]); } - - /** Retrieves the type of data contained within the source. - Common values for the type of data are POSITION, NORMAL, COLOR and TEXCOORD. - Please see FUDaeGeometryInput for more information. - @see FUDaeGeometryInput. - @return The type of data contained within the source. */ - inline FUDaeGeometryInput::Semantic GetType() const { return (FUDaeGeometryInput::Semantic) *sourceType; } - - /** Sets the type of data contained within the source. - Modifying the source type of an existing source is not recommended. - Common values for the type of data are POSITION, NORMAL, COLOR and TEXCOORD. - Please see FUDaeGeometryInput for more information. - @see FUDaeGeometryInput. - @param type The type of data to be contained within the source. */ - inline void SetType(FUDaeGeometryInput::Semantic type) { sourceType = type; } - - /** Retrieves the list of animated values for the data of the source. - @return The list of animated values. */ - inline FUObjectContainer& GetAnimatedValues() { return sourceData.GetAnimatedValues(); } - inline const FUObjectContainer& GetAnimatedValues() const { return sourceData.GetAnimatedValues(); } /**< See above. */ - - /** Sets the user-friendly name of the data source. The name is optional and is used to - keep around a user-friendly name for texture coordinate sets or color sets. - @param _name The user-friendly name of the data source. */ - inline void SetName(const fstring& _name) { name = _name; SetDirtyFlag(); } - - /** Overwrites the data contained within the data source. - @param _sourceData The new data for this source. - @param _sourceStride The stride for the new data. - @param offset The offset at which to start retrieving the new data. - This argument defaults at 0 to indicate that the data copy should start from the beginning. - @param count The number of data entries to copy into the data source. - This argument defaults at 0 to indicate that the data copy should include everything. */ - void SetData(const FloatList& _sourceData, uint32 _sourceStride, size_t count=0, size_t offset=0); - - /** Sets the stride for the source data. - @param _stride The stride for the source data. */ - inline void SetStride(uint32 _stride) { stride = _stride; SetDirtyFlag(); } - - /** [INTERNAL] Set the source type. - @param type The source type. */ - void SetSourceType(FUDaeGeometryInput::Semantic type) { sourceType = type; } - - /** Retrieves the extra information contained by this data source. - @return The extra tree. This pointer will be NULL, - in the const-version of this function, if there is no extra information. - In the modifiable-version of this function: - you will always get a valid extra tree that you can fill in. */ - FCDExtra* GetExtra(); - inline const FCDExtra* GetExtra() const { return extra; } /**< See above. */ - - /** [INTERNAL] Clones this data source. You will need to release the returned pointer manually. - @return An identical copy of the data source. */ - FCDGeometrySource* Clone() const; -}; - -#endif // _FCD_GEOMETRY_SOURCE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDGeometrySource.h + This file contains the FCDGeometrySource class. +*/ + +#ifndef _FCD_GEOMETRY_SOURCE_H_ +#define _FCD_GEOMETRY_SOURCE_H_ + +#ifndef __FCD_OBJECT_WITH_ID_H_ +#include "FCDocument/FCDObjectWithId.h" +#endif // __FCD_OBJECT_WITH_ID_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +class FCDExtra; + +/** + A COLLADA data source for geometric meshes. + + A COLLADA data source for geometric meshes contains a list of floating-point values and the information + to parse these floating-point values into meaningful content: the stride of the list and the type of data + that the floating-point values represent. When the floating-point values are split according to the stride, + you get the individual source values of the given type. A data source may also have a user-generated name to + identify the data within. The name is optional and is used to keep + around the user-friendly name for texture coordinate sets or color sets. + + Each source values of the COLLADA data source may be animated individually, or together: as an element. + + @ingroup FCDGeometry +*/ +class FCOLLADA_EXPORT FCDGeometrySource : public FCDObjectWithId +{ +private: + DeclareObjectType(FCDObjectWithId); + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name")); + DeclareParameterListAnimatable(float, FUParameterQualifiers::SIMPLE, sourceData, FC("Data")) + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, stride, FC("Stride")); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, sourceType, FC("Value Type")); // FUDaeGeometryInput::Semantic sourceType; + DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); + +public: + /** Constructor: do not use directly. + Use FCDGeometryMesh::AddSource or FCDGeometryMesh::AddValueSource instead. + @param document The COLLADA document which owns the data source. */ + FCDGeometrySource(FCDocument* document); + + /** Destructor. */ + virtual ~FCDGeometrySource(); + + /** Copies the data source into a clone. + The clone may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new data source + will be created and you will need to release the returned pointer manually. + @return The clone. */ + FCDGeometrySource* Clone(FCDGeometrySource* clone = NULL) const; + + /** Retrieves the name of the data source. The name is optional and is used to + keep around a user-friendly name for texture coordinate sets or color sets. + @return The name of the data source. */ + inline const fstring& GetName() const { return name; } + + /** Retrieves the pure data of the data source. This is a dynamically-sized array of + floating-point values that contains all the data of the source. + @return The pure data of the data source. */ + inline float* GetData() { return !sourceData.empty() ? &sourceData.front() : NULL; } + inline const float* GetData() const { return !sourceData.empty() ? &sourceData.front() : NULL; } /**< See above. */ + + /** [INTERNAL] Retrieve the reference to the source data. + @return The reference to the source data. + */ + inline FCDParameterListAnimatableFloat& GetSourceData(){ return sourceData; } + inline const FCDParameterListAnimatableFloat& GetSourceData() const { return sourceData; } + + /** Retrieves a ptr to the data of the data source. This allows external objects to + store pointers to our data even when the data memory is reallocated + @return The ptr to the pure data of the data source. */ + inline float** GetDataPtr() { return (float**) sourceData.GetDataPtr(); } + inline const float** GetDataPtr() const { return (const float**) sourceData.GetDataPtr(); } /**< See above. */ + + /** Retrieves the amount of data inside the source. + @return The number of data entries in the source. */ + inline size_t GetDataCount() const { return sourceData.size(); } + + /** Sets the amount of data contained inside the source. + It is preferable to set the stride and to use SetValueCount. + No initialization of new values is done. + @param count The amount of data for the source to contain. */ + void SetDataCount(size_t count); + + /** Retrieves the stride of the data within the source. + There is no guarantee that the number of data values within the source is a multiple of the stride, + yet you should always verify that the stride is at least the wanted dimension. For example, there is + no guarantee that your vertex position data source has a stride of 3. 3dsMax is known to always + export 3D texture coordinate positions. + @return The stride of the data. */ + inline uint32 GetStride() const { return stride; } + + /** Retrieves the number of individual source values contained in the source. + @return The number of source values. */ + inline size_t GetValueCount() const { return sourceData.size() / stride; } + + /** Retrieves the max number of values this input can handle before memory is reallocated. + @return The number of source values. */ + inline size_t GetValueReserved() const { return sourceData.capacity() / stride; } + + /** Sets the number of individual source values contained in the source. + No initialization of new values is done. + @param count The number of individual source values to contain in this source. */ + inline void SetValueCount(size_t count) { FUAssert(stride > 0, return); SetDataCount(count * stride); } + + /** Retrieves one source value out of this source. + @param index The index of the source value. + @return The source value. */ + inline const float* GetValue(size_t index) const { FUAssert(index < GetValueCount(), return NULL); return &sourceData.at(index * stride); } /**< See above. */ + + /** Sets one source value out of this source. + @param index The index of the source value. + @param value The new value. */ + inline void SetValue(size_t index, const float* value) { FUAssert(index < GetValueCount(), return); for (size_t i = 0; i < stride; ++i) sourceData.set(stride * index + i, value[i]); } + + /** Retrieves the type of data contained within the source. + Common values for the type of data are POSITION, NORMAL, COLOR and TEXCOORD. + Please see FUDaeGeometryInput for more information. + @see FUDaeGeometryInput. + @return The type of data contained within the source. */ + inline FUDaeGeometryInput::Semantic GetType() const { return (FUDaeGeometryInput::Semantic) *sourceType; } + + /** Sets the type of data contained within the source. + Modifying the source type of an existing source is not recommended. + Common values for the type of data are POSITION, NORMAL, COLOR and TEXCOORD. + Please see FUDaeGeometryInput for more information. + @see FUDaeGeometryInput. + @param type The type of data to be contained within the source. */ + inline void SetType(FUDaeGeometryInput::Semantic type) { sourceType = type; } + + /** Retrieves the list of animated values for the data of the source. + @return The list of animated values. */ + inline FUObjectContainer& GetAnimatedValues() { return sourceData.GetAnimatedValues(); } + inline const FUObjectContainer& GetAnimatedValues() const { return sourceData.GetAnimatedValues(); } /**< See above. */ + + /** Sets the user-friendly name of the data source. The name is optional and is used to + keep around a user-friendly name for texture coordinate sets or color sets. + @param _name The user-friendly name of the data source. */ + inline void SetName(const fstring& _name) { name = _name; SetDirtyFlag(); } + + /** Overwrites the data contained within the data source. + @param _sourceData The new data for this source. + @param _sourceStride The stride for the new data. + @param offset The offset at which to start retrieving the new data. + This argument defaults at 0 to indicate that the data copy should start from the beginning. + @param count The number of data entries to copy into the data source. + This argument defaults at 0 to indicate that the data copy should include everything. */ + void SetData(const FloatList& _sourceData, uint32 _sourceStride, size_t count=0, size_t offset=0); + + /** Sets the stride for the source data. + @param _stride The stride for the source data. */ + inline void SetStride(uint32 _stride) { stride = _stride; SetDirtyFlag(); } + + /** [INTERNAL] Set the source type. + @param type The source type. */ + void SetSourceType(FUDaeGeometryInput::Semantic type) { sourceType = type; } + + /** Retrieves the extra information contained by this data source. + @return The extra tree. This pointer will be NULL, + in the const-version of this function, if there is no extra information. + In the modifiable-version of this function: + you will always get a valid extra tree that you can fill in. */ + FCDExtra* GetExtra(); + inline const FCDExtra* GetExtra() const { return extra; } /**< See above. */ + + /** [INTERNAL] Clones this data source. You will need to release the returned pointer manually. + @return An identical copy of the data source. */ + FCDGeometrySource* Clone() const; +}; + +#endif // _FCD_GEOMETRY_SOURCE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySource.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDImage.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDImage.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDImage.h (revision 24247) @@ -1,132 +1,132 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDImage.h - This file contains the FCDImage class. -*/ - -#ifndef _FCD_IMAGE_H_ -#define _FCD_IMAGE_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDocument; - -/** - A COLLADA image. - - A COLLADA image encapsulates an image file and are contained - within the image library. FCollada doesn't support inlined image bits. - - An image is solely defined by its filename. For some - image types and optionally, the width, height and depth of - the image may be required and valid. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDImage : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - - DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, filename, FC("Filename")); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, width, FC("Width")); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, height, FC("Height")); - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, depth, FC("Depth")); - -public: - DeclareFlag(Video, 0); /**< Flags this image as a video stream.*/ - DeclareFlagCount(1); - -public: - /** Constructor: do not use directly. - Instead, use the FCDLibrary::AddEntity function. - @param document The COLLADA document that owns the image. */ - FCDImage(FCDocument* document); - - /** Destructor. */ - virtual ~FCDImage(); - - /** Retrieves the entity type for this class. This function is part - of the FCDEntity class interface. - @return The entity type: IMAGE. */ - virtual Type GetType() const { return IMAGE; } - - /** Retrieves the filename of the image file. - This is the image file that you should load when attempting - to use the image bits. FCollada will deal with the filename - internally and provide an absolute filename. - @return The filename of the image file. */ - const fstring& GetFilename() const { return filename; } - - /** Sets the filename of the image file. - This is the image file that you should load when attempting - to use the image bits. FCollada will deal with the filename - internally and export a relative filename. - @param _filename The filename of the image file. */ - void SetFilename(const fstring& _filename); - - /** Retrieves the width of the image. - This parameter is useful for off-screen render targets and is - optional for texture image files. - @return The width of the image. This value will be zero to indicate - that you should retrieve the width of the image from the image file. */ - const uint32& GetWidth() const { return width; } - - /** Sets the width of the image. - This parameter is useful for off-screen render targets and is - optional for texture image files. - @param _width The width of the image. This value can be zero to indicate - that you should retrieve the width of the image from the image file. */ - void SetWidth(uint32 _width) { width = _width; SetDirtyFlag(); } - - /** Retrieves the height of the image. - This parameter is useful for off-screen render targets and is - optional for texture image files. - @return The height of the image. This value will be zero to indicate - that you should retrieve the height of the image from the image file. */ - const uint32& GetHeight() const { return height; } - - /** Sets the height of the image. - This parameter is useful for off-screen render targets and is - optional for texture image files. - @param _height The height of the image. This value can be zero to indicate - that you should retrieve the width of the image from the image file. */ - void SetHeight(uint32 _height) { height = _height; SetDirtyFlag(); } - - /** Retrieves the depth of the 3D image. - This parameter is optional for texture image files. - @return The depth of the image. This value will be zero to indicate - that you should retrieve the depth of the image from the image file. */ - const uint32& GetDepth() const { return depth; } - - /** Sets the depth of the 3D image. - This parameter is optional for texture image files. - @param _depth The depth of the image. This value can be zero to indicate - that you should retrieve the depth of the image from the image file. */ - void SetDepth(uint32 _depth) { depth = _depth; SetDirtyFlag(); } - - /** Copies the image entity into a clone. - The clone may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new image - will be created and you will need to release the returned pointer manually. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; -}; - -#endif // _FCD_IMAGE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDImage.h + This file contains the FCDImage class. +*/ + +#ifndef _FCD_IMAGE_H_ +#define _FCD_IMAGE_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDocument; + +/** + A COLLADA image. + + A COLLADA image encapsulates an image file and are contained + within the image library. FCollada doesn't support inlined image bits. + + An image is solely defined by its filename. For some + image types and optionally, the width, height and depth of + the image may be required and valid. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDImage : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + + DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, filename, FC("Filename")); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, width, FC("Width")); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, height, FC("Height")); + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, depth, FC("Depth")); + +public: + DeclareFlag(Video, 0); /**< Flags this image as a video stream.*/ + DeclareFlagCount(1); + +public: + /** Constructor: do not use directly. + Instead, use the FCDLibrary::AddEntity function. + @param document The COLLADA document that owns the image. */ + FCDImage(FCDocument* document); + + /** Destructor. */ + virtual ~FCDImage(); + + /** Retrieves the entity type for this class. This function is part + of the FCDEntity class interface. + @return The entity type: IMAGE. */ + virtual Type GetType() const { return IMAGE; } + + /** Retrieves the filename of the image file. + This is the image file that you should load when attempting + to use the image bits. FCollada will deal with the filename + internally and provide an absolute filename. + @return The filename of the image file. */ + const fstring& GetFilename() const { return filename; } + + /** Sets the filename of the image file. + This is the image file that you should load when attempting + to use the image bits. FCollada will deal with the filename + internally and export a relative filename. + @param _filename The filename of the image file. */ + void SetFilename(const fstring& _filename); + + /** Retrieves the width of the image. + This parameter is useful for off-screen render targets and is + optional for texture image files. + @return The width of the image. This value will be zero to indicate + that you should retrieve the width of the image from the image file. */ + const uint32& GetWidth() const { return width; } + + /** Sets the width of the image. + This parameter is useful for off-screen render targets and is + optional for texture image files. + @param _width The width of the image. This value can be zero to indicate + that you should retrieve the width of the image from the image file. */ + void SetWidth(uint32 _width) { width = _width; SetDirtyFlag(); } + + /** Retrieves the height of the image. + This parameter is useful for off-screen render targets and is + optional for texture image files. + @return The height of the image. This value will be zero to indicate + that you should retrieve the height of the image from the image file. */ + const uint32& GetHeight() const { return height; } + + /** Sets the height of the image. + This parameter is useful for off-screen render targets and is + optional for texture image files. + @param _height The height of the image. This value can be zero to indicate + that you should retrieve the width of the image from the image file. */ + void SetHeight(uint32 _height) { height = _height; SetDirtyFlag(); } + + /** Retrieves the depth of the 3D image. + This parameter is optional for texture image files. + @return The depth of the image. This value will be zero to indicate + that you should retrieve the depth of the image from the image file. */ + const uint32& GetDepth() const { return depth; } + + /** Sets the depth of the 3D image. + This parameter is optional for texture image files. + @param _depth The depth of the image. This value can be zero to indicate + that you should retrieve the depth of the image from the image file. */ + void SetDepth(uint32 _depth) { depth = _depth; SetDirtyFlag(); } + + /** Copies the image entity into a clone. + The clone may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new image + will be created and you will need to release the returned pointer manually. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; +}; + +#endif // _FCD_IMAGE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDImage.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLight.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLight.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLight.h (revision 24247) @@ -1,272 +1,272 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDLight.h - This file contains the FCDLight class. -*/ - -#ifndef _FCD_LIGHT_H_ -#define _FCD_LIGHT_H_ - -#ifndef _FCD_TARGETED_ENTITY_H_ -#include "FCDocument/FCDTargetedEntity.h" -#endif // _FCD_TARGETED_ENTITY_H_ -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -class FCDocument; -class FCDSceneNode; -class FCDAnimated; - -/** - A COLLADA light. - Based on the FCDTargetedEntity class to supported aimed lights. - COLLADA defines four types of native lights: point, spot, ambient and directional. - These four types are fully handled by this class: make sure to check the type flag - as well as which information to expect for each light type. - - A COLLADA ambient light has a global color, which should be added to - all other lighting on all geometry. - - A COLLADA directional light has a global color, which should be multiplied - to the cosine of the angle between the normal vector of a triangle - and the direction of the light. Note that the direction will be calculated - from the transforms, for each instance, and is not provided by this class. - - A COLLADA point light has a color which attenuates as the distance increases - between the light position and the vertex being shaded. Note that the position - will be calculated from the transforms, for each instance, - and is not provided by this class. - - A COLLADA spot light is a point light which lights only the objects that - appear within a specific angle, with respect to the direction of the light. - Note that the position and the direction will be calculated from the - transforms, for each instance, and is not provided by this class. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDLight : public FCDTargetedEntity -{ -public: - /** The types of lights supported by this class. */ - enum LightType - { - POINT, /**< A point light. This is the default type. */ - SPOT, /**< A spot light. */ - AMBIENT, /**< An ambient light. */ - DIRECTIONAL /**< A directional light. */ - }; - -private: - DeclareObjectType(FCDTargetedEntity); - - // Common Light parameters - DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::COLOR, color, FC("Color")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, intensity, FC("Intensity")); // Non-standard COLLADA - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, lightType, FC("Light Type")); // LightType - - // Point and spot light parameters - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, constantAttenuationFactor, FC("Constant Attenuation Factor")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, linearAttenuationFactor, FC("Linear Attenuation Factor")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, quadracticAttenuationFactor, FC("Quadratic Attenuation Factor")); - - // Spot-specific light parameters - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, fallOffExponent, FC("Fall-off Exponent")); // Likely to be deprecated in future versions. - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, fallOffAngle, FC("Inner Cone Angle")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, outerAngle, FC("Outer Cone Angle")); // Non-standard COLLADA - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, penumbraAngle, FC("Penumbra Angle")); // *** DEPRECATED *** Replaced with the inner/outer angle. - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, dropoff, FC("Drop-off")); - -public: - /** Constructor: do not use directly. Create new lights using the FCDLibrary::AddEntity function. - @param document The COLLADA document that contains this light entity. */ - FCDLight(FCDocument* document); - - /** Destructor. */ - virtual ~FCDLight(); - - /** Retrieves the entity type for this class. This function is part of the FCDEntity interface. - @return The entity type: LIGHT. */ - virtual Type GetType() const { return LIGHT; } - - /** Checks if the light uses a DCC specific representation - Currently always returns false. - @deprecated Instead use: GetExtra()->GetDefaultType()->GetTechniques() - @return The DCC flag. */ - DEPRECATED(3.05A, GetExtra()->GetDefaultType()->GetTechniques()) virtual bool HasMaxExtras() const { return false; } - DEPRECATED(3.05A, GetExtra()->GetDefaultType()->GetTechniques()) virtual bool HasMayaExtras() const { return false; } /**< See above. */ - - /** [INTERNAL] Set DCC specific flags. - @deprecated Internal method, should never have been used. - @param value The new flag. - */ - DEPRECATED(3.05A, nothing) void SetHasMaxExtras(bool UNUSED(value)) { } - DEPRECATED(3.05A, nothing) void SetHasMayaExtras(bool UNUSED(value)) { } - - /** Retrieves the base color for the light. To calculate the light color, - multiply the base color with the intensity. - @return The base color for the light. */ - FCDParameterAnimatableColor3& GetColor() { return color; } - const FCDParameterAnimatableColor3& GetColor() const { return color; } /**< See above. */ - - /** Sets the base color for the light. To calculate the light color, - multiply the base color with the intensity. - @param col The base color for the light. */ - void SetColor(const FMVector3& col) { color = col; SetDirtyFlag(); } - - /** Sets the base color for the light. To calculate the light color, - multiply the base color with the intensity. - @param r The red component for the light color. - @param g The green component for the light color. - @param b The blue component for the light color. */ - void SetColor(float r, float g, float b) { color = FMVector3(r, g, b); SetDirtyFlag(); } - - /** Retrieves the intensity of the light. To calculate the light color, - multiply the base color with the intensity. - @return The intensity of the light. */ - FCDParameterAnimatableFloat& GetIntensity() { return intensity; } - const FCDParameterAnimatableFloat& GetIntensity() const { return intensity; } /**< See above. */ - - /** Sets the intensity of the light. To calculate the light color, - multiply the base color with the intensity. - @param _intensity The intensity of the light. */ - void SetIntensity(float _intensity) { intensity = _intensity; SetDirtyFlag(); } - - /** Retrieves the type of the light. - Make sure to check the type of light before using the values, as some values - may not make sense with some types of light. - @return The light type. */ - LightType GetLightType() const { return (LightType) *lightType; } - - /** Sets the type of the light. The default type of a new light is POINT. - @param type The light type. */ - void SetLightType(LightType type) { lightType = type; SetDirtyFlag(); } - - /** Retrieves the constant attenuation factor for the light. - This value is valid only for point and spot lights. - @return The constant attenuation factor. */ - FCDParameterAnimatableFloat& GetConstantAttenuationFactor() { return constantAttenuationFactor; } - const FCDParameterAnimatableFloat& GetConstantAttenuationFactor() const { return constantAttenuationFactor; } /**< See above. */ - - /** Sets the constant attenuation factor for the light. - This value is valid only for point and spot lights. - @param factor The constant attenuation factor. */ - void SetConstantAttenuationFactor(float factor) { constantAttenuationFactor = factor; SetDirtyFlag(); } - - /** Retrieves the linear attenuation factor for the light. - This value is valid only for point and spot lights. - @return The linear attenuation factor. */ - FCDParameterAnimatableFloat& GetLinearAttenuationFactor() { return linearAttenuationFactor; } - const FCDParameterAnimatableFloat& GetLinearAttenuationFactor() const { return linearAttenuationFactor; } /**< See above. */ - - /** Sets the linear attenuation factor for the light. - This value is valid only for point and spot lights. - @param factor The linear attenuation factor. */ - void SetLinearAttenuationFactor(float factor) { linearAttenuationFactor = factor; SetDirtyFlag(); } - - /** Retrieves the quadratic attenuation factor for the light. - This value is valid only for point and spot lights. - @return The quadratic attenuation factor. */ - FCDParameterAnimatableFloat& GetQuadraticAttenuationFactor() { return quadracticAttenuationFactor; } - const FCDParameterAnimatableFloat& GetQuadraticAttenuationFactor() const { return quadracticAttenuationFactor; } /**< See above. */ - - /** Sets the quadratic attenuation factor for the light. - This value is valid only for point and spot lights. - @param factor The quadratic attenuation factor. */ - void SetQuadraticAttenuationFactor(float factor) { quadracticAttenuationFactor = factor; SetDirtyFlag(); } - - /** Retrieves the fall-off exponent for the light. - This value is valid only for spot lights. It determines - how fast the lighting turns off, with respect to - angles greater than the fall-off angle. This results in a smooth - lighting at the spot light's edges. - - IMPORTANT NOTE: Neither ColladaMaya or ColladaMax use this value - as neither Maya or 3dsMax use this technique for soft lighting. - - @return The spot light fall-off exponent. */ - FCDParameterAnimatableFloat& GetFallOffExponent() { return fallOffExponent; } - const FCDParameterAnimatableFloat& GetFallOffExponent() const { return fallOffExponent; } /**< See above. */ - - /** Sets the fall-off exponent for the light. - @see GetFallOffExponent - @param exponent The spot light fall-off exponent. */ - void SetFallOffExponent(float exponent) { fallOffExponent = exponent; SetDirtyFlag(); } - - /** Retrieves the fall-off angle for the light. - This value is valid only for spot lights. It defines - the cone of the spot light. - @return The spot light fall-off angle. */ - FCDParameterAnimatableFloat& GetFallOffAngle() { return fallOffAngle; } - const FCDParameterAnimatableFloat& GetFallOffAngle() const { return fallOffAngle; } /**< See above. */ - - /** Sets the fall-off angle for the light. - @see GetFallOffAngle - @param angle The spot light fall-off angle. */ - void SetFallOffAngle(float angle) { fallOffAngle = angle; SetDirtyFlag(); } - - /** Retrieves the outer angle for the light. - This value is valid only for spot lights. This value is used - by documents exported by ColladaMax and ColladaMaya. This value should always be - greater than the fall-off angle. It represents the angle at which - the lighting is black. All lighting between the fall-off angle and - the outer angle is a linear interpolation between the light color - and black. - @return The spot light outer angle. */ - FCDParameterAnimatableFloat& GetOuterAngle() { return outerAngle; } - const FCDParameterAnimatableFloat& GetOuterAngle() const { return outerAngle; } /**< See above. */ - - /** Sets the outer angle for the light. - @see GetOuterAngle - @param angle The spot light outer angle. */ - void SetOuterAngle(float angle) { outerAngle = angle; SetDirtyFlag(); } - - /** Retrieves the penumbra angle for the light. - This value is valid only for spot lights. The value is only used - by documents exported by ColladaMaya. This value is relative to - the fall-off angle and may be negative. If this value is positive, - it determines the outer angle, as described above. If this value - is negative, the fall-off angle is used as the outer angle and the - fall-off angle + the penumbra angle is used as the full-lighting - angle. - This now actually does nothing but gets the value assigned in SetPenumbraAngle - @deprecated Instead use: GetOuterAngle and GetFallOffAngle - @see GetOuterAngle - @return The spot light penumbra angle. */ - DEPRECATED(3.05A, GetOuterAngle and GetFallOffAngle) float& GetPenumbraAngle() { return penumbraAngle; } - DEPRECATED(3.05A, GetOuterAngle and GetFallOffAngle) const float& GetPenumbraAngle() const { return penumbraAngle; } /**< See above. */ - - /** Sets the penumbra angle for the light. - This now actually doesn't nothing except sets a variable that you can read back with GetPenumbraAngle. - @deprecated Instead use: SetOuterAngle and SetFallOffAngle, or FCDLightTools::LoadPenumbra - @see GetPenumbraAngle - @param angle The spot light penumbra angle. */ - DEPRECATED(3.05A, SetOuterAngle and SetFallOffAngle) void SetPenumbraAngle(float angle) { penumbraAngle = angle; } - - /** Retrieves the drop-off for the light. - It defines the rate at which a spot light gets dimmer from the center - of the beam to outside angles. - @return The drop-off for the light. */ - FCDParameterAnimatableFloat& GetDropoff() { return dropoff; } - const FCDParameterAnimatableFloat& GetDropoff() const { return dropoff; } /**< See above. */ - - /** Sets the drop-off for the light. - @param factor The drop-off for the light. */ - void SetDropoff(float factor) { dropoff = factor; SetDirtyFlag(); } -}; - -#endif // _FCD_LIGHT_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDLight.h + This file contains the FCDLight class. +*/ + +#ifndef _FCD_LIGHT_H_ +#define _FCD_LIGHT_H_ + +#ifndef _FCD_TARGETED_ENTITY_H_ +#include "FCDocument/FCDTargetedEntity.h" +#endif // _FCD_TARGETED_ENTITY_H_ +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +class FCDocument; +class FCDSceneNode; +class FCDAnimated; + +/** + A COLLADA light. + Based on the FCDTargetedEntity class to supported aimed lights. + COLLADA defines four types of native lights: point, spot, ambient and directional. + These four types are fully handled by this class: make sure to check the type flag + as well as which information to expect for each light type. + + A COLLADA ambient light has a global color, which should be added to + all other lighting on all geometry. + + A COLLADA directional light has a global color, which should be multiplied + to the cosine of the angle between the normal vector of a triangle + and the direction of the light. Note that the direction will be calculated + from the transforms, for each instance, and is not provided by this class. + + A COLLADA point light has a color which attenuates as the distance increases + between the light position and the vertex being shaded. Note that the position + will be calculated from the transforms, for each instance, + and is not provided by this class. + + A COLLADA spot light is a point light which lights only the objects that + appear within a specific angle, with respect to the direction of the light. + Note that the position and the direction will be calculated from the + transforms, for each instance, and is not provided by this class. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDLight : public FCDTargetedEntity +{ +public: + /** The types of lights supported by this class. */ + enum LightType + { + POINT, /**< A point light. This is the default type. */ + SPOT, /**< A spot light. */ + AMBIENT, /**< An ambient light. */ + DIRECTIONAL /**< A directional light. */ + }; + +private: + DeclareObjectType(FCDTargetedEntity); + + // Common Light parameters + DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::COLOR, color, FC("Color")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, intensity, FC("Intensity")); // Non-standard COLLADA + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, lightType, FC("Light Type")); // LightType + + // Point and spot light parameters + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, constantAttenuationFactor, FC("Constant Attenuation Factor")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, linearAttenuationFactor, FC("Linear Attenuation Factor")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, quadracticAttenuationFactor, FC("Quadratic Attenuation Factor")); + + // Spot-specific light parameters + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, fallOffExponent, FC("Fall-off Exponent")); // Likely to be deprecated in future versions. + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, fallOffAngle, FC("Inner Cone Angle")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, outerAngle, FC("Outer Cone Angle")); // Non-standard COLLADA + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, penumbraAngle, FC("Penumbra Angle")); // *** DEPRECATED *** Replaced with the inner/outer angle. + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, dropoff, FC("Drop-off")); + +public: + /** Constructor: do not use directly. Create new lights using the FCDLibrary::AddEntity function. + @param document The COLLADA document that contains this light entity. */ + FCDLight(FCDocument* document); + + /** Destructor. */ + virtual ~FCDLight(); + + /** Retrieves the entity type for this class. This function is part of the FCDEntity interface. + @return The entity type: LIGHT. */ + virtual Type GetType() const { return LIGHT; } + + /** Checks if the light uses a DCC specific representation + Currently always returns false. + @deprecated Instead use: GetExtra()->GetDefaultType()->GetTechniques() + @return The DCC flag. */ + DEPRECATED(3.05A, GetExtra()->GetDefaultType()->GetTechniques()) virtual bool HasMaxExtras() const { return false; } + DEPRECATED(3.05A, GetExtra()->GetDefaultType()->GetTechniques()) virtual bool HasMayaExtras() const { return false; } /**< See above. */ + + /** [INTERNAL] Set DCC specific flags. + @deprecated Internal method, should never have been used. + @param value The new flag. + */ + DEPRECATED(3.05A, nothing) void SetHasMaxExtras(bool UNUSED(value)) { } + DEPRECATED(3.05A, nothing) void SetHasMayaExtras(bool UNUSED(value)) { } + + /** Retrieves the base color for the light. To calculate the light color, + multiply the base color with the intensity. + @return The base color for the light. */ + FCDParameterAnimatableColor3& GetColor() { return color; } + const FCDParameterAnimatableColor3& GetColor() const { return color; } /**< See above. */ + + /** Sets the base color for the light. To calculate the light color, + multiply the base color with the intensity. + @param col The base color for the light. */ + void SetColor(const FMVector3& col) { color = col; SetDirtyFlag(); } + + /** Sets the base color for the light. To calculate the light color, + multiply the base color with the intensity. + @param r The red component for the light color. + @param g The green component for the light color. + @param b The blue component for the light color. */ + void SetColor(float r, float g, float b) { color = FMVector3(r, g, b); SetDirtyFlag(); } + + /** Retrieves the intensity of the light. To calculate the light color, + multiply the base color with the intensity. + @return The intensity of the light. */ + FCDParameterAnimatableFloat& GetIntensity() { return intensity; } + const FCDParameterAnimatableFloat& GetIntensity() const { return intensity; } /**< See above. */ + + /** Sets the intensity of the light. To calculate the light color, + multiply the base color with the intensity. + @param _intensity The intensity of the light. */ + void SetIntensity(float _intensity) { intensity = _intensity; SetDirtyFlag(); } + + /** Retrieves the type of the light. + Make sure to check the type of light before using the values, as some values + may not make sense with some types of light. + @return The light type. */ + LightType GetLightType() const { return (LightType) *lightType; } + + /** Sets the type of the light. The default type of a new light is POINT. + @param type The light type. */ + void SetLightType(LightType type) { lightType = type; SetDirtyFlag(); } + + /** Retrieves the constant attenuation factor for the light. + This value is valid only for point and spot lights. + @return The constant attenuation factor. */ + FCDParameterAnimatableFloat& GetConstantAttenuationFactor() { return constantAttenuationFactor; } + const FCDParameterAnimatableFloat& GetConstantAttenuationFactor() const { return constantAttenuationFactor; } /**< See above. */ + + /** Sets the constant attenuation factor for the light. + This value is valid only for point and spot lights. + @param factor The constant attenuation factor. */ + void SetConstantAttenuationFactor(float factor) { constantAttenuationFactor = factor; SetDirtyFlag(); } + + /** Retrieves the linear attenuation factor for the light. + This value is valid only for point and spot lights. + @return The linear attenuation factor. */ + FCDParameterAnimatableFloat& GetLinearAttenuationFactor() { return linearAttenuationFactor; } + const FCDParameterAnimatableFloat& GetLinearAttenuationFactor() const { return linearAttenuationFactor; } /**< See above. */ + + /** Sets the linear attenuation factor for the light. + This value is valid only for point and spot lights. + @param factor The linear attenuation factor. */ + void SetLinearAttenuationFactor(float factor) { linearAttenuationFactor = factor; SetDirtyFlag(); } + + /** Retrieves the quadratic attenuation factor for the light. + This value is valid only for point and spot lights. + @return The quadratic attenuation factor. */ + FCDParameterAnimatableFloat& GetQuadraticAttenuationFactor() { return quadracticAttenuationFactor; } + const FCDParameterAnimatableFloat& GetQuadraticAttenuationFactor() const { return quadracticAttenuationFactor; } /**< See above. */ + + /** Sets the quadratic attenuation factor for the light. + This value is valid only for point and spot lights. + @param factor The quadratic attenuation factor. */ + void SetQuadraticAttenuationFactor(float factor) { quadracticAttenuationFactor = factor; SetDirtyFlag(); } + + /** Retrieves the fall-off exponent for the light. + This value is valid only for spot lights. It determines + how fast the lighting turns off, with respect to + angles greater than the fall-off angle. This results in a smooth + lighting at the spot light's edges. + + IMPORTANT NOTE: Neither ColladaMaya or ColladaMax use this value + as neither Maya or 3dsMax use this technique for soft lighting. + + @return The spot light fall-off exponent. */ + FCDParameterAnimatableFloat& GetFallOffExponent() { return fallOffExponent; } + const FCDParameterAnimatableFloat& GetFallOffExponent() const { return fallOffExponent; } /**< See above. */ + + /** Sets the fall-off exponent for the light. + @see GetFallOffExponent + @param exponent The spot light fall-off exponent. */ + void SetFallOffExponent(float exponent) { fallOffExponent = exponent; SetDirtyFlag(); } + + /** Retrieves the fall-off angle for the light. + This value is valid only for spot lights. It defines + the cone of the spot light. + @return The spot light fall-off angle. */ + FCDParameterAnimatableFloat& GetFallOffAngle() { return fallOffAngle; } + const FCDParameterAnimatableFloat& GetFallOffAngle() const { return fallOffAngle; } /**< See above. */ + + /** Sets the fall-off angle for the light. + @see GetFallOffAngle + @param angle The spot light fall-off angle. */ + void SetFallOffAngle(float angle) { fallOffAngle = angle; SetDirtyFlag(); } + + /** Retrieves the outer angle for the light. + This value is valid only for spot lights. This value is used + by documents exported by ColladaMax and ColladaMaya. This value should always be + greater than the fall-off angle. It represents the angle at which + the lighting is black. All lighting between the fall-off angle and + the outer angle is a linear interpolation between the light color + and black. + @return The spot light outer angle. */ + FCDParameterAnimatableFloat& GetOuterAngle() { return outerAngle; } + const FCDParameterAnimatableFloat& GetOuterAngle() const { return outerAngle; } /**< See above. */ + + /** Sets the outer angle for the light. + @see GetOuterAngle + @param angle The spot light outer angle. */ + void SetOuterAngle(float angle) { outerAngle = angle; SetDirtyFlag(); } + + /** Retrieves the penumbra angle for the light. + This value is valid only for spot lights. The value is only used + by documents exported by ColladaMaya. This value is relative to + the fall-off angle and may be negative. If this value is positive, + it determines the outer angle, as described above. If this value + is negative, the fall-off angle is used as the outer angle and the + fall-off angle + the penumbra angle is used as the full-lighting + angle. + This now actually does nothing but gets the value assigned in SetPenumbraAngle + @deprecated Instead use: GetOuterAngle and GetFallOffAngle + @see GetOuterAngle + @return The spot light penumbra angle. */ + DEPRECATED(3.05A, GetOuterAngle and GetFallOffAngle) float& GetPenumbraAngle() { return penumbraAngle; } + DEPRECATED(3.05A, GetOuterAngle and GetFallOffAngle) const float& GetPenumbraAngle() const { return penumbraAngle; } /**< See above. */ + + /** Sets the penumbra angle for the light. + This now actually doesn't nothing except sets a variable that you can read back with GetPenumbraAngle. + @deprecated Instead use: SetOuterAngle and SetFallOffAngle, or FCDLightTools::LoadPenumbra + @see GetPenumbraAngle + @param angle The spot light penumbra angle. */ + DEPRECATED(3.05A, SetOuterAngle and SetFallOffAngle) void SetPenumbraAngle(float angle) { penumbraAngle = angle; } + + /** Retrieves the drop-off for the light. + It defines the rate at which a spot light gets dimmer from the center + of the beam to outside angles. + @return The drop-off for the light. */ + FCDParameterAnimatableFloat& GetDropoff() { return dropoff; } + const FCDParameterAnimatableFloat& GetDropoff() const { return dropoff; } /**< See above. */ + + /** Sets the drop-off for the light. + @param factor The drop-off for the light. */ + void SetDropoff(float factor) { dropoff = factor; SetDirtyFlag(); } +}; + +#endif // _FCD_LIGHT_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLight.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterial.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterial.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterial.h (revision 24247) @@ -1,133 +1,133 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDMaterial.h - This file contains the FCDMaterail class and the FCDMaterialTechniqueHint structure. -*/ - -#ifndef _FCD_MATERIAL_H_ -#define _FCD_MATERIAL_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDocument; -class FCDEffect; -class FCDEffectParameter; -class FCDEntityReference; - -/** - A technique usage hint for a material. - This structure contains two strings to help applications - choose a technique within the material's instantiated effect - according to their application platform. -*/ -class FCOLLADA_EXPORT FCDMaterialTechniqueHint -{ -public: - fstring platform; /**< A platform semantic. COLLADA defines no platform semantics. */ - fm::string technique; /**< The sid for the technique to choose for the platform. */ -}; - -/** A dynamically-sized list of material platform-technique hints. */ -typedef fm::vector FCDMaterialTechniqueHintList; - -/** - A COLLADA material. - - A COLLADA material is one of many abstraction level that defines how - to render mesh polygon sets. It instantiates an effect and may - overrides some of the effect parameters with its own values. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDMaterial : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - bool ownsEffect; - DeclareParameterPtr(FCDEntityReference, effect, FC("Effect")); - DeclareParameterContainer(FCDEffectParameter, parameters, FC("Effect Parameters")) - FCDMaterialTechniqueHintList techniqueHints; - -public: - /** Constructor: do not use directly. - Instead, use the FCDLibrary::AddEntity function. - @param document The COLLADA document that owns the material. */ - FCDMaterial(FCDocument* document); - - /** Destructor. */ - virtual ~FCDMaterial(); - - /** Retrieves the entity type for this class. This function is part - of the FCDEntity class interface. - @return The entity type: MATERIAL. */ - virtual Type GetType() const { return FCDEntity::MATERIAL; } - - /** Retrieves the effect instantiated for this material. - The parameters of the effect may be overwritten by this material. - @return The instantiated effect. This pointer will be NULL if the material has no rendering. */ - FCDEffect* GetEffect() { return const_cast(const_cast(this)->GetEffect()); } - const FCDEffect* GetEffect() const; /**< See above. */ - - /** Retrieves the effect reference for this material. - Using the FCDEffectReference object for the effect is only useful when - dealing manually with external references. - @return The entity reference for the effect. */ - FCDEntityReference* GetEffectReference() { return effect; } - const FCDEntityReference* GetEffectReference() const { return effect; } - - /** Sets the effect instantiated for this material. - @param _effect The effect instantiated for this material. */ - void SetEffect(FCDEffect* _effect); - - /** Retrieves the list of the material platform-technique hints. - @return The list of material platform-technique hints. */ - FCDMaterialTechniqueHintList& GetTechniqueHints() { return techniqueHints; } - const FCDMaterialTechniqueHintList& GetTechniqueHints() const { return techniqueHints; } /**< See above. */ - - /** Retrieves the number of local effect parameters - @return The number of local effect parameters. */ - inline size_t GetEffectParameterCount() const { return parameters.size(); } - - /** Retrieves a given local effect parameter. - @param index An index. - @return The local effect parameter at the given index. */ - inline FCDEffectParameter* GetEffectParameter(size_t index) { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } - inline const FCDEffectParameter* GetEffectParameter(size_t index) const { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } - - /** Adds a local effect parameter to the local list. - @see FCDEffectParameter::Type - @param type The value type of the effect parameter to create. - @return The new local effect parameter. */ - FCDEffectParameter* AddEffectParameter(uint32 type); - - /** Clones the material object. - Everything is cloned, including the effect parameters. - @param clone The material clone. If this pointer is NULL, a new material object - will be created and you will need to release the returned pointer. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - - /** [INTERNAL] Flattens the material, pushing all the effect parameter overrides - into the effect parameter generators and moving all the parameters to the - effect technique level of abstraction. To flatten the material, use the - FCDMaterialInstance::FlattenMaterial function. */ - DEPRECATED(3.05A, not recommended) void Flatten() {} -}; - -#endif // _FCD_MATERIAL_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDMaterial.h + This file contains the FCDMaterail class and the FCDMaterialTechniqueHint structure. +*/ + +#ifndef _FCD_MATERIAL_H_ +#define _FCD_MATERIAL_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDocument; +class FCDEffect; +class FCDEffectParameter; +class FCDEntityReference; + +/** + A technique usage hint for a material. + This structure contains two strings to help applications + choose a technique within the material's instantiated effect + according to their application platform. +*/ +class FCOLLADA_EXPORT FCDMaterialTechniqueHint +{ +public: + fstring platform; /**< A platform semantic. COLLADA defines no platform semantics. */ + fm::string technique; /**< The sid for the technique to choose for the platform. */ +}; + +/** A dynamically-sized list of material platform-technique hints. */ +typedef fm::vector FCDMaterialTechniqueHintList; + +/** + A COLLADA material. + + A COLLADA material is one of many abstraction level that defines how + to render mesh polygon sets. It instantiates an effect and may + overrides some of the effect parameters with its own values. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDMaterial : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + bool ownsEffect; + DeclareParameterPtr(FCDEntityReference, effect, FC("Effect")); + DeclareParameterContainer(FCDEffectParameter, parameters, FC("Effect Parameters")) + FCDMaterialTechniqueHintList techniqueHints; + +public: + /** Constructor: do not use directly. + Instead, use the FCDLibrary::AddEntity function. + @param document The COLLADA document that owns the material. */ + FCDMaterial(FCDocument* document); + + /** Destructor. */ + virtual ~FCDMaterial(); + + /** Retrieves the entity type for this class. This function is part + of the FCDEntity class interface. + @return The entity type: MATERIAL. */ + virtual Type GetType() const { return FCDEntity::MATERIAL; } + + /** Retrieves the effect instantiated for this material. + The parameters of the effect may be overwritten by this material. + @return The instantiated effect. This pointer will be NULL if the material has no rendering. */ + FCDEffect* GetEffect() { return const_cast(const_cast(this)->GetEffect()); } + const FCDEffect* GetEffect() const; /**< See above. */ + + /** Retrieves the effect reference for this material. + Using the FCDEffectReference object for the effect is only useful when + dealing manually with external references. + @return The entity reference for the effect. */ + FCDEntityReference* GetEffectReference() { return effect; } + const FCDEntityReference* GetEffectReference() const { return effect; } + + /** Sets the effect instantiated for this material. + @param _effect The effect instantiated for this material. */ + void SetEffect(FCDEffect* _effect); + + /** Retrieves the list of the material platform-technique hints. + @return The list of material platform-technique hints. */ + FCDMaterialTechniqueHintList& GetTechniqueHints() { return techniqueHints; } + const FCDMaterialTechniqueHintList& GetTechniqueHints() const { return techniqueHints; } /**< See above. */ + + /** Retrieves the number of local effect parameters + @return The number of local effect parameters. */ + inline size_t GetEffectParameterCount() const { return parameters.size(); } + + /** Retrieves a given local effect parameter. + @param index An index. + @return The local effect parameter at the given index. */ + inline FCDEffectParameter* GetEffectParameter(size_t index) { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } + inline const FCDEffectParameter* GetEffectParameter(size_t index) const { FUAssert(index < parameters.size(), return NULL); return parameters.at(index); } + + /** Adds a local effect parameter to the local list. + @see FCDEffectParameter::Type + @param type The value type of the effect parameter to create. + @return The new local effect parameter. */ + FCDEffectParameter* AddEffectParameter(uint32 type); + + /** Clones the material object. + Everything is cloned, including the effect parameters. + @param clone The material clone. If this pointer is NULL, a new material object + will be created and you will need to release the returned pointer. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + + /** [INTERNAL] Flattens the material, pushing all the effect parameter overrides + into the effect parameter generators and moving all the parameters to the + effect technique level of abstraction. To flatten the material, use the + FCDMaterialInstance::FlattenMaterial function. */ + DEPRECATED(3.05A, not recommended) void Flatten() {} +}; + +#endif // _FCD_MATERIAL_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterial.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMorphController.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMorphController.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMorphController.h (revision 24247) @@ -1,194 +1,194 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDMorphController.h - This file contains the FCDMorphController and the FCDMorphTarget classes. -*/ - -#ifndef _FCD_MORPH_CONTROLLER_H_ -#define _FCD_MORPH_CONTROLLER_H_ - -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -class FCDocument; -class FCDAnimated; -class FCDController; -class FCDGeometry; -class FCDMorphController; - -/** - A COLLADA morph target. - A morph target is just a geometric entity with a weight assigned. - The weight may be animated. -*/ -class FCOLLADA_EXPORT FCDMorphTarget : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - FCDMorphController* parent; - DeclareParameterPtr(FCDGeometry, geometry, FC("Mesh")) - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, weight, FC("Weight")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDMorphController::AddTarget function. - @param document The COLLADA document that owns the morph target. - @param parent The morph controller that contains the morph target. */ - FCDMorphTarget(FCDocument* document, FCDMorphController* parent); - - /** Destructor. */ - virtual ~FCDMorphTarget(); - - /** Retrieves the morph controller which contains this target. - @return The parent morpher. */ - FCDMorphController* GetParent() { return parent; } - const FCDMorphController* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the target geometry. - This is what the morphed geometry should look like if - the morphing weight is set to 1.0f. - @return The target geometry. */ - FCDGeometry* GetGeometry() { return geometry; } - const FCDGeometry* GetGeometry() const { return geometry; } /**< See above. */ - - /** Sets the target geometry. - This is what the morphed geometry should look like if - the morphing weight is set to 1.0f. As such, the target geometry - should be similar to the base target geometry. You can verify - this using the FCDMorphController::IsSimilar function. - @param geometry The target geometry. */ - void SetGeometry(FCDGeometry* geometry); - - /** Retrieves the morphing weight. - @return The morphing weight. */ - FCDParameterAnimatableFloat& GetWeight() { return weight; } - const FCDParameterAnimatableFloat& GetWeight() const { return weight; } /**< See above. */ - - /** Sets the morphing weight. - This function has no impact on any animations that target the morphing weight. - @param _weight The morphing weight. */ - void SetWeight(float _weight) { weight = _weight; SetDirtyFlag(); } - - /** Retrieves whether the morphing weight is animated. - @return Whether the morphing weight is animated. */ - DEPRECATED(3.05A, GetWeight().IsAnimated()) bool IsAnimated() const; - - /** Retrieves the animation associated with the morphing weight. - @return The animated value associated with the morphing weight. - This pointer will be NULL if the morphing weight is not animated. */ - DEPRECATED(3.05A, GetWeight().GetAnimated()) FCDAnimated* GetAnimatedWeight(); - DEPRECATED(3.05A, GetWeight().GetAnimated()) const FCDAnimated* GetAnimatedWeight() const; /**< See above. */ -}; - -/** - A COLLADA morpher. - - A morpher holds a base geometry and a set of morph targets - that contains a geometry and a weight. The geometry must be similar to the - base geometry and the weights are used to interpolate the vertex positions - of the base geometry. To be similar, two meshes must have the same number of - vertices and two splines must have the same number of control points. - The morphing weights can be animated. - - There are two interpolation functions defined in COLLADA. - See the FUDaeMorphMethod::Method enumerated type for more information. - - @see FCDMorphTarget FUDaeMorphMethod - @ingroup FCDGeometry -*/ -class FCOLLADA_EXPORT FCDMorphController : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - FCDController* parent; - - DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, method, FC("Method")); // FUDaeMorphMethod::Method - DeclareParameterPtr(FCDEntity, baseTarget, FC("Base Mesh")); - DeclareParameterContainer(FCDMorphTarget, morphTargets, FC("Morph Targets")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDController::CreateMorphController function. - @param document The COLLADA document that owns the morpher. - @param parent The COLLADA controller that contains this morpher. */ - FCDMorphController(FCDocument* document, FCDController* parent); - - /** Destructor. */ - virtual ~FCDMorphController(); - - /** Retrieves the parent entity for the morpher. - @return The parent controller entity. */ - FCDController* GetParent() { return parent; } - const FCDController* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the base entity controlled by this morpher. - This entity may be a geometry or another controller. - @return The base target. */ - FCDEntity* GetBaseTarget() { return baseTarget; } - const FCDEntity* GetBaseTarget() const { return baseTarget; } /**< See above. */ - - /** Sets the base entity controlled by this morpher. - This entity may be a geometry or another controller. - Since the morph targets must be similar to this entity, - all the morph targets that are not similar to the new base entity will be removed. - @param entity The new base entity. */ - void SetBaseTarget(FCDEntity* entity); - - /** Retrieves the list of the morph targets. - All the morph target geometries should be similar to the base entity. - @return The morph targets. */ - DEPRECATED(3.05A, GetTargetCount and GetTarget(index)) void GetTargets() const {} - - /** Retrieves the number of morph targets. - @return The number of morph targets. */ - size_t GetTargetCount() const { return morphTargets.size(); } - - /** Retrieves a specific morph target. - @param index The index of the morph target. - @return The morph target. This pointer will be NULL if the index is out-of-bounds. */ - FCDMorphTarget* GetTarget(size_t index) { FUAssert(index < GetTargetCount(), return NULL); return morphTargets.at(index); } - const FCDMorphTarget* GetTarget(size_t index) const { FUAssert(index < GetTargetCount(), return NULL); return morphTargets.at(index); } /**< See above. */ - - /** Adds a new morph target. - @param geometry The morph target geometry. - @param weight The morphing weight. - @return The new morph target. */ - FCDMorphTarget* AddTarget(FCDGeometry* geometry = NULL, float weight = 0.0f); - - /** Retrieves the method used to interpolate between the different morph targets. - @return The interpolation method. */ - FUDaeMorphMethod::Method GetMethod() const { return (FUDaeMorphMethod::Method) *method; } - - /** Sets the method used to interpolate between the different morph targets. - @param _method The interpolation method. */ - void SetMethod(FUDaeMorphMethod::Method _method) { method = _method; } - - /** Retrieves whether a given entity is similar to the base target. - Entities must be similar to be able to morph between them. - @param entity An entity. - @return Whether the given entity is similar to the base target. */ - bool IsSimilar(FCDEntity* entity); -}; - -#endif // _FCD_MORPH_CONTROLLER_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDMorphController.h + This file contains the FCDMorphController and the FCDMorphTarget classes. +*/ + +#ifndef _FCD_MORPH_CONTROLLER_H_ +#define _FCD_MORPH_CONTROLLER_H_ + +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +class FCDocument; +class FCDAnimated; +class FCDController; +class FCDGeometry; +class FCDMorphController; + +/** + A COLLADA morph target. + A morph target is just a geometric entity with a weight assigned. + The weight may be animated. +*/ +class FCOLLADA_EXPORT FCDMorphTarget : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + FCDMorphController* parent; + DeclareParameterPtr(FCDGeometry, geometry, FC("Mesh")) + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, weight, FC("Weight")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDMorphController::AddTarget function. + @param document The COLLADA document that owns the morph target. + @param parent The morph controller that contains the morph target. */ + FCDMorphTarget(FCDocument* document, FCDMorphController* parent); + + /** Destructor. */ + virtual ~FCDMorphTarget(); + + /** Retrieves the morph controller which contains this target. + @return The parent morpher. */ + FCDMorphController* GetParent() { return parent; } + const FCDMorphController* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the target geometry. + This is what the morphed geometry should look like if + the morphing weight is set to 1.0f. + @return The target geometry. */ + FCDGeometry* GetGeometry() { return geometry; } + const FCDGeometry* GetGeometry() const { return geometry; } /**< See above. */ + + /** Sets the target geometry. + This is what the morphed geometry should look like if + the morphing weight is set to 1.0f. As such, the target geometry + should be similar to the base target geometry. You can verify + this using the FCDMorphController::IsSimilar function. + @param geometry The target geometry. */ + void SetGeometry(FCDGeometry* geometry); + + /** Retrieves the morphing weight. + @return The morphing weight. */ + FCDParameterAnimatableFloat& GetWeight() { return weight; } + const FCDParameterAnimatableFloat& GetWeight() const { return weight; } /**< See above. */ + + /** Sets the morphing weight. + This function has no impact on any animations that target the morphing weight. + @param _weight The morphing weight. */ + void SetWeight(float _weight) { weight = _weight; SetDirtyFlag(); } + + /** Retrieves whether the morphing weight is animated. + @return Whether the morphing weight is animated. */ + DEPRECATED(3.05A, GetWeight().IsAnimated()) bool IsAnimated() const; + + /** Retrieves the animation associated with the morphing weight. + @return The animated value associated with the morphing weight. + This pointer will be NULL if the morphing weight is not animated. */ + DEPRECATED(3.05A, GetWeight().GetAnimated()) FCDAnimated* GetAnimatedWeight(); + DEPRECATED(3.05A, GetWeight().GetAnimated()) const FCDAnimated* GetAnimatedWeight() const; /**< See above. */ +}; + +/** + A COLLADA morpher. + + A morpher holds a base geometry and a set of morph targets + that contains a geometry and a weight. The geometry must be similar to the + base geometry and the weights are used to interpolate the vertex positions + of the base geometry. To be similar, two meshes must have the same number of + vertices and two splines must have the same number of control points. + The morphing weights can be animated. + + There are two interpolation functions defined in COLLADA. + See the FUDaeMorphMethod::Method enumerated type for more information. + + @see FCDMorphTarget FUDaeMorphMethod + @ingroup FCDGeometry +*/ +class FCOLLADA_EXPORT FCDMorphController : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + FCDController* parent; + + DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, method, FC("Method")); // FUDaeMorphMethod::Method + DeclareParameterPtr(FCDEntity, baseTarget, FC("Base Mesh")); + DeclareParameterContainer(FCDMorphTarget, morphTargets, FC("Morph Targets")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDController::CreateMorphController function. + @param document The COLLADA document that owns the morpher. + @param parent The COLLADA controller that contains this morpher. */ + FCDMorphController(FCDocument* document, FCDController* parent); + + /** Destructor. */ + virtual ~FCDMorphController(); + + /** Retrieves the parent entity for the morpher. + @return The parent controller entity. */ + FCDController* GetParent() { return parent; } + const FCDController* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the base entity controlled by this morpher. + This entity may be a geometry or another controller. + @return The base target. */ + FCDEntity* GetBaseTarget() { return baseTarget; } + const FCDEntity* GetBaseTarget() const { return baseTarget; } /**< See above. */ + + /** Sets the base entity controlled by this morpher. + This entity may be a geometry or another controller. + Since the morph targets must be similar to this entity, + all the morph targets that are not similar to the new base entity will be removed. + @param entity The new base entity. */ + void SetBaseTarget(FCDEntity* entity); + + /** Retrieves the list of the morph targets. + All the morph target geometries should be similar to the base entity. + @return The morph targets. */ + DEPRECATED(3.05A, GetTargetCount and GetTarget(index)) void GetTargets() const {} + + /** Retrieves the number of morph targets. + @return The number of morph targets. */ + size_t GetTargetCount() const { return morphTargets.size(); } + + /** Retrieves a specific morph target. + @param index The index of the morph target. + @return The morph target. This pointer will be NULL if the index is out-of-bounds. */ + FCDMorphTarget* GetTarget(size_t index) { FUAssert(index < GetTargetCount(), return NULL); return morphTargets.at(index); } + const FCDMorphTarget* GetTarget(size_t index) const { FUAssert(index < GetTargetCount(), return NULL); return morphTargets.at(index); } /**< See above. */ + + /** Adds a new morph target. + @param geometry The morph target geometry. + @param weight The morphing weight. + @return The new morph target. */ + FCDMorphTarget* AddTarget(FCDGeometry* geometry = NULL, float weight = 0.0f); + + /** Retrieves the method used to interpolate between the different morph targets. + @return The interpolation method. */ + FUDaeMorphMethod::Method GetMethod() const { return (FUDaeMorphMethod::Method) *method; } + + /** Sets the method used to interpolate between the different morph targets. + @param _method The interpolation method. */ + void SetMethod(FUDaeMorphMethod::Method _method) { method = _method; } + + /** Retrieves whether a given entity is similar to the base target. + Entities must be similar to be able to morph between them. + @param entity An entity. + @return Whether the given entity is similar to the base target. */ + bool IsSimilar(FCDEntity* entity); +}; + +#endif // _FCD_MORPH_CONTROLLER_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMorphController.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryInstance.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryInstance.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryInstance.cpp (revision 24247) @@ -1,143 +1,143 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterFactory.h" -#include "FCDocument/FCDEntity.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDGeometryInstance.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDGeometrySpline.h" -#include "FCDocument/FCDGeometryNURBSSurface.h" -#include "FCDocument/FCDMaterial.h" -#include "FCDocument/FCDMaterialInstance.h" -#include "FUtils/FUUniqueStringMap.h" - -// -// FCDGeometryInstance -// - -ImplementObjectType(FCDGeometryInstance); -ImplementParameterObject(FCDGeometryInstance, FCDMaterialInstance, materials, new FCDMaterialInstance(parent->GetDocument(), parent)) -ImplementParameterObjectNoCtr(FCDGeometryInstance, FCDEffectParameter, parameters) - -FCDGeometryInstance::FCDGeometryInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType) -: FCDEntityInstance(document, parent, entityType) -, InitializeParameterNoArg(materials) -, InitializeParameterNoArg(parameters) -{ -} - -FCDGeometryInstance::~FCDGeometryInstance() -{ -} - -FCDEffectParameter* FCDGeometryInstance::AddEffectParameter(uint32 type) -{ - FCDEffectParameter* parameter = FCDEffectParameterFactory::Create(GetDocument(), type); - parameters.push_back(parameter); - SetNewChildFlag(); - return parameter; -} - -// Access Bound Materials -const FCDMaterialInstance* FCDGeometryInstance::FindMaterialInstance(const fchar* semantic) const -{ - for (const FCDMaterialInstance** itB = materials.begin(); itB != materials.end(); ++itB) - { - if ((*itB)->GetSemantic() == semantic) return (*itB); - } - return NULL; -} - -FCDMaterialInstance* FCDGeometryInstance::AddMaterialInstance() -{ - FCDMaterialInstance* instance = new FCDMaterialInstance(GetDocument(), this); - materials.push_back(instance); - SetNewChildFlag(); - return instance; -} - -FCDMaterialInstance* FCDGeometryInstance::AddMaterialInstance(FCDMaterial* material, FCDGeometryPolygons* polygons) -{ - FCDMaterialInstance* instance = AddMaterialInstance(); - instance->SetMaterial(material); - if (polygons != NULL) - { - const fstring& semantic = polygons->GetMaterialSemantic(); - if (!semantic.empty()) - { - instance->SetSemantic(polygons->GetMaterialSemantic()); - } - else - { - // Generate a semantic. - fstring semantic = TO_FSTRING(material->GetDaeId()) + TO_FSTRING(polygons->GetFaceOffset()); - polygons->SetMaterialSemantic(semantic); - instance->SetSemantic(semantic); - } - } - return instance; -} - - -FCDMaterialInstance* FCDGeometryInstance::AddMaterialInstance(FCDMaterial* material, const fchar* semantic) -{ - FCDMaterialInstance* instance = AddMaterialInstance(); - instance->SetMaterial(material); - instance->SetSemantic(semantic); - return instance; -} - -FCDEntityInstance* FCDGeometryInstance::Clone(FCDEntityInstance* _clone) const -{ - FCDGeometryInstance* clone = NULL; - if (_clone == NULL) clone = new FCDGeometryInstance(const_cast(GetDocument()), const_cast(GetParent()), GetEntityType()); - else if (!_clone->HasType(FCDGeometryInstance::GetClassType())) return Parent::Clone(_clone); - else clone = (FCDGeometryInstance*) _clone; - - Parent::Clone(clone); - - size_t parameterCount = parameters.size(); - for (size_t p = 0; p < parameterCount; ++p) - { - FCDEffectParameter* clonedParameter = clone->AddEffectParameter(parameters[p]->GetType()); - parameters[p]->Clone(clonedParameter); - } - - // Clone the material instances. - for (const FCDMaterialInstance** it = materials.begin(); it != materials.end(); ++it) - { - FCDMaterialInstance* materialInstance = clone->AddMaterialInstance(); - (*it)->Clone(materialInstance); - } - - return clone; -} - -void FCDGeometryInstance::CleanSubId(FUSUniqueStringMap* parentStringMap) -{ - Parent::CleanSubId(parentStringMap); - FUSUniqueStringMap myStringMap; - - size_t materialCount = materials.size(); - for (size_t i = 0; i < materialCount; ++i) - { - materials[i]->CleanSubId(&myStringMap); - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterFactory.h" +#include "FCDocument/FCDEntity.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDGeometryInstance.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDGeometrySpline.h" +#include "FCDocument/FCDGeometryNURBSSurface.h" +#include "FCDocument/FCDMaterial.h" +#include "FCDocument/FCDMaterialInstance.h" +#include "FUtils/FUUniqueStringMap.h" + +// +// FCDGeometryInstance +// + +ImplementObjectType(FCDGeometryInstance); +ImplementParameterObject(FCDGeometryInstance, FCDMaterialInstance, materials, new FCDMaterialInstance(parent->GetDocument(), parent)) +ImplementParameterObjectNoCtr(FCDGeometryInstance, FCDEffectParameter, parameters) + +FCDGeometryInstance::FCDGeometryInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType) +: FCDEntityInstance(document, parent, entityType) +, InitializeParameterNoArg(materials) +, InitializeParameterNoArg(parameters) +{ +} + +FCDGeometryInstance::~FCDGeometryInstance() +{ +} + +FCDEffectParameter* FCDGeometryInstance::AddEffectParameter(uint32 type) +{ + FCDEffectParameter* parameter = FCDEffectParameterFactory::Create(GetDocument(), type); + parameters.push_back(parameter); + SetNewChildFlag(); + return parameter; +} + +// Access Bound Materials +const FCDMaterialInstance* FCDGeometryInstance::FindMaterialInstance(const fchar* semantic) const +{ + for (const FCDMaterialInstance** itB = materials.begin(); itB != materials.end(); ++itB) + { + if ((*itB)->GetSemantic() == semantic) return (*itB); + } + return NULL; +} + +FCDMaterialInstance* FCDGeometryInstance::AddMaterialInstance() +{ + FCDMaterialInstance* instance = new FCDMaterialInstance(GetDocument(), this); + materials.push_back(instance); + SetNewChildFlag(); + return instance; +} + +FCDMaterialInstance* FCDGeometryInstance::AddMaterialInstance(FCDMaterial* material, FCDGeometryPolygons* polygons) +{ + FCDMaterialInstance* instance = AddMaterialInstance(); + instance->SetMaterial(material); + if (polygons != NULL) + { + const fstring& semantic = polygons->GetMaterialSemantic(); + if (!semantic.empty()) + { + instance->SetSemantic(polygons->GetMaterialSemantic()); + } + else + { + // Generate a semantic. + fstring semantic = TO_FSTRING(material->GetDaeId()) + TO_FSTRING(polygons->GetFaceOffset()); + polygons->SetMaterialSemantic(semantic); + instance->SetSemantic(semantic); + } + } + return instance; +} + + +FCDMaterialInstance* FCDGeometryInstance::AddMaterialInstance(FCDMaterial* material, const fchar* semantic) +{ + FCDMaterialInstance* instance = AddMaterialInstance(); + instance->SetMaterial(material); + instance->SetSemantic(semantic); + return instance; +} + +FCDEntityInstance* FCDGeometryInstance::Clone(FCDEntityInstance* _clone) const +{ + FCDGeometryInstance* clone = NULL; + if (_clone == NULL) clone = new FCDGeometryInstance(const_cast(GetDocument()), const_cast(GetParent()), GetEntityType()); + else if (!_clone->HasType(FCDGeometryInstance::GetClassType())) return Parent::Clone(_clone); + else clone = (FCDGeometryInstance*) _clone; + + Parent::Clone(clone); + + size_t parameterCount = parameters.size(); + for (size_t p = 0; p < parameterCount; ++p) + { + FCDEffectParameter* clonedParameter = clone->AddEffectParameter(parameters[p]->GetType()); + parameters[p]->Clone(clonedParameter); + } + + // Clone the material instances. + for (const FCDMaterialInstance** it = materials.begin(); it != materials.end(); ++it) + { + FCDMaterialInstance* materialInstance = clone->AddMaterialInstance(); + (*it)->Clone(materialInstance); + } + + return clone; +} + +void FCDGeometryInstance::CleanSubId(FUSUniqueStringMap* parentStringMap) +{ + Parent::CleanSubId(parentStringMap); + FUSUniqueStringMap myStringMap; + + size_t materialCount = materials.size(); + for (size_t i = 0; i < materialCount; ++i) + { + materials[i]->CleanSubId(&myStringMap); + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryInstance.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryNURBSSurface.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryNURBSSurface.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryNURBSSurface.cpp (revision 24247) @@ -1,9 +1,9 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryNURBSSurface.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsInput.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsInput.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsInput.cpp (revision 24247) @@ -1,138 +1,138 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDGeometryPolygonsInput.h" -#include "FCDocument/FCDGeometrySource.h" - -// -// FCDGeometryPolygonsInput -// - -ImplementObjectType(FCDGeometryPolygonsInput); -ImplementParameterObject(FCDGeometryPolygonsInput, FCDGeometrySource, source, new FCDGeometrySource(parent->GetDocument())); - -FCDGeometryPolygonsInput::FCDGeometryPolygonsInput(FCDocument* document, FCDGeometryPolygons* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(source) -, InitializeParameter(set, -1) -, InitializeParameter(offset, 0) -, InitializeParameterNoArg(indices) -{ -} - -FCDGeometryPolygonsInput::~FCDGeometryPolygonsInput() -{ - if (source != NULL) - { - UntrackObject(source); - source = NULL; - } -} - -FUDaeGeometryInput::Semantic FCDGeometryPolygonsInput::GetSemantic() const -{ - FUAssert(source != NULL, return FUDaeGeometryInput::UNKNOWN); - return source->GetType(); -} - -// Sets the referenced source -void FCDGeometryPolygonsInput::SetSource(FCDGeometrySource* _source) -{ - // Untrack the old source and track the new source - if (source != NULL) UntrackObject(source); - source = _source; - if (source != NULL) TrackObject(source); -} - -// Callback when the tracked source is released. -void FCDGeometryPolygonsInput::OnObjectReleased(FUTrackable* object) -{ - if (source == object) - { - source = NULL; - - // Verify whether we own/share the index list. - if (!indices.empty()) - { - size_t inputCount = parent->GetInputCount(); - for (size_t i = 0; i < inputCount; ++i) - { - FCDGeometryPolygonsInput* other = parent->GetInput(i); - if (other->offset == offset) - { - // Move the shared list of indices to the other input. - other->indices = indices; - indices.clear(); - break; - } - } - } - } -} - -void FCDGeometryPolygonsInput::SetIndices(const uint32* _indices, size_t count) -{ - FUParameterUInt32List& indices = FindIndices(); - if (count > 0) - { - indices.resize(count); - memcpy(&indices.front(), _indices, count * sizeof(uint32)); - } - else indices.clear(); -} - -void FCDGeometryPolygonsInput::SetIndexCount(size_t count) -{ - FUParameterUInt32List& indices = FindIndices(); - indices.resize(count); -} - -const uint32* FCDGeometryPolygonsInput::GetIndices() const -{ - return FindIndices().begin(); -} - -size_t FCDGeometryPolygonsInput::GetIndexCount() const -{ - return FindIndices().size(); -} - -void FCDGeometryPolygonsInput::ReserveIndexCount(size_t count) -{ - FUParameterUInt32List& indices = FindIndices(); - if (count > indices.size()) indices.reserve(count); -} - -void FCDGeometryPolygonsInput::AddIndex(uint32 index) -{ - FindIndices().push_back(index); -} - -void FCDGeometryPolygonsInput::AddIndices(const UInt32List& _indices) -{ - FUParameterUInt32List& indices = FindIndices(); - indices.insert(indices.size(), _indices.begin(), _indices.size()); -} - -const FUParameterUInt32List& FCDGeometryPolygonsInput::FindIndices() const -{ - if (OwnsIndices()) return indices; // Early exit for local owner. - - size_t inputCount = parent->GetInputCount(); - for (size_t i = 0; i < inputCount; ++i) - { - FCDGeometryPolygonsInput* input = parent->GetInput(i); - if (input->offset == offset && input->OwnsIndices()) return input->indices; - } - - // No indices allocated yet. - return indices; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDGeometryPolygonsInput.h" +#include "FCDocument/FCDGeometrySource.h" + +// +// FCDGeometryPolygonsInput +// + +ImplementObjectType(FCDGeometryPolygonsInput); +ImplementParameterObject(FCDGeometryPolygonsInput, FCDGeometrySource, source, new FCDGeometrySource(parent->GetDocument())); + +FCDGeometryPolygonsInput::FCDGeometryPolygonsInput(FCDocument* document, FCDGeometryPolygons* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(source) +, InitializeParameter(set, -1) +, InitializeParameter(offset, 0) +, InitializeParameterNoArg(indices) +{ +} + +FCDGeometryPolygonsInput::~FCDGeometryPolygonsInput() +{ + if (source != NULL) + { + UntrackObject(source); + source = NULL; + } +} + +FUDaeGeometryInput::Semantic FCDGeometryPolygonsInput::GetSemantic() const +{ + FUAssert(source != NULL, return FUDaeGeometryInput::UNKNOWN); + return source->GetType(); +} + +// Sets the referenced source +void FCDGeometryPolygonsInput::SetSource(FCDGeometrySource* _source) +{ + // Untrack the old source and track the new source + if (source != NULL) UntrackObject(source); + source = _source; + if (source != NULL) TrackObject(source); +} + +// Callback when the tracked source is released. +void FCDGeometryPolygonsInput::OnObjectReleased(FUTrackable* object) +{ + if (source == object) + { + source = NULL; + + // Verify whether we own/share the index list. + if (!indices.empty()) + { + size_t inputCount = parent->GetInputCount(); + for (size_t i = 0; i < inputCount; ++i) + { + FCDGeometryPolygonsInput* other = parent->GetInput(i); + if (other->offset == offset) + { + // Move the shared list of indices to the other input. + other->indices = indices; + indices.clear(); + break; + } + } + } + } +} + +void FCDGeometryPolygonsInput::SetIndices(const uint32* _indices, size_t count) +{ + FUParameterUInt32List& indices = FindIndices(); + if (count > 0) + { + indices.resize(count); + memcpy(&indices.front(), _indices, count * sizeof(uint32)); + } + else indices.clear(); +} + +void FCDGeometryPolygonsInput::SetIndexCount(size_t count) +{ + FUParameterUInt32List& indices = FindIndices(); + indices.resize(count); +} + +const uint32* FCDGeometryPolygonsInput::GetIndices() const +{ + return FindIndices().begin(); +} + +size_t FCDGeometryPolygonsInput::GetIndexCount() const +{ + return FindIndices().size(); +} + +void FCDGeometryPolygonsInput::ReserveIndexCount(size_t count) +{ + FUParameterUInt32List& indices = FindIndices(); + if (count > indices.size()) indices.reserve(count); +} + +void FCDGeometryPolygonsInput::AddIndex(uint32 index) +{ + FindIndices().push_back(index); +} + +void FCDGeometryPolygonsInput::AddIndices(const UInt32List& _indices) +{ + FUParameterUInt32List& indices = FindIndices(); + indices.insert(indices.size(), _indices.begin(), _indices.size()); +} + +const FUParameterUInt32List& FCDGeometryPolygonsInput::FindIndices() const +{ + if (OwnsIndices()) return indices; // Early exit for local owner. + + size_t inputCount = parent->GetInputCount(); + for (size_t i = 0; i < inputCount; ++i) + { + FCDGeometryPolygonsInput* input = parent->GetInput(i); + if (input->offset == offset && input->OwnsIndices()) return input->indices; + } + + // No indices allocated yet. + return indices; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometryPolygonsInput.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySource.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySource.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySource.cpp (revision 24247) @@ -1,81 +1,81 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDGeometrySource.h" -#include "FUtils/FUDaeEnum.h" - -// -// FCDGeometrySource -// - -ImplementObjectType(FCDGeometrySource); -ImplementParameterObject(FCDGeometrySource, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); - -FCDGeometrySource::FCDGeometrySource(FCDocument* document) -: FCDObjectWithId(document, "GeometrySource") -, InitializeParameterNoArg(name) -, InitializeParameterAnimatableNoArg(sourceData) -, InitializeParameter(stride, 0) -, InitializeParameter(sourceType, (uint32) FUDaeGeometryInput::UNKNOWN) -, InitializeParameterNoArg(extra) -{ -} - -FCDGeometrySource::~FCDGeometrySource() -{ -} - -void FCDGeometrySource::SetDataCount(size_t count) -{ - sourceData.resize(count); - SetDirtyFlag(); -} - -FCDGeometrySource* FCDGeometrySource::Clone(FCDGeometrySource* clone) const -{ - if (clone == NULL) clone = new FCDGeometrySource(const_cast(GetDocument())); - FCDObjectWithId::Clone(clone); - clone->name = name; - clone->sourceType = sourceType; - - // Clone the data of this source. - clone->stride = stride; - clone->sourceData.GetDataList() = sourceData.GetDataList(); // this should be replaced by an operator= where even the FCDAnimated* list is copied. - clone->sourceType = sourceType; - - // Clone the extra information. - if (extra != NULL) - { - extra->Clone(clone->GetExtra()); - } - - return clone; -} - -void FCDGeometrySource::SetData(const FloatList& _sourceData, uint32 _sourceStride, size_t offset, size_t count) -{ - // Remove all the data currently held by the source. - sourceData.clear(); - stride = _sourceStride; - - // Check the given bounds - size_t beg = min(offset, _sourceData.size()), end; - if (count == 0) end = _sourceData.size(); - else end = min(count + offset, _sourceData.size()); - sourceData.insert(0, _sourceData.begin() + beg, end - beg); - - SetDirtyFlag(); -} - -FCDExtra* FCDGeometrySource::GetExtra() -{ - return (extra != NULL) ? extra : extra = new FCDExtra(GetDocument(), this); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDGeometrySource.h" +#include "FUtils/FUDaeEnum.h" + +// +// FCDGeometrySource +// + +ImplementObjectType(FCDGeometrySource); +ImplementParameterObject(FCDGeometrySource, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); + +FCDGeometrySource::FCDGeometrySource(FCDocument* document) +: FCDObjectWithId(document, "GeometrySource") +, InitializeParameterNoArg(name) +, InitializeParameterAnimatableNoArg(sourceData) +, InitializeParameter(stride, 0) +, InitializeParameter(sourceType, (uint32) FUDaeGeometryInput::UNKNOWN) +, InitializeParameterNoArg(extra) +{ +} + +FCDGeometrySource::~FCDGeometrySource() +{ +} + +void FCDGeometrySource::SetDataCount(size_t count) +{ + sourceData.resize(count); + SetDirtyFlag(); +} + +FCDGeometrySource* FCDGeometrySource::Clone(FCDGeometrySource* clone) const +{ + if (clone == NULL) clone = new FCDGeometrySource(const_cast(GetDocument())); + FCDObjectWithId::Clone(clone); + clone->name = name; + clone->sourceType = sourceType; + + // Clone the data of this source. + clone->stride = stride; + clone->sourceData.GetDataList() = sourceData.GetDataList(); // this should be replaced by an operator= where even the FCDAnimated* list is copied. + clone->sourceType = sourceType; + + // Clone the extra information. + if (extra != NULL) + { + extra->Clone(clone->GetExtra()); + } + + return clone; +} + +void FCDGeometrySource::SetData(const FloatList& _sourceData, uint32 _sourceStride, size_t offset, size_t count) +{ + // Remove all the data currently held by the source. + sourceData.clear(); + stride = _sourceStride; + + // Check the given bounds + size_t beg = min(offset, _sourceData.size()), end; + if (count == 0) end = _sourceData.size(); + else end = min(count + offset, _sourceData.size()); + sourceData.insert(0, _sourceData.begin() + beg, end - beg); + + SetDirtyFlag(); +} + +FCDExtra* FCDGeometrySource::GetExtra() +{ + return (extra != NULL) ? extra : extra = new FCDExtra(GetDocument(), this); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDGeometrySource.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDImage.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDImage.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDImage.cpp (revision 24247) @@ -1,69 +1,69 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDImage.h" -#include "FUtils/FUUri.h" -#include "FUtils/FUFileManager.h" - -// -// FCDImage -// - -ImplementObjectType(FCDImage); - -FCDImage::FCDImage(FCDocument* document) -: FCDEntity(document, "Image") -, InitializeParameterNoArg(filename) -, InitializeParameter(width, 0) -, InitializeParameter(height, 0) -, InitializeParameter(depth, 0) -{ -} - -FCDImage::~FCDImage() -{ -} - -void FCDImage::SetFilename(const fstring& _filename) -{ - ResetVideoFlag(); - if (_filename.empty()) filename->clear(); - else - { - filename = GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(_filename); - } - SetDirtyFlag(); -} - -// Copies the image entity into a clone. -FCDEntity* FCDImage::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDImage* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDImage(const_cast(GetDocument())); - else if (_clone->HasType(FCDImage::GetClassType())) clone = (FCDImage*) _clone; - - FCDEntity::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - clone->width = width; - clone->height = height; - clone->depth = depth; - clone->filename = filename; - clone->SetVideoFlag(GetVideoFlag()); - } - return _clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDImage.h" +#include "FUtils/FUUri.h" +#include "FUtils/FUFileManager.h" + +// +// FCDImage +// + +ImplementObjectType(FCDImage); + +FCDImage::FCDImage(FCDocument* document) +: FCDEntity(document, "Image") +, InitializeParameterNoArg(filename) +, InitializeParameter(width, 0) +, InitializeParameter(height, 0) +, InitializeParameter(depth, 0) +{ +} + +FCDImage::~FCDImage() +{ +} + +void FCDImage::SetFilename(const fstring& _filename) +{ + ResetVideoFlag(); + if (_filename.empty()) filename->clear(); + else + { + filename = GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(_filename); + } + SetDirtyFlag(); +} + +// Copies the image entity into a clone. +FCDEntity* FCDImage::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDImage* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDImage(const_cast(GetDocument())); + else if (_clone->HasType(FCDImage::GetClassType())) clone = (FCDImage*) _clone; + + FCDEntity::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + clone->width = width; + clone->height = height; + clone->depth = depth; + clone->filename = filename; + clone->SetVideoFlag(GetVideoFlag()); + } + return _clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDImage.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLight.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLight.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLight.cpp (revision 24247) @@ -1,43 +1,43 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument.h" -#include "FCDLight.h" - -// -// FCDLight -// - -ImplementObjectType(FCDLight); - -FCDLight::FCDLight(FCDocument* document) -: FCDTargetedEntity(document, "Light") -, InitializeParameterAnimatable(color, FMVector3::One) -, InitializeParameterAnimatable(intensity, 1.0f) -, InitializeParameter(lightType, FCDLight::POINT) -, InitializeParameterAnimatable(constantAttenuationFactor, 1.0f) -, InitializeParameterAnimatable(linearAttenuationFactor, 0.0f) -, InitializeParameterAnimatable(quadracticAttenuationFactor, 0.0f) -, InitializeParameterAnimatable(fallOffExponent, 1.0f) -, InitializeParameterAnimatable(fallOffAngle, 5.0f) -, InitializeParameterAnimatable(outerAngle, 5.0f) -, InitializeParameterAnimatable(penumbraAngle, 0.0f) // not used by default -, InitializeParameterAnimatable(dropoff, 0.0f) // not used by default -{ -} - -FCDLight::~FCDLight() -{ -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument.h" +#include "FCDLight.h" + +// +// FCDLight +// + +ImplementObjectType(FCDLight); + +FCDLight::FCDLight(FCDocument* document) +: FCDTargetedEntity(document, "Light") +, InitializeParameterAnimatable(color, FMVector3::One) +, InitializeParameterAnimatable(intensity, 1.0f) +, InitializeParameter(lightType, FCDLight::POINT) +, InitializeParameterAnimatable(constantAttenuationFactor, 1.0f) +, InitializeParameterAnimatable(linearAttenuationFactor, 0.0f) +, InitializeParameterAnimatable(quadracticAttenuationFactor, 0.0f) +, InitializeParameterAnimatable(fallOffExponent, 1.0f) +, InitializeParameterAnimatable(fallOffAngle, 5.0f) +, InitializeParameterAnimatable(outerAngle, 5.0f) +, InitializeParameterAnimatable(penumbraAngle, 0.0f) // not used by default +, InitializeParameterAnimatable(dropoff, 0.0f) // not used by default +{ +} + +FCDLight::~FCDLight() +{ +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDLight.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterial.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterial.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterial.cpp (revision 24247) @@ -1,112 +1,112 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffect.h" -#include "FCDocument/FCDEffectTools.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterFactory.h" -#include "FCDocument/FCDEntityReference.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDMaterial.h" - -// -// FCDMaterial -// - -ImplementObjectType(FCDMaterial); -ImplementParameterObjectNoCtr(FCDMaterial, FCDEntityReference, effect); -ImplementParameterObjectNoCtr(FCDMaterial, FCDEffectParameter, parameters); - -FCDMaterial::FCDMaterial(FCDocument* document) -: FCDEntity(document, "VisualMaterial") -, ownsEffect(false) -, InitializeParameterNoArg(effect) -, InitializeParameterNoArg(parameters) -{ - effect = new FCDEntityReference(document, this); -} - -FCDMaterial::~FCDMaterial() -{ - if (ownsEffect) - { - FCDEntity* _effect = effect->GetEntity(); - SAFE_RELEASE(_effect); - } - SAFE_RELEASE(effect); - techniqueHints.clear(); -} - -FCDEffectParameter* FCDMaterial::AddEffectParameter(uint32 type) -{ - FCDEffectParameter* parameter = FCDEffectParameterFactory::Create(GetDocument(), type); - parameters.push_back(parameter); - SetNewChildFlag(); - return parameter; -} - -const FCDEffect* FCDMaterial::GetEffect() const -{ - FUAssert(effect != NULL, return NULL); - const FCDEntity* entity = effect->GetEntity(); - if (entity != NULL && entity->HasType(FCDEffect::GetClassType())) return (const FCDEffect*) entity; - else return NULL; -} - -void FCDMaterial::SetEffect(FCDEffect* _effect) -{ - effect->SetEntity(_effect); - SetNewChildFlag(); -} - -// Cloning -FCDEntity* FCDMaterial::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDMaterial* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDMaterial(const_cast(GetDocument())); - else if (_clone->HasType(FCDMaterial::GetClassType())) clone = (FCDMaterial*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - // Clone the effect and the local list of parameters - const FCDEffect* _effect = GetEffect(); - if (_effect != NULL) - { - if (cloneChildren) - { - clone->ownsEffect = true; - FCDEffect* clonedEffect = clone->GetDocument()->GetEffectLibrary()->AddEntity(); - _effect->Clone(clonedEffect, cloneChildren); - } - else - { - clone->SetEffect(const_cast(_effect)); - } - } - - // Clone the effect parameters - size_t parameterCount = parameters.size(); - for (size_t p = 0; p < parameterCount; ++p) - { - FCDEffectParameter* parameter = clone->AddEffectParameter(parameters[p]->GetType()); - parameters[p]->Clone(parameter); - } - } - - return _clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffect.h" +#include "FCDocument/FCDEffectTools.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterFactory.h" +#include "FCDocument/FCDEntityReference.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDMaterial.h" + +// +// FCDMaterial +// + +ImplementObjectType(FCDMaterial); +ImplementParameterObjectNoCtr(FCDMaterial, FCDEntityReference, effect); +ImplementParameterObjectNoCtr(FCDMaterial, FCDEffectParameter, parameters); + +FCDMaterial::FCDMaterial(FCDocument* document) +: FCDEntity(document, "VisualMaterial") +, ownsEffect(false) +, InitializeParameterNoArg(effect) +, InitializeParameterNoArg(parameters) +{ + effect = new FCDEntityReference(document, this); +} + +FCDMaterial::~FCDMaterial() +{ + if (ownsEffect) + { + FCDEntity* _effect = effect->GetEntity(); + SAFE_RELEASE(_effect); + } + SAFE_RELEASE(effect); + techniqueHints.clear(); +} + +FCDEffectParameter* FCDMaterial::AddEffectParameter(uint32 type) +{ + FCDEffectParameter* parameter = FCDEffectParameterFactory::Create(GetDocument(), type); + parameters.push_back(parameter); + SetNewChildFlag(); + return parameter; +} + +const FCDEffect* FCDMaterial::GetEffect() const +{ + FUAssert(effect != NULL, return NULL); + const FCDEntity* entity = effect->GetEntity(); + if (entity != NULL && entity->HasType(FCDEffect::GetClassType())) return (const FCDEffect*) entity; + else return NULL; +} + +void FCDMaterial::SetEffect(FCDEffect* _effect) +{ + effect->SetEntity(_effect); + SetNewChildFlag(); +} + +// Cloning +FCDEntity* FCDMaterial::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDMaterial* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDMaterial(const_cast(GetDocument())); + else if (_clone->HasType(FCDMaterial::GetClassType())) clone = (FCDMaterial*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + // Clone the effect and the local list of parameters + const FCDEffect* _effect = GetEffect(); + if (_effect != NULL) + { + if (cloneChildren) + { + clone->ownsEffect = true; + FCDEffect* clonedEffect = clone->GetDocument()->GetEffectLibrary()->AddEntity(); + _effect->Clone(clonedEffect, cloneChildren); + } + else + { + clone->SetEffect(const_cast(_effect)); + } + } + + // Clone the effect parameters + size_t parameterCount = parameters.size(); + for (size_t p = 0; p < parameterCount; ++p) + { + FCDEffectParameter* parameter = clone->AddEffectParameter(parameters[p]->GetType()); + parameters[p]->Clone(parameter); + } + } + + return _clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMaterial.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMorphController.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMorphController.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMorphController.cpp (revision 24247) @@ -1,216 +1,216 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDGeometrySource.h" -#include "FCDocument/FCDGeometrySpline.h" -#include "FCDocument/FCDMorphController.h" - -// -// FCDMorphController -// - -ImplementObjectType(FCDMorphController); -ImplementParameterObjectNoCtr(FCDMorphController, FCDEntity, baseTarget); -ImplementParameterObject(FCDMorphController, FCDMorphTarget, morphTargets, new FCDMorphTarget(parent->GetDocument(), parent)); - -FCDMorphController::FCDMorphController(FCDocument* document, FCDController* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameter(method, FUDaeMorphMethod::NORMALIZED) -, InitializeParameterNoArg(baseTarget) -, InitializeParameterNoArg(morphTargets) -{ -} - -FCDMorphController::~FCDMorphController() -{ - parent = NULL; -} - -// Changes the base target of the morpher -void FCDMorphController::SetBaseTarget(FCDEntity* entity) -{ - baseTarget = NULL; - - // Retrieve the actual base entity, as you can chain controllers. - FCDEntity* baseEntity = entity; - if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::CONTROLLER) - { - baseEntity = ((FCDController*) baseEntity)->GetBaseGeometry(); - } - if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::GEOMETRY) - { - baseTarget = entity; - - // Remove the old morph targets which are not similar, anymore, to the new base entity. - for (size_t i = 0; i < morphTargets.size();) - { - if (IsSimilar(morphTargets[i]->GetGeometry())) - { - ++i; - } - else - { - morphTargets[i]->Release(); - } - } - } - else - { - // The new base target is not valid. - morphTargets.clear(); - } - - SetNewChildFlag(); -} - -// Adds a new morph target. -FCDMorphTarget* FCDMorphController::AddTarget(FCDGeometry* geometry, float weight) -{ - FCDMorphTarget* target = NULL; - // It is legal to add targets with out a base geometry - if (baseTarget == NULL || IsSimilar(geometry)) - { - target = new FCDMorphTarget(GetDocument(), this); - morphTargets.push_back(target); - target->SetGeometry(geometry); - target->SetWeight(weight); - } - SetNewChildFlag(); - return target; -} - -// Retrieves whether a given entity is similar to the base target. -bool FCDMorphController::IsSimilar(FCDEntity* entity) -{ - bool similar = false; - if (entity != NULL && baseTarget != NULL) - { - size_t vertexCount = 0; - bool isMesh = false; - bool isSpline = false; - - // Find the number of vertices in the base target - FCDEntity* baseEntity = baseTarget; - if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::CONTROLLER) - { - baseEntity = ((FCDController*) baseEntity)->GetBaseGeometry(); - } - if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::GEOMETRY) - { - FCDGeometry* g = (FCDGeometry*) baseEntity; - if (g->IsMesh()) - { - isMesh = true; - FCDGeometryMesh* m = g->GetMesh(); - FCDGeometrySource* positions = m->GetPositionSource(); - if (positions != NULL) - { - vertexCount = positions->GetValueCount(); - } - } - - if (g->IsSpline()) - { - isSpline = true; - FCDGeometrySpline* s = g->GetSpline(); - vertexCount = s->GetTotalCVCount(); - } - } - - - // Find the number of vertices in the given entity - baseEntity = entity; - if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::CONTROLLER) - { - baseEntity = ((FCDController*) baseEntity)->GetBaseGeometry(); - } - if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::GEOMETRY) - { - FCDGeometry* g = (FCDGeometry*) baseEntity; - if (g->IsMesh() && isMesh) - { - FCDGeometryMesh* m = g->GetMesh(); - FCDGeometrySource* positions = m->GetPositionSource(); - if (positions != NULL) - { - similar = (vertexCount == positions->GetValueCount()); - } - } - - if (g->IsSpline() && isSpline) - { - FCDGeometrySpline* s = g->GetSpline(); - similar = (vertexCount == s->GetTotalCVCount()); - } - } - } - - return similar; -} - -// -// FCDMorphTarget -// - -ImplementObjectType(FCDMorphTarget); -ImplementParameterObjectNoCtr(FCDMorphTarget, FCDGeometry, geometry); - -FCDMorphTarget::FCDMorphTarget(FCDocument* document, FCDMorphController* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(geometry) -, InitializeParameterAnimatable(weight, 0.0f) -{ -} - -FCDMorphTarget::~FCDMorphTarget() -{ - parent = NULL; -} - -void FCDMorphTarget::SetGeometry(FCDGeometry* _geometry) -{ - // Let go of the old geometry - FCDGeometry* oldGeometry = geometry; - if (oldGeometry != NULL && oldGeometry->GetTrackerCount() == 1) - { - SAFE_RELEASE(geometry); - } - - // Check if this geometry is similar to the controller base target - if (GetParent()->GetBaseTarget() == NULL || GetParent()->IsSimilar(_geometry)) - { - geometry = _geometry; - } - SetNewChildFlag(); -} - -FCDAnimated* FCDMorphTarget::GetAnimatedWeight() -{ - return weight.GetAnimated(); -} -const FCDAnimated* FCDMorphTarget::GetAnimatedWeight() const -{ - return weight.GetAnimated(); -} - -bool FCDMorphTarget::IsAnimated() const -{ - return weight.IsAnimated(); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDGeometrySource.h" +#include "FCDocument/FCDGeometrySpline.h" +#include "FCDocument/FCDMorphController.h" + +// +// FCDMorphController +// + +ImplementObjectType(FCDMorphController); +ImplementParameterObjectNoCtr(FCDMorphController, FCDEntity, baseTarget); +ImplementParameterObject(FCDMorphController, FCDMorphTarget, morphTargets, new FCDMorphTarget(parent->GetDocument(), parent)); + +FCDMorphController::FCDMorphController(FCDocument* document, FCDController* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameter(method, FUDaeMorphMethod::NORMALIZED) +, InitializeParameterNoArg(baseTarget) +, InitializeParameterNoArg(morphTargets) +{ +} + +FCDMorphController::~FCDMorphController() +{ + parent = NULL; +} + +// Changes the base target of the morpher +void FCDMorphController::SetBaseTarget(FCDEntity* entity) +{ + baseTarget = NULL; + + // Retrieve the actual base entity, as you can chain controllers. + FCDEntity* baseEntity = entity; + if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::CONTROLLER) + { + baseEntity = ((FCDController*) baseEntity)->GetBaseGeometry(); + } + if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::GEOMETRY) + { + baseTarget = entity; + + // Remove the old morph targets which are not similar, anymore, to the new base entity. + for (size_t i = 0; i < morphTargets.size();) + { + if (IsSimilar(morphTargets[i]->GetGeometry())) + { + ++i; + } + else + { + morphTargets[i]->Release(); + } + } + } + else + { + // The new base target is not valid. + morphTargets.clear(); + } + + SetNewChildFlag(); +} + +// Adds a new morph target. +FCDMorphTarget* FCDMorphController::AddTarget(FCDGeometry* geometry, float weight) +{ + FCDMorphTarget* target = NULL; + // It is legal to add targets with out a base geometry + if (baseTarget == NULL || IsSimilar(geometry)) + { + target = new FCDMorphTarget(GetDocument(), this); + morphTargets.push_back(target); + target->SetGeometry(geometry); + target->SetWeight(weight); + } + SetNewChildFlag(); + return target; +} + +// Retrieves whether a given entity is similar to the base target. +bool FCDMorphController::IsSimilar(FCDEntity* entity) +{ + bool similar = false; + if (entity != NULL && baseTarget != NULL) + { + size_t vertexCount = 0; + bool isMesh = false; + bool isSpline = false; + + // Find the number of vertices in the base target + FCDEntity* baseEntity = baseTarget; + if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::CONTROLLER) + { + baseEntity = ((FCDController*) baseEntity)->GetBaseGeometry(); + } + if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::GEOMETRY) + { + FCDGeometry* g = (FCDGeometry*) baseEntity; + if (g->IsMesh()) + { + isMesh = true; + FCDGeometryMesh* m = g->GetMesh(); + FCDGeometrySource* positions = m->GetPositionSource(); + if (positions != NULL) + { + vertexCount = positions->GetValueCount(); + } + } + + if (g->IsSpline()) + { + isSpline = true; + FCDGeometrySpline* s = g->GetSpline(); + vertexCount = s->GetTotalCVCount(); + } + } + + + // Find the number of vertices in the given entity + baseEntity = entity; + if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::CONTROLLER) + { + baseEntity = ((FCDController*) baseEntity)->GetBaseGeometry(); + } + if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::GEOMETRY) + { + FCDGeometry* g = (FCDGeometry*) baseEntity; + if (g->IsMesh() && isMesh) + { + FCDGeometryMesh* m = g->GetMesh(); + FCDGeometrySource* positions = m->GetPositionSource(); + if (positions != NULL) + { + similar = (vertexCount == positions->GetValueCount()); + } + } + + if (g->IsSpline() && isSpline) + { + FCDGeometrySpline* s = g->GetSpline(); + similar = (vertexCount == s->GetTotalCVCount()); + } + } + } + + return similar; +} + +// +// FCDMorphTarget +// + +ImplementObjectType(FCDMorphTarget); +ImplementParameterObjectNoCtr(FCDMorphTarget, FCDGeometry, geometry); + +FCDMorphTarget::FCDMorphTarget(FCDocument* document, FCDMorphController* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(geometry) +, InitializeParameterAnimatable(weight, 0.0f) +{ +} + +FCDMorphTarget::~FCDMorphTarget() +{ + parent = NULL; +} + +void FCDMorphTarget::SetGeometry(FCDGeometry* _geometry) +{ + // Let go of the old geometry + FCDGeometry* oldGeometry = geometry; + if (oldGeometry != NULL && oldGeometry->GetTrackerCount() == 1) + { + SAFE_RELEASE(geometry); + } + + // Check if this geometry is similar to the controller base target + if (GetParent()->GetBaseTarget() == NULL || GetParent()->IsSimilar(_geometry)) + { + geometry = _geometry; + } + SetNewChildFlag(); +} + +FCDAnimated* FCDMorphTarget::GetAnimatedWeight() +{ + return weight.GetAnimated(); +} +const FCDAnimated* FCDMorphTarget::GetAnimatedWeight() const +{ + return weight.GetAnimated(); +} + +bool FCDMorphTarget::IsAnimated() const +{ + return weight.IsAnimated(); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDMorphController.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.cpp (revision 24247) Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.hpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.hpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.hpp (revision 24247) Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.hpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObject.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObject.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObject.h (revision 24247) @@ -1,104 +1,104 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDObject.h - This file contains the FCDObject class. -*/ - -#ifndef __FCD_OBJECT_H_ -#define __FCD_OBJECT_H_ - -#ifndef _FU_PARAMETERIZABLE_H_ -#include "FUtils/FUParameterizable.h" -#endif // _FU_PARAMETERIZABLE_H_ - -class FCDocument; - -/** - A basic COLLADA document object. - - All the objects owned by the COLLADA document derive from this class. - The FCDocument object is accessible through this interface to all the object which it owns. - - Space for an handle which has no meaning to FCollada is available in this base class, for our users. - You can therefore attach your own objects to most FCollada objects. If you assign memory buffers - to the user-specified handle, be aware that FCollada will make no attempt to release it. - - 32 flags are also available within this object. You can use the DeclareFlag - and DeclareFlagCount macros to include flags within your custom classes. This object reverses - the first four bits for its own flags: dirty, value changed, transient and new child. - - All FCollada objects should set the dirty flag when modifications are made - to the objects, but FCollada will never reset it. This flag should be used by - multi-tier applications. This flag defaults to 'true'. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDObject : public FUParameterizable -{ -private: - DeclareObjectType(FUParameterizable); - - // The COLLADA document that owns this object - FCDocument* document; - - // An handle which has no meaning to FCollada but is available for users to - // attach objects to most FCollada objects. - void* userHandle; - -public: - /** Declare the flags to set various states available on an FCDObject - Each Declare flag requires its local index. It is required to - DeclareFlagCount, declaring the amount of flags specified locally */ - DeclareFlag(Transient, 0); /**< [EXPERIMENTAL] This object exists for the application to use. - This object should be not archived/saved. */ - DeclareFlag(NewChild, 1); /**< [EXPERIMENTAL] A new child has been assigned to this object. - Should be replaced by the StructureChanged flag in future versions. */ - DeclareFlagCount(2); /**< 5 flags are locally declared. */ - -public: - /** Constructor: sets the COLLADA document object. - @param document The COLLADA document which owns this object. */ - FCDObject(FCDocument* document); - - /** Destructor. */ - virtual ~FCDObject(); - - /** Retrieves the COLLADA document which owns this object. - @return The COLLADA document. */ - inline FCDocument* GetDocument() { return document; } - inline const FCDocument* GetDocument() const { return document; } /**< See above. */ - - /** Retrieves whether a given object is a local reference from this object. - @param object A data object. - @return Whether a reference from this object to the given object is local. */ - inline bool IsLocal(const FCDObject* object) const { return document == object->document; } - - /** Retrieves whether a given object is an external reference from this object. - @param object A data object. - @return Whether a reference from this object to the given object is external. */ - inline bool IsExternal(const FCDObject* object) const { return document != object->document; } - - /** Retrieves the object's user-specified handle. - This handle is available for users and has no - meaning to FCollada. - @return The object user-specified handle. */ - inline void* GetUserHandle() const { return userHandle; } - - /** Sets the object's user-specified handle. - This handle is available for users and has no - meaning to FCollada. - @param handle The user-specified handle. */ - inline void SetUserHandle(void* handle) { userHandle = handle; SetDirtyFlag(); } - - /** ValueChangedFlag override, this allows objects to react if necessary. */ - virtual void SetValueChange() { SetValueChangedFlag(); } -}; - -#endif // __FCD_OBJECT_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDObject.h + This file contains the FCDObject class. +*/ + +#ifndef __FCD_OBJECT_H_ +#define __FCD_OBJECT_H_ + +#ifndef _FU_PARAMETERIZABLE_H_ +#include "FUtils/FUParameterizable.h" +#endif // _FU_PARAMETERIZABLE_H_ + +class FCDocument; + +/** + A basic COLLADA document object. + + All the objects owned by the COLLADA document derive from this class. + The FCDocument object is accessible through this interface to all the object which it owns. + + Space for an handle which has no meaning to FCollada is available in this base class, for our users. + You can therefore attach your own objects to most FCollada objects. If you assign memory buffers + to the user-specified handle, be aware that FCollada will make no attempt to release it. + + 32 flags are also available within this object. You can use the DeclareFlag + and DeclareFlagCount macros to include flags within your custom classes. This object reverses + the first four bits for its own flags: dirty, value changed, transient and new child. + + All FCollada objects should set the dirty flag when modifications are made + to the objects, but FCollada will never reset it. This flag should be used by + multi-tier applications. This flag defaults to 'true'. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDObject : public FUParameterizable +{ +private: + DeclareObjectType(FUParameterizable); + + // The COLLADA document that owns this object + FCDocument* document; + + // An handle which has no meaning to FCollada but is available for users to + // attach objects to most FCollada objects. + void* userHandle; + +public: + /** Declare the flags to set various states available on an FCDObject + Each Declare flag requires its local index. It is required to + DeclareFlagCount, declaring the amount of flags specified locally */ + DeclareFlag(Transient, 0); /**< [EXPERIMENTAL] This object exists for the application to use. + This object should be not archived/saved. */ + DeclareFlag(NewChild, 1); /**< [EXPERIMENTAL] A new child has been assigned to this object. + Should be replaced by the StructureChanged flag in future versions. */ + DeclareFlagCount(2); /**< 5 flags are locally declared. */ + +public: + /** Constructor: sets the COLLADA document object. + @param document The COLLADA document which owns this object. */ + FCDObject(FCDocument* document); + + /** Destructor. */ + virtual ~FCDObject(); + + /** Retrieves the COLLADA document which owns this object. + @return The COLLADA document. */ + inline FCDocument* GetDocument() { return document; } + inline const FCDocument* GetDocument() const { return document; } /**< See above. */ + + /** Retrieves whether a given object is a local reference from this object. + @param object A data object. + @return Whether a reference from this object to the given object is local. */ + inline bool IsLocal(const FCDObject* object) const { return document == object->document; } + + /** Retrieves whether a given object is an external reference from this object. + @param object A data object. + @return Whether a reference from this object to the given object is external. */ + inline bool IsExternal(const FCDObject* object) const { return document != object->document; } + + /** Retrieves the object's user-specified handle. + This handle is available for users and has no + meaning to FCollada. + @return The object user-specified handle. */ + inline void* GetUserHandle() const { return userHandle; } + + /** Sets the object's user-specified handle. + This handle is available for users and has no + meaning to FCollada. + @param handle The user-specified handle. */ + inline void SetUserHandle(void* handle) { userHandle = handle; SetDirtyFlag(); } + + /** ValueChangedFlag override, this allows objects to react if necessary. */ + virtual void SetValueChange() { SetValueChangedFlag(); } +}; + +#endif // __FCD_OBJECT_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObject.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.h (revision 24247) @@ -1,404 +1,404 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#define _FCD_PARAMETER_ANIMATABLE_H_ - -/** - @file FCDParameterAnimatable.h - This file contains the FCDParameterAnimatable template and related functions. -*/ - -#ifndef _FU_PARAMETER_H_ -#include -#endif // _FU_PARAMETER_H_ -#ifndef _FM_ANGLEAXIS_H_ -#include -#endif // _FM_ANGLEAXIS_H_ -#ifndef _FM_LOOKAT_H_ -#include -#endif // _FM_LOOKAT_H_ -#ifndef _FM_SKEW_H_ -#include -#endif // _FM_SKEW_H_ - -class FCDAnimated; -class FUParameterizable; - -/** - An animatable value parameter. - @ingroup FUParameter -*/ -class FCOLLADA_EXPORT FCDParameterAnimatable -{ -private: - FUParameterizable* parent; - FUObjectRef animated; - -public: - /** Constructor. - @param parent The FCollada object that owns this parameter. */ - FCDParameterAnimatable(FUParameterizable* parent); - - /** Destructor. */ - virtual ~FCDParameterAnimatable(); - - /** Retrieves the parent object for this animatable parameter. - @return The parent object of the parameter. */ - virtual FUParameterizable* GetParent() { return parent; } - - /** Retrieves the animation helper for this animatable parameter. - This animation helper will be created if non-existant. - @return The animation helper for this parameter. */ - FCDAnimated* GetAnimated(); - const FCDAnimated* GetAnimated() const; /**< See above. */ - - /** Retrieves whether this animatable parameter has valid animation data. - @return Whether this animatable parameter is animated. */ - bool IsAnimated() const; - - /** Copy operator. - Note: the animation is not copied, right now. - @param parameter The other parameter. - @return This parameter. */ - FCDParameterAnimatable& operator= (FCDParameterAnimatable& parameter); - -protected: - /** Requests from the up-class that the correct FCDAnimated helper - class be created for this parameter. - This should be handled by the FCDParameterAnimatableT template specializations. - @return A newly-created FCDAnimated helper object. */ - virtual FCDAnimated* CreateAnimated(); -}; - -/** - A typed animatable FCollada value parameter. - @ingroup FUParameter -*/ -template -class FCOLLADA_EXPORT FCDParameterAnimatableT : public FCDParameterAnimatable -{ -private: - TYPE value; - -public: - /** Constructor. - @param parent The FCollada object that owns this parameter. */ - FCDParameterAnimatableT(FUParameterizable* parent); - - /** Constructor. - @param parent The FCollada object that owns this parameter. - @param defaultValue A default value to assign to this parameter. */ - FCDParameterAnimatableT(FUParameterizable* parent, const TYPE& defaultValue); - - /** Destructor. */ - virtual ~FCDParameterAnimatableT(); - - /** Retrieves the value or a reference to the value. - @return The value or a reference to it. */ - inline operator TYPE&() { return value; } - inline operator const TYPE&() const { return value; } /**< See above. */ - inline TYPE& operator *() { return value; } /**< See above. */ - inline const TYPE& operator *() const { return value; } /**< See above. */ - inline TYPE* operator->() { return &value; } /**< See above. */ - inline const TYPE* operator->() const { return &value; } /**< See above. */ - - /** Assigns to this parameter the given value. - @param copy A value of the correct type. - @return A reference to this parameter. */ - FCDParameterAnimatableT& operator= (const TYPE& copy); - -protected: - /** Created the correct FCDAnimated helper object, done by request - from the parent class. - @return A newly-created FCDAnimated helper object. */ - virtual FCDAnimated* CreateAnimated(); -}; - -typedef FCDParameterAnimatableT FCDParameterAnimatableFloat; /**< A floating-point value animatable parameter. */ -typedef FCDParameterAnimatableT FCDParameterAnimatableVector2; /**< A 2D vector animatable parameter. */ -typedef FCDParameterAnimatableT FCDParameterAnimatableVector3; /**< A 3D vector animatable parameter. */ -typedef FCDParameterAnimatableT FCDParameterAnimatableColor3; /**< A 3D vector animatable parameter. */ -typedef FCDParameterAnimatableT FCDParameterAnimatableVector4; /**< A 4D vector animatable parameter. */ -typedef FCDParameterAnimatableT FCDParameterAnimatableColor4; /**< A 4D color animatable parameter. */ -typedef FCDParameterAnimatableT FCDParameterAnimatableMatrix44; /**< A matrix animatable parameter. */ -typedef FCDParameterAnimatableT FCDParameterAnimatableAngleAxis; /**< An angle-axis rotation animatable parameter. */ -typedef FCDParameterAnimatableT FCDParameterAnimatableLookAt; /**< A look-at animatable parameter. */ -typedef FCDParameterAnimatableT FCDParameterAnimatableSkew; /**< A skew animatable parameter. */ - -/** - An animatable value parameter. - @ingroup FUParameter -*/ -class FCOLLADA_EXPORT FCDParameterListAnimatable -{ -private: - FUParameterizable* parent; - -protected: - /** The list of FCDAnimated helpers. - This value is marked "protected" because - OnPotentialSizeChange uses it.. Needs some more thought? */ - FUObjectContainer animateds; - -public: - /** Constructor. - @param parent The FCollada object that owns this parameter. */ - FCDParameterListAnimatable(FUParameterizable* parent); - - /** Destructor. */ - virtual ~FCDParameterListAnimatable(); - - /** Retrieves the parent object for this animatable parameter. - @return The parent object of the parameter. */ - virtual FUParameterizable* GetParent() { return parent; } - - /** Retrieves the animation helper for an animatable value in this parameter. - This animation helper will be created if non-existant. - @param The index of the animatable value. - @return The animation helper for the value at the given index. */ - FCDAnimated* GetAnimated(size_t index); - const FCDAnimated* GetAnimated(size_t index) const; /**< See above. */ - - /** Retrieves whether this animatable list parameter has valid animation data. - @param The index of the animatable value within the list parameter. - If this index is -1, then whether the whole list is returned. - @return Whether this animatable value is animated. */ - bool IsAnimated(size_t index = ~(size_t)0) const; - - /** Retrieves the list of animated values for this list parameter. - @return The list of animated values. */ - inline FUObjectContainer& GetAnimatedValues() { return animateds; } - inline const FUObjectContainer& GetAnimatedValues() const { return animateds; } /**< See above. */ - -protected: - /** Requests from the up-class that the correct FCDAnimated helper - class be created for this parameter. - This should be handled by the FCDParameterAnimatableT template specializations. - @param index The element array index of the animatable value. - @return A newly-created FCDAnimated helper object. */ - virtual FCDAnimated* CreateAnimated(size_t index); - - /** Process a list insertion event. - The affected array element indices in the FCDAnimated helpers - will be modified accordingly. - @param offset The index of where the insertion was done. - @param count The number of values inserted in the list. */ - void OnInsertion(size_t offset, size_t count); - - /** Process a list removal event. - The affected FCDAnimated helpers will be released and - the element indices of the other helpers will be modified accordingly. - @param offset The index of where the removal was done. - @param count The number of values removed from the list. */ - void OnRemoval(size_t offset, size_t count); - -private: - size_t BinarySearch(size_t arrayElementIndex) const; -}; - -/** - A typed animatable FCollada value parameter. - @ingroup FUParameter -*/ -template -class FCOLLADA_EXPORT FCDParameterListAnimatableT : public FCDParameterListAnimatable -{ -private: - fm::vector values; - -public: - /** Constructor. - @param parent The FCollada object that owns this parameter. */ - FCDParameterListAnimatableT(FUParameterizable* parent); - - /** Destructor. */ - virtual ~FCDParameterListAnimatableT(); - - /** Retrieves the number of values in this parameter list. - @return The number of values. */ - inline size_t size() const { return values.size(); } /**< See above. */ - - /** Retrieves whether this list parameter contains values. - @return Whether the list parameter is empty. */ - inline bool empty() const { return values.size() == 0; } - - /** Sets the number of values contained in the list parameter. - @param count The new number of values contained in the parameter. */ - void resize(size_t count); - - /** Sets the number of values contained in the list parameter. - @param count The new number of values contained in the parameter. - @param value The default value to insert in the new slots of the list parameter. */ - void resize(size_t count, const TYPE& value); - - /** Retrieves one value held by this parameter. - Important: it is intentional that you cannot modify a list value using these function. - Instead, use the set function. - @param index The index of the value held by this parameter. - @return The number of values in this parameter. */ - inline const TYPE& at(size_t index) const { return values[index]; } - inline const TYPE& operator[](size_t index) const { return values[index]; } /**< See above. */ - template inline const TYPE& operator[](INTEGER index) const { return values[index]; } /**< See above. */ - - /** Modifies one existing value held by this parameter. - @param index The index of the value to change. - @param value The new value. */ - void set(size_t index, const TYPE& value); - - /** Inserts a value to this parameter. - @param index Where to insert the value. - @param value The values to insert to this parameter. */ - void insert(size_t index, const TYPE& value); - - /** Inserts one value, multiple times, to this list parameter. - @param index Where to insert the value. - @param count The number of times to insert this value. - @param value The value to insert to this parameter. */ - void insert(size_t index, size_t count, const TYPE& value); - - /** Inserts multiple values to this list parameter. - @param index Where to insert the values. - @param values A static list of values. - @param count The number of values to insert. */ - void insert(size_t index, const TYPE* values, size_t count); - - /** Removes one element from this list parameter. - @param index The index of the element to remove. */ - void erase(size_t index); - - /** Removes one element from this list parameter. - @param value The value to remove. */ - void erase(const TYPE& value); - - /** Removes a contiguous series of elements from this list parameter. - @param start The index of the first element to remove. - @param end The index past the last element to remove. */ - void erase(size_t start, size_t end); - - /** Removes all the element of the list parameter. */ - void clear(); - - /** Retrieves the index of an existing value in this parameter. - @param value The value to look for. - @return The index of the given value within the parameter. - The size of the list is returned if the value is not found. */ - inline size_t find(const TYPE& value) const { return values.find(value) - values.begin(); } - - /** Retrieves whether the list parameter contains a specific value. - @param value A value. - @return Whether the given value is contained within the list parameter. */ - inline bool contains(const TYPE& value) const { return values.contains(value); } - - /** Appends one value to this parameter. - @param value The value to add to this parameter. */ - void push_back(const TYPE& value); - - /** Adds one value at the beginning of this list parameter. - @param value The value to add to this parameter. */ - void push_front(const TYPE& value); - - /** Removes the value at the end of the list parameter. */ - void pop_back(); - - /** Removes the value at the end of the list parameter. */ - void pop_front(); - - /** Retrieves the first element from this list parameter. - @param The first element in the list parameter. */ - inline TYPE& front() { return values.front(); } - inline const TYPE& front() const { return values.front(); } /**< See above. */ - - /** Retrieves the last element from this list parameter. - @param The last element in the list parameter. */ - inline TYPE& back() { return values.back(); } - inline const TYPE& back() const { return values.back(); } /**< See above. */ - - /** [INTERNAL] Retrieves a pointer to the source data. Not recommended. - @return A pointer to the source data. */ - inline TYPE** GetDataPtr() { return values.GetDataPtr(); } - inline const TYPE** GetDataPtr() const { return values.GetDataPtr(); } /**< See above. */ - - /** [INTERNAL] Retrieves a reference to the inner value list. Not recommended. - @return A reference to the value list. */ - inline fm::vector& GetDataList() { return values; } - inline const fm::vector& GetDataList() const { return values; } /**< See above. */ - - /** Retrieves the number of pre-allocated values reserved by this value list. - @return The number of pre-allocated values reserved. */ - inline size_t capacity() const { return values.capacity(); } - -protected: - /** Created the correct FCDAnimated helper object, done by request - from the parent class. - @return A newly-created FCDAnimated helper object. */ - virtual FCDAnimated* CreateAnimated(size_t index); - -private: - /** Verifies whether a size change was triggered and - if it is the case, forces the animateds to update their - value pointers. */ - void OnPotentialSizeChange(); -}; - -typedef FCDParameterListAnimatableT FCDParameterListAnimatableFloat; /**< A floating-point value animatable list parameter. */ -typedef FCDParameterListAnimatableT FCDParameterListAnimatableVector2; /**< A 2D vector animatable list parameter. */ -typedef FCDParameterListAnimatableT FCDParameterListAnimatableVector3; /**< A 3D vector animatable list parameter. */ -typedef FCDParameterListAnimatableT FCDParameterListAnimatableColor3; /**< A 3D color animatable list parameter. */ -typedef FCDParameterListAnimatableT FCDParameterListAnimatableVector4; /**< A 4D vector animatable list parameter. */ -typedef FCDParameterListAnimatableT FCDParameterListAnimatableColor4; /**< A 4D color animatable list parameter. */ - -/** Declares an animatable parameter for the objects of the current class. - Use this macro within a class declaration to add an animatable parameter to it. - The different versions of this macro are used for different parameter types: - - For floats, Booleans, vectors and strings, use DeclareParameterAnimatable. - For arrays of floats, Booleans, vectors and strings, use DeclareParameterListAnimatable. - For tracked pointers, use DeclareParameterPtr. - For contained pointers, use DeclareParameterRef. - For tracked lists of objects, use DeclareParameterTrackList. - For containers of objects, use DeclareParameterContainer. - - @param type The value type of the animatable parameter. Ex: float, bool, FMVector4 or string. - @param qual The qualifier for the animatable parameter type. @see FUParameterQualifiers::Qualifiers. - @param parameterName The member variable name for the animatable parameter. - @param niceName The Unicode string to identify this animatable parameter to users. */ -#define DeclareParameterAnimatable(type, qual, parameterName, niceName) \ - class Parameter_##parameterName : public FCDParameterAnimatableT { \ - public: Parameter_##parameterName(FUParameterizable* parent) : FCDParameterAnimatableT(parent) {} \ - Parameter_##parameterName(FUParameterizable* parent, const type& defaultValue) : FCDParameterAnimatableT(parent, defaultValue) {} \ - virtual ~Parameter_##parameterName() {} \ - Parameter_##parameterName& operator= (const type& copy) { FCDParameterAnimatableT::operator=(copy); return *this; } \ - } parameterName; - -/** See above. */ -#define DeclareParameterListAnimatable(type, qual, parameterName, niceName) \ - class Parameter_##parameterName : public FCDParameterListAnimatableT { \ - public: Parameter_##parameterName(FUParameterizable* parent) : FCDParameterListAnimatableT(parent) {} \ - virtual ~Parameter_##parameterName() {} \ - } parameterName; - -/** Initializes the member variable for an animatable parameter. - Either one of these macros must be included for each member animatable - parameter of a class, within that class' constructors. - The different versions of this macro are used for different contexts: - - For a parameter where the default constructor is to be used, use InitializeParameterAnimatableNoArg. - For a parameter where one or more values should be used in the constructor, use InitializeParameterAnimatable. - - @param parameterName The member variable name of the parameter within the class. */ -#define InitializeParameterAnimatableNoArg(parameterName) parameterName(this) -/** See above. */ -#define InitializeParameterAnimatable(parameterName, ...) parameterName(this, __VA_ARGS__) - -#if defined(__APPLE__) || defined(LINUX) -#include -#endif // MAC + LINUX - -#endif // _FCD_PARAMETER_ANIMATABLE_H - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#define _FCD_PARAMETER_ANIMATABLE_H_ + +/** + @file FCDParameterAnimatable.h + This file contains the FCDParameterAnimatable template and related functions. +*/ + +#ifndef _FU_PARAMETER_H_ +#include +#endif // _FU_PARAMETER_H_ +#ifndef _FM_ANGLEAXIS_H_ +#include +#endif // _FM_ANGLEAXIS_H_ +#ifndef _FM_LOOKAT_H_ +#include +#endif // _FM_LOOKAT_H_ +#ifndef _FM_SKEW_H_ +#include +#endif // _FM_SKEW_H_ + +class FCDAnimated; +class FUParameterizable; + +/** + An animatable value parameter. + @ingroup FUParameter +*/ +class FCOLLADA_EXPORT FCDParameterAnimatable +{ +private: + FUParameterizable* parent; + FUObjectRef animated; + +public: + /** Constructor. + @param parent The FCollada object that owns this parameter. */ + FCDParameterAnimatable(FUParameterizable* parent); + + /** Destructor. */ + virtual ~FCDParameterAnimatable(); + + /** Retrieves the parent object for this animatable parameter. + @return The parent object of the parameter. */ + virtual FUParameterizable* GetParent() { return parent; } + + /** Retrieves the animation helper for this animatable parameter. + This animation helper will be created if non-existant. + @return The animation helper for this parameter. */ + FCDAnimated* GetAnimated(); + const FCDAnimated* GetAnimated() const; /**< See above. */ + + /** Retrieves whether this animatable parameter has valid animation data. + @return Whether this animatable parameter is animated. */ + bool IsAnimated() const; + + /** Copy operator. + Note: the animation is not copied, right now. + @param parameter The other parameter. + @return This parameter. */ + FCDParameterAnimatable& operator= (FCDParameterAnimatable& parameter); + +protected: + /** Requests from the up-class that the correct FCDAnimated helper + class be created for this parameter. + This should be handled by the FCDParameterAnimatableT template specializations. + @return A newly-created FCDAnimated helper object. */ + virtual FCDAnimated* CreateAnimated(); +}; + +/** + A typed animatable FCollada value parameter. + @ingroup FUParameter +*/ +template +class FCOLLADA_EXPORT FCDParameterAnimatableT : public FCDParameterAnimatable +{ +private: + TYPE value; + +public: + /** Constructor. + @param parent The FCollada object that owns this parameter. */ + FCDParameterAnimatableT(FUParameterizable* parent); + + /** Constructor. + @param parent The FCollada object that owns this parameter. + @param defaultValue A default value to assign to this parameter. */ + FCDParameterAnimatableT(FUParameterizable* parent, const TYPE& defaultValue); + + /** Destructor. */ + virtual ~FCDParameterAnimatableT(); + + /** Retrieves the value or a reference to the value. + @return The value or a reference to it. */ + inline operator TYPE&() { return value; } + inline operator const TYPE&() const { return value; } /**< See above. */ + inline TYPE& operator *() { return value; } /**< See above. */ + inline const TYPE& operator *() const { return value; } /**< See above. */ + inline TYPE* operator->() { return &value; } /**< See above. */ + inline const TYPE* operator->() const { return &value; } /**< See above. */ + + /** Assigns to this parameter the given value. + @param copy A value of the correct type. + @return A reference to this parameter. */ + FCDParameterAnimatableT& operator= (const TYPE& copy); + +protected: + /** Created the correct FCDAnimated helper object, done by request + from the parent class. + @return A newly-created FCDAnimated helper object. */ + virtual FCDAnimated* CreateAnimated(); +}; + +typedef FCDParameterAnimatableT FCDParameterAnimatableFloat; /**< A floating-point value animatable parameter. */ +typedef FCDParameterAnimatableT FCDParameterAnimatableVector2; /**< A 2D vector animatable parameter. */ +typedef FCDParameterAnimatableT FCDParameterAnimatableVector3; /**< A 3D vector animatable parameter. */ +typedef FCDParameterAnimatableT FCDParameterAnimatableColor3; /**< A 3D vector animatable parameter. */ +typedef FCDParameterAnimatableT FCDParameterAnimatableVector4; /**< A 4D vector animatable parameter. */ +typedef FCDParameterAnimatableT FCDParameterAnimatableColor4; /**< A 4D color animatable parameter. */ +typedef FCDParameterAnimatableT FCDParameterAnimatableMatrix44; /**< A matrix animatable parameter. */ +typedef FCDParameterAnimatableT FCDParameterAnimatableAngleAxis; /**< An angle-axis rotation animatable parameter. */ +typedef FCDParameterAnimatableT FCDParameterAnimatableLookAt; /**< A look-at animatable parameter. */ +typedef FCDParameterAnimatableT FCDParameterAnimatableSkew; /**< A skew animatable parameter. */ + +/** + An animatable value parameter. + @ingroup FUParameter +*/ +class FCOLLADA_EXPORT FCDParameterListAnimatable +{ +private: + FUParameterizable* parent; + +protected: + /** The list of FCDAnimated helpers. + This value is marked "protected" because + OnPotentialSizeChange uses it.. Needs some more thought? */ + FUObjectContainer animateds; + +public: + /** Constructor. + @param parent The FCollada object that owns this parameter. */ + FCDParameterListAnimatable(FUParameterizable* parent); + + /** Destructor. */ + virtual ~FCDParameterListAnimatable(); + + /** Retrieves the parent object for this animatable parameter. + @return The parent object of the parameter. */ + virtual FUParameterizable* GetParent() { return parent; } + + /** Retrieves the animation helper for an animatable value in this parameter. + This animation helper will be created if non-existant. + @param The index of the animatable value. + @return The animation helper for the value at the given index. */ + FCDAnimated* GetAnimated(size_t index); + const FCDAnimated* GetAnimated(size_t index) const; /**< See above. */ + + /** Retrieves whether this animatable list parameter has valid animation data. + @param The index of the animatable value within the list parameter. + If this index is -1, then whether the whole list is returned. + @return Whether this animatable value is animated. */ + bool IsAnimated(size_t index = ~(size_t)0) const; + + /** Retrieves the list of animated values for this list parameter. + @return The list of animated values. */ + inline FUObjectContainer& GetAnimatedValues() { return animateds; } + inline const FUObjectContainer& GetAnimatedValues() const { return animateds; } /**< See above. */ + +protected: + /** Requests from the up-class that the correct FCDAnimated helper + class be created for this parameter. + This should be handled by the FCDParameterAnimatableT template specializations. + @param index The element array index of the animatable value. + @return A newly-created FCDAnimated helper object. */ + virtual FCDAnimated* CreateAnimated(size_t index); + + /** Process a list insertion event. + The affected array element indices in the FCDAnimated helpers + will be modified accordingly. + @param offset The index of where the insertion was done. + @param count The number of values inserted in the list. */ + void OnInsertion(size_t offset, size_t count); + + /** Process a list removal event. + The affected FCDAnimated helpers will be released and + the element indices of the other helpers will be modified accordingly. + @param offset The index of where the removal was done. + @param count The number of values removed from the list. */ + void OnRemoval(size_t offset, size_t count); + +private: + size_t BinarySearch(size_t arrayElementIndex) const; +}; + +/** + A typed animatable FCollada value parameter. + @ingroup FUParameter +*/ +template +class FCOLLADA_EXPORT FCDParameterListAnimatableT : public FCDParameterListAnimatable +{ +private: + fm::vector values; + +public: + /** Constructor. + @param parent The FCollada object that owns this parameter. */ + FCDParameterListAnimatableT(FUParameterizable* parent); + + /** Destructor. */ + virtual ~FCDParameterListAnimatableT(); + + /** Retrieves the number of values in this parameter list. + @return The number of values. */ + inline size_t size() const { return values.size(); } /**< See above. */ + + /** Retrieves whether this list parameter contains values. + @return Whether the list parameter is empty. */ + inline bool empty() const { return values.size() == 0; } + + /** Sets the number of values contained in the list parameter. + @param count The new number of values contained in the parameter. */ + void resize(size_t count); + + /** Sets the number of values contained in the list parameter. + @param count The new number of values contained in the parameter. + @param value The default value to insert in the new slots of the list parameter. */ + void resize(size_t count, const TYPE& value); + + /** Retrieves one value held by this parameter. + Important: it is intentional that you cannot modify a list value using these function. + Instead, use the set function. + @param index The index of the value held by this parameter. + @return The number of values in this parameter. */ + inline const TYPE& at(size_t index) const { return values[index]; } + inline const TYPE& operator[](size_t index) const { return values[index]; } /**< See above. */ + template inline const TYPE& operator[](INTEGER index) const { return values[index]; } /**< See above. */ + + /** Modifies one existing value held by this parameter. + @param index The index of the value to change. + @param value The new value. */ + void set(size_t index, const TYPE& value); + + /** Inserts a value to this parameter. + @param index Where to insert the value. + @param value The values to insert to this parameter. */ + void insert(size_t index, const TYPE& value); + + /** Inserts one value, multiple times, to this list parameter. + @param index Where to insert the value. + @param count The number of times to insert this value. + @param value The value to insert to this parameter. */ + void insert(size_t index, size_t count, const TYPE& value); + + /** Inserts multiple values to this list parameter. + @param index Where to insert the values. + @param values A static list of values. + @param count The number of values to insert. */ + void insert(size_t index, const TYPE* values, size_t count); + + /** Removes one element from this list parameter. + @param index The index of the element to remove. */ + void erase(size_t index); + + /** Removes one element from this list parameter. + @param value The value to remove. */ + void erase(const TYPE& value); + + /** Removes a contiguous series of elements from this list parameter. + @param start The index of the first element to remove. + @param end The index past the last element to remove. */ + void erase(size_t start, size_t end); + + /** Removes all the element of the list parameter. */ + void clear(); + + /** Retrieves the index of an existing value in this parameter. + @param value The value to look for. + @return The index of the given value within the parameter. + The size of the list is returned if the value is not found. */ + inline size_t find(const TYPE& value) const { return values.find(value) - values.begin(); } + + /** Retrieves whether the list parameter contains a specific value. + @param value A value. + @return Whether the given value is contained within the list parameter. */ + inline bool contains(const TYPE& value) const { return values.contains(value); } + + /** Appends one value to this parameter. + @param value The value to add to this parameter. */ + void push_back(const TYPE& value); + + /** Adds one value at the beginning of this list parameter. + @param value The value to add to this parameter. */ + void push_front(const TYPE& value); + + /** Removes the value at the end of the list parameter. */ + void pop_back(); + + /** Removes the value at the end of the list parameter. */ + void pop_front(); + + /** Retrieves the first element from this list parameter. + @param The first element in the list parameter. */ + inline TYPE& front() { return values.front(); } + inline const TYPE& front() const { return values.front(); } /**< See above. */ + + /** Retrieves the last element from this list parameter. + @param The last element in the list parameter. */ + inline TYPE& back() { return values.back(); } + inline const TYPE& back() const { return values.back(); } /**< See above. */ + + /** [INTERNAL] Retrieves a pointer to the source data. Not recommended. + @return A pointer to the source data. */ + inline TYPE** GetDataPtr() { return values.GetDataPtr(); } + inline const TYPE** GetDataPtr() const { return values.GetDataPtr(); } /**< See above. */ + + /** [INTERNAL] Retrieves a reference to the inner value list. Not recommended. + @return A reference to the value list. */ + inline fm::vector& GetDataList() { return values; } + inline const fm::vector& GetDataList() const { return values; } /**< See above. */ + + /** Retrieves the number of pre-allocated values reserved by this value list. + @return The number of pre-allocated values reserved. */ + inline size_t capacity() const { return values.capacity(); } + +protected: + /** Created the correct FCDAnimated helper object, done by request + from the parent class. + @return A newly-created FCDAnimated helper object. */ + virtual FCDAnimated* CreateAnimated(size_t index); + +private: + /** Verifies whether a size change was triggered and + if it is the case, forces the animateds to update their + value pointers. */ + void OnPotentialSizeChange(); +}; + +typedef FCDParameterListAnimatableT FCDParameterListAnimatableFloat; /**< A floating-point value animatable list parameter. */ +typedef FCDParameterListAnimatableT FCDParameterListAnimatableVector2; /**< A 2D vector animatable list parameter. */ +typedef FCDParameterListAnimatableT FCDParameterListAnimatableVector3; /**< A 3D vector animatable list parameter. */ +typedef FCDParameterListAnimatableT FCDParameterListAnimatableColor3; /**< A 3D color animatable list parameter. */ +typedef FCDParameterListAnimatableT FCDParameterListAnimatableVector4; /**< A 4D vector animatable list parameter. */ +typedef FCDParameterListAnimatableT FCDParameterListAnimatableColor4; /**< A 4D color animatable list parameter. */ + +/** Declares an animatable parameter for the objects of the current class. + Use this macro within a class declaration to add an animatable parameter to it. + The different versions of this macro are used for different parameter types: + + For floats, Booleans, vectors and strings, use DeclareParameterAnimatable. + For arrays of floats, Booleans, vectors and strings, use DeclareParameterListAnimatable. + For tracked pointers, use DeclareParameterPtr. + For contained pointers, use DeclareParameterRef. + For tracked lists of objects, use DeclareParameterTrackList. + For containers of objects, use DeclareParameterContainer. + + @param type The value type of the animatable parameter. Ex: float, bool, FMVector4 or string. + @param qual The qualifier for the animatable parameter type. @see FUParameterQualifiers::Qualifiers. + @param parameterName The member variable name for the animatable parameter. + @param niceName The Unicode string to identify this animatable parameter to users. */ +#define DeclareParameterAnimatable(type, qual, parameterName, niceName) \ + class Parameter_##parameterName : public FCDParameterAnimatableT { \ + public: Parameter_##parameterName(FUParameterizable* parent) : FCDParameterAnimatableT(parent) {} \ + Parameter_##parameterName(FUParameterizable* parent, const type& defaultValue) : FCDParameterAnimatableT(parent, defaultValue) {} \ + virtual ~Parameter_##parameterName() {} \ + Parameter_##parameterName& operator= (const type& copy) { FCDParameterAnimatableT::operator=(copy); return *this; } \ + } parameterName; + +/** See above. */ +#define DeclareParameterListAnimatable(type, qual, parameterName, niceName) \ + class Parameter_##parameterName : public FCDParameterListAnimatableT { \ + public: Parameter_##parameterName(FUParameterizable* parent) : FCDParameterListAnimatableT(parent) {} \ + virtual ~Parameter_##parameterName() {} \ + } parameterName; + +/** Initializes the member variable for an animatable parameter. + Either one of these macros must be included for each member animatable + parameter of a class, within that class' constructors. + The different versions of this macro are used for different contexts: + + For a parameter where the default constructor is to be used, use InitializeParameterAnimatableNoArg. + For a parameter where one or more values should be used in the constructor, use InitializeParameterAnimatable. + + @param parameterName The member variable name of the parameter within the class. */ +#define InitializeParameterAnimatableNoArg(parameterName) parameterName(this) +/** See above. */ +#define InitializeParameterAnimatable(parameterName, ...) parameterName(this, __VA_ARGS__) + +#if defined(__APPLE__) || defined(LINUX) +#include +#endif // MAC + LINUX + +#endif // _FCD_PARAMETER_ANIMATABLE_H + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.cpp (revision 24247) @@ -1,358 +1,358 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDParameterAnimatable.h" -#if !defined (__APPLE__) && !defined(LINUX) -#include "FCDParameterAnimatable.hpp" -#endif -#include "FCDAnimated.h" -#include -#include -#include -#include - -// -// FCDParameterAnimatable -// - -FCDParameterAnimatable::FCDParameterAnimatable(FUParameterizable* _parent) -: parent(_parent) -{ -} - -FCDParameterAnimatable::~FCDParameterAnimatable() -{ - parent = NULL; -} - -FCDAnimated* FCDParameterAnimatable::GetAnimated() { if (animated == NULL) animated = CreateAnimated(); return animated; } -const FCDAnimated* FCDParameterAnimatable::GetAnimated() const -{ - if (animated == NULL) - { - FCDParameterAnimatable* _this = const_cast(this); - _this->animated = _this->CreateAnimated(); - } - return animated; -} - -bool FCDParameterAnimatable::IsAnimated() const -{ - return animated != NULL && animated->HasCurve(); -} - -FCDAnimated* FCDParameterAnimatable::CreateAnimated() -{ - // Implemented below in template specializations of FCDParameterAnimatableT. - return NULL; -} - -FCDParameterAnimatable& FCDParameterAnimatable::operator= (FCDParameterAnimatable& UNUSED(parameter)) -{ - // This empty copy operator is necessary to avoid the default copy operator - // generated by the compiler which copies the parent pointer. - return *this; -} - -// -// FCDParameterAnimatableT -// - -template <> FCDAnimated* FCDParameterAnimatableFloat::CreateAnimated() -{ - float* values[1] = { &value }; - return new FCDAnimated((FCDObject*) GetParent(), 1, FCDAnimatedStandardQualifiers::EMPTY, values); -} - -template <> FCDAnimated* FCDParameterAnimatableVector2::CreateAnimated() -{ - float* values[2] = { &value.x, &value.y }; - return new FCDAnimated((FCDObject*) GetParent(), 2, FCDAnimatedStandardQualifiers::XYZW, values); -} - -template <> FCDAnimated* FCDParameterAnimatableVector3::CreateAnimated() -{ - float* values[3] = { &value.x, &value.y, &value.z }; - return new FCDAnimated((FCDObject*) GetParent(), 3, FCDAnimatedStandardQualifiers::XYZW, values); -} - -template <> FCDAnimated* FCDParameterAnimatableColor3::CreateAnimated() -{ - float* values[3] = { &value.x, &value.y, &value.z }; - return new FCDAnimated((FCDObject*) GetParent(), 3, FCDAnimatedStandardQualifiers::RGBA, values); -} - -template <> FCDAnimated* FCDParameterAnimatableVector4::CreateAnimated() -{ - float* values[4] = { &value.x, &value.y, &value.z, &value.w }; - return new FCDAnimated((FCDObject*) GetParent(), 4, FCDAnimatedStandardQualifiers::XYZW, values); -} - -template <> FCDAnimated* FCDParameterAnimatableColor4::CreateAnimated() -{ - float* values[4] = { &value.x, &value.y, &value.z, &value.w }; - return new FCDAnimated((FCDObject*) GetParent(), 4, FCDAnimatedStandardQualifiers::RGBA, values); -} - -template <> FCDAnimated* FCDParameterAnimatableMatrix44::CreateAnimated() -{ - float* values[16] = - { - &value[0][0], &value[1][0], &value[2][0], &value[3][0], - &value[0][1], &value[1][1], &value[2][1], &value[3][1], - &value[0][2], &value[1][2], &value[2][2], &value[3][2], - &value[0][3], &value[1][3], &value[2][3], &value[3][3] - }; - return new FCDAnimated((FCDObject*) GetParent(), 16, FCDAnimatedStandardQualifiers::MATRIX, values); -} - -template <> FCDAnimated* FCDParameterAnimatableAngleAxis::CreateAnimated() -{ - float* values[4] = { &value.axis.x, &value.axis.y, &value.axis.z, &value.angle }; - return new FCDAnimated((FCDObject*) GetParent(), 4, FCDAnimatedStandardQualifiers::ROTATE_AXIS, values); -} - -template <> FCDAnimated* FCDParameterAnimatableLookAt::CreateAnimated() -{ - float* values[9] = - { - &value.position.x, &value.position.y, &value.position.z, - &value.target.x, &value.target.y, &value.target.z, - &value.up.x, &value.up.y, &value.up.z - }; - return new FCDAnimated((FCDObject*) GetParent(), 9, FCDAnimatedStandardQualifiers::LOOKAT, values); -} - -template <> FCDAnimated* FCDParameterAnimatableSkew::CreateAnimated() -{ - float* values[7] = - { - &value.rotateAxis.x, &value.rotateAxis.y, &value.rotateAxis.z, - &value.aroundAxis.x, &value.aroundAxis.y, &value.aroundAxis.z, - &value.angle - }; - return new FCDAnimated((FCDObject*) GetParent(), 7, FCDAnimatedStandardQualifiers::LOOKAT, values); -} - -// -// FCDParameterListAnimatable -// -FCDParameterListAnimatable::FCDParameterListAnimatable(FUParameterizable* _parent) -: parent(_parent) -{ -} - -FCDParameterListAnimatable::~FCDParameterListAnimatable() -{ - parent = NULL; -} - -const FCDAnimated* FCDParameterListAnimatable::GetAnimated(size_t index) const { return const_cast(const_cast(this)->GetAnimated(index)); } -FCDAnimated* FCDParameterListAnimatable::GetAnimated(size_t index) -{ - // Check for existing - size_t mid = BinarySearch(index); - if (mid < animateds.size() && animateds[mid]->GetArrayElement() == (int32) index) - { - return animateds[mid]; - } - - // Create new animated value. - FCDAnimated* animated = CreateAnimated(index); - animated->SetArrayElement((int32) index); - animateds.insert(mid, animated); - return animated; -} - -bool FCDParameterListAnimatable::IsAnimated(size_t index) const -{ - size_t animatedCount = animateds.size(); - if (index == ~(size_t)0) - { - for (size_t i = 0; i < animatedCount; ++i) - { - if (animateds[i]->HasCurve()) return true; - } - return false; - } - else - { - size_t i = BinarySearch(index); - return i < animatedCount && animateds[i]->GetArrayElement() == (int32) index && animateds[i]->HasCurve(); - } -} - -void FCDParameterListAnimatable::OnInsertion(size_t offset, size_t count) -{ - // Push forward all the array element indices starting at "offset" by "count". - for (size_t i = BinarySearch(offset); i < animateds.size(); ++i) - { - int32 arrayElement = animateds[i]->GetArrayElement(); - FUAssert(arrayElement >= (int32) offset, continue); - animateds[i]->SetArrayElement(arrayElement + (int32) count); - } -} - -void FCDParameterListAnimatable::OnRemoval(size_t offset, size_t count) -{ - // Release all the animated helpers for the removed values. - for (size_t i = BinarySearch(offset); i < animateds.size();) - { - int32 arrayElement = animateds[i]->GetArrayElement(); - FUAssert(arrayElement >= (int32) offset, continue); - if (arrayElement >= (int32) (offset + count)) break; - animateds[i]->Release(); // automatic removal from this array.. - } - - // Push back all the array element indices starting at "offset + count" by "count". - for (size_t i = BinarySearch(offset + count); i < animateds.size(); ++i) - { - int32 arrayElement = animateds[i]->GetArrayElement(); - FUAssert(arrayElement >= (int32) (offset + count), continue); - animateds[i]->SetArrayElement(arrayElement - (int32) count); - } -} - -size_t FCDParameterListAnimatable::BinarySearch(size_t arrayElementIndex) const -{ - // Binary search.. - size_t start = 0, end = animateds.size(); - size_t mid; - for (mid = (end + start) / 2; start < end; mid = (end + start) / 2) - { - int32 arrayElement = animateds[mid]->GetArrayElement(); - if (arrayElement < (int32) arrayElementIndex) start = mid + 1; - else if (arrayElement > (int32) arrayElementIndex) end = mid; - else break; - } - return mid; -} - -FCDAnimated* FCDParameterListAnimatable::CreateAnimated(size_t UNUSED(index)) -{ - // Implemented by the specialized template functions below. - return NULL; -} - -// -// FCDParameterListAnimatableT -// - -template <> FCDAnimated* FCDParameterListAnimatableFloat::CreateAnimated(size_t index) -{ - float* _values[1] = { &values[index] }; - return new FCDAnimated((FCDObject*) GetParent(), 1, FCDAnimatedStandardQualifiers::EMPTY, _values); -} - -template <> FCDAnimated* FCDParameterListAnimatableVector2::CreateAnimated(size_t index) -{ - float* _values[2] = { &values[index].x, &values[index].y }; - return new FCDAnimated((FCDObject*) GetParent(), 2, FCDAnimatedStandardQualifiers::XYZW, _values); -} - -template <> FCDAnimated* FCDParameterListAnimatableVector3::CreateAnimated(size_t index) -{ - float* _values[3] = { &values[index].x, &values[index].y, &values[index].z }; - return new FCDAnimated((FCDObject*) GetParent(), 3, FCDAnimatedStandardQualifiers::XYZW, _values); -} - -template <> FCDAnimated* FCDParameterListAnimatableColor3::CreateAnimated(size_t index) -{ - float* _values[3] = { &values[index].x, &values[index].y, &values[index].z }; - return new FCDAnimated((FCDObject*) GetParent(), 3, FCDAnimatedStandardQualifiers::RGBA, _values); -} - -template <> FCDAnimated* FCDParameterListAnimatableVector4::CreateAnimated(size_t index) -{ - float* _values[4] = { &values[index].x, &values[index].y, &values[index].z, &values[index].w }; - return new FCDAnimated((FCDObject*) GetParent(), 4, FCDAnimatedStandardQualifiers::XYZW, _values); -} - -template <> FCDAnimated* FCDParameterListAnimatableColor4::CreateAnimated(size_t index) -{ - float* _values[4] = { &values[index].x, &values[index].y, &values[index].z, &values[index].w }; - return new FCDAnimated((FCDObject*) GetParent(), 4, FCDAnimatedStandardQualifiers::RGBA, _values); -} - -// -// Templatization Trick -// -template void TrickLinkerFCDParameterAnimatableT(const T& value) -{ - FCDParameterAnimatableT v1((FUParameterizable*) NULL), v2((FUParameterizable*) NULL, value); - if (v1 == value) v1 = value; - T bb = (T) v1; (void) bb; - T& bb2 = (T&) v1; (void) bb2; - const T& bb3 = (const T&) v2; (void) bb3; - *v1; - v1.operator->(); - v1.operator*(); - *const_cast&>(v1); - const_cast&>(v1).operator->(); - const_cast&>(v1).operator*(); - FCDAnimated* aa = v1.GetAnimated(); - if (v1.IsAnimated()) ++aa; -} - - -template void TrickLinkerFCDParameterListAnimatableT(const T& value) -{ - FCDParameterListAnimatableT v1((FUParameterizable*) NULL); - v1.push_back(value); - v1 = v1; - v1.set(0, value); - v1.clear(); - v1.insert(0, value); - v1.insert(0, &value, 1); - v1.insert(0, 5, value); - v1.erase((size_t) 5); - v1.erase(value); - v1.erase((size_t) 0, (size_t) 4); - v1.push_back(v1.front()); - v1.push_front(v1.back()); - v1.pop_back(); - v1.pop_front(); - v1.resize(4); - v1.resize(6, value); - v1.empty(); - v1.size(); - if (v1.contains(value) && v1.empty()) v1.find(value); - v1[0]; - v1.at(0); - FCDAnimated* aa = v1.GetAnimated(0); - v1.GetDataList(); - if (v1.IsAnimated()) ++aa; - const_cast&>(v1).front(); - const_cast&>(v1).back(); - const_cast&>(v1).GetDataList(); -} - -extern void TrickLinkerFCDParameterAnimatable() -{ - // Primitive animatables - TrickLinkerFCDParameterAnimatableT(0.03f); - TrickLinkerFCDParameterAnimatableT(FMVector2::XAxis); - TrickLinkerFCDParameterAnimatableT(FMVector3::YAxis); - TrickLinkerFCDParameterAnimatableT(FMVector3::YAxis); - TrickLinkerFCDParameterAnimatableT(FMVector4::Zero); - TrickLinkerFCDParameterAnimatableT(FMVector4::Zero); - TrickLinkerFCDParameterAnimatableT(FMMatrix44::Identity); - TrickLinkerFCDParameterAnimatableT(FMSkew()); - TrickLinkerFCDParameterAnimatableT(FMLookAt()); - TrickLinkerFCDParameterAnimatableT(FMAngleAxis()); - - // Primitive list animatables - TrickLinkerFCDParameterListAnimatableT(0.03f); - TrickLinkerFCDParameterListAnimatableT(FMVector2::XAxis); - TrickLinkerFCDParameterListAnimatableT(FMVector3::YAxis); - TrickLinkerFCDParameterListAnimatableT(FMVector3::YAxis); - TrickLinkerFCDParameterListAnimatableT(FMVector4::Zero); - TrickLinkerFCDParameterListAnimatableT(FMVector4::Zero); -} - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDParameterAnimatable.h" +#if !defined (__APPLE__) && !defined(LINUX) +#include "FCDParameterAnimatable.hpp" +#endif +#include "FCDAnimated.h" +#include +#include +#include +#include + +// +// FCDParameterAnimatable +// + +FCDParameterAnimatable::FCDParameterAnimatable(FUParameterizable* _parent) +: parent(_parent) +{ +} + +FCDParameterAnimatable::~FCDParameterAnimatable() +{ + parent = NULL; +} + +FCDAnimated* FCDParameterAnimatable::GetAnimated() { if (animated == NULL) animated = CreateAnimated(); return animated; } +const FCDAnimated* FCDParameterAnimatable::GetAnimated() const +{ + if (animated == NULL) + { + FCDParameterAnimatable* _this = const_cast(this); + _this->animated = _this->CreateAnimated(); + } + return animated; +} + +bool FCDParameterAnimatable::IsAnimated() const +{ + return animated != NULL && animated->HasCurve(); +} + +FCDAnimated* FCDParameterAnimatable::CreateAnimated() +{ + // Implemented below in template specializations of FCDParameterAnimatableT. + return NULL; +} + +FCDParameterAnimatable& FCDParameterAnimatable::operator= (FCDParameterAnimatable& UNUSED(parameter)) +{ + // This empty copy operator is necessary to avoid the default copy operator + // generated by the compiler which copies the parent pointer. + return *this; +} + +// +// FCDParameterAnimatableT +// + +template <> FCDAnimated* FCDParameterAnimatableFloat::CreateAnimated() +{ + float* values[1] = { &value }; + return new FCDAnimated((FCDObject*) GetParent(), 1, FCDAnimatedStandardQualifiers::EMPTY, values); +} + +template <> FCDAnimated* FCDParameterAnimatableVector2::CreateAnimated() +{ + float* values[2] = { &value.x, &value.y }; + return new FCDAnimated((FCDObject*) GetParent(), 2, FCDAnimatedStandardQualifiers::XYZW, values); +} + +template <> FCDAnimated* FCDParameterAnimatableVector3::CreateAnimated() +{ + float* values[3] = { &value.x, &value.y, &value.z }; + return new FCDAnimated((FCDObject*) GetParent(), 3, FCDAnimatedStandardQualifiers::XYZW, values); +} + +template <> FCDAnimated* FCDParameterAnimatableColor3::CreateAnimated() +{ + float* values[3] = { &value.x, &value.y, &value.z }; + return new FCDAnimated((FCDObject*) GetParent(), 3, FCDAnimatedStandardQualifiers::RGBA, values); +} + +template <> FCDAnimated* FCDParameterAnimatableVector4::CreateAnimated() +{ + float* values[4] = { &value.x, &value.y, &value.z, &value.w }; + return new FCDAnimated((FCDObject*) GetParent(), 4, FCDAnimatedStandardQualifiers::XYZW, values); +} + +template <> FCDAnimated* FCDParameterAnimatableColor4::CreateAnimated() +{ + float* values[4] = { &value.x, &value.y, &value.z, &value.w }; + return new FCDAnimated((FCDObject*) GetParent(), 4, FCDAnimatedStandardQualifiers::RGBA, values); +} + +template <> FCDAnimated* FCDParameterAnimatableMatrix44::CreateAnimated() +{ + float* values[16] = + { + &value[0][0], &value[1][0], &value[2][0], &value[3][0], + &value[0][1], &value[1][1], &value[2][1], &value[3][1], + &value[0][2], &value[1][2], &value[2][2], &value[3][2], + &value[0][3], &value[1][3], &value[2][3], &value[3][3] + }; + return new FCDAnimated((FCDObject*) GetParent(), 16, FCDAnimatedStandardQualifiers::MATRIX, values); +} + +template <> FCDAnimated* FCDParameterAnimatableAngleAxis::CreateAnimated() +{ + float* values[4] = { &value.axis.x, &value.axis.y, &value.axis.z, &value.angle }; + return new FCDAnimated((FCDObject*) GetParent(), 4, FCDAnimatedStandardQualifiers::ROTATE_AXIS, values); +} + +template <> FCDAnimated* FCDParameterAnimatableLookAt::CreateAnimated() +{ + float* values[9] = + { + &value.position.x, &value.position.y, &value.position.z, + &value.target.x, &value.target.y, &value.target.z, + &value.up.x, &value.up.y, &value.up.z + }; + return new FCDAnimated((FCDObject*) GetParent(), 9, FCDAnimatedStandardQualifiers::LOOKAT, values); +} + +template <> FCDAnimated* FCDParameterAnimatableSkew::CreateAnimated() +{ + float* values[7] = + { + &value.rotateAxis.x, &value.rotateAxis.y, &value.rotateAxis.z, + &value.aroundAxis.x, &value.aroundAxis.y, &value.aroundAxis.z, + &value.angle + }; + return new FCDAnimated((FCDObject*) GetParent(), 7, FCDAnimatedStandardQualifiers::LOOKAT, values); +} + +// +// FCDParameterListAnimatable +// +FCDParameterListAnimatable::FCDParameterListAnimatable(FUParameterizable* _parent) +: parent(_parent) +{ +} + +FCDParameterListAnimatable::~FCDParameterListAnimatable() +{ + parent = NULL; +} + +const FCDAnimated* FCDParameterListAnimatable::GetAnimated(size_t index) const { return const_cast(const_cast(this)->GetAnimated(index)); } +FCDAnimated* FCDParameterListAnimatable::GetAnimated(size_t index) +{ + // Check for existing + size_t mid = BinarySearch(index); + if (mid < animateds.size() && animateds[mid]->GetArrayElement() == (int32) index) + { + return animateds[mid]; + } + + // Create new animated value. + FCDAnimated* animated = CreateAnimated(index); + animated->SetArrayElement((int32) index); + animateds.insert(mid, animated); + return animated; +} + +bool FCDParameterListAnimatable::IsAnimated(size_t index) const +{ + size_t animatedCount = animateds.size(); + if (index == ~(size_t)0) + { + for (size_t i = 0; i < animatedCount; ++i) + { + if (animateds[i]->HasCurve()) return true; + } + return false; + } + else + { + size_t i = BinarySearch(index); + return i < animatedCount && animateds[i]->GetArrayElement() == (int32) index && animateds[i]->HasCurve(); + } +} + +void FCDParameterListAnimatable::OnInsertion(size_t offset, size_t count) +{ + // Push forward all the array element indices starting at "offset" by "count". + for (size_t i = BinarySearch(offset); i < animateds.size(); ++i) + { + int32 arrayElement = animateds[i]->GetArrayElement(); + FUAssert(arrayElement >= (int32) offset, continue); + animateds[i]->SetArrayElement(arrayElement + (int32) count); + } +} + +void FCDParameterListAnimatable::OnRemoval(size_t offset, size_t count) +{ + // Release all the animated helpers for the removed values. + for (size_t i = BinarySearch(offset); i < animateds.size();) + { + int32 arrayElement = animateds[i]->GetArrayElement(); + FUAssert(arrayElement >= (int32) offset, continue); + if (arrayElement >= (int32) (offset + count)) break; + animateds[i]->Release(); // automatic removal from this array.. + } + + // Push back all the array element indices starting at "offset + count" by "count". + for (size_t i = BinarySearch(offset + count); i < animateds.size(); ++i) + { + int32 arrayElement = animateds[i]->GetArrayElement(); + FUAssert(arrayElement >= (int32) (offset + count), continue); + animateds[i]->SetArrayElement(arrayElement - (int32) count); + } +} + +size_t FCDParameterListAnimatable::BinarySearch(size_t arrayElementIndex) const +{ + // Binary search.. + size_t start = 0, end = animateds.size(); + size_t mid; + for (mid = (end + start) / 2; start < end; mid = (end + start) / 2) + { + int32 arrayElement = animateds[mid]->GetArrayElement(); + if (arrayElement < (int32) arrayElementIndex) start = mid + 1; + else if (arrayElement > (int32) arrayElementIndex) end = mid; + else break; + } + return mid; +} + +FCDAnimated* FCDParameterListAnimatable::CreateAnimated(size_t UNUSED(index)) +{ + // Implemented by the specialized template functions below. + return NULL; +} + +// +// FCDParameterListAnimatableT +// + +template <> FCDAnimated* FCDParameterListAnimatableFloat::CreateAnimated(size_t index) +{ + float* _values[1] = { &values[index] }; + return new FCDAnimated((FCDObject*) GetParent(), 1, FCDAnimatedStandardQualifiers::EMPTY, _values); +} + +template <> FCDAnimated* FCDParameterListAnimatableVector2::CreateAnimated(size_t index) +{ + float* _values[2] = { &values[index].x, &values[index].y }; + return new FCDAnimated((FCDObject*) GetParent(), 2, FCDAnimatedStandardQualifiers::XYZW, _values); +} + +template <> FCDAnimated* FCDParameterListAnimatableVector3::CreateAnimated(size_t index) +{ + float* _values[3] = { &values[index].x, &values[index].y, &values[index].z }; + return new FCDAnimated((FCDObject*) GetParent(), 3, FCDAnimatedStandardQualifiers::XYZW, _values); +} + +template <> FCDAnimated* FCDParameterListAnimatableColor3::CreateAnimated(size_t index) +{ + float* _values[3] = { &values[index].x, &values[index].y, &values[index].z }; + return new FCDAnimated((FCDObject*) GetParent(), 3, FCDAnimatedStandardQualifiers::RGBA, _values); +} + +template <> FCDAnimated* FCDParameterListAnimatableVector4::CreateAnimated(size_t index) +{ + float* _values[4] = { &values[index].x, &values[index].y, &values[index].z, &values[index].w }; + return new FCDAnimated((FCDObject*) GetParent(), 4, FCDAnimatedStandardQualifiers::XYZW, _values); +} + +template <> FCDAnimated* FCDParameterListAnimatableColor4::CreateAnimated(size_t index) +{ + float* _values[4] = { &values[index].x, &values[index].y, &values[index].z, &values[index].w }; + return new FCDAnimated((FCDObject*) GetParent(), 4, FCDAnimatedStandardQualifiers::RGBA, _values); +} + +// +// Templatization Trick +// +template void TrickLinkerFCDParameterAnimatableT(const T& value) +{ + FCDParameterAnimatableT v1((FUParameterizable*) NULL), v2((FUParameterizable*) NULL, value); + if (v1 == value) v1 = value; + T bb = (T) v1; (void) bb; + T& bb2 = (T&) v1; (void) bb2; + const T& bb3 = (const T&) v2; (void) bb3; + *v1; + v1.operator->(); + v1.operator*(); + *const_cast&>(v1); + const_cast&>(v1).operator->(); + const_cast&>(v1).operator*(); + FCDAnimated* aa = v1.GetAnimated(); + if (v1.IsAnimated()) ++aa; +} + + +template void TrickLinkerFCDParameterListAnimatableT(const T& value) +{ + FCDParameterListAnimatableT v1((FUParameterizable*) NULL); + v1.push_back(value); + v1 = v1; + v1.set(0, value); + v1.clear(); + v1.insert(0, value); + v1.insert(0, &value, 1); + v1.insert(0, 5, value); + v1.erase((size_t) 5); + v1.erase(value); + v1.erase((size_t) 0, (size_t) 4); + v1.push_back(v1.front()); + v1.push_front(v1.back()); + v1.pop_back(); + v1.pop_front(); + v1.resize(4); + v1.resize(6, value); + v1.empty(); + v1.size(); + if (v1.contains(value) && v1.empty()) v1.find(value); + v1[0]; + v1.at(0); + FCDAnimated* aa = v1.GetAnimated(0); + v1.GetDataList(); + if (v1.IsAnimated()) ++aa; + const_cast&>(v1).front(); + const_cast&>(v1).back(); + const_cast&>(v1).GetDataList(); +} + +extern void TrickLinkerFCDParameterAnimatable() +{ + // Primitive animatables + TrickLinkerFCDParameterAnimatableT(0.03f); + TrickLinkerFCDParameterAnimatableT(FMVector2::XAxis); + TrickLinkerFCDParameterAnimatableT(FMVector3::YAxis); + TrickLinkerFCDParameterAnimatableT(FMVector3::YAxis); + TrickLinkerFCDParameterAnimatableT(FMVector4::Zero); + TrickLinkerFCDParameterAnimatableT(FMVector4::Zero); + TrickLinkerFCDParameterAnimatableT(FMMatrix44::Identity); + TrickLinkerFCDParameterAnimatableT(FMSkew()); + TrickLinkerFCDParameterAnimatableT(FMLookAt()); + TrickLinkerFCDParameterAnimatableT(FMAngleAxis()); + + // Primitive list animatables + TrickLinkerFCDParameterListAnimatableT(0.03f); + TrickLinkerFCDParameterListAnimatableT(FMVector2::XAxis); + TrickLinkerFCDParameterListAnimatableT(FMVector3::YAxis); + TrickLinkerFCDParameterListAnimatableT(FMVector3::YAxis); + TrickLinkerFCDParameterListAnimatableT(FMVector4::Zero); + TrickLinkerFCDParameterListAnimatableT(FMVector4::Zero); +} + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObjectWithId.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObjectWithId.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObjectWithId.h (revision 24247) @@ -1,108 +1,108 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDObjectWithId.h - This file contains the FCDObjectWithId class. -*/ - -#ifndef __FCD_OBJECT_WITH_ID_H_ -#define __FCD_OBJECT_WITH_ID_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -/** - A basic COLLADA object which has a unique COLLADA id. - - Many COLLADA structures such as entities and sources need a unique COLLADA id. - The COLLADA document contains a map of all the COLLADA ids known in its scope. - The interface of the FCDObjectWithId class allows for the retrieval and the modification - of the unique COLLADA id attached to these objects. - - A unique COLLADA id is built, if none are provided, using the 'baseId' field of the constructor. - A unique COLLADA id is generated only on demand. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDObjectWithId : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, daeId, FC("Unique Id")); - -private: - DeclareFlag(UniqueId, 0); /**< Whether the object's current id is considered unique. */ -public: - DeclareFlag(DaeIdChanged, 1); - DeclareFlagCount(2); - -public: - /** Constructor: sets the prefix COLLADA id to be used if no COLLADA id is provided. - @param document The COLLADA document which owns this object. - @param baseId The prefix COLLADA id to be used if no COLLADA id is provided. */ - FCDObjectWithId(FCDocument* document, const char* baseId = "ObjectWithID"); - - /** Destructor. */ - virtual ~FCDObjectWithId(); - - /** Retrieves the unique COLLADA id for this object. - If no unique COLLADA id has been previously generated or provided, this function - has the side-effect of generating a unique COLLADA id. - @return The unique COLLADA id. */ - const fm::string& GetDaeId() const; - - /** Sets the COLLADA id for this object. - There is no guarantee that the given COLLADA id will be used, as it may not be unique. - You can call the GetDaeId function after this call to retrieve the final, unique COLLADA id. - @param id The wanted COLLADA id for this object. This COLLADA id does not need to be unique. - If the COLLADA id is not unique, a new unique COLLADA id will be generated. */ - void SetDaeId(const fm::string& id); - - /** Sets the COLLADA id for this object. - There is no guarantee that the given COLLADA id will be used, as it may not be unique. - @param id The wanted COLLADA id for this object. This COLLADA id does not need to be unique. - If the COLLADA id is not unique, a new unique COLLADA id will be generated and - this formal variable will be modified to contain the new COLLADA id. */ - void SetDaeId(fm::string& id); - - /** [INTERNAL] Release the unique COLLADA id of an object. - Use this function wisely, as it leaves the object id-less and without a way to automatically - generate a COLLADA id. */ - void RemoveDaeId(); - - /** [INTERNAL] Clones the object. The unique COLLADA id will be copied over to the clone object. - Use carefully: when a cloned object with an id is released, it - does remove the unique COLLADA id from the unique name map. - @param clone The object clone. */ - void Clone(FCDObjectWithId* clone) const; - - /** Cleans up a given name into a valid COLLADA id. - This function does no check for uniqueness. - @param id A name. - @return A valid COLLADA id. The returned value is a static variable reference. - If you want to keep this information, copy it to a local value. */ - static fm::string CleanId(const char* id); - inline static const fm::string CleanId(const fm::string& id) { return CleanId(id.c_str()); } /**< See above. */ - - /** Cleans up a given name into a valid COLLADA sub-id. - This function does no check for uniqueness. - Sub-ids support even less characters than ids. - @param sid A sub-id. - @return A valid COLLADA id. The returned value is a static variable reference. - If you want to keep this information, copy it to a local value. */ - static fm::string CleanSubId(const char* sid); - inline static const fm::string CleanSubId(const fm::string& sid) { return CleanSubId(sid.c_str()); } /**< See above. */ -}; - -#endif // __FCD_OBJECT_WITH_ID_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDObjectWithId.h + This file contains the FCDObjectWithId class. +*/ + +#ifndef __FCD_OBJECT_WITH_ID_H_ +#define __FCD_OBJECT_WITH_ID_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +/** + A basic COLLADA object which has a unique COLLADA id. + + Many COLLADA structures such as entities and sources need a unique COLLADA id. + The COLLADA document contains a map of all the COLLADA ids known in its scope. + The interface of the FCDObjectWithId class allows for the retrieval and the modification + of the unique COLLADA id attached to these objects. + + A unique COLLADA id is built, if none are provided, using the 'baseId' field of the constructor. + A unique COLLADA id is generated only on demand. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDObjectWithId : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, daeId, FC("Unique Id")); + +private: + DeclareFlag(UniqueId, 0); /**< Whether the object's current id is considered unique. */ +public: + DeclareFlag(DaeIdChanged, 1); + DeclareFlagCount(2); + +public: + /** Constructor: sets the prefix COLLADA id to be used if no COLLADA id is provided. + @param document The COLLADA document which owns this object. + @param baseId The prefix COLLADA id to be used if no COLLADA id is provided. */ + FCDObjectWithId(FCDocument* document, const char* baseId = "ObjectWithID"); + + /** Destructor. */ + virtual ~FCDObjectWithId(); + + /** Retrieves the unique COLLADA id for this object. + If no unique COLLADA id has been previously generated or provided, this function + has the side-effect of generating a unique COLLADA id. + @return The unique COLLADA id. */ + const fm::string& GetDaeId() const; + + /** Sets the COLLADA id for this object. + There is no guarantee that the given COLLADA id will be used, as it may not be unique. + You can call the GetDaeId function after this call to retrieve the final, unique COLLADA id. + @param id The wanted COLLADA id for this object. This COLLADA id does not need to be unique. + If the COLLADA id is not unique, a new unique COLLADA id will be generated. */ + void SetDaeId(const fm::string& id); + + /** Sets the COLLADA id for this object. + There is no guarantee that the given COLLADA id will be used, as it may not be unique. + @param id The wanted COLLADA id for this object. This COLLADA id does not need to be unique. + If the COLLADA id is not unique, a new unique COLLADA id will be generated and + this formal variable will be modified to contain the new COLLADA id. */ + void SetDaeId(fm::string& id); + + /** [INTERNAL] Release the unique COLLADA id of an object. + Use this function wisely, as it leaves the object id-less and without a way to automatically + generate a COLLADA id. */ + void RemoveDaeId(); + + /** [INTERNAL] Clones the object. The unique COLLADA id will be copied over to the clone object. + Use carefully: when a cloned object with an id is released, it + does remove the unique COLLADA id from the unique name map. + @param clone The object clone. */ + void Clone(FCDObjectWithId* clone) const; + + /** Cleans up a given name into a valid COLLADA id. + This function does no check for uniqueness. + @param id A name. + @return A valid COLLADA id. The returned value is a static variable reference. + If you want to keep this information, copy it to a local value. */ + static fm::string CleanId(const char* id); + inline static const fm::string CleanId(const fm::string& id) { return CleanId(id.c_str()); } /**< See above. */ + + /** Cleans up a given name into a valid COLLADA sub-id. + This function does no check for uniqueness. + Sub-ids support even less characters than ids. + @param sid A sub-id. + @return A valid COLLADA id. The returned value is a static variable reference. + If you want to keep this information, copy it to a local value. */ + static fm::string CleanSubId(const char* sid); + inline static const fm::string CleanSubId(const fm::string& sid) { return CleanSubId(sid.c_str()); } /**< See above. */ +}; + +#endif // __FCD_OBJECT_WITH_ID_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObjectWithId.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObjectWithId.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObjectWithId.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObjectWithId.cpp (revision 24247) @@ -1,139 +1,139 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument.h" -#include "FCDObjectWithId.h" -#include "FUtils/FUUniqueStringMap.h" - -static const size_t MAX_ID_LENGTH = 512; - -// -// FCDObjectWithId -// - -ImplementObjectType(FCDObjectWithId); - -FCDObjectWithId::FCDObjectWithId(FCDocument* document, const char* baseId) -: FCDObject(document) -, InitializeParameter(daeId, baseId) -{ - ResetUniqueIdFlag(); -} - -FCDObjectWithId::~FCDObjectWithId() -{ - RemoveDaeId(); -} - -void FCDObjectWithId::Clone(FCDObjectWithId* clone) const -{ - clone->daeId = daeId; - const_cast(this)->RemoveDaeId(); -} - -const fm::string& FCDObjectWithId::GetDaeId() const -{ - if (!GetUniqueIdFlag()) - { - // Generate a new id - FCDObjectWithId* e = const_cast(this); - FUSUniqueStringMap* names = e->GetDocument()->GetUniqueNameMap(); - FUAssert(!e->daeId->empty(), e->daeId = "unknown_object"); - names->insert(e->daeId); - e->SetUniqueIdFlag(); - } - return daeId; -} - -void FCDObjectWithId::SetDaeId(const fm::string& id) -{ - RemoveDaeId(); - - // Use this id to enforce a unique id. - FUSUniqueStringMap* names = GetDocument()->GetUniqueNameMap(); - daeId = CleanId(id); - names->insert(daeId); - SetUniqueIdFlag(); - SetDirtyFlag(); -} - -void FCDObjectWithId::SetDaeId(fm::string& id) -{ - SetDaeId(*(const fm::string*)&id); - id = daeId; // We return back the new value. -} - -void FCDObjectWithId::RemoveDaeId() -{ - if (GetUniqueIdFlag()) - { - FUSUniqueStringMap* names = GetDocument()->GetUniqueNameMap(); - names->erase(daeId); - ResetUniqueIdFlag(); - SetDirtyFlag(); - } -} - -// Clean-up the id and names to match the schema definitions of 'IDref' and 'Name'. -fm::string FCDObjectWithId::CleanId(const char* c) -{ - size_t len = 0; - for (; len < MAX_ID_LENGTH; len++) { if (c[len] == 0) break; } - fm::string out(len, *c); - char* id = out.begin(); - if (*c != 0) - { - // First character: alphabetic or '_'. - if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') *id = *c; - else *id = '_'; - - // Other characters: alphabetic, numeric, '_', '-' or '.'. - // Otherwise, use HTML extended character write-up: &#; - // NOTE: ':' is not an acceptable characters. - //for (++c, ++id; *c != 0; ++c, ++id) - for (size_t i = 1; i < len; i++) - { - ++c; ++id; - if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_' || *c == '-' || *c == '.') *id = *c; - else *id = '_'; - } - // Dont forget to close. - *(++id) = 0; - } - return out; -} - -fm::string FCDObjectWithId::CleanSubId(const char* c) -{ - size_t len = 0; - for (; len < MAX_ID_LENGTH; len++) { if (c[len] == 0) break; } - fm::string out(len, *c); - char* sid = out.begin(); - if (*c != 0) - { - // First character: alphabetic or '_'. - if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') *sid = *c; - else *sid = '_'; - - // Other characters: alphabetic, numeric, '_', '-' or '.'. - // Otherwise, use HTML extended character write-up: &#; - // NOTE: ':' is not an acceptable characters. - //for (++c, ++id; *c != 0; ++c, ++id) - for (size_t i = 1; i < len; i++) - { - ++c; ++sid; - if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_' || *c == '-') *sid = *c; - else *sid = '_'; - } - // Dont forget to close. - *(++sid) = 0; - } - return out; -} - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument.h" +#include "FCDObjectWithId.h" +#include "FUtils/FUUniqueStringMap.h" + +static const size_t MAX_ID_LENGTH = 512; + +// +// FCDObjectWithId +// + +ImplementObjectType(FCDObjectWithId); + +FCDObjectWithId::FCDObjectWithId(FCDocument* document, const char* baseId) +: FCDObject(document) +, InitializeParameter(daeId, baseId) +{ + ResetUniqueIdFlag(); +} + +FCDObjectWithId::~FCDObjectWithId() +{ + RemoveDaeId(); +} + +void FCDObjectWithId::Clone(FCDObjectWithId* clone) const +{ + clone->daeId = daeId; + const_cast(this)->RemoveDaeId(); +} + +const fm::string& FCDObjectWithId::GetDaeId() const +{ + if (!GetUniqueIdFlag()) + { + // Generate a new id + FCDObjectWithId* e = const_cast(this); + FUSUniqueStringMap* names = e->GetDocument()->GetUniqueNameMap(); + FUAssert(!e->daeId->empty(), e->daeId = "unknown_object"); + names->insert(e->daeId); + e->SetUniqueIdFlag(); + } + return daeId; +} + +void FCDObjectWithId::SetDaeId(const fm::string& id) +{ + RemoveDaeId(); + + // Use this id to enforce a unique id. + FUSUniqueStringMap* names = GetDocument()->GetUniqueNameMap(); + daeId = CleanId(id); + names->insert(daeId); + SetUniqueIdFlag(); + SetDirtyFlag(); +} + +void FCDObjectWithId::SetDaeId(fm::string& id) +{ + SetDaeId(*(const fm::string*)&id); + id = daeId; // We return back the new value. +} + +void FCDObjectWithId::RemoveDaeId() +{ + if (GetUniqueIdFlag()) + { + FUSUniqueStringMap* names = GetDocument()->GetUniqueNameMap(); + names->erase(daeId); + ResetUniqueIdFlag(); + SetDirtyFlag(); + } +} + +// Clean-up the id and names to match the schema definitions of 'IDref' and 'Name'. +fm::string FCDObjectWithId::CleanId(const char* c) +{ + size_t len = 0; + for (; len < MAX_ID_LENGTH; len++) { if (c[len] == 0) break; } + fm::string out(len, *c); + char* id = out.begin(); + if (*c != 0) + { + // First character: alphabetic or '_'. + if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') *id = *c; + else *id = '_'; + + // Other characters: alphabetic, numeric, '_', '-' or '.'. + // Otherwise, use HTML extended character write-up: &#; + // NOTE: ':' is not an acceptable characters. + //for (++c, ++id; *c != 0; ++c, ++id) + for (size_t i = 1; i < len; i++) + { + ++c; ++id; + if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_' || *c == '-' || *c == '.') *id = *c; + else *id = '_'; + } + // Dont forget to close. + *(++id) = 0; + } + return out; +} + +fm::string FCDObjectWithId::CleanSubId(const char* c) +{ + size_t len = 0; + for (; len < MAX_ID_LENGTH; len++) { if (c[len] == 0) break; } + fm::string out(len, *c); + char* sid = out.begin(); + if (*c != 0) + { + // First character: alphabetic or '_'. + if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') *sid = *c; + else *sid = '_'; + + // Other characters: alphabetic, numeric, '_', '-' or '.'. + // Otherwise, use HTML extended character write-up: &#; + // NOTE: ':' is not an acceptable characters. + //for (++c, ++id; *c != 0; ++c, ++id) + for (size_t i = 1; i < len; i++) + { + ++c; ++sid; + if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_' || *c == '-') *sid = *c; + else *sid = '_'; + } + // Dont forget to close. + *(++sid) = 0; + } + return out; +} + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDObjectWithId.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.hpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.hpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.hpp (revision 24247) @@ -1,217 +1,217 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#ifndef _FCD_ANIMATED_H_ -#include "FCDocument/FCDAnimated.h" -#endif // _FCD_ANIMATED_H_ - -// -// FCDParameterAnimatableT -// - -template -FCDParameterAnimatableT::FCDParameterAnimatableT(FUParameterizable* _parent) -: FCDParameterAnimatable(_parent) -{ -} - -template -FCDParameterAnimatableT::FCDParameterAnimatableT(FUParameterizable* _parent, const TYPE& defaultValue) -: FCDParameterAnimatable(_parent) -, value(defaultValue) -{ -} - -template -FCDParameterAnimatableT::~FCDParameterAnimatableT() -{ -} - -template -FCDParameterAnimatableT& FCDParameterAnimatableT::operator= (const TYPE& copy) -{ - value = copy; - GetParent()->SetValueChange(); - return *this; -} - -// -// FCDParameterListAnimatableT -// - -template -FCDParameterListAnimatableT::FCDParameterListAnimatableT(FUParameterizable* parent) -: FCDParameterListAnimatable(parent) -{ -} - -template -FCDParameterListAnimatableT::~FCDParameterListAnimatableT() -{ -} - -template -void FCDParameterListAnimatableT::set(size_t index, const TYPE& value) -{ - values.at(index) = value; - GetParent()->SetValueChange(); -} - -template -void FCDParameterListAnimatableT::insert(size_t index, const TYPE& value) -{ - values.insert(values.begin() + index, value); - GetParent()->SetStructureChangedFlag(); - GetParent()->SetDirtyFlag(); - OnInsertion(index, 1); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::insert(size_t index, const TYPE* _values, size_t count) -{ - values.insert(values.begin() + index, _values, count); - GetParent()->SetStructureChangedFlag(); - GetParent()->SetDirtyFlag(); - OnInsertion(index, count); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::insert(size_t index, size_t count, const TYPE& value) -{ - values.insert(values.begin() + index, count, value); - GetParent()->SetStructureChangedFlag(); - GetParent()->SetDirtyFlag(); - OnInsertion(index, count); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::erase(size_t index) -{ - values.erase(index); - GetParent()->SetStructureChangedFlag(); - GetParent()->SetDirtyFlag(); - OnRemoval(index, 1); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::erase(const TYPE& value) -{ - size_t index = find(value); - if (index < values.size()) erase(index); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::erase(size_t start, size_t end) -{ - values.erase(values.begin() + start, values.begin() + end); - GetParent()->SetStructureChangedFlag(); - GetParent()->SetDirtyFlag(); - OnRemoval(start, end - start); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::clear() -{ - OnRemoval(0, values.size()); - values.clear(); - GetParent()->SetStructureChangedFlag(); - GetParent()->SetDirtyFlag(); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::push_back(const TYPE& value) -{ - OnInsertion(values.size(), 1); - values.push_back(value); - GetParent()->SetStructureChangedFlag(); - GetParent()->SetDirtyFlag(); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::push_front(const TYPE& value) -{ - values.push_front(value); - GetParent()->SetStructureChangedFlag(); - GetParent()->SetDirtyFlag(); - OnInsertion(0, 1); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::pop_back() -{ - OnRemoval(size() - 1, 1); - values.pop_back(); - GetParent()->SetStructureChangedFlag(); - GetParent()->SetDirtyFlag(); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::pop_front() -{ - values.pop_front(); - GetParent()->SetStructureChangedFlag(); - GetParent()->SetDirtyFlag(); - OnRemoval(0, 1); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::resize(size_t count) -{ - if (count > values.size()) OnInsertion(values.size(), count - values.size()); - else if (count < values.size()) OnRemoval(count, values.size() - count); - values.resize(count); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::resize(size_t count, const TYPE& value) -{ - if (count > values.size()) OnInsertion(values.size(), count - values.size()); - else if (count < values.size()) OnRemoval(count - values.size(), values.size()); - values.resize(count, value); - OnPotentialSizeChange(); -} - -template -void FCDParameterListAnimatableT::OnPotentialSizeChange() -{ - size_t animatedCount = animateds.size(); - if (animatedCount == 0) return; - - // Check if the first FCDAnimated points to the correct values. - // If it does, then they all should be fine. - FCDAnimated* animated = animateds.front(); - FUAssert((size_t) animated->GetArrayElement() < values.size(), return); - if (animated->GetValue(0) == (void*) &values[animated->GetArrayElement()]) return; - - // Process all the animateds and set their value pointers. - // IMPORTANT: it is assumed that these values are FLOATS and ORDERED. - size_t stride = animated->GetValueCount(); - for (size_t i = 0; i < animatedCount; ++i) - { - animated = animateds[i]; - size_t arrayElement = animated->GetArrayElement(); - FUAssert(arrayElement < values.size(), return); - for (size_t j = 0; j < stride; ++j) - { - animated->SetValue(j, (float*) (j * sizeof(float) + ((char*) &values[arrayElement]))); - } - } -} - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef _FCD_ANIMATED_H_ +#include "FCDocument/FCDAnimated.h" +#endif // _FCD_ANIMATED_H_ + +// +// FCDParameterAnimatableT +// + +template +FCDParameterAnimatableT::FCDParameterAnimatableT(FUParameterizable* _parent) +: FCDParameterAnimatable(_parent) +{ +} + +template +FCDParameterAnimatableT::FCDParameterAnimatableT(FUParameterizable* _parent, const TYPE& defaultValue) +: FCDParameterAnimatable(_parent) +, value(defaultValue) +{ +} + +template +FCDParameterAnimatableT::~FCDParameterAnimatableT() +{ +} + +template +FCDParameterAnimatableT& FCDParameterAnimatableT::operator= (const TYPE& copy) +{ + value = copy; + GetParent()->SetValueChange(); + return *this; +} + +// +// FCDParameterListAnimatableT +// + +template +FCDParameterListAnimatableT::FCDParameterListAnimatableT(FUParameterizable* parent) +: FCDParameterListAnimatable(parent) +{ +} + +template +FCDParameterListAnimatableT::~FCDParameterListAnimatableT() +{ +} + +template +void FCDParameterListAnimatableT::set(size_t index, const TYPE& value) +{ + values.at(index) = value; + GetParent()->SetValueChange(); +} + +template +void FCDParameterListAnimatableT::insert(size_t index, const TYPE& value) +{ + values.insert(values.begin() + index, value); + GetParent()->SetStructureChangedFlag(); + GetParent()->SetDirtyFlag(); + OnInsertion(index, 1); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::insert(size_t index, const TYPE* _values, size_t count) +{ + values.insert(values.begin() + index, _values, count); + GetParent()->SetStructureChangedFlag(); + GetParent()->SetDirtyFlag(); + OnInsertion(index, count); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::insert(size_t index, size_t count, const TYPE& value) +{ + values.insert(values.begin() + index, count, value); + GetParent()->SetStructureChangedFlag(); + GetParent()->SetDirtyFlag(); + OnInsertion(index, count); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::erase(size_t index) +{ + values.erase(index); + GetParent()->SetStructureChangedFlag(); + GetParent()->SetDirtyFlag(); + OnRemoval(index, 1); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::erase(const TYPE& value) +{ + size_t index = find(value); + if (index < values.size()) erase(index); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::erase(size_t start, size_t end) +{ + values.erase(values.begin() + start, values.begin() + end); + GetParent()->SetStructureChangedFlag(); + GetParent()->SetDirtyFlag(); + OnRemoval(start, end - start); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::clear() +{ + OnRemoval(0, values.size()); + values.clear(); + GetParent()->SetStructureChangedFlag(); + GetParent()->SetDirtyFlag(); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::push_back(const TYPE& value) +{ + OnInsertion(values.size(), 1); + values.push_back(value); + GetParent()->SetStructureChangedFlag(); + GetParent()->SetDirtyFlag(); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::push_front(const TYPE& value) +{ + values.push_front(value); + GetParent()->SetStructureChangedFlag(); + GetParent()->SetDirtyFlag(); + OnInsertion(0, 1); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::pop_back() +{ + OnRemoval(size() - 1, 1); + values.pop_back(); + GetParent()->SetStructureChangedFlag(); + GetParent()->SetDirtyFlag(); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::pop_front() +{ + values.pop_front(); + GetParent()->SetStructureChangedFlag(); + GetParent()->SetDirtyFlag(); + OnRemoval(0, 1); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::resize(size_t count) +{ + if (count > values.size()) OnInsertion(values.size(), count - values.size()); + else if (count < values.size()) OnRemoval(count, values.size() - count); + values.resize(count); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::resize(size_t count, const TYPE& value) +{ + if (count > values.size()) OnInsertion(values.size(), count - values.size()); + else if (count < values.size()) OnRemoval(count - values.size(), values.size()); + values.resize(count, value); + OnPotentialSizeChange(); +} + +template +void FCDParameterListAnimatableT::OnPotentialSizeChange() +{ + size_t animatedCount = animateds.size(); + if (animatedCount == 0) return; + + // Check if the first FCDAnimated points to the correct values. + // If it does, then they all should be fine. + FCDAnimated* animated = animateds.front(); + FUAssert((size_t) animated->GetArrayElement() < values.size(), return); + if (animated->GetValue(0) == (void*) &values[animated->GetArrayElement()]) return; + + // Process all the animateds and set their value pointers. + // IMPORTANT: it is assumed that these values are FLOATS and ORDERED. + size_t stride = animated->GetValueCount(); + for (size_t i = 0; i < animatedCount; ++i) + { + animated = animateds[i]; + size_t arrayElement = animated->GetArrayElement(); + FUAssert(arrayElement < values.size(), return); + for (size_t j = 0; j < stride; ++j) + { + animated->SetValue(j, (float*) (j * sizeof(float) + ((char*) &values[arrayElement]))); + } + } +} + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParameterAnimatable.hpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleModifier.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleModifier.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleModifier.h (revision 24247) @@ -1,25 +1,25 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDParticleModifier.h - This file contains the FCDParticleModifier base class, and - its various definitions. -*/ - -#ifndef _FCD_PARTICLE_MODIFIER_H_ -#define _FCD_PARTICLE_MODIFIER_H_ - -#ifndef _FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // _FCD_OBJECT_H_ -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -#endif // _FCD_PARTICLE_MODIFIER_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDParticleModifier.h + This file contains the FCDParticleModifier base class, and + its various definitions. +*/ + +#ifndef _FCD_PARTICLE_MODIFIER_H_ +#define _FCD_PARTICLE_MODIFIER_H_ + +#ifndef _FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // _FCD_OBJECT_H_ +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +#endif // _FCD_PARTICLE_MODIFIER_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleModifier.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsForceFieldInstance.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsForceFieldInstance.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsForceFieldInstance.h (revision 24247) @@ -1,68 +1,68 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsForceFieldInstance.h - This file contains the FCDPhysicsForceFieldInstance class. -*/ -#ifndef _FCD_PHYSICS_FORCE_FIELD_INSTANCE_H_ -#define _FCD_PHYSICS_FORCE_FIELD_INSTANCE_H_ - -#ifndef _FCD_ENTITY_INSTANCE_H_ -#include "FCDocument/FCDEntityInstance.h" -#endif // _FCD_ENTITY_INSTANCE_H_ - -class FCDocument; - -/** - A COLLADA force field instance. -*/ -class FCOLLADA_EXPORT FCDPhysicsForceFieldInstance : public FCDEntityInstance -{ -private: - DeclareObjectType(FCDEntityInstance); - - friend class FCDEntityInstanceFactory; - -protected: - /** Constructor: do not use directly. Create new physics force fields using - the FCDEntityInstanceFactory::CreateInstance function. - @param document The COLLADA document that contains this physics model - instance. - @param parent The parent node for this force field. At the time of - writing, this should be NULL since only parents are physics model - instances and physics scene. - @param entityType The entity type: FORCE_FIELD. */ - FCDPhysicsForceFieldInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType = FCDEntity::FORCE_FIELD); - -public: - /** Destructor. */ - virtual ~FCDPhysicsForceFieldInstance(); - - /** Retrieves the entity instance class type. - This is used to determine the up-class for the entity instance object. - @deprecated Instead use: FCDEntityInstance::HasType( - FCDGeometryInstance::GetClassType()) - @return The class type: PHYSICS_FORCE_FIELD. */ - virtual Type GetType() const { return PHYSICS_FORCE_FIELD; } - - /** Clones the physics force field instance. - @param clone The physics force field instance to become the clone. - If this pointer is NULL, a new physics force field instance will be - created and you will need to release it. - @return The clone. */ - virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; -}; - -#endif // _FCD_PHYSICS_FORCE_FIELD_INSTANCE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsForceFieldInstance.h + This file contains the FCDPhysicsForceFieldInstance class. +*/ +#ifndef _FCD_PHYSICS_FORCE_FIELD_INSTANCE_H_ +#define _FCD_PHYSICS_FORCE_FIELD_INSTANCE_H_ + +#ifndef _FCD_ENTITY_INSTANCE_H_ +#include "FCDocument/FCDEntityInstance.h" +#endif // _FCD_ENTITY_INSTANCE_H_ + +class FCDocument; + +/** + A COLLADA force field instance. +*/ +class FCOLLADA_EXPORT FCDPhysicsForceFieldInstance : public FCDEntityInstance +{ +private: + DeclareObjectType(FCDEntityInstance); + + friend class FCDEntityInstanceFactory; + +protected: + /** Constructor: do not use directly. Create new physics force fields using + the FCDEntityInstanceFactory::CreateInstance function. + @param document The COLLADA document that contains this physics model + instance. + @param parent The parent node for this force field. At the time of + writing, this should be NULL since only parents are physics model + instances and physics scene. + @param entityType The entity type: FORCE_FIELD. */ + FCDPhysicsForceFieldInstance(FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType = FCDEntity::FORCE_FIELD); + +public: + /** Destructor. */ + virtual ~FCDPhysicsForceFieldInstance(); + + /** Retrieves the entity instance class type. + This is used to determine the up-class for the entity instance object. + @deprecated Instead use: FCDEntityInstance::HasType( + FCDGeometryInstance::GetClassType()) + @return The class type: PHYSICS_FORCE_FIELD. */ + virtual Type GetType() const { return PHYSICS_FORCE_FIELD; } + + /** Clones the physics force field instance. + @param clone The physics force field instance to become the clone. + If this pointer is NULL, a new physics force field instance will be + created and you will need to release it. + @return The clone. */ + virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; +}; + +#endif // _FCD_PHYSICS_FORCE_FIELD_INSTANCE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsForceFieldInstance.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModel.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModel.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModel.h (revision 24247) @@ -1,169 +1,169 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsModel.h - This file contains the FCDPhysicsModel class. -*/ - -#ifndef _FCD_PHYSICSMODEL_H_ -#define _FCD_PHYSICSMODEL_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ -#ifndef _FU_URI_H_ -#include "FUtils/FUUri.h" -#endif // _FU_URI_H_ - -class FCDocument; -class FCDPhysicsRigidBody; -class FCDPhysicsRigidConstraint; -class FCDPhysicsModelInstance; -class FUUri; - -typedef FUObjectContainer FCDPhysicsModelInstanceContainer; /**< A dynamically-sized containment array for physics mode instances. */ -typedef FUObjectContainer FCDPhysicsRigidBodyContainer; /**< A dynamically-sized containment array for rigid bodies. */ -typedef FUObjectContainer FCDPhysicsRigidConstraintContainer; /**< A dynamically-sized containment array for rigid constraints. */ - -/** - A COLLADA physics model. - - A physics model can contain rigid bodies, rigid constraints, or instances - of previously defined physics models. For example, a house physics model - could contain a number of instantiated physics models such as walls. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPhysicsModel : public FCDEntity -{ -private: - typedef fm::map ModelInstanceNameNodeMap; - - DeclareObjectType(FCDEntity); - FCDPhysicsModelInstanceContainer instances; - FCDPhysicsRigidBodyContainer rigidBodies; - FCDPhysicsRigidConstraintContainer rigidConstraints; - ModelInstanceNameNodeMap modelInstancesMap; - -public: - /** Constructor: do not use directly. Create new physics models using the - FCDLibrary::AddEntity function. - @param document The COLLADA document that contains this physics model. - */ - FCDPhysicsModel(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPhysicsModel(); - - /** Retrieves the entity type for this class. This function is part of the - FCDEntity interface. - @return The entity type: PHYSICS_MODEL. */ - virtual Type GetType() const { return FCDEntity::PHYSICS_MODEL; } - - /** Retrieves the instantiated physics models that are part of this physics - model. - @return The physics model instances. */ - FCDPhysicsModelInstanceContainer& GetInstances() { return instances; } - const FCDPhysicsModelInstanceContainer& GetInstances() const { return instances; } /**< See above. */ - - /** Retrieves the number of instantiated physics models that are part of - this physics model. - @return The number of instantiated physics models. */ - size_t GetInstanceCount() const { return instances.size(); } - - /** Retrieves a specific instantiated physics model that is a part of this - physics model. - @param index The index of the instance. - @return The physics model instance. */ - FCDPhysicsModelInstance* GetInstance(size_t index) { FUAssert(index < instances.size(), return NULL); return instances.at(index); } - const FCDPhysicsModelInstance* GetInstance(size_t index) const { FUAssert(index < instances.size(), return NULL); return instances.at(index); } /**< See above. */ - - /** Adds a instantiated physics model to this physics model. - @param model The physics model to be instanced in this physics model. - If this value is NULL, then there is no associated physics model - for the instance yet. It should be filled in. - @return The new physics model instance. */ - FCDPhysicsModelInstance* AddPhysicsModelInstance(FCDPhysicsModel* model = NULL); - - /** Retrieves the rigid bodies that are a part of this physics model. - @return The rigid bodies. */ - FCDPhysicsRigidBodyContainer& GetRigidBodies() { return rigidBodies; } - const FCDPhysicsRigidBodyContainer& GetRigidBodies() const { return rigidBodies; } /**< See above. */ - - /** Retrieves the number of rigid bodies that are a part of this physics - model. - @return The number of rigid bodies. */ - size_t GetRigidBodyCount() const { return rigidBodies.size(); } - - /** Retrieves a specific rigid body that is a part of this physics model - by its index. - @param index The index of the rigid body. - @return The rigid body. */ - FCDPhysicsRigidBody* GetRigidBody(size_t index) { FUAssert(index < rigidBodies.size(), return NULL); return rigidBodies.at(index); } - const FCDPhysicsRigidBody* GetRigidBody(size_t index) const { FUAssert(index < rigidBodies.size(), return NULL); return rigidBodies.at(index); } /**< See above. */ - - /** Retrieves a specific rigid body that is a part of this physics model - by its sid. - @param sid The sid of the rigid body. - @return The rigid body. */ - inline FCDPhysicsRigidBody* FindRigidBodyFromSid(const fm::string& sid) { return const_cast(const_cast(this)->FindRigidBodyFromSid(sid)); } - const FCDPhysicsRigidBody* FindRigidBodyFromSid(const fm::string& sid) const; /**< See above. */ - - /** Adds a rigid body to this physics model. - @return The new rigid body. */ - FCDPhysicsRigidBody* AddRigidBody(); - - /** Retrieves the rigid constraints that are a part of this physics model. - @return The rigid constraints. */ - FCDPhysicsRigidConstraintContainer& GetRigidConstraints() { return rigidConstraints; } - const FCDPhysicsRigidConstraintContainer& GetRigidConstraints() const { return rigidConstraints; } /**< See above. */ - - /** Retrieves the number of rigid constraints that are a part of this - physics model. - @return The number of rigid constraints. */ - size_t GetRigidConstraintCount() const { return rigidConstraints.size(); } - - /** Retrieves a specific rigid constraint that is a part of tihs physics - model by its index. - @param index The index of the rigid constraint. - @return The rigid constraint. */ - FCDPhysicsRigidConstraint* GetRigidConstraint(size_t index) { FUAssert(index < GetRigidConstraintCount(), return NULL); return rigidConstraints.at(index); } - const FCDPhysicsRigidConstraint* GetRigidConstraint(size_t index) const { FUAssert(index < GetRigidConstraintCount(), return NULL); return rigidConstraints.at(index); } /**< See above. */ - - /** Retrieves a specific rigid constraint that is a part of tihs physics - model by its sid. - @param sid The sid of the rigid constraint. - @return The rigid constraint. */ - inline FCDPhysicsRigidConstraint* FindRigidConstraintFromSid(const fm::string& sid) { return const_cast(const_cast(this)->FindRigidConstraintFromSid(sid)); } - const FCDPhysicsRigidConstraint* FindRigidConstraintFromSid(const fm::string& sid) const; /**< See above. */ - - /** Adds a rigid constraint to this physics model. - @return The new rigid constraint. */ - FCDPhysicsRigidConstraint* AddRigidConstraint(); - - /** Copies the physics model into a clone. - @param clone The empty clone. If this pointer is NULL, a new physics - model will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - - /** [INTERNAL] Attaches the model instances. - Because model instances can instance other models, the ordering is unknown so this cannot be done in the - LoadFromXML call. This method should be called after LoadFromXML is applied to all physics models. */ - bool AttachModelInstances(); - - /** [INTERNAL] Cleans up the sub identifiers. - The sub identifiers must be unique with respect to its parent. This method corrects the sub ids if there are conflicts. */ - virtual void CleanSubId(); -}; - -#endif // _FCD_PHYSICSMODEL_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsModel.h + This file contains the FCDPhysicsModel class. +*/ + +#ifndef _FCD_PHYSICSMODEL_H_ +#define _FCD_PHYSICSMODEL_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ +#ifndef _FU_URI_H_ +#include "FUtils/FUUri.h" +#endif // _FU_URI_H_ + +class FCDocument; +class FCDPhysicsRigidBody; +class FCDPhysicsRigidConstraint; +class FCDPhysicsModelInstance; +class FUUri; + +typedef FUObjectContainer FCDPhysicsModelInstanceContainer; /**< A dynamically-sized containment array for physics mode instances. */ +typedef FUObjectContainer FCDPhysicsRigidBodyContainer; /**< A dynamically-sized containment array for rigid bodies. */ +typedef FUObjectContainer FCDPhysicsRigidConstraintContainer; /**< A dynamically-sized containment array for rigid constraints. */ + +/** + A COLLADA physics model. + + A physics model can contain rigid bodies, rigid constraints, or instances + of previously defined physics models. For example, a house physics model + could contain a number of instantiated physics models such as walls. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPhysicsModel : public FCDEntity +{ +private: + typedef fm::map ModelInstanceNameNodeMap; + + DeclareObjectType(FCDEntity); + FCDPhysicsModelInstanceContainer instances; + FCDPhysicsRigidBodyContainer rigidBodies; + FCDPhysicsRigidConstraintContainer rigidConstraints; + ModelInstanceNameNodeMap modelInstancesMap; + +public: + /** Constructor: do not use directly. Create new physics models using the + FCDLibrary::AddEntity function. + @param document The COLLADA document that contains this physics model. + */ + FCDPhysicsModel(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPhysicsModel(); + + /** Retrieves the entity type for this class. This function is part of the + FCDEntity interface. + @return The entity type: PHYSICS_MODEL. */ + virtual Type GetType() const { return FCDEntity::PHYSICS_MODEL; } + + /** Retrieves the instantiated physics models that are part of this physics + model. + @return The physics model instances. */ + FCDPhysicsModelInstanceContainer& GetInstances() { return instances; } + const FCDPhysicsModelInstanceContainer& GetInstances() const { return instances; } /**< See above. */ + + /** Retrieves the number of instantiated physics models that are part of + this physics model. + @return The number of instantiated physics models. */ + size_t GetInstanceCount() const { return instances.size(); } + + /** Retrieves a specific instantiated physics model that is a part of this + physics model. + @param index The index of the instance. + @return The physics model instance. */ + FCDPhysicsModelInstance* GetInstance(size_t index) { FUAssert(index < instances.size(), return NULL); return instances.at(index); } + const FCDPhysicsModelInstance* GetInstance(size_t index) const { FUAssert(index < instances.size(), return NULL); return instances.at(index); } /**< See above. */ + + /** Adds a instantiated physics model to this physics model. + @param model The physics model to be instanced in this physics model. + If this value is NULL, then there is no associated physics model + for the instance yet. It should be filled in. + @return The new physics model instance. */ + FCDPhysicsModelInstance* AddPhysicsModelInstance(FCDPhysicsModel* model = NULL); + + /** Retrieves the rigid bodies that are a part of this physics model. + @return The rigid bodies. */ + FCDPhysicsRigidBodyContainer& GetRigidBodies() { return rigidBodies; } + const FCDPhysicsRigidBodyContainer& GetRigidBodies() const { return rigidBodies; } /**< See above. */ + + /** Retrieves the number of rigid bodies that are a part of this physics + model. + @return The number of rigid bodies. */ + size_t GetRigidBodyCount() const { return rigidBodies.size(); } + + /** Retrieves a specific rigid body that is a part of this physics model + by its index. + @param index The index of the rigid body. + @return The rigid body. */ + FCDPhysicsRigidBody* GetRigidBody(size_t index) { FUAssert(index < rigidBodies.size(), return NULL); return rigidBodies.at(index); } + const FCDPhysicsRigidBody* GetRigidBody(size_t index) const { FUAssert(index < rigidBodies.size(), return NULL); return rigidBodies.at(index); } /**< See above. */ + + /** Retrieves a specific rigid body that is a part of this physics model + by its sid. + @param sid The sid of the rigid body. + @return The rigid body. */ + inline FCDPhysicsRigidBody* FindRigidBodyFromSid(const fm::string& sid) { return const_cast(const_cast(this)->FindRigidBodyFromSid(sid)); } + const FCDPhysicsRigidBody* FindRigidBodyFromSid(const fm::string& sid) const; /**< See above. */ + + /** Adds a rigid body to this physics model. + @return The new rigid body. */ + FCDPhysicsRigidBody* AddRigidBody(); + + /** Retrieves the rigid constraints that are a part of this physics model. + @return The rigid constraints. */ + FCDPhysicsRigidConstraintContainer& GetRigidConstraints() { return rigidConstraints; } + const FCDPhysicsRigidConstraintContainer& GetRigidConstraints() const { return rigidConstraints; } /**< See above. */ + + /** Retrieves the number of rigid constraints that are a part of this + physics model. + @return The number of rigid constraints. */ + size_t GetRigidConstraintCount() const { return rigidConstraints.size(); } + + /** Retrieves a specific rigid constraint that is a part of tihs physics + model by its index. + @param index The index of the rigid constraint. + @return The rigid constraint. */ + FCDPhysicsRigidConstraint* GetRigidConstraint(size_t index) { FUAssert(index < GetRigidConstraintCount(), return NULL); return rigidConstraints.at(index); } + const FCDPhysicsRigidConstraint* GetRigidConstraint(size_t index) const { FUAssert(index < GetRigidConstraintCount(), return NULL); return rigidConstraints.at(index); } /**< See above. */ + + /** Retrieves a specific rigid constraint that is a part of tihs physics + model by its sid. + @param sid The sid of the rigid constraint. + @return The rigid constraint. */ + inline FCDPhysicsRigidConstraint* FindRigidConstraintFromSid(const fm::string& sid) { return const_cast(const_cast(this)->FindRigidConstraintFromSid(sid)); } + const FCDPhysicsRigidConstraint* FindRigidConstraintFromSid(const fm::string& sid) const; /**< See above. */ + + /** Adds a rigid constraint to this physics model. + @return The new rigid constraint. */ + FCDPhysicsRigidConstraint* AddRigidConstraint(); + + /** Copies the physics model into a clone. + @param clone The empty clone. If this pointer is NULL, a new physics + model will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + + /** [INTERNAL] Attaches the model instances. + Because model instances can instance other models, the ordering is unknown so this cannot be done in the + LoadFromXML call. This method should be called after LoadFromXML is applied to all physics models. */ + bool AttachModelInstances(); + + /** [INTERNAL] Cleans up the sub identifiers. + The sub identifiers must be unique with respect to its parent. This method corrects the sub ids if there are conflicts. */ + virtual void CleanSubId(); +}; + +#endif // _FCD_PHYSICSMODEL_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModel.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBody.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBody.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBody.h (revision 24247) @@ -1,85 +1,85 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsRigidBody.h - This file contains the FCDPhysicsRigidBody class. -*/ - -#ifndef _FCD_PHYSICSRIGIDBODY_H_ -#define _FCD_PHYSICSRIGIDBODY_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDocument; -class FCDPhysicsRigidBodyParameters; - -/** - A COLLADA rigid body. - - A rigid body contains all the information needed for collision detection. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPhysicsRigidBody : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - - DeclareParameterRef(FCDPhysicsRigidBodyParameters, parameters, FC("Parameters")); - -public: - /** Constructor: do not use directly. Create new rigid bodies using the - FCDPhysicsModel::AddRigidBody function. - @param document The COLLADA document that contains this rigid body. */ - FCDPhysicsRigidBody(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPhysicsRigidBody(); - - /** Retrieves the entity type for this class. This function is part of the - FCDEntity interface. - @return The entity type: PHYSICS_RIGID_BODY. */ - virtual Type GetType() const { return FCDEntity::PHYSICS_RIGID_BODY; } - - /** Retrieves the sub id (sid) of this rigid body. - @return The sub id. */ - inline const fm::string& GetSubId() const { return Parent::GetDaeId(); } - - /** Sets the sub id (sid) of this rigid body. - @param sid The new sub id. */ - inline void SetSubId(const char* sid) { Parent::SetDaeId(sid); } - inline void SetSubId(const fm::string& sid) { Parent::SetDaeId(sid); } /**< See above. */ - - /** Retrieves the parameters of tihs rigid body. - @return The parameters. */ - FCDPhysicsRigidBodyParameters* GetParameters() { return parameters; } - const FCDPhysicsRigidBodyParameters* GetParameters() const { return parameters; } /**< See above. */ - - /** Retrieves the factor to multiple by to ensure shape masses are correct. - According to the COLLADA spec in 1.4.1, if the total mass of the rigid - body is 6 and there are 2 shapes with mass of 1 and 2, then it will be - interpreted as 2 shapes with mass of 2 and 4 respectively. This method - gives the factor to convert from the shape's mass to the one that - should be interpreted as. - @return The factor for shape mass. */ - float GetShapeMassFactor() const; - - /** Copies the rigid body into a clone. - @param clone The empty clone. If this pointer is NULL, a new rigid - body will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; -}; - -#endif // _FCD_PHYSICSRIGIDBODY_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsRigidBody.h + This file contains the FCDPhysicsRigidBody class. +*/ + +#ifndef _FCD_PHYSICSRIGIDBODY_H_ +#define _FCD_PHYSICSRIGIDBODY_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDocument; +class FCDPhysicsRigidBodyParameters; + +/** + A COLLADA rigid body. + + A rigid body contains all the information needed for collision detection. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPhysicsRigidBody : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + + DeclareParameterRef(FCDPhysicsRigidBodyParameters, parameters, FC("Parameters")); + +public: + /** Constructor: do not use directly. Create new rigid bodies using the + FCDPhysicsModel::AddRigidBody function. + @param document The COLLADA document that contains this rigid body. */ + FCDPhysicsRigidBody(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPhysicsRigidBody(); + + /** Retrieves the entity type for this class. This function is part of the + FCDEntity interface. + @return The entity type: PHYSICS_RIGID_BODY. */ + virtual Type GetType() const { return FCDEntity::PHYSICS_RIGID_BODY; } + + /** Retrieves the sub id (sid) of this rigid body. + @return The sub id. */ + inline const fm::string& GetSubId() const { return Parent::GetDaeId(); } + + /** Sets the sub id (sid) of this rigid body. + @param sid The new sub id. */ + inline void SetSubId(const char* sid) { Parent::SetDaeId(sid); } + inline void SetSubId(const fm::string& sid) { Parent::SetDaeId(sid); } /**< See above. */ + + /** Retrieves the parameters of tihs rigid body. + @return The parameters. */ + FCDPhysicsRigidBodyParameters* GetParameters() { return parameters; } + const FCDPhysicsRigidBodyParameters* GetParameters() const { return parameters; } /**< See above. */ + + /** Retrieves the factor to multiple by to ensure shape masses are correct. + According to the COLLADA spec in 1.4.1, if the total mass of the rigid + body is 6 and there are 2 shapes with mass of 1 and 2, then it will be + interpreted as 2 shapes with mass of 2 and 4 respectively. This method + gives the factor to convert from the shape's mass to the one that + should be interpreted as. + @return The factor for shape mass. */ + float GetShapeMassFactor() const; + + /** Copies the rigid body into a clone. + @param clone The empty clone. If this pointer is NULL, a new rigid + body will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; +}; + +#endif // _FCD_PHYSICSRIGIDBODY_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBody.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyParameters.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyParameters.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyParameters.h (revision 24247) @@ -1,239 +1,239 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsRigidBodyParameters.h - This file contains the FCDPhysicsRigidBodyParameters class. -*/ - -#ifndef _FCD_PHYSICS_RIGID_BODY_PARAMETERS_H_ -#define _FCD_PHYSICS_RIGID_BODY_PARAMETERS_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -class FCDPhysicsMaterial; -class FCDPhysicsShape; -class FCDPhysicsRigidBody; -class FCDPhysicsRigidBodyInstance; -class FCDEntityInstance; - -/** - A structure to hold the parameters for rigid body and rigid body instance. - - Because many of the parameters found in the rigid body can be overwritten - by the rigid body instance, it is useful to keep it in one single place. - This class is responsible for loading, storing, and writing these - parameters. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPhysicsRigidBodyParameters : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - bool ownsPhysicsMaterial; /**< This thing is stopping me from parameterizing the physics material. */ - FUTrackedPtr physicsMaterial; - FUTrackedPtr instanceMaterialRef; - - FCDObject* parent; - - DeclareParameterContainer(FCDPhysicsShape, physicsShape, FC("Shapes")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, dynamic, FC("IsDynamic")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, mass, FC("Mass")); - DeclareParameter(float, FUParameterQualifiers::SIMPLE, density, FC("Density")); - DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, inertia, FC("Inertia")); - DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, massFrameTranslate, FC("Center of Mass Position")); - DeclareParameterAnimatable(FMAngleAxis, FUParameterQualifiers::SIMPLE, massFrameOrientation, FC("Center of Mass Orientation")); - - FUTrackedPtr entityOwner; - FUTrackedPtr instanceOwner; - - DeclareParameter(bool, FUParameterQualifiers::SIMPLE, isDensityMoreAccurate, FC("Use Density")); - DeclareParameter(bool, FUParameterQualifiers::SIMPLE, isInertiaAccurate, FC("Use Inertia")); - -public: - /** Constructor. - @param owner The owner of this parameters holder. Its SetDirty will be - called whenever this class is modified. It cannot be NULL. */ - FCDPhysicsRigidBodyParameters(FCDocument* document, FCDPhysicsRigidBody* owner); - FCDPhysicsRigidBodyParameters(FCDocument* document, FCDPhysicsRigidBodyInstance* owner); /**< See above. */ - - /** Destructor. */ - virtual ~FCDPhysicsRigidBodyParameters(); - - /** Retrieves whether the owner is dynamic. If it is dynamic, forces like - gravity affect it. - @return True if dynamic. */ - FCDParameterAnimatableFloat& GetDynamic() { return dynamic; } - const FCDParameterAnimatableFloat& GetDynamic() const { return dynamic; } /**< See above. */ - bool IsDynamic() { return dynamic >= 0.5f; } /**< See above. */ - - /** Sets whether the owner is dynamic. If it is dynamic, forces like - gravity affect it. - @param dynamic True if dynamic. */ - void SetDynamic(bool dynamic); - - /** Retrieves whether density is more accurate. Because we are using an approximating algorithm for volume, density will be more accurate when - dealing with non-analytical shapes. Density is calculated as the average density of the shapes. Shapes defining a mass will have density - of 0.0f. A rigid body containing both shapes with only density and shapes with only mass will have both GetMass and GetDensity - approximated. - @return True if density is more accurate. */ - bool IsDensityMoreAccurate() { return isDensityMoreAccurate; } - - /** [INTERNAL] Set 'DensityMoreAccurate'. - @parame value Value to be set. - */ - void SetDensityMoreAccurate(bool value){ isDensityMoreAccurate = value; } - - /** Retrieves the density of the owner. The client should call IsDensityMoreAccurate to make sure this is what we want instead of mass. - @return The density. */ - FUParameterFloat& GetDensity() { return density; } - const FUParameterFloat& GetDensity() const { return density; } /**< See above. */ - - /** [INTERNAL] Set the densisty. - @param dens The density to set. - */ - void SetDensity(float dens) { density = dens; } - - /** Retrieves the mass of the owner. - @return The mass. */ - FCDParameterAnimatableFloat& GetMass() { return mass; } - const FCDParameterAnimatableFloat& GetMass() const { return mass; } /**< See above. */ - - /** Sets the mass of the owner. - @param _mass The mass. */ - inline void SetMass(float _mass) { mass = _mass; parent->SetDirtyFlag(); } - - /** Retrieves the inertia of the owner. - @return The inertia. */ - FCDParameterAnimatableVector3& GetInertia() { return inertia; } - const FCDParameterAnimatableVector3& GetInertia() const { return inertia; } /**< See above. */ - - /** Inertia is accurate only if it comes directly from the COLLADA file. - We are using a simple sphere approximation for the inertia if there is - none specified. - @return True if the inertia is accurate. */ - bool IsInertiaAccurate() { return isInertiaAccurate; } - - /** [INTERNAL] Sets the inertia accuracy flag. - @param value The value to set. */ - void SetInertiaAccurate(bool value){ isInertiaAccurate = value; } - - /** Sets the inertia of the owner. - @param _inertia The inertia. */ - inline void SetInertia(const FMVector3& _inertia) - { inertia = _inertia; isInertiaAccurate = true; parent->SetDirtyFlag(); } - - /** Retrieves the center of mass of the owner. - @return The center of mass. */ - FCDParameterAnimatableVector3& GetMassFrameTranslate() { return massFrameTranslate; } - const FCDParameterAnimatableVector3& GetMassFrameTranslate() const { return massFrameTranslate; } /**< See above. */ - - /** Sets the center of mass of the owner. - @param position The center of mass. */ - inline void SetMassFrameTranslate(const FMVector3& position) { massFrameTranslate = position; parent->SetDirtyFlag(); } - - /** Retrieves the orientation of mass of the owner. - @return The orientation of mass. */ - inline FCDParameterAnimatableAngleAxis& GetMassFrameOrientation() { return massFrameOrientation; } - inline const FCDParameterAnimatableAngleAxis& GetMassFrameOrientation() const { return massFrameOrientation; } /**< See above. */ - - /** Sets the orientation of mass of the owner. - @param angleAxis The orientation of mass. */ - inline void SetMassFrameOrientation(const FMAngleAxis& angleAxis) { massFrameOrientation = angleAxis; } - - /** Retrieves the axis of orientation of mass of the owner. - @return The axis of orientation of mass. */ - inline FMVector3& GetMassFrameRotateAxis() { return massFrameOrientation->axis; } - inline const FMVector3& GetMassFrameRotateAxis() const { return massFrameOrientation->axis; } /**< See above. */ - - /** Sets the axis of orientation of mass of the owner. - @param axis The axis of orientation of mass. */ - inline void SetMassFrameRotateAxis(const FMVector3& axis) { massFrameOrientation->axis = axis; parent->SetDirtyFlag(); } - - /** Retrieves the angle of orientation of mass of the owner along the axis - retrieved from GetMassFrameRotateAxis. - @return The angle of orientation of mass. */ - float& GetMassFrameRotateAngle() { return massFrameOrientation->angle; } - const float& GetMassFrameRotateAngle() const { return massFrameOrientation->angle; } /**< See above. */ - - /** Sets the angle of orientation of mass of the owner along the axis - retrieved from GetMassFrameRotateAxis. - @param angle The angle of orientation of mass. */ - inline void SetMassFrameRotateAngle(float angle) { massFrameOrientation->angle = angle; parent->SetDirtyFlag(); } - - /** Retrives the physics material of the owner. - @return The physics material. */ - FCDPhysicsMaterial* GetPhysicsMaterial() { return physicsMaterial; } - const FCDPhysicsMaterial* GetPhysicsMaterial() const { return physicsMaterial; } /**< See above. */ - - /** Sets the physics material of the owner. - @param physicsMaterial The physics material. */ - void SetPhysicsMaterial(FCDPhysicsMaterial* physicsMaterial); - - /** Adds a physics material for the owner. This parameter structuer is - responsible for releasing the physics material. - @return The new physics material. */ - FCDPhysicsMaterial* AddOwnPhysicsMaterial(); - - /** Retrieves the physics shapes of the owner. - @return The physics shapes. */ - DEPRECATED(3.05A, GetPhysicsShapeCount and GetPhysicsShape(index)) void GetPhysicsShapeList() const {} - - /** Retrieves the number of physics shapes of the owner. - @return The number of physics shapes. */ - size_t GetPhysicsShapeCount() const { return physicsShape.size(); } - - /** Retrieves a speficied physics shape of the owner by index. - @param index The index of the physics shape. - @return The physics shape. */ - FCDPhysicsShape* GetPhysicsShape(size_t index) { FUAssert(index < physicsShape.size(), return NULL) return physicsShape.at(index); } - const FCDPhysicsShape* GetPhysicsShape(size_t index) const { FUAssert(index < physicsShape.size(), return NULL) return physicsShape.at(index); } /**< See above. */ - - /** Adds a physics shape to the owner. - @return The new physics shape. */ - FCDPhysicsShape* AddPhysicsShape(); - - /** Copies the rigid body parameters into this parameters structure. - @param original The original rigid body parameters to get values from. */ - virtual void CopyFrom(const FCDPhysicsRigidBodyParameters& original); - - /** [INTERNAL] Retrieves the owner of the parameters. - @return The owner of the parameters */ - DEPRECATED(3.05A, GetParent) FCDObject* GetOwner() { return parent; } - FCDObject* GetParent() { return parent; } /**< See above. */ - const FCDObject* GetParent() const { return parent; } /**< See above. */ - - /** [INTERNAL] Retrieve the entity owner. - @return The entity owner. */ - FCDPhysicsRigidBody* GetEntityOwner(){ return entityOwner; } - - /** [INTERNAL] Retrieve the instance owner. - @return The instance owner. */ - FCDPhysicsRigidBodyInstance* GetInstanceOwner(){ return instanceOwner; } - - /** [INTERNAL] Determine if the model owns the maaterial. - @return true if the model owns the material. */ - bool OwnsPhysicsMaterial() { return ownsPhysicsMaterial; } - - /** [INTERNAL] Set the material instance. - @instance The new material instance. */ - void SetInstanceMaterial(FCDEntityInstance* instance) { instanceMaterialRef = instance; } - - /** [INTERNAL] Retrieve the material instance. - @return The material instance. */ - FCDEntityInstance* GetInstanceMaterial(){ return instanceMaterialRef; } -}; - -#endif // _FCD_PHYSICS_RIGID_BODY_PARAMETERS_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsRigidBodyParameters.h + This file contains the FCDPhysicsRigidBodyParameters class. +*/ + +#ifndef _FCD_PHYSICS_RIGID_BODY_PARAMETERS_H_ +#define _FCD_PHYSICS_RIGID_BODY_PARAMETERS_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +class FCDPhysicsMaterial; +class FCDPhysicsShape; +class FCDPhysicsRigidBody; +class FCDPhysicsRigidBodyInstance; +class FCDEntityInstance; + +/** + A structure to hold the parameters for rigid body and rigid body instance. + + Because many of the parameters found in the rigid body can be overwritten + by the rigid body instance, it is useful to keep it in one single place. + This class is responsible for loading, storing, and writing these + parameters. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPhysicsRigidBodyParameters : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + bool ownsPhysicsMaterial; /**< This thing is stopping me from parameterizing the physics material. */ + FUTrackedPtr physicsMaterial; + FUTrackedPtr instanceMaterialRef; + + FCDObject* parent; + + DeclareParameterContainer(FCDPhysicsShape, physicsShape, FC("Shapes")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, dynamic, FC("IsDynamic")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, mass, FC("Mass")); + DeclareParameter(float, FUParameterQualifiers::SIMPLE, density, FC("Density")); + DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, inertia, FC("Inertia")); + DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, massFrameTranslate, FC("Center of Mass Position")); + DeclareParameterAnimatable(FMAngleAxis, FUParameterQualifiers::SIMPLE, massFrameOrientation, FC("Center of Mass Orientation")); + + FUTrackedPtr entityOwner; + FUTrackedPtr instanceOwner; + + DeclareParameter(bool, FUParameterQualifiers::SIMPLE, isDensityMoreAccurate, FC("Use Density")); + DeclareParameter(bool, FUParameterQualifiers::SIMPLE, isInertiaAccurate, FC("Use Inertia")); + +public: + /** Constructor. + @param owner The owner of this parameters holder. Its SetDirty will be + called whenever this class is modified. It cannot be NULL. */ + FCDPhysicsRigidBodyParameters(FCDocument* document, FCDPhysicsRigidBody* owner); + FCDPhysicsRigidBodyParameters(FCDocument* document, FCDPhysicsRigidBodyInstance* owner); /**< See above. */ + + /** Destructor. */ + virtual ~FCDPhysicsRigidBodyParameters(); + + /** Retrieves whether the owner is dynamic. If it is dynamic, forces like + gravity affect it. + @return True if dynamic. */ + FCDParameterAnimatableFloat& GetDynamic() { return dynamic; } + const FCDParameterAnimatableFloat& GetDynamic() const { return dynamic; } /**< See above. */ + bool IsDynamic() { return dynamic >= 0.5f; } /**< See above. */ + + /** Sets whether the owner is dynamic. If it is dynamic, forces like + gravity affect it. + @param dynamic True if dynamic. */ + void SetDynamic(bool dynamic); + + /** Retrieves whether density is more accurate. Because we are using an approximating algorithm for volume, density will be more accurate when + dealing with non-analytical shapes. Density is calculated as the average density of the shapes. Shapes defining a mass will have density + of 0.0f. A rigid body containing both shapes with only density and shapes with only mass will have both GetMass and GetDensity + approximated. + @return True if density is more accurate. */ + bool IsDensityMoreAccurate() { return isDensityMoreAccurate; } + + /** [INTERNAL] Set 'DensityMoreAccurate'. + @parame value Value to be set. + */ + void SetDensityMoreAccurate(bool value){ isDensityMoreAccurate = value; } + + /** Retrieves the density of the owner. The client should call IsDensityMoreAccurate to make sure this is what we want instead of mass. + @return The density. */ + FUParameterFloat& GetDensity() { return density; } + const FUParameterFloat& GetDensity() const { return density; } /**< See above. */ + + /** [INTERNAL] Set the densisty. + @param dens The density to set. + */ + void SetDensity(float dens) { density = dens; } + + /** Retrieves the mass of the owner. + @return The mass. */ + FCDParameterAnimatableFloat& GetMass() { return mass; } + const FCDParameterAnimatableFloat& GetMass() const { return mass; } /**< See above. */ + + /** Sets the mass of the owner. + @param _mass The mass. */ + inline void SetMass(float _mass) { mass = _mass; parent->SetDirtyFlag(); } + + /** Retrieves the inertia of the owner. + @return The inertia. */ + FCDParameterAnimatableVector3& GetInertia() { return inertia; } + const FCDParameterAnimatableVector3& GetInertia() const { return inertia; } /**< See above. */ + + /** Inertia is accurate only if it comes directly from the COLLADA file. + We are using a simple sphere approximation for the inertia if there is + none specified. + @return True if the inertia is accurate. */ + bool IsInertiaAccurate() { return isInertiaAccurate; } + + /** [INTERNAL] Sets the inertia accuracy flag. + @param value The value to set. */ + void SetInertiaAccurate(bool value){ isInertiaAccurate = value; } + + /** Sets the inertia of the owner. + @param _inertia The inertia. */ + inline void SetInertia(const FMVector3& _inertia) + { inertia = _inertia; isInertiaAccurate = true; parent->SetDirtyFlag(); } + + /** Retrieves the center of mass of the owner. + @return The center of mass. */ + FCDParameterAnimatableVector3& GetMassFrameTranslate() { return massFrameTranslate; } + const FCDParameterAnimatableVector3& GetMassFrameTranslate() const { return massFrameTranslate; } /**< See above. */ + + /** Sets the center of mass of the owner. + @param position The center of mass. */ + inline void SetMassFrameTranslate(const FMVector3& position) { massFrameTranslate = position; parent->SetDirtyFlag(); } + + /** Retrieves the orientation of mass of the owner. + @return The orientation of mass. */ + inline FCDParameterAnimatableAngleAxis& GetMassFrameOrientation() { return massFrameOrientation; } + inline const FCDParameterAnimatableAngleAxis& GetMassFrameOrientation() const { return massFrameOrientation; } /**< See above. */ + + /** Sets the orientation of mass of the owner. + @param angleAxis The orientation of mass. */ + inline void SetMassFrameOrientation(const FMAngleAxis& angleAxis) { massFrameOrientation = angleAxis; } + + /** Retrieves the axis of orientation of mass of the owner. + @return The axis of orientation of mass. */ + inline FMVector3& GetMassFrameRotateAxis() { return massFrameOrientation->axis; } + inline const FMVector3& GetMassFrameRotateAxis() const { return massFrameOrientation->axis; } /**< See above. */ + + /** Sets the axis of orientation of mass of the owner. + @param axis The axis of orientation of mass. */ + inline void SetMassFrameRotateAxis(const FMVector3& axis) { massFrameOrientation->axis = axis; parent->SetDirtyFlag(); } + + /** Retrieves the angle of orientation of mass of the owner along the axis + retrieved from GetMassFrameRotateAxis. + @return The angle of orientation of mass. */ + float& GetMassFrameRotateAngle() { return massFrameOrientation->angle; } + const float& GetMassFrameRotateAngle() const { return massFrameOrientation->angle; } /**< See above. */ + + /** Sets the angle of orientation of mass of the owner along the axis + retrieved from GetMassFrameRotateAxis. + @param angle The angle of orientation of mass. */ + inline void SetMassFrameRotateAngle(float angle) { massFrameOrientation->angle = angle; parent->SetDirtyFlag(); } + + /** Retrives the physics material of the owner. + @return The physics material. */ + FCDPhysicsMaterial* GetPhysicsMaterial() { return physicsMaterial; } + const FCDPhysicsMaterial* GetPhysicsMaterial() const { return physicsMaterial; } /**< See above. */ + + /** Sets the physics material of the owner. + @param physicsMaterial The physics material. */ + void SetPhysicsMaterial(FCDPhysicsMaterial* physicsMaterial); + + /** Adds a physics material for the owner. This parameter structuer is + responsible for releasing the physics material. + @return The new physics material. */ + FCDPhysicsMaterial* AddOwnPhysicsMaterial(); + + /** Retrieves the physics shapes of the owner. + @return The physics shapes. */ + DEPRECATED(3.05A, GetPhysicsShapeCount and GetPhysicsShape(index)) void GetPhysicsShapeList() const {} + + /** Retrieves the number of physics shapes of the owner. + @return The number of physics shapes. */ + size_t GetPhysicsShapeCount() const { return physicsShape.size(); } + + /** Retrieves a speficied physics shape of the owner by index. + @param index The index of the physics shape. + @return The physics shape. */ + FCDPhysicsShape* GetPhysicsShape(size_t index) { FUAssert(index < physicsShape.size(), return NULL) return physicsShape.at(index); } + const FCDPhysicsShape* GetPhysicsShape(size_t index) const { FUAssert(index < physicsShape.size(), return NULL) return physicsShape.at(index); } /**< See above. */ + + /** Adds a physics shape to the owner. + @return The new physics shape. */ + FCDPhysicsShape* AddPhysicsShape(); + + /** Copies the rigid body parameters into this parameters structure. + @param original The original rigid body parameters to get values from. */ + virtual void CopyFrom(const FCDPhysicsRigidBodyParameters& original); + + /** [INTERNAL] Retrieves the owner of the parameters. + @return The owner of the parameters */ + DEPRECATED(3.05A, GetParent) FCDObject* GetOwner() { return parent; } + FCDObject* GetParent() { return parent; } /**< See above. */ + const FCDObject* GetParent() const { return parent; } /**< See above. */ + + /** [INTERNAL] Retrieve the entity owner. + @return The entity owner. */ + FCDPhysicsRigidBody* GetEntityOwner(){ return entityOwner; } + + /** [INTERNAL] Retrieve the instance owner. + @return The instance owner. */ + FCDPhysicsRigidBodyInstance* GetInstanceOwner(){ return instanceOwner; } + + /** [INTERNAL] Determine if the model owns the maaterial. + @return true if the model owns the material. */ + bool OwnsPhysicsMaterial() { return ownsPhysicsMaterial; } + + /** [INTERNAL] Set the material instance. + @instance The new material instance. */ + void SetInstanceMaterial(FCDEntityInstance* instance) { instanceMaterialRef = instance; } + + /** [INTERNAL] Retrieve the material instance. + @return The material instance. */ + FCDEntityInstance* GetInstanceMaterial(){ return instanceMaterialRef; } +}; + +#endif // _FCD_PHYSICS_RIGID_BODY_PARAMETERS_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyParameters.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraintInstance.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraintInstance.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraintInstance.h (revision 24247) @@ -1,90 +1,90 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsRigidConstraintInstance.h - This file contains the FCDPhysicsRigidConstraintInstance class. -*/ - -#ifndef _FCD_PHYSICS_RIGID_CONSTRAINT_INSTANCE_H_ -#define _FCD_PHYSICS_RIGID_CONSTRAINT_INSTANCE_H_ - -#ifndef _FCD_ENTITY_INSTANCE_H_ -#include "FCDocument/FCDEntityInstance.h" -#endif // _FCD_ENTITY_INSTANCE_H_ - -class FCDocument; -class FCDEntity; -class FCDSceneNode; -class FCDPhysicsModel; -class FCDPhysicsModelInstance; -class FCDPhysicsRigidConstraint; - -/** - A COLLADA rigid constraint instance. - - They are instantiated in the instance_physics_model node. The only - documentation on them is that it allows overriding of properties. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPhysicsRigidConstraintInstance : public FCDEntityInstance -{ -private: - DeclareObjectType(FCDEntityInstance); - FCDPhysicsModelInstance* parent; - -public: - /** Constructor: do not use directly. Create new rigid constraints - instances using the FCDPhysicsModel::AddRigidConstraintInstance - function. - @param document The COLLADA document that contains this rigid - constraint instance. - @param parent The physics model instance that contains this rigid - constraint instance. - @param constraint The rigid constraint to instance. This should not be - NULL unless it is expected to be filled in by LoadFromXML. */ - FCDPhysicsRigidConstraintInstance(FCDocument* document, FCDPhysicsModelInstance* parent, FCDPhysicsRigidConstraint* constraint); - - /** Destructor. */ - virtual ~FCDPhysicsRigidConstraintInstance(); - - /** Retrieves the entity type for this class. This function is part of the - FCDEntity interface. - @return The entity type: PHYSICS_RIGID_CONSTRAINT. */ - virtual Type GetType() const { return PHYSICS_RIGID_CONSTRAINT; } - - /** Retrieves the physics model instance that contraints this rigid - constraint. - @return The physics model instance. */ - FCDPhysicsModelInstance* GetParent() { return parent; } - const FCDPhysicsModelInstance* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the rigid constraint for this rigid constraint instance. - @return The rigid constraint. */ - inline FCDPhysicsRigidConstraint* GetRigidConstraint() { return (FCDPhysicsRigidConstraint*) GetEntity(); } - - /** Clones the rigid constraint instance. - @param clone The rigid constraint instance to become the clone. - If this pointer is NULL, a new rigid constraint instance will be - created and you will need to release it. - @return The clone. */ - virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; - - /** [INTERNAL] Retrieve it's parent model instance. - @return The parent of the intance. - */ - FCDPhysicsModelInstance* GetModelParentInstance(){ return parent; } - - /** [INTERNAL] Sets the rigid body for this rigid body instance. Default values are - taken from the rigid body. - @param body The rigid body. */ - void SetRigidConstraint(FCDPhysicsRigidConstraint* constraint); -}; - -#endif // _FCD_PHYSICS_RIGID_CONSTRAINT_INSTANCE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsRigidConstraintInstance.h + This file contains the FCDPhysicsRigidConstraintInstance class. +*/ + +#ifndef _FCD_PHYSICS_RIGID_CONSTRAINT_INSTANCE_H_ +#define _FCD_PHYSICS_RIGID_CONSTRAINT_INSTANCE_H_ + +#ifndef _FCD_ENTITY_INSTANCE_H_ +#include "FCDocument/FCDEntityInstance.h" +#endif // _FCD_ENTITY_INSTANCE_H_ + +class FCDocument; +class FCDEntity; +class FCDSceneNode; +class FCDPhysicsModel; +class FCDPhysicsModelInstance; +class FCDPhysicsRigidConstraint; + +/** + A COLLADA rigid constraint instance. + + They are instantiated in the instance_physics_model node. The only + documentation on them is that it allows overriding of properties. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPhysicsRigidConstraintInstance : public FCDEntityInstance +{ +private: + DeclareObjectType(FCDEntityInstance); + FCDPhysicsModelInstance* parent; + +public: + /** Constructor: do not use directly. Create new rigid constraints + instances using the FCDPhysicsModel::AddRigidConstraintInstance + function. + @param document The COLLADA document that contains this rigid + constraint instance. + @param parent The physics model instance that contains this rigid + constraint instance. + @param constraint The rigid constraint to instance. This should not be + NULL unless it is expected to be filled in by LoadFromXML. */ + FCDPhysicsRigidConstraintInstance(FCDocument* document, FCDPhysicsModelInstance* parent, FCDPhysicsRigidConstraint* constraint); + + /** Destructor. */ + virtual ~FCDPhysicsRigidConstraintInstance(); + + /** Retrieves the entity type for this class. This function is part of the + FCDEntity interface. + @return The entity type: PHYSICS_RIGID_CONSTRAINT. */ + virtual Type GetType() const { return PHYSICS_RIGID_CONSTRAINT; } + + /** Retrieves the physics model instance that contraints this rigid + constraint. + @return The physics model instance. */ + FCDPhysicsModelInstance* GetParent() { return parent; } + const FCDPhysicsModelInstance* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the rigid constraint for this rigid constraint instance. + @return The rigid constraint. */ + inline FCDPhysicsRigidConstraint* GetRigidConstraint() { return (FCDPhysicsRigidConstraint*) GetEntity(); } + + /** Clones the rigid constraint instance. + @param clone The rigid constraint instance to become the clone. + If this pointer is NULL, a new rigid constraint instance will be + created and you will need to release it. + @return The clone. */ + virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; + + /** [INTERNAL] Retrieve it's parent model instance. + @return The parent of the intance. + */ + FCDPhysicsModelInstance* GetModelParentInstance(){ return parent; } + + /** [INTERNAL] Sets the rigid body for this rigid body instance. Default values are + taken from the rigid body. + @param body The rigid body. */ + void SetRigidConstraint(FCDPhysicsRigidConstraint* constraint); +}; + +#endif // _FCD_PHYSICS_RIGID_CONSTRAINT_INSTANCE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraintInstance.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsShape.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsShape.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsShape.h (revision 24247) @@ -1,217 +1,217 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsShape.h - This file contains the FCDPhysicsShape class. -*/ - -#ifndef _FCD_PHYSICS_SHAPE_H_ -#define _FCD_PHYSICS_SHAPE_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FCD_PHYSICS_ANALYTICAL_GEOM_H_ -#include "FCDocument/FCDPhysicsAnalyticalGeometry.h" -#endif // _FCD_PHYSICS_ANALYTICAL_GEOM_H_ -#ifndef _FCD_TRANSFORM_H_ -#include "FCDocument/FCDTransform.h" /** @todo Remove this include by moving the FCDTransform::Type enum to FUDaeEnum.h. */ -#endif // _FCD_TRANSFORM_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ - -class FCDEntityInstance; -class FCDGeometry; -class FCDGeometryInstance; -class FCDPhysicsAnalyticalGeometry; -class FCDPhysicsMaterial; - -typedef FUObjectContainer FCDTransformContainer; /**< A dynamically-sized containment array for transforms. */ - -/** - A COLLADA shape object. - - A shape describes the boundary used for collision detection within a rigid - body. It belongs to a single rigid body and cannot be referenced from other - elements. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPhysicsShape : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - bool hollow; - FUTrackedPtr physicsMaterial; - bool ownsPhysicsMaterial; - - //one of these two will define the rigid body - FUTrackedPtr geometry; - FUObjectRef analGeom; - - float* mass; - float* density; - FCDTransformContainer transforms; - FCDEntityInstance* instanceMaterialRef; - - bool isDensityMoreAccurate; - -public: - /** Constructor: do not use directly. Create new shapes using the - FCDPhysicsRigidBody::AddPhysicsShape function. - @param document The COLLADA document that contains this rigid body. */ - FCDPhysicsShape(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPhysicsShape(); - - /** Retrieves the mass of this shape. - @return The mass. */ - float GetMass() const; - const float* GetMassPointer() const { return mass; } /** [INTERNAL] */ - - /** Sets the mass of this shape. - @param mass The new mass. */ - void SetMass(float mass); - - /** Retrieves whether density of this shape is more accurate than mass. It is more accurate if mass is not defined. In that case mass is - calculated using approximations when it is non-analytic. - @return True if density is more accurate. */ - bool IsDensityMoreAccurate() const { return isDensityMoreAccurate; } - - /** [INTERNAL] Set 'DensityMoreAccurate'. - @parame value Value to be set. - */ - void SetDensityMoreAccurate(bool value){ isDensityMoreAccurate = value; } - - /** Retrieves the density of this shape. - @return The density. */ - float GetDensity() const; - const float* GetDensityPointer() const { return density; } /** [INTERNAL] */ - - /** Sets the density of this shape. - @param density The new density. */ - void SetDensity(float density); - - /** Retrives whether this shape is hollow. - @return True if this shape is hollow. */ - bool IsHollow() const {return hollow;} - - /** Sets whether this shape is hollow. - @param _hollow True if this shape is hollow. */ - void SetHollow(bool _hollow) {hollow = _hollow;} - - /** Retrieves whether this shape is an analyical geometry such as a box, - plane, sphere, cylinder, tapered cylinder, capsule, or tapered capsule. - @return True if this shape is an analytical geometry. */ - bool IsAnalyticalGeometry() const { return analGeom != NULL; } - - /** Gets the analytic geometry. NULL is returned if IsAnalyticalGeometry - returns false. - @return The analytical geometry. */ - FCDPhysicsAnalyticalGeometry* GetAnalyticalGeometry() { return analGeom; } - const FCDPhysicsAnalyticalGeometry* GetAnalyticalGeometry() const { return analGeom; } /**< See above. */ - - /** [INTERNAL] Set the analytical geometry. - @param aGeom The analytical geometry. - */ - void SetAnalyticalGeometry(FCDPhysicsAnalyticalGeometry* aGeom){ analGeom = aGeom; } - - /** Retrieves whether this shape is a geometry instance such as from mesh, - convex mesh, or spline. - @returns True if this shape is a geometry instance. */ - bool IsGeometryInstance() const { return geometry != NULL; } - - /** Gets the geometry instance. NULL is returned if IsGeometryInstance - returns false. - @return The geometry instance. */ - FCDGeometryInstance* GetGeometryInstance() { return geometry; } - const FCDGeometryInstance* GetGeometryInstance() const { return geometry; } /**< See above. */ - - /** [INTERNAL] Set the geometry instance. - @param instance The new geometry instance. - */ - void SetGeometryInstance(FCDGeometryInstance* instance){ geometry = instance; } - - /** Creates a geometry instance for this shape. If IsAnalyticalGeometry - returned true before this call, it will return false afterwards as the - analytical geometry is released. - @param geom The geometry to instance. - @param createConvexMesh True if want to create a convex mesh from geom - @return The new geometry instance. */ - FCDGeometryInstance* CreateGeometryInstance(FCDGeometry* geom, bool createConvexMesh=false); - - /** Creates an analytical geometry for this shape. If IsGeometryInstance - returned true before this call, it will return false afterwards as the - geometry instance is released. - @param type The type of analytical geometry to create. - @return The new analytical geometry. */ - FCDPhysicsAnalyticalGeometry* CreateAnalyticalGeometry(FCDPhysicsAnalyticalGeometry::GeomType type); - - /** Retrieves the transforms for this shape. - @return The transforms. */ - FCDTransformContainer& GetTransforms() {return transforms;} - const FCDTransformContainer& GetTransforms() const {return transforms;} /**< See above. */ - - /** Adds a transform for this shape. - @param type The type of transform. - @param index The position in the transform list to add it to; an index - greater than the size indicates adding the transform to the end. - @return The new transform. */ - FCDTransform* AddTransform(FCDTransform::Type type, size_t index = (size_t)-1); - - /** Retrieves the physics material for this shape. - @return The physics material for this shape. */ - FCDPhysicsMaterial* GetPhysicsMaterial() {return physicsMaterial;} - const FCDPhysicsMaterial* GetPhysicsMaterial() const {return physicsMaterial;} /**< See above. */ - - /** Sets the physics material for this shape. - @param physicsMaterial The physics material for this shape. */ - void SetPhysicsMaterial(FCDPhysicsMaterial* physicsMaterial); - - /** Adds a physics material for this shape. This shape is responsible for - releasing the physics material. - @return The new physics material. */ - FCDPhysicsMaterial* AddOwnPhysicsMaterial(); - - /** Copies the shape into a clone. - @param clone The empty clone. If this pointer is NULL, a new physics - shape will be created and you will need to release the returned - pointer manually. - @return The clone. */ - FCDPhysicsShape* Clone(FCDPhysicsShape* clone = NULL) const; - - /** Calculates the volume of the shape. Currently it is calculating a - simple bounding box volume if IsGeometryInstance it true, and it is - calculating the exact volume if IsAnalyticalGeometry is true. Note that - a volume of 1.0f is returned if it is a spline or plane. - @return The volume of the shape. */ - float CalculateVolume() const; - - /** [INTERNAL] Set the material instance. - @instance The new material instance. - */ - void SetInstanceMaterial(FCDEntityInstance* instance){ instanceMaterialRef = instance; } - - /** [INTERNAL] Retrieve the material instance. - @return The material instance. - */ - FCDEntityInstance* GetInstanceMaterial(){ return instanceMaterialRef; } - - /** [INTERNAL] Determin if it owns the material. - @return True if this owns the material, false otherwise. - */ - bool OwnsPhysicsMaterial() { return ownsPhysicsMaterial; } - - -}; - -#endif // _FCD_PHYSICS_SHAPE_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsShape.h + This file contains the FCDPhysicsShape class. +*/ + +#ifndef _FCD_PHYSICS_SHAPE_H_ +#define _FCD_PHYSICS_SHAPE_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FCD_PHYSICS_ANALYTICAL_GEOM_H_ +#include "FCDocument/FCDPhysicsAnalyticalGeometry.h" +#endif // _FCD_PHYSICS_ANALYTICAL_GEOM_H_ +#ifndef _FCD_TRANSFORM_H_ +#include "FCDocument/FCDTransform.h" /** @todo Remove this include by moving the FCDTransform::Type enum to FUDaeEnum.h. */ +#endif // _FCD_TRANSFORM_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ + +class FCDEntityInstance; +class FCDGeometry; +class FCDGeometryInstance; +class FCDPhysicsAnalyticalGeometry; +class FCDPhysicsMaterial; + +typedef FUObjectContainer FCDTransformContainer; /**< A dynamically-sized containment array for transforms. */ + +/** + A COLLADA shape object. + + A shape describes the boundary used for collision detection within a rigid + body. It belongs to a single rigid body and cannot be referenced from other + elements. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPhysicsShape : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + bool hollow; + FUTrackedPtr physicsMaterial; + bool ownsPhysicsMaterial; + + //one of these two will define the rigid body + FUTrackedPtr geometry; + FUObjectRef analGeom; + + float* mass; + float* density; + FCDTransformContainer transforms; + FCDEntityInstance* instanceMaterialRef; + + bool isDensityMoreAccurate; + +public: + /** Constructor: do not use directly. Create new shapes using the + FCDPhysicsRigidBody::AddPhysicsShape function. + @param document The COLLADA document that contains this rigid body. */ + FCDPhysicsShape(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPhysicsShape(); + + /** Retrieves the mass of this shape. + @return The mass. */ + float GetMass() const; + const float* GetMassPointer() const { return mass; } /** [INTERNAL] */ + + /** Sets the mass of this shape. + @param mass The new mass. */ + void SetMass(float mass); + + /** Retrieves whether density of this shape is more accurate than mass. It is more accurate if mass is not defined. In that case mass is + calculated using approximations when it is non-analytic. + @return True if density is more accurate. */ + bool IsDensityMoreAccurate() const { return isDensityMoreAccurate; } + + /** [INTERNAL] Set 'DensityMoreAccurate'. + @parame value Value to be set. + */ + void SetDensityMoreAccurate(bool value){ isDensityMoreAccurate = value; } + + /** Retrieves the density of this shape. + @return The density. */ + float GetDensity() const; + const float* GetDensityPointer() const { return density; } /** [INTERNAL] */ + + /** Sets the density of this shape. + @param density The new density. */ + void SetDensity(float density); + + /** Retrives whether this shape is hollow. + @return True if this shape is hollow. */ + bool IsHollow() const {return hollow;} + + /** Sets whether this shape is hollow. + @param _hollow True if this shape is hollow. */ + void SetHollow(bool _hollow) {hollow = _hollow;} + + /** Retrieves whether this shape is an analyical geometry such as a box, + plane, sphere, cylinder, tapered cylinder, capsule, or tapered capsule. + @return True if this shape is an analytical geometry. */ + bool IsAnalyticalGeometry() const { return analGeom != NULL; } + + /** Gets the analytic geometry. NULL is returned if IsAnalyticalGeometry + returns false. + @return The analytical geometry. */ + FCDPhysicsAnalyticalGeometry* GetAnalyticalGeometry() { return analGeom; } + const FCDPhysicsAnalyticalGeometry* GetAnalyticalGeometry() const { return analGeom; } /**< See above. */ + + /** [INTERNAL] Set the analytical geometry. + @param aGeom The analytical geometry. + */ + void SetAnalyticalGeometry(FCDPhysicsAnalyticalGeometry* aGeom){ analGeom = aGeom; } + + /** Retrieves whether this shape is a geometry instance such as from mesh, + convex mesh, or spline. + @returns True if this shape is a geometry instance. */ + bool IsGeometryInstance() const { return geometry != NULL; } + + /** Gets the geometry instance. NULL is returned if IsGeometryInstance + returns false. + @return The geometry instance. */ + FCDGeometryInstance* GetGeometryInstance() { return geometry; } + const FCDGeometryInstance* GetGeometryInstance() const { return geometry; } /**< See above. */ + + /** [INTERNAL] Set the geometry instance. + @param instance The new geometry instance. + */ + void SetGeometryInstance(FCDGeometryInstance* instance){ geometry = instance; } + + /** Creates a geometry instance for this shape. If IsAnalyticalGeometry + returned true before this call, it will return false afterwards as the + analytical geometry is released. + @param geom The geometry to instance. + @param createConvexMesh True if want to create a convex mesh from geom + @return The new geometry instance. */ + FCDGeometryInstance* CreateGeometryInstance(FCDGeometry* geom, bool createConvexMesh=false); + + /** Creates an analytical geometry for this shape. If IsGeometryInstance + returned true before this call, it will return false afterwards as the + geometry instance is released. + @param type The type of analytical geometry to create. + @return The new analytical geometry. */ + FCDPhysicsAnalyticalGeometry* CreateAnalyticalGeometry(FCDPhysicsAnalyticalGeometry::GeomType type); + + /** Retrieves the transforms for this shape. + @return The transforms. */ + FCDTransformContainer& GetTransforms() {return transforms;} + const FCDTransformContainer& GetTransforms() const {return transforms;} /**< See above. */ + + /** Adds a transform for this shape. + @param type The type of transform. + @param index The position in the transform list to add it to; an index + greater than the size indicates adding the transform to the end. + @return The new transform. */ + FCDTransform* AddTransform(FCDTransform::Type type, size_t index = (size_t)-1); + + /** Retrieves the physics material for this shape. + @return The physics material for this shape. */ + FCDPhysicsMaterial* GetPhysicsMaterial() {return physicsMaterial;} + const FCDPhysicsMaterial* GetPhysicsMaterial() const {return physicsMaterial;} /**< See above. */ + + /** Sets the physics material for this shape. + @param physicsMaterial The physics material for this shape. */ + void SetPhysicsMaterial(FCDPhysicsMaterial* physicsMaterial); + + /** Adds a physics material for this shape. This shape is responsible for + releasing the physics material. + @return The new physics material. */ + FCDPhysicsMaterial* AddOwnPhysicsMaterial(); + + /** Copies the shape into a clone. + @param clone The empty clone. If this pointer is NULL, a new physics + shape will be created and you will need to release the returned + pointer manually. + @return The clone. */ + FCDPhysicsShape* Clone(FCDPhysicsShape* clone = NULL) const; + + /** Calculates the volume of the shape. Currently it is calculating a + simple bounding box volume if IsGeometryInstance it true, and it is + calculating the exact volume if IsAnalyticalGeometry is true. Note that + a volume of 1.0f is returned if it is a spline or plane. + @return The volume of the shape. */ + float CalculateVolume() const; + + /** [INTERNAL] Set the material instance. + @instance The new material instance. + */ + void SetInstanceMaterial(FCDEntityInstance* instance){ instanceMaterialRef = instance; } + + /** [INTERNAL] Retrieve the material instance. + @return The material instance. + */ + FCDEntityInstance* GetInstanceMaterial(){ return instanceMaterialRef; } + + /** [INTERNAL] Determin if it owns the material. + @return True if this owns the material, false otherwise. + */ + bool OwnsPhysicsMaterial() { return ownsPhysicsMaterial; } + + +}; + +#endif // _FCD_PHYSICS_SHAPE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsShape.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNode.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNode.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNode.h (revision 24247) @@ -1,302 +1,302 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDSceneNode.h - This file contains the FCDSceneNode class. -*/ - -#ifndef _FCD_SCENE_NODE_ -#define _FCD_SCENE_NODE_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ -#ifndef _FCD_TRANSFORM_H_ -#include "FCDocument/FCDTransform.h" /** @todo Remove this include by moving the FCDTransform::Type enum to FUDaeEnum.h. */ -#endif // _FCD_TRANSFORM_H_ -#ifndef _FCD_ENTITY_INSTANCE_H_ -#include "FCDocument/FCDEntityInstance.h" /** @todo Remove this include by moving the FCDEntityInstance::Type enum to FUDaeEnum.h. */ -#endif // _FCD_ENTITY_INSTANCE_H_ - -class FCDocument; -class FCDEntityInstance; -class FCDSceneNode; -class FCDTransform; - -/** - A COLLADA visual scene node. - This class is also used to represent COLLADA visual scene entities. - - A visual scene node contains child scene nodes to make a tree. - A visual scene node may appear multiple times within the scene graph, - but checks are made to verify that there are no cycles within the graph. - - A visual scene node also contained an ordered list of transformations - and a list of entity instances. - - NOTE: The GenerateSampledMatrixAnimation function was moved to the - FCDSceneNodeTools namespace to improve DLL support. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDSceneNode : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - - // Hierarchy and instances - DeclareParameterTrackList(FCDSceneNode, parents, FC("Parents")); - DeclareParameterTrackList(FCDSceneNode, children, FC("Child Nodes")); - DeclareParameterContainer(FCDTransform, transforms, FC("Transforms")); - DeclareParameterContainer(FCDEntityInstance, instances, FC("Instances")); - - // Visibility parameter. - // Should be a boolean, but is animated as float. - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, visibility, FC("Visibility")); - - // The number of entities that target this node - uint32 targetCount; - - // Mainly for joints. - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, daeSubId, FC("Sub-id")); - -public: - DeclareFlag(TransformsDirty, 0); /**< Whether the transforms have been dirtied. */ - DeclareFlag(Joint, 1); /**< Whether the scene node is a joint. */ - DeclareFlagCount(2); /**< . */ - -public: - /** Constructor: do not use directly. - Instead, use the FCDSceneNode::AddChild function for child - visual scene nodes or the FCDLibrary::AddEntity function - for visual scenes. - @param document The COLLADA document that owns the scene node. */ - FCDSceneNode(FCDocument* document); - - /** Destructor. */ - virtual ~FCDSceneNode(); - - /** Retrieves the type of the entity class. - @return The type of entity class: SCENE_NODE. */ - virtual Type GetType() const { return SCENE_NODE; } - - /** Retrieves the number of parent nodes for this visual scene node. - @return The number of parents. */ - inline size_t GetParentCount() const { return parents.size(); }; - - /** Retrieves a specific parent of the visual scene node. - @param index The index of the parent. - @return The parent visual scene node. This pointer will be NULL if - the scene node has no parents or if the index is out-of-bounds. */ - inline FCDSceneNode* GetParent(size_t index = 0) { FUAssert(index == 0 || index < parents.size(), return NULL); return (!parents.empty()) ? parents.at(index) : NULL; } - inline const FCDSceneNode* GetParent(size_t index = 0) const { FUAssert(index == 0 || index < parents.size(), return NULL); return (!parents.empty()) ? parents.at(index) : NULL; } /**< See above. */ - - /** Retrieves the list of parents for the visual scene node. - @return The list of parents. */ - inline const FCDSceneNode** GetParents() const { return parents.begin(); } - - /** Retrieves the number of child nodes for this visual scene node. - @return The number of children. */ - inline size_t GetChildrenCount() const { return children.size(); }; - - /** Retrieves a specific child of the visual scene node. - @param index The index of the child. - @return The child scene node. This pointer will be NULL if the - index is out-of-bounds. */ - inline FCDSceneNode* GetChild(size_t index) { FUAssert(index < children.size(), return NULL); return children.at(index); } - inline const FCDSceneNode* GetChild(size_t index) const { FUAssert(index < children.size(), return NULL); return children.at(index); } /**< See above. */ - - /** Retrieves the list of children of the visual scene node. - @return The list of child scene nodes. */ - inline const FCDSceneNode** GetChildren() const { return children.begin(); } - - /** Creates a new child scene node. - @return The new child scene node. */ - FCDSceneNode* AddChildNode(); - - /** Attaches a existing scene node to this visual scene node. - This function will fail if attaching the given scene node - to this visual scene node creates a cycle within the scene graph. - @param sceneNode The scene node to attach. - @return Whether the given scene node was attached to this scene node. */ - bool AddChildNode(FCDSceneNode* sceneNode); - - /** Removes a scene node from this scene node direct child list. - This function should be used to detach a scene node with multiple parents. - To completely delete a scene node, you should use the FCDSceneNode::Release function - on the scene node to delete. - If the given child node is instanced multiple times within this scene node, - only the first instance will be removed. - @param childNode The child node to remove from the direct hierarchy. */ - void RemoveChildNode(FCDSceneNode* childNode); - - /** Retrieves the number of entity instances at this node of the scene graph. - @return The number of entity instances. */ - inline size_t GetInstanceCount() const { return instances.size(); }; - - /** Retrieves a specific entity instance. - @param index The index of the instance. - @return The entity instance at the given index. This pointer will be - NULL if the index is out-of-bounds. */ - inline FCDEntityInstance* GetInstance(size_t index) { FUAssert(index < instances.size(), return NULL); return instances.at(index); } - inline const FCDEntityInstance* GetInstance(size_t index) const { FUAssert(index < instances.size(), return NULL); return instances.at(index); } /**< See above. */ - - /** Retrieves the list of entity instances at this node of the scene graph. - @return The list of entity instances. */ - inline const FCDEntityInstance** GetInstances() const { return instances.begin(); } - - /** Creates a new entity instance. - Only geometric entities, controllers, light and cameras - can be instantiated in the scene graph. - To instantiate visual scene nodes, use the AddChildNode function. - @param entity The entity to instantiate. This pointer cannot be NULL. - @return The entity instance structure. This pointer will be NULL - if the entity cannot be instantiated here or if the entity is a scene node. */ - FCDEntityInstance* AddInstance(FCDEntity* entity); - - /** Creates a new entity instance. - Only geometric entities, controllers, light and cameras - can be instantiated in the scene graph. - To instantiate visual scene nodes, use the AddChildNode function. - @param type The type of entity to instantiate. - @return The entity instance structure. This pointer will be NULL - if the entity cannot be instantiated here. */ - FCDEntityInstance* AddInstance(FCDEntity::Type type); - - /** Retrieves the number of transforms for this node of the scene graph. - @return The number of transforms. */ - inline size_t GetTransformCount() const { return transforms.size(); }; - - /** Retrieves a specific transform. - @param index The index of the transform. - @return The transform at the given index. This pointer will be NULL - if the index is out-of-bounds. */ - inline FCDTransform* GetTransform(size_t index) { FUAssert(index < transforms.size(), return NULL); return transforms.at(index); } - inline const FCDTransform* GetTransform(size_t index) const { FUAssert(index < transforms.size(), return NULL); return transforms.at(index); } /**< See above. */ - - /** Retrieves the list of transforms for this node of the scene graph. - @return The list of transforms. */ - inline const FCDTransform** GetTransforms() const { return transforms.begin(); } /**< See above. */ - - /** Creates a new transform for this visual scene node. - The transforms are processed in order and COLLADA is column-major. - For row-major matrix stacks, such as DirectX, this implies that the - transformations will be processed in reverse order. - By default, a transform is added at the end of the list. - @param type The type of transform to create. - @param index The index at which to insert the transform. Set this value to -1 - to indicate that you want this transform at the end of the stack. - @return The created transform. */ - FCDTransform* AddTransform(FCDTransform::Type type, size_t index = (size_t)-1); - - /** Retrieves the asset information structures that affect - this entity in its hierarchy. - @param assets A list of asset information structures to fill in. */ - inline void GetHierarchicalAssets(FCDAssetList& assets) { GetHierarchicalAssets(*(FCDAssetConstList*) &assets); } - virtual void GetHierarchicalAssets(FCDAssetConstList& assets) const; /**< See above. */ - - /** Retrieves the visual scene node with the given id. - This function looks through the whole sub-tree of visual scene nodes - for the wanted COLLADA id. - @param daeId The COLLADA id to look for. - @return The visual scene node which has the given COLLADA id. This pointer - will be NULL if no visual scene node can be found with the given COLLADA id. */ - virtual FCDEntity* FindDaeId(const fm::string& daeId) { return const_cast(const_cast(this)->FindDaeId(daeId)); } - virtual const FCDEntity* FindDaeId(const fm::string& daeId) const; /** < See above. */ - - /** Retrieves the optional sub-id of the node. - This sub-id is neither unique nor guaranteed to exist. - @return The sub-id of the node. */ - inline const fm::string& GetSubId() const { return daeSubId; } - - /** Sets the sub-id for this node. - The sub-id of an object is not required to be unique. - @param id The new sub-id of the node. */ - void SetSubId(const fm::string& id); - - /** Retrieves the visual scene node with the given sub-id. - This function looks through the whole sub-tree of visual scene nodes - for the wanted COLLADA sub-id. - @param subId The COLLADA sub-id to look for. - @return The visual scene node which has the given COLLADA sub-id. This pointer - will be NULL if no visual scene node can be found with the given COLLADA sub-id. */ - inline FCDEntity* FindSubId(const fm::string& subId) { return const_cast(const_cast(this)->FindSubId(subId)); } - const FCDEntity* FindSubId(const fm::string& subId) const; /**< See above. */ - - /** Retrieves whether the visual scene node is visible. - A hidden visual scene node will not be rendered but will - still affect the world. This parameter is a floating-point value - because it is animated. It should be intepreted as a Boolean value. - @return Whether the scene node is visible. */ - inline FCDParameterAnimatableFloat& GetVisibility() { return visibility; } - inline const FCDParameterAnimatableFloat& GetVisibility() const { return visibility; } /**< See above. */ - inline bool IsVisible() const { return visibility > 0.5f; } /**< See above. */ - - /** Sets the visibility of the visual scene node. - A hidden visual scene node will not be rendered but will - still affect the world. - @param isVisible Whether the visual scene node is visible. */ - inline void SetVisibility(bool isVisible) { visibility = isVisible ? 1.0f : 0.0f; } - - /** Retrieves whether this visual scene node is the target of an entity. - @return Whether this is an entity target. */ - inline bool IsTarget() const { return targetCount > 0; } - - /** Retrieves whether this visual scene node is a joint. - Joints are called bones in 3dsMax. A joint is a scene node that is used in skinning. - @return Whether this node is a joint. */ - DEPRECATED(3.05A, GetJointFlag) bool IsJoint() const { return GetJointFlag(); } - - /** Retrieves the local transform for this visual scene node. - This function does not handle or apply animations. - @return The local transform. */ - FMMatrix44 ToMatrix() const; - - /** Retrieves the local transform for this visual scene node. - This is a shortcut to the above function. The above function - will be deprecated in the future. - @return The local transform. */ - inline FMMatrix44 CalculateLocalTransform() const { return ToMatrix(); } - - /** Retrieves the world transform for this visual scene node. - This function is not optimized and will not work with node instances. - @return The world transform. */ - FMMatrix44 CalculateWorldTransform() const; - - /** Copies the entity information into a clone. - All the overwriting functions of this function should call this function - to copy the COLLADA id and the other entity-level information. - All the up-classes of this class should implement this function. - The cloned entity may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new entity - will be created and you will need to release the returned pointer manually. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - - /** [INTERNAL] Increments the number of entities target this node. - To set targets, use the FCDTargetedEntity::SetTarget function. */ - inline void IncrementTargetCount() { ++targetCount; } - - /** [INTERNAL] Decrements the number of entities target this node. - To set targets, use the FCDTargetedEntity::SetTarget function. */ - inline void DecrementTargetCount() { if (targetCount > 0) --targetCount; } - - /** [INTERNAL] Cleans up the sub identifiers. - The sub identifiers must be unique with respect to its parent. This method corrects the sub ids if there are conflicts. */ - virtual void CleanSubId(); -}; - -#endif // _FCD_SCENE_NODE_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDSceneNode.h + This file contains the FCDSceneNode class. +*/ + +#ifndef _FCD_SCENE_NODE_ +#define _FCD_SCENE_NODE_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ +#ifndef _FCD_TRANSFORM_H_ +#include "FCDocument/FCDTransform.h" /** @todo Remove this include by moving the FCDTransform::Type enum to FUDaeEnum.h. */ +#endif // _FCD_TRANSFORM_H_ +#ifndef _FCD_ENTITY_INSTANCE_H_ +#include "FCDocument/FCDEntityInstance.h" /** @todo Remove this include by moving the FCDEntityInstance::Type enum to FUDaeEnum.h. */ +#endif // _FCD_ENTITY_INSTANCE_H_ + +class FCDocument; +class FCDEntityInstance; +class FCDSceneNode; +class FCDTransform; + +/** + A COLLADA visual scene node. + This class is also used to represent COLLADA visual scene entities. + + A visual scene node contains child scene nodes to make a tree. + A visual scene node may appear multiple times within the scene graph, + but checks are made to verify that there are no cycles within the graph. + + A visual scene node also contained an ordered list of transformations + and a list of entity instances. + + NOTE: The GenerateSampledMatrixAnimation function was moved to the + FCDSceneNodeTools namespace to improve DLL support. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDSceneNode : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + + // Hierarchy and instances + DeclareParameterTrackList(FCDSceneNode, parents, FC("Parents")); + DeclareParameterTrackList(FCDSceneNode, children, FC("Child Nodes")); + DeclareParameterContainer(FCDTransform, transforms, FC("Transforms")); + DeclareParameterContainer(FCDEntityInstance, instances, FC("Instances")); + + // Visibility parameter. + // Should be a boolean, but is animated as float. + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, visibility, FC("Visibility")); + + // The number of entities that target this node + uint32 targetCount; + + // Mainly for joints. + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, daeSubId, FC("Sub-id")); + +public: + DeclareFlag(TransformsDirty, 0); /**< Whether the transforms have been dirtied. */ + DeclareFlag(Joint, 1); /**< Whether the scene node is a joint. */ + DeclareFlagCount(2); /**< . */ + +public: + /** Constructor: do not use directly. + Instead, use the FCDSceneNode::AddChild function for child + visual scene nodes or the FCDLibrary::AddEntity function + for visual scenes. + @param document The COLLADA document that owns the scene node. */ + FCDSceneNode(FCDocument* document); + + /** Destructor. */ + virtual ~FCDSceneNode(); + + /** Retrieves the type of the entity class. + @return The type of entity class: SCENE_NODE. */ + virtual Type GetType() const { return SCENE_NODE; } + + /** Retrieves the number of parent nodes for this visual scene node. + @return The number of parents. */ + inline size_t GetParentCount() const { return parents.size(); }; + + /** Retrieves a specific parent of the visual scene node. + @param index The index of the parent. + @return The parent visual scene node. This pointer will be NULL if + the scene node has no parents or if the index is out-of-bounds. */ + inline FCDSceneNode* GetParent(size_t index = 0) { FUAssert(index == 0 || index < parents.size(), return NULL); return (!parents.empty()) ? parents.at(index) : NULL; } + inline const FCDSceneNode* GetParent(size_t index = 0) const { FUAssert(index == 0 || index < parents.size(), return NULL); return (!parents.empty()) ? parents.at(index) : NULL; } /**< See above. */ + + /** Retrieves the list of parents for the visual scene node. + @return The list of parents. */ + inline const FCDSceneNode** GetParents() const { return parents.begin(); } + + /** Retrieves the number of child nodes for this visual scene node. + @return The number of children. */ + inline size_t GetChildrenCount() const { return children.size(); }; + + /** Retrieves a specific child of the visual scene node. + @param index The index of the child. + @return The child scene node. This pointer will be NULL if the + index is out-of-bounds. */ + inline FCDSceneNode* GetChild(size_t index) { FUAssert(index < children.size(), return NULL); return children.at(index); } + inline const FCDSceneNode* GetChild(size_t index) const { FUAssert(index < children.size(), return NULL); return children.at(index); } /**< See above. */ + + /** Retrieves the list of children of the visual scene node. + @return The list of child scene nodes. */ + inline const FCDSceneNode** GetChildren() const { return children.begin(); } + + /** Creates a new child scene node. + @return The new child scene node. */ + FCDSceneNode* AddChildNode(); + + /** Attaches a existing scene node to this visual scene node. + This function will fail if attaching the given scene node + to this visual scene node creates a cycle within the scene graph. + @param sceneNode The scene node to attach. + @return Whether the given scene node was attached to this scene node. */ + bool AddChildNode(FCDSceneNode* sceneNode); + + /** Removes a scene node from this scene node direct child list. + This function should be used to detach a scene node with multiple parents. + To completely delete a scene node, you should use the FCDSceneNode::Release function + on the scene node to delete. + If the given child node is instanced multiple times within this scene node, + only the first instance will be removed. + @param childNode The child node to remove from the direct hierarchy. */ + void RemoveChildNode(FCDSceneNode* childNode); + + /** Retrieves the number of entity instances at this node of the scene graph. + @return The number of entity instances. */ + inline size_t GetInstanceCount() const { return instances.size(); }; + + /** Retrieves a specific entity instance. + @param index The index of the instance. + @return The entity instance at the given index. This pointer will be + NULL if the index is out-of-bounds. */ + inline FCDEntityInstance* GetInstance(size_t index) { FUAssert(index < instances.size(), return NULL); return instances.at(index); } + inline const FCDEntityInstance* GetInstance(size_t index) const { FUAssert(index < instances.size(), return NULL); return instances.at(index); } /**< See above. */ + + /** Retrieves the list of entity instances at this node of the scene graph. + @return The list of entity instances. */ + inline const FCDEntityInstance** GetInstances() const { return instances.begin(); } + + /** Creates a new entity instance. + Only geometric entities, controllers, light and cameras + can be instantiated in the scene graph. + To instantiate visual scene nodes, use the AddChildNode function. + @param entity The entity to instantiate. This pointer cannot be NULL. + @return The entity instance structure. This pointer will be NULL + if the entity cannot be instantiated here or if the entity is a scene node. */ + FCDEntityInstance* AddInstance(FCDEntity* entity); + + /** Creates a new entity instance. + Only geometric entities, controllers, light and cameras + can be instantiated in the scene graph. + To instantiate visual scene nodes, use the AddChildNode function. + @param type The type of entity to instantiate. + @return The entity instance structure. This pointer will be NULL + if the entity cannot be instantiated here. */ + FCDEntityInstance* AddInstance(FCDEntity::Type type); + + /** Retrieves the number of transforms for this node of the scene graph. + @return The number of transforms. */ + inline size_t GetTransformCount() const { return transforms.size(); }; + + /** Retrieves a specific transform. + @param index The index of the transform. + @return The transform at the given index. This pointer will be NULL + if the index is out-of-bounds. */ + inline FCDTransform* GetTransform(size_t index) { FUAssert(index < transforms.size(), return NULL); return transforms.at(index); } + inline const FCDTransform* GetTransform(size_t index) const { FUAssert(index < transforms.size(), return NULL); return transforms.at(index); } /**< See above. */ + + /** Retrieves the list of transforms for this node of the scene graph. + @return The list of transforms. */ + inline const FCDTransform** GetTransforms() const { return transforms.begin(); } /**< See above. */ + + /** Creates a new transform for this visual scene node. + The transforms are processed in order and COLLADA is column-major. + For row-major matrix stacks, such as DirectX, this implies that the + transformations will be processed in reverse order. + By default, a transform is added at the end of the list. + @param type The type of transform to create. + @param index The index at which to insert the transform. Set this value to -1 + to indicate that you want this transform at the end of the stack. + @return The created transform. */ + FCDTransform* AddTransform(FCDTransform::Type type, size_t index = (size_t)-1); + + /** Retrieves the asset information structures that affect + this entity in its hierarchy. + @param assets A list of asset information structures to fill in. */ + inline void GetHierarchicalAssets(FCDAssetList& assets) { GetHierarchicalAssets(*(FCDAssetConstList*) &assets); } + virtual void GetHierarchicalAssets(FCDAssetConstList& assets) const; /**< See above. */ + + /** Retrieves the visual scene node with the given id. + This function looks through the whole sub-tree of visual scene nodes + for the wanted COLLADA id. + @param daeId The COLLADA id to look for. + @return The visual scene node which has the given COLLADA id. This pointer + will be NULL if no visual scene node can be found with the given COLLADA id. */ + virtual FCDEntity* FindDaeId(const fm::string& daeId) { return const_cast(const_cast(this)->FindDaeId(daeId)); } + virtual const FCDEntity* FindDaeId(const fm::string& daeId) const; /** < See above. */ + + /** Retrieves the optional sub-id of the node. + This sub-id is neither unique nor guaranteed to exist. + @return The sub-id of the node. */ + inline const fm::string& GetSubId() const { return daeSubId; } + + /** Sets the sub-id for this node. + The sub-id of an object is not required to be unique. + @param id The new sub-id of the node. */ + void SetSubId(const fm::string& id); + + /** Retrieves the visual scene node with the given sub-id. + This function looks through the whole sub-tree of visual scene nodes + for the wanted COLLADA sub-id. + @param subId The COLLADA sub-id to look for. + @return The visual scene node which has the given COLLADA sub-id. This pointer + will be NULL if no visual scene node can be found with the given COLLADA sub-id. */ + inline FCDEntity* FindSubId(const fm::string& subId) { return const_cast(const_cast(this)->FindSubId(subId)); } + const FCDEntity* FindSubId(const fm::string& subId) const; /**< See above. */ + + /** Retrieves whether the visual scene node is visible. + A hidden visual scene node will not be rendered but will + still affect the world. This parameter is a floating-point value + because it is animated. It should be intepreted as a Boolean value. + @return Whether the scene node is visible. */ + inline FCDParameterAnimatableFloat& GetVisibility() { return visibility; } + inline const FCDParameterAnimatableFloat& GetVisibility() const { return visibility; } /**< See above. */ + inline bool IsVisible() const { return visibility > 0.5f; } /**< See above. */ + + /** Sets the visibility of the visual scene node. + A hidden visual scene node will not be rendered but will + still affect the world. + @param isVisible Whether the visual scene node is visible. */ + inline void SetVisibility(bool isVisible) { visibility = isVisible ? 1.0f : 0.0f; } + + /** Retrieves whether this visual scene node is the target of an entity. + @return Whether this is an entity target. */ + inline bool IsTarget() const { return targetCount > 0; } + + /** Retrieves whether this visual scene node is a joint. + Joints are called bones in 3dsMax. A joint is a scene node that is used in skinning. + @return Whether this node is a joint. */ + DEPRECATED(3.05A, GetJointFlag) bool IsJoint() const { return GetJointFlag(); } + + /** Retrieves the local transform for this visual scene node. + This function does not handle or apply animations. + @return The local transform. */ + FMMatrix44 ToMatrix() const; + + /** Retrieves the local transform for this visual scene node. + This is a shortcut to the above function. The above function + will be deprecated in the future. + @return The local transform. */ + inline FMMatrix44 CalculateLocalTransform() const { return ToMatrix(); } + + /** Retrieves the world transform for this visual scene node. + This function is not optimized and will not work with node instances. + @return The world transform. */ + FMMatrix44 CalculateWorldTransform() const; + + /** Copies the entity information into a clone. + All the overwriting functions of this function should call this function + to copy the COLLADA id and the other entity-level information. + All the up-classes of this class should implement this function. + The cloned entity may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new entity + will be created and you will need to release the returned pointer manually. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + + /** [INTERNAL] Increments the number of entities target this node. + To set targets, use the FCDTargetedEntity::SetTarget function. */ + inline void IncrementTargetCount() { ++targetCount; } + + /** [INTERNAL] Decrements the number of entities target this node. + To set targets, use the FCDTargetedEntity::SetTarget function. */ + inline void DecrementTargetCount() { if (targetCount > 0) --targetCount; } + + /** [INTERNAL] Cleans up the sub identifiers. + The sub identifiers must be unique with respect to its parent. This method corrects the sub ids if there are conflicts. */ + virtual void CleanSubId(); +}; + +#endif // _FCD_SCENE_NODE_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNode.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSkinController.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSkinController.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSkinController.cpp (revision 24247) @@ -1,213 +1,213 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDGeometrySource.h" -#include "FCDocument/FCDGeometrySpline.h" -#include "FCDocument/FCDSkinController.h" -#include "FCDocument/FCDEntityReference.h" - -// -// FCDSkinController -// - -ImplementObjectType(FCDSkinController); - -FCDSkinController::FCDSkinController(FCDocument* document, FCDController* _parent) -: FCDObject(document) -, parent(_parent) -, InitializeParameter(bindShapeTransform, FMMatrix44::Identity) -{ - // Always create this. - target = new FCDEntityReference(document, parent); -} - -FCDSkinController::~FCDSkinController() -{ - SAFE_RELEASE(target); -} - -FUUri FCDSkinController::GetTargetUri() const -{ - return target->GetUri(); -} - -void FCDSkinController::SetTargetUri(const FUUri& uri) -{ - target->SetUri(uri); -} - -FCDEntity* FCDSkinController::GetTarget() -{ - return target->GetEntity(); -} - -const FCDEntity* FCDSkinController::GetTarget() const -{ - return target->GetEntity(); -} - -void FCDSkinController::SetTarget(FCDEntity* _target) -{ - target->SetEntity(NULL); - SetNewChildFlag(); - - // Retrieve the actual base entity, as you can chain controllers. - FCDEntity* baseEntity = _target; - if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::CONTROLLER) - { - baseEntity = ((FCDController*) baseEntity)->GetBaseGeometry(); - } - - if (baseEntity == NULL || baseEntity->GetType() != FCDEntity::GEOMETRY) - { - // The new target is no good! - return; - } - - target->SetEntity(_target); - FCDGeometry* geometry = (FCDGeometry*) baseEntity; - - // Retrieve the new vertex count - size_t vertexCount = 0; - if (geometry->IsMesh()) - { - FCDGeometryMesh* mesh = geometry->GetMesh(); - FCDGeometrySource* positionSource = mesh->GetPositionSource(); - if (positionSource != NULL) - { - vertexCount = positionSource->GetValueCount(); - } - } - else if (geometry->IsSpline()) - { - FCDGeometrySpline* spline = geometry->GetSpline(); - vertexCount = spline->GetTotalCVCount(); - } - - // Modify the list of influences to match the new target's vertex count. - if (influences.size() != 0) - { - // This is only really acceptable with equivalent meshes. Ensure we - // are still compatable. - FUAssert(vertexCount == influences.size(), SetInfluenceCount(vertexCount)); - } - else - { - SetInfluenceCount(vertexCount); - } -} - -void FCDSkinController::SetInfluenceCount(size_t count) -{ - // None of the list structures are allocated directly: resize() will work fine. - influences.resize(count); - SetDirtyFlag(); -} - -void FCDSkinController::SetJointCount(size_t count) -{ - joints.resize(count); - SetDirtyFlag(); -} - -FCDSkinControllerJoint* FCDSkinController::AddJoint(const fm::string jSubId, const FMMatrix44& bindPose) -{ - SetJointCount(GetJointCount() + 1); - FCDSkinControllerJoint* joint = &joints.back(); - joint->SetId(jSubId); - joint->SetBindPoseInverse(bindPose); - SetDirtyFlag(); - return joint; -} - - -// Reduce the number of joints influencing each vertex to a maximum count -void FCDSkinController::ReduceInfluences(uint32 maxInfluenceCount, float minimumWeight) -{ - // Pre-cache an empty weight list to the reduced count - fm::vector reducedWeights; - reducedWeights.reserve(maxInfluenceCount + 1); - - for (FCDSkinControllerVertex* itM = influences.begin(); itM != influences.end(); ++itM) - { - FCDSkinControllerVertex& influence = (*itM); - size_t oldInfluenceCount = influence.GetPairCount(); - - // Reduce the weights, keeping only the more important ones using a sorting algorithm. - // Also, calculate the current total of the weights, to re-normalize the reduced weights - float oldTotal = 0.0f; - reducedWeights.clear(); - for (size_t i = 0; i < oldInfluenceCount; ++i) - { - FCDJointWeightPair* pair = influence.GetPair(i); - if (pair->weight >= minimumWeight) - { - FCDJointWeightPair* itRW = reducedWeights.begin(); - for (; itRW != reducedWeights.end() && (*itRW).weight > pair->weight; ++itRW) {} - if (itRW != reducedWeights.end() || reducedWeights.size() <= maxInfluenceCount) - { - reducedWeights.insert(itRW, *pair); - if (reducedWeights.size() > maxInfluenceCount) reducedWeights.pop_back(); - } - } - oldTotal += pair->weight; - } - - size_t newInfluenceCount = reducedWeights.size(); - if (oldInfluenceCount > newInfluenceCount) - { - // Replace the old weights and re-normalize to their old total - influence.SetPairCount(newInfluenceCount); - for (size_t i = 0; i < newInfluenceCount; ++i) (*(influence.GetPair(i))) = reducedWeights[i]; - - float newTotal = 0.0f; - for (size_t i = 0; i < newInfluenceCount; ++i) newTotal += influence.GetPair(i)->weight; - float renormalizingFactor = oldTotal / newTotal; - for (size_t i = 0; i < newInfluenceCount; ++i) influence.GetPair(i)->weight *= renormalizingFactor; - } - } - - SetDirtyFlag(); -} - -// -// FCDSkinControllerVertex -// - - -void FCDSkinControllerVertex::SetPairCount(size_t count) -{ - pairs.resize(count); -} - -void FCDSkinControllerVertex::AddPair(int32 jointIndex, float weight) -{ - pairs.push_back(FCDJointWeightPair(jointIndex, weight)); -} - -// -// FCDSkinControllerJoint -// - -void FCDSkinControllerJoint::SetId(const fm::string& _id) -{ - // Do not inline, since the line below does memory allocation. - id = _id; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDGeometrySource.h" +#include "FCDocument/FCDGeometrySpline.h" +#include "FCDocument/FCDSkinController.h" +#include "FCDocument/FCDEntityReference.h" + +// +// FCDSkinController +// + +ImplementObjectType(FCDSkinController); + +FCDSkinController::FCDSkinController(FCDocument* document, FCDController* _parent) +: FCDObject(document) +, parent(_parent) +, InitializeParameter(bindShapeTransform, FMMatrix44::Identity) +{ + // Always create this. + target = new FCDEntityReference(document, parent); +} + +FCDSkinController::~FCDSkinController() +{ + SAFE_RELEASE(target); +} + +FUUri FCDSkinController::GetTargetUri() const +{ + return target->GetUri(); +} + +void FCDSkinController::SetTargetUri(const FUUri& uri) +{ + target->SetUri(uri); +} + +FCDEntity* FCDSkinController::GetTarget() +{ + return target->GetEntity(); +} + +const FCDEntity* FCDSkinController::GetTarget() const +{ + return target->GetEntity(); +} + +void FCDSkinController::SetTarget(FCDEntity* _target) +{ + target->SetEntity(NULL); + SetNewChildFlag(); + + // Retrieve the actual base entity, as you can chain controllers. + FCDEntity* baseEntity = _target; + if (baseEntity != NULL && baseEntity->GetType() == FCDEntity::CONTROLLER) + { + baseEntity = ((FCDController*) baseEntity)->GetBaseGeometry(); + } + + if (baseEntity == NULL || baseEntity->GetType() != FCDEntity::GEOMETRY) + { + // The new target is no good! + return; + } + + target->SetEntity(_target); + FCDGeometry* geometry = (FCDGeometry*) baseEntity; + + // Retrieve the new vertex count + size_t vertexCount = 0; + if (geometry->IsMesh()) + { + FCDGeometryMesh* mesh = geometry->GetMesh(); + FCDGeometrySource* positionSource = mesh->GetPositionSource(); + if (positionSource != NULL) + { + vertexCount = positionSource->GetValueCount(); + } + } + else if (geometry->IsSpline()) + { + FCDGeometrySpline* spline = geometry->GetSpline(); + vertexCount = spline->GetTotalCVCount(); + } + + // Modify the list of influences to match the new target's vertex count. + if (influences.size() != 0) + { + // This is only really acceptable with equivalent meshes. Ensure we + // are still compatable. + FUAssert(vertexCount == influences.size(), SetInfluenceCount(vertexCount)); + } + else + { + SetInfluenceCount(vertexCount); + } +} + +void FCDSkinController::SetInfluenceCount(size_t count) +{ + // None of the list structures are allocated directly: resize() will work fine. + influences.resize(count); + SetDirtyFlag(); +} + +void FCDSkinController::SetJointCount(size_t count) +{ + joints.resize(count); + SetDirtyFlag(); +} + +FCDSkinControllerJoint* FCDSkinController::AddJoint(const fm::string jSubId, const FMMatrix44& bindPose) +{ + SetJointCount(GetJointCount() + 1); + FCDSkinControllerJoint* joint = &joints.back(); + joint->SetId(jSubId); + joint->SetBindPoseInverse(bindPose); + SetDirtyFlag(); + return joint; +} + + +// Reduce the number of joints influencing each vertex to a maximum count +void FCDSkinController::ReduceInfluences(uint32 maxInfluenceCount, float minimumWeight) +{ + // Pre-cache an empty weight list to the reduced count + fm::vector reducedWeights; + reducedWeights.reserve(maxInfluenceCount + 1); + + for (FCDSkinControllerVertex* itM = influences.begin(); itM != influences.end(); ++itM) + { + FCDSkinControllerVertex& influence = (*itM); + size_t oldInfluenceCount = influence.GetPairCount(); + + // Reduce the weights, keeping only the more important ones using a sorting algorithm. + // Also, calculate the current total of the weights, to re-normalize the reduced weights + float oldTotal = 0.0f; + reducedWeights.clear(); + for (size_t i = 0; i < oldInfluenceCount; ++i) + { + FCDJointWeightPair* pair = influence.GetPair(i); + if (pair->weight >= minimumWeight) + { + FCDJointWeightPair* itRW = reducedWeights.begin(); + for (; itRW != reducedWeights.end() && (*itRW).weight > pair->weight; ++itRW) {} + if (itRW != reducedWeights.end() || reducedWeights.size() <= maxInfluenceCount) + { + reducedWeights.insert(itRW, *pair); + if (reducedWeights.size() > maxInfluenceCount) reducedWeights.pop_back(); + } + } + oldTotal += pair->weight; + } + + size_t newInfluenceCount = reducedWeights.size(); + if (oldInfluenceCount > newInfluenceCount) + { + // Replace the old weights and re-normalize to their old total + influence.SetPairCount(newInfluenceCount); + for (size_t i = 0; i < newInfluenceCount; ++i) (*(influence.GetPair(i))) = reducedWeights[i]; + + float newTotal = 0.0f; + for (size_t i = 0; i < newInfluenceCount; ++i) newTotal += influence.GetPair(i)->weight; + float renormalizingFactor = oldTotal / newTotal; + for (size_t i = 0; i < newInfluenceCount; ++i) influence.GetPair(i)->weight *= renormalizingFactor; + } + } + + SetDirtyFlag(); +} + +// +// FCDSkinControllerVertex +// + + +void FCDSkinControllerVertex::SetPairCount(size_t count) +{ + pairs.resize(count); +} + +void FCDSkinControllerVertex::AddPair(int32 jointIndex, float weight) +{ + pairs.push_back(FCDJointWeightPair(jointIndex, weight)); +} + +// +// FCDSkinControllerJoint +// + +void FCDSkinControllerJoint::SetId(const fm::string& _id) +{ + // Do not inline, since the line below does memory allocation. + id = _id; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSkinController.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleModifier.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleModifier.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleModifier.cpp (revision 24247) @@ -1,10 +1,10 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - - -#include "StdAfx.h" +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + + +#include "StdAfx.h" Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleModifier.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsForceFieldInstance.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsForceFieldInstance.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsForceFieldInstance.cpp (revision 24247) @@ -1,46 +1,46 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDPhysicsForceFieldInstance.h" - -ImplementObjectType(FCDPhysicsForceFieldInstance); - -FCDPhysicsForceFieldInstance::FCDPhysicsForceFieldInstance( - FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType) -: FCDEntityInstance(document, parent, entityType) -{ -} - -FCDPhysicsForceFieldInstance::~FCDPhysicsForceFieldInstance() -{ -} - -FCDEntityInstance* FCDPhysicsForceFieldInstance::Clone( - FCDEntityInstance* _clone) const -{ - FCDPhysicsForceFieldInstance* clone = NULL; - if (_clone == NULL) clone = new FCDPhysicsForceFieldInstance( - const_cast(GetDocument()), - const_cast(GetParent()), GetEntityType()); - else if (!_clone->HasType(FCDPhysicsForceFieldInstance::GetClassType())) - return Parent::Clone(_clone); - else clone = (FCDPhysicsForceFieldInstance*) _clone; - - Parent::Clone(clone); - - // nothing interesting in force field instance to copy - - return clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDPhysicsForceFieldInstance.h" + +ImplementObjectType(FCDPhysicsForceFieldInstance); + +FCDPhysicsForceFieldInstance::FCDPhysicsForceFieldInstance( + FCDocument* document, FCDSceneNode* parent, FCDEntity::Type entityType) +: FCDEntityInstance(document, parent, entityType) +{ +} + +FCDPhysicsForceFieldInstance::~FCDPhysicsForceFieldInstance() +{ +} + +FCDEntityInstance* FCDPhysicsForceFieldInstance::Clone( + FCDEntityInstance* _clone) const +{ + FCDPhysicsForceFieldInstance* clone = NULL; + if (_clone == NULL) clone = new FCDPhysicsForceFieldInstance( + const_cast(GetDocument()), + const_cast(GetParent()), GetEntityType()); + else if (!_clone->HasType(FCDPhysicsForceFieldInstance::GetClassType())) + return Parent::Clone(_clone); + else clone = (FCDPhysicsForceFieldInstance*) _clone; + + Parent::Clone(clone); + + // nothing interesting in force field instance to copy + + return clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsForceFieldInstance.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModel.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModel.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModel.cpp (revision 24247) @@ -1,170 +1,170 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDPhysicsModel.h" -#include "FCDocument/FCDPhysicsModelInstance.h" -#include "FCDocument/FCDPhysicsRigidBody.h" -#include "FCDocument/FCDPhysicsRigidConstraint.h" -#include "FCDocument/FCDocument.h" -#include "FUtils/FUStringConversion.h" -#include "FUtils/FUUniqueStringMap.h" -#include "FUtils/FUUri.h" - -ImplementObjectType(FCDPhysicsModel); - -FCDPhysicsModel::FCDPhysicsModel(FCDocument* document) -: FCDEntity(document, "PhysicsModel") -{ -} - -FCDPhysicsModel::~FCDPhysicsModel() -{ -} - -FCDPhysicsModelInstance* FCDPhysicsModel::AddPhysicsModelInstance(FCDPhysicsModel* model) -{ - FCDPhysicsModelInstance* instance = instances.Add(GetDocument()); - instance->SetEntity(model); - SetNewChildFlag(); - return instance; -} - -FCDPhysicsRigidBody* FCDPhysicsModel::AddRigidBody() -{ - FCDPhysicsRigidBody* rigidBody = rigidBodies.Add(GetDocument()); - SetNewChildFlag(); - return rigidBody; -} - -FCDPhysicsRigidConstraint* FCDPhysicsModel::AddRigidConstraint() -{ - FCDPhysicsRigidConstraint* constraint = rigidConstraints.Add(GetDocument(), this); - SetNewChildFlag(); - return constraint; -} - -FCDEntity* FCDPhysicsModel::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPhysicsModel* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPhysicsModel(const_cast(GetDocument())); - else if (_clone->HasType(FCDPhysicsModel::GetClassType())) clone = (FCDPhysicsModel*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - // Clone the rigid bodies - for (FCDPhysicsRigidBodyContainer::const_iterator it = rigidBodies.begin(); it != rigidBodies.end(); ++it) - { - FCDPhysicsRigidBody* clonedRigidBody = clone->AddRigidBody(); - (*it)->Clone(clonedRigidBody, cloneChildren); - } - - // Clone the rigid constraints - for (FCDPhysicsRigidConstraintContainer::const_iterator it = rigidConstraints.begin(); it != rigidConstraints.end(); ++it) - { - FCDPhysicsRigidConstraint* clonedConstraint = clone->AddRigidConstraint(); - (*it)->Clone(clonedConstraint, cloneChildren); - } - - // Clone the model instances - for (FCDPhysicsModelInstanceContainer::const_iterator it = instances.begin(); it != instances.end(); ++it) - { - FCDPhysicsModelInstance* clonedInstance = clone->AddPhysicsModelInstance(); - (*it)->Clone(clonedInstance); - } - } - return _clone; -} - -const FCDPhysicsRigidBody* FCDPhysicsModel::FindRigidBodyFromSid(const fm::string& sid) const -{ - for (FCDPhysicsRigidBodyContainer::const_iterator it = rigidBodies.begin(); it!= rigidBodies.end(); ++it) - { - if ((*it)->GetSubId() == sid) return (*it); - } - return NULL; -} - -const FCDPhysicsRigidConstraint* FCDPhysicsModel::FindRigidConstraintFromSid(const fm::string& sid) const -{ - for (FCDPhysicsRigidConstraintContainer::const_iterator it = rigidConstraints.begin(); it!= rigidConstraints.end(); ++it) - { - if ((*it)->GetSubId() == sid) return (*it); - } - return NULL; -} - -bool FCDPhysicsModel::AttachModelInstances() -{ - bool status = true; - while (!modelInstancesMap.empty()) - { - ModelInstanceNameNodeMap::iterator modelNameNode = modelInstancesMap.begin(); - - FUUri url = modelNameNode->second; - if (!url.IsFile()) - { - FCDEntity* entity = GetDocument()->FindPhysicsModel(TO_STRING(url.GetFragment())); - if (entity != NULL) - { - FCDPhysicsModel* model = (FCDPhysicsModel*) entity; - - // - // [sli 2007-06-11] Need partial loading to be implemented for the plug-in. - // - //FCDPhysicsModelInstance* instance = AddPhysicsModelInstance(model); - //status &= (instance->LoadFromXML(modelNameNode->first)); - - // check for cyclic referencing - fm::pvector modelQueue; - modelQueue.push_back(model); - while (!modelQueue.empty()) - { - FCDPhysicsModel* currentModel = modelQueue.back(); - modelQueue.pop_back(); - - if (currentModel == this) - { - // we have cyclic referencing! - FUError::Error(FUError::ERROR_LEVEL, FUError::ERROR_PHYSICS_MODEL_CYCLE_DETECTED, - modelNameNode->first->line); - status &= false; - break; - } - - FCDPhysicsModelInstanceContainer& modelInstances = currentModel->GetInstances(); - for (FCDPhysicsModelInstanceContainer::iterator modelInstancesIt = modelInstances.begin(); - modelInstancesIt != modelInstances.end(); modelInstancesIt++) - { - modelQueue.push_back((FCDPhysicsModel*)(*modelInstancesIt)->GetEntity()); - } - } - } - else - { - FUError::Error(FUError::WARNING_LEVEL, FUError::WARNING_CORRUPTED_INSTANCE, modelNameNode->first->line); - } - } - - modelInstancesMap.erase(modelNameNode); - } - - return status; -} - -void FCDPhysicsModel::CleanSubId() -{ - FUSUniqueStringMap myStringMap; - - for (FCDPhysicsModelInstanceContainer::iterator it = instances.begin(); it != instances.end(); ++it) - { - (*it)->CleanSubId(&myStringMap); - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDPhysicsModel.h" +#include "FCDocument/FCDPhysicsModelInstance.h" +#include "FCDocument/FCDPhysicsRigidBody.h" +#include "FCDocument/FCDPhysicsRigidConstraint.h" +#include "FCDocument/FCDocument.h" +#include "FUtils/FUStringConversion.h" +#include "FUtils/FUUniqueStringMap.h" +#include "FUtils/FUUri.h" + +ImplementObjectType(FCDPhysicsModel); + +FCDPhysicsModel::FCDPhysicsModel(FCDocument* document) +: FCDEntity(document, "PhysicsModel") +{ +} + +FCDPhysicsModel::~FCDPhysicsModel() +{ +} + +FCDPhysicsModelInstance* FCDPhysicsModel::AddPhysicsModelInstance(FCDPhysicsModel* model) +{ + FCDPhysicsModelInstance* instance = instances.Add(GetDocument()); + instance->SetEntity(model); + SetNewChildFlag(); + return instance; +} + +FCDPhysicsRigidBody* FCDPhysicsModel::AddRigidBody() +{ + FCDPhysicsRigidBody* rigidBody = rigidBodies.Add(GetDocument()); + SetNewChildFlag(); + return rigidBody; +} + +FCDPhysicsRigidConstraint* FCDPhysicsModel::AddRigidConstraint() +{ + FCDPhysicsRigidConstraint* constraint = rigidConstraints.Add(GetDocument(), this); + SetNewChildFlag(); + return constraint; +} + +FCDEntity* FCDPhysicsModel::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPhysicsModel* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPhysicsModel(const_cast(GetDocument())); + else if (_clone->HasType(FCDPhysicsModel::GetClassType())) clone = (FCDPhysicsModel*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + // Clone the rigid bodies + for (FCDPhysicsRigidBodyContainer::const_iterator it = rigidBodies.begin(); it != rigidBodies.end(); ++it) + { + FCDPhysicsRigidBody* clonedRigidBody = clone->AddRigidBody(); + (*it)->Clone(clonedRigidBody, cloneChildren); + } + + // Clone the rigid constraints + for (FCDPhysicsRigidConstraintContainer::const_iterator it = rigidConstraints.begin(); it != rigidConstraints.end(); ++it) + { + FCDPhysicsRigidConstraint* clonedConstraint = clone->AddRigidConstraint(); + (*it)->Clone(clonedConstraint, cloneChildren); + } + + // Clone the model instances + for (FCDPhysicsModelInstanceContainer::const_iterator it = instances.begin(); it != instances.end(); ++it) + { + FCDPhysicsModelInstance* clonedInstance = clone->AddPhysicsModelInstance(); + (*it)->Clone(clonedInstance); + } + } + return _clone; +} + +const FCDPhysicsRigidBody* FCDPhysicsModel::FindRigidBodyFromSid(const fm::string& sid) const +{ + for (FCDPhysicsRigidBodyContainer::const_iterator it = rigidBodies.begin(); it!= rigidBodies.end(); ++it) + { + if ((*it)->GetSubId() == sid) return (*it); + } + return NULL; +} + +const FCDPhysicsRigidConstraint* FCDPhysicsModel::FindRigidConstraintFromSid(const fm::string& sid) const +{ + for (FCDPhysicsRigidConstraintContainer::const_iterator it = rigidConstraints.begin(); it!= rigidConstraints.end(); ++it) + { + if ((*it)->GetSubId() == sid) return (*it); + } + return NULL; +} + +bool FCDPhysicsModel::AttachModelInstances() +{ + bool status = true; + while (!modelInstancesMap.empty()) + { + ModelInstanceNameNodeMap::iterator modelNameNode = modelInstancesMap.begin(); + + FUUri url = modelNameNode->second; + if (!url.IsFile()) + { + FCDEntity* entity = GetDocument()->FindPhysicsModel(TO_STRING(url.GetFragment())); + if (entity != NULL) + { + FCDPhysicsModel* model = (FCDPhysicsModel*) entity; + + // + // [sli 2007-06-11] Need partial loading to be implemented for the plug-in. + // + //FCDPhysicsModelInstance* instance = AddPhysicsModelInstance(model); + //status &= (instance->LoadFromXML(modelNameNode->first)); + + // check for cyclic referencing + fm::pvector modelQueue; + modelQueue.push_back(model); + while (!modelQueue.empty()) + { + FCDPhysicsModel* currentModel = modelQueue.back(); + modelQueue.pop_back(); + + if (currentModel == this) + { + // we have cyclic referencing! + FUError::Error(FUError::ERROR_LEVEL, FUError::ERROR_PHYSICS_MODEL_CYCLE_DETECTED, + modelNameNode->first->line); + status &= false; + break; + } + + FCDPhysicsModelInstanceContainer& modelInstances = currentModel->GetInstances(); + for (FCDPhysicsModelInstanceContainer::iterator modelInstancesIt = modelInstances.begin(); + modelInstancesIt != modelInstances.end(); modelInstancesIt++) + { + modelQueue.push_back((FCDPhysicsModel*)(*modelInstancesIt)->GetEntity()); + } + } + } + else + { + FUError::Error(FUError::WARNING_LEVEL, FUError::WARNING_CORRUPTED_INSTANCE, modelNameNode->first->line); + } + } + + modelInstancesMap.erase(modelNameNode); + } + + return status; +} + +void FCDPhysicsModel::CleanSubId() +{ + FUSUniqueStringMap myStringMap; + + for (FCDPhysicsModelInstanceContainer::iterator it = instances.begin(); it != instances.end(); ++it) + { + (*it)->CleanSubId(&myStringMap); + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModel.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBody.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBody.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBody.cpp (revision 24247) @@ -1,56 +1,56 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDPhysicsRigidBody.h" -#include "FCDocument/FCDPhysicsRigidBodyParameters.h" -#include "FCDocument/FCDPhysicsShape.h" - -// -// FCDPhysicsRigidBody -// - -ImplementObjectType(FCDPhysicsRigidBody); -ImplementParameterObject(FCDPhysicsRigidBody, FCDPhysicsRigidBodyParameters, parameters, new FCDPhysicsRigidBodyParameters(parent->GetDocument(), parent)); - -FCDPhysicsRigidBody::FCDPhysicsRigidBody(FCDocument* document) -: FCDEntity(document, "RigidBody") -, InitializeParameterNoArg(parameters) -{ - parameters = new FCDPhysicsRigidBodyParameters(document, this); -} - -FCDPhysicsRigidBody::~FCDPhysicsRigidBody() -{ -} - -FCDEntity* FCDPhysicsRigidBody::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPhysicsRigidBody* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPhysicsRigidBody(const_cast(GetDocument())); - else if (_clone->HasType(FCDPhysicsRigidBody::GetClassType())) clone = (FCDPhysicsRigidBody*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - clone->GetParameters()->CopyFrom(*parameters); - } - return _clone; -} - -float FCDPhysicsRigidBody::GetShapeMassFactor() const -{ - float shapesMass = 0.0f; - size_t shapeCount = parameters->GetPhysicsShapeCount(); - for (size_t s = 0; s < shapeCount; ++s) - { - shapesMass += parameters->GetPhysicsShape(s)->GetMass(); - } - return parameters->GetMass() / shapesMass; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDPhysicsRigidBody.h" +#include "FCDocument/FCDPhysicsRigidBodyParameters.h" +#include "FCDocument/FCDPhysicsShape.h" + +// +// FCDPhysicsRigidBody +// + +ImplementObjectType(FCDPhysicsRigidBody); +ImplementParameterObject(FCDPhysicsRigidBody, FCDPhysicsRigidBodyParameters, parameters, new FCDPhysicsRigidBodyParameters(parent->GetDocument(), parent)); + +FCDPhysicsRigidBody::FCDPhysicsRigidBody(FCDocument* document) +: FCDEntity(document, "RigidBody") +, InitializeParameterNoArg(parameters) +{ + parameters = new FCDPhysicsRigidBodyParameters(document, this); +} + +FCDPhysicsRigidBody::~FCDPhysicsRigidBody() +{ +} + +FCDEntity* FCDPhysicsRigidBody::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPhysicsRigidBody* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPhysicsRigidBody(const_cast(GetDocument())); + else if (_clone->HasType(FCDPhysicsRigidBody::GetClassType())) clone = (FCDPhysicsRigidBody*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + clone->GetParameters()->CopyFrom(*parameters); + } + return _clone; +} + +float FCDPhysicsRigidBody::GetShapeMassFactor() const +{ + float shapesMass = 0.0f; + size_t shapeCount = parameters->GetPhysicsShapeCount(); + for (size_t s = 0; s < shapeCount; ++s) + { + shapesMass += parameters->GetPhysicsShape(s)->GetMass(); + } + return parameters->GetMass() / shapesMass; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBody.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyParameters.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyParameters.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyParameters.cpp (revision 24247) @@ -1,147 +1,147 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDPhysicsRigidBodyParameters.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEntityInstance.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDPhysicsRigidBody.h" -#include "FCDocument/FCDPhysicsRigidBodyInstance.h" -#include "FCDocument/FCDPhysicsMaterial.h" -#include "FCDocument/FCDPhysicsShape.h" - -// -// FCDPhysicsRigidBodyParameters -// - -ImplementObjectType(FCDPhysicsRigidBodyParameters); -ImplementParameterObject(FCDPhysicsRigidBodyParameters, FCDPhysicsShape, physicsShape, new FCDPhysicsShape(parent->GetDocument())); - -FCDPhysicsRigidBodyParameters::FCDPhysicsRigidBodyParameters(FCDocument* document, FCDPhysicsRigidBody* _owner) -: FCDObject(document) -, ownsPhysicsMaterial(false) -, parent(_owner) -, InitializeParameterNoArg(physicsShape) -, InitializeParameterAnimatable(dynamic, true) -, InitializeParameterAnimatable(mass, 1.0f) -, InitializeParameter(density, 0.0f) -, InitializeParameterAnimatable(inertia, FMVector3::Zero) -, InitializeParameterAnimatable(massFrameTranslate, FMVector3::Zero) -, InitializeParameterAnimatable(massFrameOrientation, FMAngleAxis(FMVector3::XAxis, 0.0f)) -, entityOwner(_owner) -, InitializeParameter(isDensityMoreAccurate, false) -, InitializeParameter(isInertiaAccurate, false) -{ -} - -FCDPhysicsRigidBodyParameters::FCDPhysicsRigidBodyParameters(FCDocument* document, FCDPhysicsRigidBodyInstance* _owner) -: FCDObject(document) -, ownsPhysicsMaterial(false) -, parent(_owner) -, InitializeParameterNoArg(physicsShape) -, InitializeParameterAnimatable(dynamic, true) -, InitializeParameterAnimatable(mass, 1.0f) -, InitializeParameter(density, 0.0f) -, InitializeParameterAnimatable(inertia, FMVector3::Zero) -, InitializeParameterAnimatable(massFrameTranslate, FMVector3::Zero) -, InitializeParameterAnimatable(massFrameOrientation, FMAngleAxis(FMVector3::XAxis, 0.0f)) -, instanceOwner(_owner) -, InitializeParameter(isDensityMoreAccurate, false) -, InitializeParameter(isInertiaAccurate, false) -{ -} - -FCDPhysicsRigidBodyParameters::~FCDPhysicsRigidBodyParameters() -{ - if (physicsMaterial && ownsPhysicsMaterial) SAFE_RELEASE(physicsMaterial); - SAFE_RELEASE(instanceMaterialRef); - if (ownsPhysicsMaterial) - { - SAFE_RELEASE(physicsMaterial); - } - else - { - physicsMaterial = NULL; - } -} - -void FCDPhysicsRigidBodyParameters::CopyFrom(const FCDPhysicsRigidBodyParameters& original) -{ - // copy everything except parent since this is set already in constructor - - dynamic = original.dynamic; - mass = original.mass; - inertia = original.inertia; - massFrameTranslate = original.massFrameTranslate; - massFrameOrientation = original.massFrameOrientation; - - for (const FCDPhysicsShape** it = original.physicsShape.begin(); it != original.physicsShape.end(); ++it) - { - FCDPhysicsShape* clonedShape = AddPhysicsShape(); - (*it)->Clone(clonedShape); - } - - if (original.physicsMaterial != NULL) - { - if (parent->IsLocal(original.parent)) - { - SetPhysicsMaterial(const_cast (original.physicsMaterial.operator->())); - } - else - { - FCDPhysicsMaterial* clonedMaterial = AddOwnPhysicsMaterial(); - original.physicsMaterial->Clone(clonedMaterial); - } - } - - // Clone the material instance - if (original.instanceMaterialRef != NULL) - { - instanceMaterialRef = original.instanceMaterialRef->Clone(); - } -} - -FCDPhysicsShape* FCDPhysicsRigidBodyParameters::AddPhysicsShape() -{ - FCDPhysicsShape* shape = new FCDPhysicsShape(GetDocument()); - physicsShape.push_back(shape); - parent->SetNewChildFlag(); - return shape; -} - -void FCDPhysicsRigidBodyParameters::SetPhysicsMaterial(FCDPhysicsMaterial* _physicsMaterial) -{ - if (physicsMaterial && ownsPhysicsMaterial) - { - SAFE_RELEASE(physicsMaterial); - } - - physicsMaterial = _physicsMaterial; - ownsPhysicsMaterial = false; - parent->SetNewChildFlag(); -} - -void FCDPhysicsRigidBodyParameters::SetDynamic(bool _dynamic) -{ - dynamic = _dynamic; - parent->SetDirtyFlag(); -} - -FCDPhysicsMaterial* FCDPhysicsRigidBodyParameters::AddOwnPhysicsMaterial() -{ - if (physicsMaterial && ownsPhysicsMaterial) - { - SAFE_RELEASE(physicsMaterial); - } - - physicsMaterial = new FCDPhysicsMaterial(parent->GetDocument()); - ownsPhysicsMaterial = true; - parent->SetNewChildFlag(); - return physicsMaterial; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDPhysicsRigidBodyParameters.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEntityInstance.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDPhysicsRigidBody.h" +#include "FCDocument/FCDPhysicsRigidBodyInstance.h" +#include "FCDocument/FCDPhysicsMaterial.h" +#include "FCDocument/FCDPhysicsShape.h" + +// +// FCDPhysicsRigidBodyParameters +// + +ImplementObjectType(FCDPhysicsRigidBodyParameters); +ImplementParameterObject(FCDPhysicsRigidBodyParameters, FCDPhysicsShape, physicsShape, new FCDPhysicsShape(parent->GetDocument())); + +FCDPhysicsRigidBodyParameters::FCDPhysicsRigidBodyParameters(FCDocument* document, FCDPhysicsRigidBody* _owner) +: FCDObject(document) +, ownsPhysicsMaterial(false) +, parent(_owner) +, InitializeParameterNoArg(physicsShape) +, InitializeParameterAnimatable(dynamic, true) +, InitializeParameterAnimatable(mass, 1.0f) +, InitializeParameter(density, 0.0f) +, InitializeParameterAnimatable(inertia, FMVector3::Zero) +, InitializeParameterAnimatable(massFrameTranslate, FMVector3::Zero) +, InitializeParameterAnimatable(massFrameOrientation, FMAngleAxis(FMVector3::XAxis, 0.0f)) +, entityOwner(_owner) +, InitializeParameter(isDensityMoreAccurate, false) +, InitializeParameter(isInertiaAccurate, false) +{ +} + +FCDPhysicsRigidBodyParameters::FCDPhysicsRigidBodyParameters(FCDocument* document, FCDPhysicsRigidBodyInstance* _owner) +: FCDObject(document) +, ownsPhysicsMaterial(false) +, parent(_owner) +, InitializeParameterNoArg(physicsShape) +, InitializeParameterAnimatable(dynamic, true) +, InitializeParameterAnimatable(mass, 1.0f) +, InitializeParameter(density, 0.0f) +, InitializeParameterAnimatable(inertia, FMVector3::Zero) +, InitializeParameterAnimatable(massFrameTranslate, FMVector3::Zero) +, InitializeParameterAnimatable(massFrameOrientation, FMAngleAxis(FMVector3::XAxis, 0.0f)) +, instanceOwner(_owner) +, InitializeParameter(isDensityMoreAccurate, false) +, InitializeParameter(isInertiaAccurate, false) +{ +} + +FCDPhysicsRigidBodyParameters::~FCDPhysicsRigidBodyParameters() +{ + if (physicsMaterial && ownsPhysicsMaterial) SAFE_RELEASE(physicsMaterial); + SAFE_RELEASE(instanceMaterialRef); + if (ownsPhysicsMaterial) + { + SAFE_RELEASE(physicsMaterial); + } + else + { + physicsMaterial = NULL; + } +} + +void FCDPhysicsRigidBodyParameters::CopyFrom(const FCDPhysicsRigidBodyParameters& original) +{ + // copy everything except parent since this is set already in constructor + + dynamic = original.dynamic; + mass = original.mass; + inertia = original.inertia; + massFrameTranslate = original.massFrameTranslate; + massFrameOrientation = original.massFrameOrientation; + + for (const FCDPhysicsShape** it = original.physicsShape.begin(); it != original.physicsShape.end(); ++it) + { + FCDPhysicsShape* clonedShape = AddPhysicsShape(); + (*it)->Clone(clonedShape); + } + + if (original.physicsMaterial != NULL) + { + if (parent->IsLocal(original.parent)) + { + SetPhysicsMaterial(const_cast (original.physicsMaterial.operator->())); + } + else + { + FCDPhysicsMaterial* clonedMaterial = AddOwnPhysicsMaterial(); + original.physicsMaterial->Clone(clonedMaterial); + } + } + + // Clone the material instance + if (original.instanceMaterialRef != NULL) + { + instanceMaterialRef = original.instanceMaterialRef->Clone(); + } +} + +FCDPhysicsShape* FCDPhysicsRigidBodyParameters::AddPhysicsShape() +{ + FCDPhysicsShape* shape = new FCDPhysicsShape(GetDocument()); + physicsShape.push_back(shape); + parent->SetNewChildFlag(); + return shape; +} + +void FCDPhysicsRigidBodyParameters::SetPhysicsMaterial(FCDPhysicsMaterial* _physicsMaterial) +{ + if (physicsMaterial && ownsPhysicsMaterial) + { + SAFE_RELEASE(physicsMaterial); + } + + physicsMaterial = _physicsMaterial; + ownsPhysicsMaterial = false; + parent->SetNewChildFlag(); +} + +void FCDPhysicsRigidBodyParameters::SetDynamic(bool _dynamic) +{ + dynamic = _dynamic; + parent->SetDirtyFlag(); +} + +FCDPhysicsMaterial* FCDPhysicsRigidBodyParameters::AddOwnPhysicsMaterial() +{ + if (physicsMaterial && ownsPhysicsMaterial) + { + SAFE_RELEASE(physicsMaterial); + } + + physicsMaterial = new FCDPhysicsMaterial(parent->GetDocument()); + ownsPhysicsMaterial = true; + parent->SetNewChildFlag(); + return physicsMaterial; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyParameters.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraintInstance.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraintInstance.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraintInstance.cpp (revision 24247) @@ -1,57 +1,57 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEntity.h" -#include "FCDocument/FCDPhysicsModel.h" -#include "FCDocument/FCDPhysicsModelInstance.h" -#include "FCDocument/FCDPhysicsRigidBody.h" -#include "FCDocument/FCDPhysicsRigidConstraint.h" -#include "FCDocument/FCDPhysicsRigidConstraintInstance.h" -#include "FUtils/FUUri.h" - -ImplementObjectType(FCDPhysicsRigidConstraintInstance); - -FCDPhysicsRigidConstraintInstance::FCDPhysicsRigidConstraintInstance(FCDocument* document, FCDPhysicsModelInstance* _parent, FCDPhysicsRigidConstraint* constraint) -: FCDEntityInstance(document, NULL, FCDEntity::PHYSICS_RIGID_CONSTRAINT), parent(_parent) -{ - if (constraint != NULL) - { - SetRigidConstraint(constraint); - } -} - -FCDPhysicsRigidConstraintInstance::~FCDPhysicsRigidConstraintInstance() -{ - parent = NULL; -} - -FCDEntityInstance* FCDPhysicsRigidConstraintInstance::Clone(FCDEntityInstance* _clone) const -{ - FCDPhysicsRigidConstraintInstance* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPhysicsRigidConstraintInstance(const_cast(GetDocument()), NULL, NULL); - else if (_clone->HasType(FCDPhysicsRigidConstraintInstance::GetClassType())) clone = (FCDPhysicsRigidConstraintInstance*) _clone; - - Parent::Clone(_clone); - - if (clone != NULL) - { - // No interesting data to clone. - } - - return _clone; -} - -void FCDPhysicsRigidConstraintInstance::SetRigidConstraint( - FCDPhysicsRigidConstraint* constraint) -{ - FUAssert(constraint != NULL, ;); - - SetEntity(constraint); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEntity.h" +#include "FCDocument/FCDPhysicsModel.h" +#include "FCDocument/FCDPhysicsModelInstance.h" +#include "FCDocument/FCDPhysicsRigidBody.h" +#include "FCDocument/FCDPhysicsRigidConstraint.h" +#include "FCDocument/FCDPhysicsRigidConstraintInstance.h" +#include "FUtils/FUUri.h" + +ImplementObjectType(FCDPhysicsRigidConstraintInstance); + +FCDPhysicsRigidConstraintInstance::FCDPhysicsRigidConstraintInstance(FCDocument* document, FCDPhysicsModelInstance* _parent, FCDPhysicsRigidConstraint* constraint) +: FCDEntityInstance(document, NULL, FCDEntity::PHYSICS_RIGID_CONSTRAINT), parent(_parent) +{ + if (constraint != NULL) + { + SetRigidConstraint(constraint); + } +} + +FCDPhysicsRigidConstraintInstance::~FCDPhysicsRigidConstraintInstance() +{ + parent = NULL; +} + +FCDEntityInstance* FCDPhysicsRigidConstraintInstance::Clone(FCDEntityInstance* _clone) const +{ + FCDPhysicsRigidConstraintInstance* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPhysicsRigidConstraintInstance(const_cast(GetDocument()), NULL, NULL); + else if (_clone->HasType(FCDPhysicsRigidConstraintInstance::GetClassType())) clone = (FCDPhysicsRigidConstraintInstance*) _clone; + + Parent::Clone(_clone); + + if (clone != NULL) + { + // No interesting data to clone. + } + + return _clone; +} + +void FCDPhysicsRigidConstraintInstance::SetRigidConstraint( + FCDPhysicsRigidConstraint* constraint) +{ + FUAssert(constraint != NULL, ;); + + SetEntity(constraint); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraintInstance.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsShape.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsShape.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsShape.cpp (revision 24247) @@ -1,241 +1,241 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDGeometryInstance.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDGeometryPolygonsInput.h" -#include "FCDocument/FCDGeometrySource.h" -#include "FCDocument/FCDPhysicsAnalyticalGeometry.h" -#include "FCDocument/FCDPhysicsMaterial.h" -#include "FCDocument/FCDPhysicsRigidBody.h" -#include "FCDocument/FCDPhysicsShape.h" -#include "FCDocument/FCDTransform.h" -#include "FUtils/FUBoundingBox.h" - -ImplementObjectType(FCDPhysicsShape); - -FCDPhysicsShape::FCDPhysicsShape(FCDocument* document) : FCDObject(document) -{ - hollow = true; // COLLADA 1.4.1 no default specified - physicsMaterial = NULL; - ownsPhysicsMaterial = false; - isDensityMoreAccurate = false; - geometry = NULL; - analGeom = NULL; - mass = NULL; - density = NULL; - instanceMaterialRef = NULL; -} - -FCDPhysicsShape::~FCDPhysicsShape() -{ - SetPhysicsMaterial(NULL); - SAFE_DELETE(mass); - SAFE_DELETE(density); - SAFE_RELEASE(instanceMaterialRef); - - if (ownsPhysicsMaterial) SAFE_RELEASE(physicsMaterial); - SAFE_RELEASE(geometry); - geometry = NULL; -} - -FCDTransform* FCDPhysicsShape::AddTransform(FCDTransform::Type type, size_t index) -{ - FCDTransform* transform = FCDTFactory::CreateTransform(GetDocument(), NULL, type); - if (transform != NULL) - { - if (index > transforms.size()) transforms.push_back(transform); - else transforms.insert(transforms.begin() + index, transform); - } - SetNewChildFlag(); - return transform; -} - -FCDPhysicsMaterial* FCDPhysicsShape::AddOwnPhysicsMaterial() -{ - if (ownsPhysicsMaterial) SAFE_RELEASE(physicsMaterial); - - physicsMaterial = new FCDPhysicsMaterial(GetDocument()); - ownsPhysicsMaterial = true; - SetNewChildFlag(); - return physicsMaterial; -} - -void FCDPhysicsShape::SetPhysicsMaterial(FCDPhysicsMaterial* _physicsMaterial) -{ - if (ownsPhysicsMaterial) SAFE_RELEASE(physicsMaterial); - ownsPhysicsMaterial = false; - physicsMaterial = _physicsMaterial; - SetNewChildFlag(); -} - -FCDGeometryInstance* FCDPhysicsShape::CreateGeometryInstance(FCDGeometry* geom, bool createConvexMesh) -{ - analGeom = NULL; - SAFE_RELEASE(geometry); - - geometry = (FCDGeometryInstance*)FCDEntityInstanceFactory::CreateInstance(GetDocument(), NULL, FCDEntity::GEOMETRY); - - if (createConvexMesh) - { - FCDGeometry* convexHullGeom = GetDocument()->GetGeometryLibrary()->AddEntity(); - fm::string convexId = geom->GetDaeId()+"-convex"; - convexHullGeom->SetDaeId(convexId); - convexHullGeom->SetName(FUStringConversion::ToFString(convexId)); - FCDGeometryMesh* convexHullGeomMesh = convexHullGeom->CreateMesh(); - convexHullGeomMesh->SetConvexHullOf(geom); - convexHullGeomMesh->SetConvex(true); - geometry->SetEntity(convexHullGeom); - } - else - { - geometry->SetEntity(geom); - } - - SetNewChildFlag(); - return geometry; -} - -FCDPhysicsAnalyticalGeometry* FCDPhysicsShape::CreateAnalyticalGeometry(FCDPhysicsAnalyticalGeometry::GeomType type) -{ - SAFE_RELEASE(geometry); - analGeom = FCDPASFactory::CreatePAS(GetDocument(), type); - SetNewChildFlag(); - return analGeom; -} - -// Create a copy of this shape -// Note: geometries are just shallow-copied -FCDPhysicsShape* FCDPhysicsShape::Clone(FCDPhysicsShape* clone) const -{ - if (clone == NULL) clone = new FCDPhysicsShape(const_cast(GetDocument())); - - if (mass != NULL) clone->SetMass(*mass); - if (density != NULL) clone->SetDensity(*density); - clone->SetHollow(hollow); - - // Clone the material instance - if (instanceMaterialRef != NULL) - { - clone->instanceMaterialRef = FCDEntityInstanceFactory::CreateInstance(clone->GetDocument(), NULL, FCDEntity::PHYSICS_MATERIAL); - instanceMaterialRef->Clone(instanceMaterialRef); - } - if (physicsMaterial != NULL) - { - FCDPhysicsMaterial* clonedMaterial = clone->AddOwnPhysicsMaterial(); - physicsMaterial->Clone(clonedMaterial); - } - - // Clone the analytical geometry or the mesh geometry - if (analGeom != NULL) - { - clone->analGeom = FCDPASFactory::CreatePAS(clone->GetDocument(), analGeom->GetGeomType()); - analGeom->Clone(clone->analGeom); - } - if (geometry != NULL) - { - clone->geometry = (FCDGeometryInstance*)FCDEntityInstanceFactory::CreateInstance(clone->GetDocument(), NULL, geometry->GetEntityType()); - geometry->Clone(clone->geometry); - } - - // Clone the shape placement transform - for (size_t i = 0; i < transforms.size(); ++i) - { - FCDTransform* clonedTransform = clone->AddTransform(transforms[i]->GetType()); - transforms[i]->Clone(clonedTransform); - } - - return clone; -} - -float FCDPhysicsShape::GetMass() const -{ - if (mass) - return *mass; - - return 0.f; -} - -void FCDPhysicsShape::SetMass(float _mass) -{ - SAFE_DELETE(mass); - mass = new float; - *mass = _mass; - SetDirtyFlag(); -} - -float FCDPhysicsShape::GetDensity() const -{ - if (density) - return *density; - - return 0.f; -} - -void FCDPhysicsShape::SetDensity(float _density) -{ - SAFE_DELETE(density); - density = new float; - *density = _density; - SetDirtyFlag(); -} - -float FCDPhysicsShape::CalculateVolume() const -{ - if (IsGeometryInstance()) - { - FCDGeometry* geom = ((FCDGeometry*)geometry->GetEntity()); - if (geom->IsMesh()) - { - FUBoundingBox boundary; - float countingVolume = 0.0f; - const FCDGeometryMesh* mesh = geom->GetMesh(); - - if (!mesh->GetConvexHullOf().empty()) - { - mesh = mesh->FindConvexHullOfMesh(); - } - if (mesh == NULL) return 1.0f; // missing convex hull or of spline - - for (size_t i = 0; i < mesh->GetPolygonsCount(); i++) - { - const FCDGeometryPolygons* polygons = mesh->GetPolygons(i); - const FCDGeometryPolygonsInput* positionInput = polygons->FindInput(FUDaeGeometryInput::POSITION); - const FCDGeometrySource* positionSource = positionInput->GetSource(); - uint32 positionStride = positionSource->GetStride(); - FUAssert(positionStride == 3, continue;); - const float* positionData = positionSource->GetData(); - size_t positionDataLength = positionSource->GetDataCount(); - for (size_t pos = 0; pos < positionDataLength;) - { - boundary.Include(FMVector3(positionData, (uint32)pos)); - pos += positionStride; - } - - FMVector3 min = boundary.GetMin(); - FMVector3 max = boundary.GetMax(); - countingVolume += - (max.x - min.x) * (max.y - min.y) * (max.z - min.z); - boundary.Reset(); - } - return countingVolume; - } - // splines have no volume! - return 1.0f; - } - else - { - FUAssert(IsAnalyticalGeometry(), return 1.0f;); - return (analGeom->CalculateVolume()); - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDGeometryInstance.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDGeometryPolygonsInput.h" +#include "FCDocument/FCDGeometrySource.h" +#include "FCDocument/FCDPhysicsAnalyticalGeometry.h" +#include "FCDocument/FCDPhysicsMaterial.h" +#include "FCDocument/FCDPhysicsRigidBody.h" +#include "FCDocument/FCDPhysicsShape.h" +#include "FCDocument/FCDTransform.h" +#include "FUtils/FUBoundingBox.h" + +ImplementObjectType(FCDPhysicsShape); + +FCDPhysicsShape::FCDPhysicsShape(FCDocument* document) : FCDObject(document) +{ + hollow = true; // COLLADA 1.4.1 no default specified + physicsMaterial = NULL; + ownsPhysicsMaterial = false; + isDensityMoreAccurate = false; + geometry = NULL; + analGeom = NULL; + mass = NULL; + density = NULL; + instanceMaterialRef = NULL; +} + +FCDPhysicsShape::~FCDPhysicsShape() +{ + SetPhysicsMaterial(NULL); + SAFE_DELETE(mass); + SAFE_DELETE(density); + SAFE_RELEASE(instanceMaterialRef); + + if (ownsPhysicsMaterial) SAFE_RELEASE(physicsMaterial); + SAFE_RELEASE(geometry); + geometry = NULL; +} + +FCDTransform* FCDPhysicsShape::AddTransform(FCDTransform::Type type, size_t index) +{ + FCDTransform* transform = FCDTFactory::CreateTransform(GetDocument(), NULL, type); + if (transform != NULL) + { + if (index > transforms.size()) transforms.push_back(transform); + else transforms.insert(transforms.begin() + index, transform); + } + SetNewChildFlag(); + return transform; +} + +FCDPhysicsMaterial* FCDPhysicsShape::AddOwnPhysicsMaterial() +{ + if (ownsPhysicsMaterial) SAFE_RELEASE(physicsMaterial); + + physicsMaterial = new FCDPhysicsMaterial(GetDocument()); + ownsPhysicsMaterial = true; + SetNewChildFlag(); + return physicsMaterial; +} + +void FCDPhysicsShape::SetPhysicsMaterial(FCDPhysicsMaterial* _physicsMaterial) +{ + if (ownsPhysicsMaterial) SAFE_RELEASE(physicsMaterial); + ownsPhysicsMaterial = false; + physicsMaterial = _physicsMaterial; + SetNewChildFlag(); +} + +FCDGeometryInstance* FCDPhysicsShape::CreateGeometryInstance(FCDGeometry* geom, bool createConvexMesh) +{ + analGeom = NULL; + SAFE_RELEASE(geometry); + + geometry = (FCDGeometryInstance*)FCDEntityInstanceFactory::CreateInstance(GetDocument(), NULL, FCDEntity::GEOMETRY); + + if (createConvexMesh) + { + FCDGeometry* convexHullGeom = GetDocument()->GetGeometryLibrary()->AddEntity(); + fm::string convexId = geom->GetDaeId()+"-convex"; + convexHullGeom->SetDaeId(convexId); + convexHullGeom->SetName(FUStringConversion::ToFString(convexId)); + FCDGeometryMesh* convexHullGeomMesh = convexHullGeom->CreateMesh(); + convexHullGeomMesh->SetConvexHullOf(geom); + convexHullGeomMesh->SetConvex(true); + geometry->SetEntity(convexHullGeom); + } + else + { + geometry->SetEntity(geom); + } + + SetNewChildFlag(); + return geometry; +} + +FCDPhysicsAnalyticalGeometry* FCDPhysicsShape::CreateAnalyticalGeometry(FCDPhysicsAnalyticalGeometry::GeomType type) +{ + SAFE_RELEASE(geometry); + analGeom = FCDPASFactory::CreatePAS(GetDocument(), type); + SetNewChildFlag(); + return analGeom; +} + +// Create a copy of this shape +// Note: geometries are just shallow-copied +FCDPhysicsShape* FCDPhysicsShape::Clone(FCDPhysicsShape* clone) const +{ + if (clone == NULL) clone = new FCDPhysicsShape(const_cast(GetDocument())); + + if (mass != NULL) clone->SetMass(*mass); + if (density != NULL) clone->SetDensity(*density); + clone->SetHollow(hollow); + + // Clone the material instance + if (instanceMaterialRef != NULL) + { + clone->instanceMaterialRef = FCDEntityInstanceFactory::CreateInstance(clone->GetDocument(), NULL, FCDEntity::PHYSICS_MATERIAL); + instanceMaterialRef->Clone(instanceMaterialRef); + } + if (physicsMaterial != NULL) + { + FCDPhysicsMaterial* clonedMaterial = clone->AddOwnPhysicsMaterial(); + physicsMaterial->Clone(clonedMaterial); + } + + // Clone the analytical geometry or the mesh geometry + if (analGeom != NULL) + { + clone->analGeom = FCDPASFactory::CreatePAS(clone->GetDocument(), analGeom->GetGeomType()); + analGeom->Clone(clone->analGeom); + } + if (geometry != NULL) + { + clone->geometry = (FCDGeometryInstance*)FCDEntityInstanceFactory::CreateInstance(clone->GetDocument(), NULL, geometry->GetEntityType()); + geometry->Clone(clone->geometry); + } + + // Clone the shape placement transform + for (size_t i = 0; i < transforms.size(); ++i) + { + FCDTransform* clonedTransform = clone->AddTransform(transforms[i]->GetType()); + transforms[i]->Clone(clonedTransform); + } + + return clone; +} + +float FCDPhysicsShape::GetMass() const +{ + if (mass) + return *mass; + + return 0.f; +} + +void FCDPhysicsShape::SetMass(float _mass) +{ + SAFE_DELETE(mass); + mass = new float; + *mass = _mass; + SetDirtyFlag(); +} + +float FCDPhysicsShape::GetDensity() const +{ + if (density) + return *density; + + return 0.f; +} + +void FCDPhysicsShape::SetDensity(float _density) +{ + SAFE_DELETE(density); + density = new float; + *density = _density; + SetDirtyFlag(); +} + +float FCDPhysicsShape::CalculateVolume() const +{ + if (IsGeometryInstance()) + { + FCDGeometry* geom = ((FCDGeometry*)geometry->GetEntity()); + if (geom->IsMesh()) + { + FUBoundingBox boundary; + float countingVolume = 0.0f; + const FCDGeometryMesh* mesh = geom->GetMesh(); + + if (!mesh->GetConvexHullOf().empty()) + { + mesh = mesh->FindConvexHullOfMesh(); + } + if (mesh == NULL) return 1.0f; // missing convex hull or of spline + + for (size_t i = 0; i < mesh->GetPolygonsCount(); i++) + { + const FCDGeometryPolygons* polygons = mesh->GetPolygons(i); + const FCDGeometryPolygonsInput* positionInput = polygons->FindInput(FUDaeGeometryInput::POSITION); + const FCDGeometrySource* positionSource = positionInput->GetSource(); + uint32 positionStride = positionSource->GetStride(); + FUAssert(positionStride == 3, continue;); + const float* positionData = positionSource->GetData(); + size_t positionDataLength = positionSource->GetDataCount(); + for (size_t pos = 0; pos < positionDataLength;) + { + boundary.Include(FMVector3(positionData, (uint32)pos)); + pos += positionStride; + } + + FMVector3 min = boundary.GetMin(); + FMVector3 max = boundary.GetMax(); + countingVolume += + (max.x - min.x) * (max.y - min.y) * (max.z - min.z); + boundary.Reset(); + } + return countingVolume; + } + // splines have no volume! + return 1.0f; + } + else + { + FUAssert(IsAnalyticalGeometry(), return 1.0f;); + return (analGeom->CalculateVolume()); + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsShape.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNode.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNode.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNode.cpp (revision 24247) @@ -1,329 +1,329 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAsset.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDAnimationCurve.h" -#include "FCDocument/FCDCamera.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDEntityInstance.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDLight.h" -#include "FCDocument/FCDPhysicsModelInstance.h" -#include "FCDocument/FCDPhysicsRigidBodyInstance.h" -#include "FCDocument/FCDSceneNode.h" -#include "FCDocument/FCDTransform.h" -#include "FUtils/FUFileManager.h" -#include "FUtils/FUStringConversion.h" -#include "FUtils/FUUniqueStringMap.h" - -// -// FCDSceneNode -// - -ImplementObjectType(FCDSceneNode); -ImplementParameterObjectNoCtr(FCDSceneNode, FCDSceneNode, parents); -ImplementParameterObject(FCDSceneNode, FCDSceneNode, children, new FCDSceneNode(parent->GetDocument())); -ImplementParameterObjectNoCtr(FCDSceneNode, FCDTransform, transforms); /** Needs custom construction in the UI */ -ImplementParameterObjectNoCtr(FCDSceneNode, FCDEntityInstance, instances); /** Needs custom construction in the UI */ - -FCDSceneNode::FCDSceneNode(FCDocument* document) -: FCDEntity(document, "VisualSceneNode") -, InitializeParameterNoArg(parents) -, InitializeParameterNoArg(children) -, InitializeParameterNoArg(transforms) -, InitializeParameterNoArg(instances) -, InitializeParameterAnimatable(visibility, 1.0f) -, targetCount(0) -, InitializeParameterNoArg(daeSubId) -{ - SetTransformsDirtyFlag(); - ResetJointFlag(); -} - -FCDSceneNode::~FCDSceneNode() -{ - parents.clear(); - - // Delete the children, be watchful for the instantiated nodes - while (!children.empty()) - { - FCDSceneNode* child = children.front(); - child->parents.erase(this); - - if (child->parents.empty()) { SAFE_RELEASE(child); } - else - { - // Check for external references in the parents - bool hasLocalReferences = false; - size_t parentCount = parents.size(); - for (size_t p = 0; p < parentCount; ++p) - { - FCDSceneNode* parent = parents[p]; - if (parent == this) children.erase(parent); - else - { - hasLocalReferences |= parent->GetDocument() == GetDocument(); - } - } - - if (!hasLocalReferences) SAFE_RELEASE(child); - } - } -} - -// Add this scene node to the list of children scene node -bool FCDSceneNode::AddChildNode(FCDSceneNode* sceneNode) -{ - if (this == sceneNode || sceneNode == NULL) - { - return false; - } - - // Verify that we don't already contain this child node. - if (children.contains(sceneNode)) return false; - - // Verify that this node is not one of the parents in the full hierarchically. - fm::pvector queue; - size_t parentCount = parents.size(); - for (size_t i = 0; i < parentCount; ++i) queue.push_back(parents.at(i)); - while (!queue.empty()) - { - FCDSceneNode* parent = queue.back(); - queue.pop_back(); - if (parent == sceneNode) return false; - queue.insert(queue.end(), parent->parents.begin(), parent->parents.end()); - } - - children.push_back(sceneNode); - sceneNode->parents.push_back(this); - SetNewChildFlag(); - return true; -} - -FCDSceneNode* FCDSceneNode::AddChildNode() -{ - FCDSceneNode* node = new FCDSceneNode(GetDocument()); - AddChildNode(node); - return node; -} - -void FCDSceneNode::RemoveChildNode(FCDSceneNode* sceneNode) -{ - sceneNode->parents.erase(this); - children.erase(sceneNode); -} - -// Instantiates an entity -FCDEntityInstance* FCDSceneNode::AddInstance(FCDEntity* entity) -{ - if (entity == NULL) return NULL; - FCDEntityInstance* instance = AddInstance(entity->GetType()); - instance->SetEntity(entity); - return instance; -} - -FCDEntityInstance* FCDSceneNode::AddInstance(FCDEntity::Type type) -{ - FCDEntityInstance* instance = FCDEntityInstanceFactory::CreateInstance(GetDocument(), this, type); - - instances.push_back(instance); - SetNewChildFlag(); - return instance; -} - -// Adds a transform to the stack, at a given position. -FCDTransform* FCDSceneNode::AddTransform(FCDTransform::Type type, size_t index) -{ - FCDTransform* transform = FCDTFactory::CreateTransform(GetDocument(), this, type); - if (transform != NULL) - { - if (index > transforms.size()) transforms.push_back(transform); - else transforms.insert(index, transform); - } - SetNewChildFlag(); - SetTransformsDirtyFlag(); - return transform; -} - -// Traverse the scene graph, searching for a node with the given COLLADA id -const FCDEntity* FCDSceneNode::FindDaeId(const fm::string& daeId) const -{ - if (GetDaeId() == daeId) return this; - - for (const FCDSceneNode** it = children.begin(); it != children.end(); ++it) - { - const FCDEntity* found = (*it)->FindDaeId(daeId); - if (found != NULL) return found; - } - return NULL; -} - -void FCDSceneNode::SetSubId(const fm::string& subId) -{ - daeSubId = ""; - if (subId.empty()) return; - - // We must ensure that our sub id is unique in the our scope - // First, build a list of subIds above us (in the graph) - FCDSceneNode* curNode = this; - - // Flatten parents up-tree to find all parents subIds - fm::pvector parentTree; - StringList parentSubIds; - size_t curParent = 0; - do - { - for (size_t i = 0; i < curNode->GetParentCount(); i++) - { - FCDSceneNode* parentNode = curNode->GetParent(i); - parentTree.push_back(parentNode); - fm::string parentSubId = parentNode->GetSubId(); - if (!parentSubId.empty()) parentSubIds.push_back(parentSubId); - } - // Continue iteration. - if (parentTree.size() > curParent) - { - curNode = parentTree[curParent]; - curParent++; - } - else curNode = NULL; - } - while (curNode != NULL); - - // Now, test for uniqueness, This is enforced for both descendants and ancestors - fm::string newSubId = FCDObjectWithId::CleanSubId(subId); - int32 idMod = 0; - while (FindSubId(newSubId) != NULL || parentSubIds.find(newSubId) != parentSubIds.end()) - { - newSubId = subId + "_" + FUStringConversion::ToString(idMod++); - - // Dont keep doing this forever. - if (idMod > 512) break; - } - daeSubId = newSubId; -} - -// Traverse the scene graph, searching for a node with the given COLLADA sub id -const FCDEntity* FCDSceneNode::FindSubId(const fm::string& subId) const -{ - if (GetSubId() == subId) return this; - - for (const FCDSceneNode** it = children.begin(); it != children.end(); ++it) - { - const FCDEntity* found = (*it)->FindSubId(subId); - if (found != NULL) return found; - } - return NULL; -} - -// Retrieve the list of hierarchical asset information structures that affect this scene node. -void FCDSceneNode::GetHierarchicalAssets(FCDAssetConstList& assets) const -{ - for (const FCDSceneNode* node = this; node != NULL; node = node->GetParent(0)) - { - // Retrieve the asset information structure for this node. - const FCDAsset* asset = node->GetAsset(); - if (asset != NULL) assets.push_back(asset); - } - assets.push_back(GetDocument()->GetAsset()); -} - -// Calculate the transform matrix for a given scene node -FMMatrix44 FCDSceneNode::ToMatrix() const -{ - FMMatrix44 localTransform = FMMatrix44::Identity; - for (const FCDTransform** it = transforms.begin(); it != transforms.end(); ++it) - { - localTransform = localTransform * (*it)->ToMatrix(); - } - return localTransform; -} - -FMMatrix44 FCDSceneNode::CalculateWorldTransform() const -{ - const FCDSceneNode* parent = GetParent(); - if (parent != NULL) - { - //FMMatrix44 tm1 = parent->CalculateWorldTransform(); - //FMMatrix44 tm2 = CalculateLocalTransform(); - //return tm1 * tm2; - return parent->CalculateWorldTransform() * CalculateLocalTransform(); - } - else - { - return CalculateLocalTransform(); - } -} - -void FCDSceneNode::CleanSubId() -{ - FUSUniqueStringMap myStringMap; - - size_t instanceCount = instances.size(); - for (size_t i = 0; i < instanceCount; ++i) - { - instances[i]->CleanSubId(&myStringMap); - } - - size_t childCount = children.size(); - for (size_t c = 0; c < childCount; ++c) - { - children[c]->CleanSubId(); - } -} - -FCDEntity* FCDSceneNode::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDSceneNode* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDSceneNode(const_cast(GetDocument())); - else if (_clone->HasType(FCDSceneNode::GetClassType())) clone = (FCDSceneNode*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - // Copy over the simple information. - clone->SetJointFlag(GetJointFlag()); - clone->visibility = visibility; - - // Don't copy the parents list but do clone all the children, transforms and instances - for (const FCDTransform** it = transforms.begin(); it != transforms.end(); ++it) - { - FCDTransform* transform = clone->AddTransform((*it)->GetType()); - (*it)->Clone(transform); - } - - if (cloneChildren) - { - for (const FCDSceneNode** it = children.begin(); it != children.end(); ++it) - { - FCDSceneNode* child = clone->AddChildNode(); - (*it)->Clone(child, cloneChildren); - } - } - - for (const FCDEntityInstance** it = instances.begin(); it != instances.end(); ++it) - { - FCDEntityInstance* instance = clone->AddInstance((*it)->GetEntityType()); - (*it)->Clone(instance); - } - } - - return _clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAsset.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDAnimationCurve.h" +#include "FCDocument/FCDCamera.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDEntityInstance.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDLight.h" +#include "FCDocument/FCDPhysicsModelInstance.h" +#include "FCDocument/FCDPhysicsRigidBodyInstance.h" +#include "FCDocument/FCDSceneNode.h" +#include "FCDocument/FCDTransform.h" +#include "FUtils/FUFileManager.h" +#include "FUtils/FUStringConversion.h" +#include "FUtils/FUUniqueStringMap.h" + +// +// FCDSceneNode +// + +ImplementObjectType(FCDSceneNode); +ImplementParameterObjectNoCtr(FCDSceneNode, FCDSceneNode, parents); +ImplementParameterObject(FCDSceneNode, FCDSceneNode, children, new FCDSceneNode(parent->GetDocument())); +ImplementParameterObjectNoCtr(FCDSceneNode, FCDTransform, transforms); /** Needs custom construction in the UI */ +ImplementParameterObjectNoCtr(FCDSceneNode, FCDEntityInstance, instances); /** Needs custom construction in the UI */ + +FCDSceneNode::FCDSceneNode(FCDocument* document) +: FCDEntity(document, "VisualSceneNode") +, InitializeParameterNoArg(parents) +, InitializeParameterNoArg(children) +, InitializeParameterNoArg(transforms) +, InitializeParameterNoArg(instances) +, InitializeParameterAnimatable(visibility, 1.0f) +, targetCount(0) +, InitializeParameterNoArg(daeSubId) +{ + SetTransformsDirtyFlag(); + ResetJointFlag(); +} + +FCDSceneNode::~FCDSceneNode() +{ + parents.clear(); + + // Delete the children, be watchful for the instantiated nodes + while (!children.empty()) + { + FCDSceneNode* child = children.front(); + child->parents.erase(this); + + if (child->parents.empty()) { SAFE_RELEASE(child); } + else + { + // Check for external references in the parents + bool hasLocalReferences = false; + size_t parentCount = parents.size(); + for (size_t p = 0; p < parentCount; ++p) + { + FCDSceneNode* parent = parents[p]; + if (parent == this) children.erase(parent); + else + { + hasLocalReferences |= parent->GetDocument() == GetDocument(); + } + } + + if (!hasLocalReferences) SAFE_RELEASE(child); + } + } +} + +// Add this scene node to the list of children scene node +bool FCDSceneNode::AddChildNode(FCDSceneNode* sceneNode) +{ + if (this == sceneNode || sceneNode == NULL) + { + return false; + } + + // Verify that we don't already contain this child node. + if (children.contains(sceneNode)) return false; + + // Verify that this node is not one of the parents in the full hierarchically. + fm::pvector queue; + size_t parentCount = parents.size(); + for (size_t i = 0; i < parentCount; ++i) queue.push_back(parents.at(i)); + while (!queue.empty()) + { + FCDSceneNode* parent = queue.back(); + queue.pop_back(); + if (parent == sceneNode) return false; + queue.insert(queue.end(), parent->parents.begin(), parent->parents.end()); + } + + children.push_back(sceneNode); + sceneNode->parents.push_back(this); + SetNewChildFlag(); + return true; +} + +FCDSceneNode* FCDSceneNode::AddChildNode() +{ + FCDSceneNode* node = new FCDSceneNode(GetDocument()); + AddChildNode(node); + return node; +} + +void FCDSceneNode::RemoveChildNode(FCDSceneNode* sceneNode) +{ + sceneNode->parents.erase(this); + children.erase(sceneNode); +} + +// Instantiates an entity +FCDEntityInstance* FCDSceneNode::AddInstance(FCDEntity* entity) +{ + if (entity == NULL) return NULL; + FCDEntityInstance* instance = AddInstance(entity->GetType()); + instance->SetEntity(entity); + return instance; +} + +FCDEntityInstance* FCDSceneNode::AddInstance(FCDEntity::Type type) +{ + FCDEntityInstance* instance = FCDEntityInstanceFactory::CreateInstance(GetDocument(), this, type); + + instances.push_back(instance); + SetNewChildFlag(); + return instance; +} + +// Adds a transform to the stack, at a given position. +FCDTransform* FCDSceneNode::AddTransform(FCDTransform::Type type, size_t index) +{ + FCDTransform* transform = FCDTFactory::CreateTransform(GetDocument(), this, type); + if (transform != NULL) + { + if (index > transforms.size()) transforms.push_back(transform); + else transforms.insert(index, transform); + } + SetNewChildFlag(); + SetTransformsDirtyFlag(); + return transform; +} + +// Traverse the scene graph, searching for a node with the given COLLADA id +const FCDEntity* FCDSceneNode::FindDaeId(const fm::string& daeId) const +{ + if (GetDaeId() == daeId) return this; + + for (const FCDSceneNode** it = children.begin(); it != children.end(); ++it) + { + const FCDEntity* found = (*it)->FindDaeId(daeId); + if (found != NULL) return found; + } + return NULL; +} + +void FCDSceneNode::SetSubId(const fm::string& subId) +{ + daeSubId = ""; + if (subId.empty()) return; + + // We must ensure that our sub id is unique in the our scope + // First, build a list of subIds above us (in the graph) + FCDSceneNode* curNode = this; + + // Flatten parents up-tree to find all parents subIds + fm::pvector parentTree; + StringList parentSubIds; + size_t curParent = 0; + do + { + for (size_t i = 0; i < curNode->GetParentCount(); i++) + { + FCDSceneNode* parentNode = curNode->GetParent(i); + parentTree.push_back(parentNode); + fm::string parentSubId = parentNode->GetSubId(); + if (!parentSubId.empty()) parentSubIds.push_back(parentSubId); + } + // Continue iteration. + if (parentTree.size() > curParent) + { + curNode = parentTree[curParent]; + curParent++; + } + else curNode = NULL; + } + while (curNode != NULL); + + // Now, test for uniqueness, This is enforced for both descendants and ancestors + fm::string newSubId = FCDObjectWithId::CleanSubId(subId); + int32 idMod = 0; + while (FindSubId(newSubId) != NULL || parentSubIds.find(newSubId) != parentSubIds.end()) + { + newSubId = subId + "_" + FUStringConversion::ToString(idMod++); + + // Dont keep doing this forever. + if (idMod > 512) break; + } + daeSubId = newSubId; +} + +// Traverse the scene graph, searching for a node with the given COLLADA sub id +const FCDEntity* FCDSceneNode::FindSubId(const fm::string& subId) const +{ + if (GetSubId() == subId) return this; + + for (const FCDSceneNode** it = children.begin(); it != children.end(); ++it) + { + const FCDEntity* found = (*it)->FindSubId(subId); + if (found != NULL) return found; + } + return NULL; +} + +// Retrieve the list of hierarchical asset information structures that affect this scene node. +void FCDSceneNode::GetHierarchicalAssets(FCDAssetConstList& assets) const +{ + for (const FCDSceneNode* node = this; node != NULL; node = node->GetParent(0)) + { + // Retrieve the asset information structure for this node. + const FCDAsset* asset = node->GetAsset(); + if (asset != NULL) assets.push_back(asset); + } + assets.push_back(GetDocument()->GetAsset()); +} + +// Calculate the transform matrix for a given scene node +FMMatrix44 FCDSceneNode::ToMatrix() const +{ + FMMatrix44 localTransform = FMMatrix44::Identity; + for (const FCDTransform** it = transforms.begin(); it != transforms.end(); ++it) + { + localTransform = localTransform * (*it)->ToMatrix(); + } + return localTransform; +} + +FMMatrix44 FCDSceneNode::CalculateWorldTransform() const +{ + const FCDSceneNode* parent = GetParent(); + if (parent != NULL) + { + //FMMatrix44 tm1 = parent->CalculateWorldTransform(); + //FMMatrix44 tm2 = CalculateLocalTransform(); + //return tm1 * tm2; + return parent->CalculateWorldTransform() * CalculateLocalTransform(); + } + else + { + return CalculateLocalTransform(); + } +} + +void FCDSceneNode::CleanSubId() +{ + FUSUniqueStringMap myStringMap; + + size_t instanceCount = instances.size(); + for (size_t i = 0; i < instanceCount; ++i) + { + instances[i]->CleanSubId(&myStringMap); + } + + size_t childCount = children.size(); + for (size_t c = 0; c < childCount; ++c) + { + children[c]->CleanSubId(); + } +} + +FCDEntity* FCDSceneNode::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDSceneNode* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDSceneNode(const_cast(GetDocument())); + else if (_clone->HasType(FCDSceneNode::GetClassType())) clone = (FCDSceneNode*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + // Copy over the simple information. + clone->SetJointFlag(GetJointFlag()); + clone->visibility = visibility; + + // Don't copy the parents list but do clone all the children, transforms and instances + for (const FCDTransform** it = transforms.begin(); it != transforms.end(); ++it) + { + FCDTransform* transform = clone->AddTransform((*it)->GetType()); + (*it)->Clone(transform); + } + + if (cloneChildren) + { + for (const FCDSceneNode** it = children.begin(); it != children.end(); ++it) + { + FCDSceneNode* child = clone->AddChildNode(); + (*it)->Clone(child, cloneChildren); + } + } + + for (const FCDEntityInstance** it = instances.begin(); it != instances.end(); ++it) + { + FCDEntityInstance* instance = clone->AddInstance((*it)->GetEntityType()); + (*it)->Clone(instance); + } + } + + return _clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNode.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeTools.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeTools.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeTools.h (revision 24247) @@ -1,52 +1,52 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDSceneNodeTools.h - This file contains the FCDSceneNodeTools namespace. -*/ - -#ifndef _FCD_SCENE_NODE_TOOLS_H_ -#define _FCD_SCENE_NODE_TOOLS_H_ - -class FCDSceneNode; - -/** A set of tools that operates or modifies visual scene nodes. */ -namespace FCDSceneNodeTools -{ - /** Generate a list of matrices, with corresponding key times that - represent an animation curve for the local transform of a scene node. - This function will permanently modify the transforms of this visual scene node. -

Because of DLL support, this function was split into four functions - and only one animation curve is available at one time within this - namespace. First, call GenerateSampledAnimation. Then, call - GetSampledAnimationKeys and GetSampledAnimationMatrices to process - or retrieve the resulting animation curve. Finally, optionally - call ClearSampledAnimation in order to free up the internal memory buffers. - Every call to GenerateSampledAnimation start by calling ClearSampledAnimation. - @param sceneNode The scene node. */ - FCOLLADA_EXPORT void GenerateSampledAnimation(FCDSceneNode* sceneNode); - - /** Retrieves the generated sampled animation curve's keys. - @see GenerateSampledAnimation. - @return The generated sampled animation curve's keys. */ - FCOLLADA_EXPORT const FloatList& GetSampledAnimationKeys(); - - /** Retrieves the generated sampled animation curve's values. - @see GenerateSampledAnimation. - @return The generated sampled animation curve's values. */ - FCOLLADA_EXPORT const FMMatrix44List& GetSampledAnimationMatrices(); - - /** Frees up the memory used by any previous call to GenerateSampledAnimation. - It is recommended, but not necessary, to call this function after retrieving - and copying locally the keys and values for the generated sampled - animation curve. */ - FCOLLADA_EXPORT void ClearSampledAnimation(); -}; - -#endif // _FCD_SCENE_NODE_TOOLS_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDSceneNodeTools.h + This file contains the FCDSceneNodeTools namespace. +*/ + +#ifndef _FCD_SCENE_NODE_TOOLS_H_ +#define _FCD_SCENE_NODE_TOOLS_H_ + +class FCDSceneNode; + +/** A set of tools that operates or modifies visual scene nodes. */ +namespace FCDSceneNodeTools +{ + /** Generate a list of matrices, with corresponding key times that + represent an animation curve for the local transform of a scene node. + This function will permanently modify the transforms of this visual scene node. +

Because of DLL support, this function was split into four functions + and only one animation curve is available at one time within this + namespace. First, call GenerateSampledAnimation. Then, call + GetSampledAnimationKeys and GetSampledAnimationMatrices to process + or retrieve the resulting animation curve. Finally, optionally + call ClearSampledAnimation in order to free up the internal memory buffers. + Every call to GenerateSampledAnimation start by calling ClearSampledAnimation. + @param sceneNode The scene node. */ + FCOLLADA_EXPORT void GenerateSampledAnimation(FCDSceneNode* sceneNode); + + /** Retrieves the generated sampled animation curve's keys. + @see GenerateSampledAnimation. + @return The generated sampled animation curve's keys. */ + FCOLLADA_EXPORT const FloatList& GetSampledAnimationKeys(); + + /** Retrieves the generated sampled animation curve's values. + @see GenerateSampledAnimation. + @return The generated sampled animation curve's values. */ + FCOLLADA_EXPORT const FMMatrix44List& GetSampledAnimationMatrices(); + + /** Frees up the memory used by any previous call to GenerateSampledAnimation. + It is recommended, but not necessary, to call this function after retrieving + and copying locally the keys and values for the generated sampled + animation curve. */ + FCOLLADA_EXPORT void ClearSampledAnimation(); +}; + +#endif // _FCD_SCENE_NODE_TOOLS_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeTools.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTargetedEntity.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTargetedEntity.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTargetedEntity.h (revision 24247) @@ -1,85 +1,85 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDTargetedEntity.h - This file contains the FCDTargetedEntity class. -*/ - -#ifndef _FCD_TARGETED_ENTITY_H_ -#define _FCD_TARGETED_ENTITY_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDSceneNode; - -/** - A targeted entity. - - COLLADA doesn't have targeted entity. - Therefore: the behavior of a targeted entity is application-defined. - - This class is used to support 3dsMax's targeted cameras and lights - and we also plan to support Maya's targeted cameras and lights. - - @see FCDCamera FCDLight - @ingroup FCDEntity -*/ -class FCOLLADA_EXPORT FCDTargetedEntity : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - - // Target - DeclareParameterPtr(FCDSceneNode, targetNode, FC("Target Node")); - -public: - /** Constructor: do not use directly. - Instead, create objects of the up-classes. - @param document The COLLADA document that owns the targeted entity. - @param baseId The prefix COLLADA id to be used if no COLLADA id is provided. */ - FCDTargetedEntity(FCDocument* document, const char* baseId); - - /** Destructor. */ - virtual ~FCDTargetedEntity(); - - /** Retrieves whether a target is defined for this entity. - @return Whether a target is defined for this entity. */ - inline bool HasTarget() const { return targetNode != NULL; } - - /** Retrieves the target visual scene node for this entity. - @return The target visual scene node. */ - inline FCDSceneNode* GetTargetNode() { return targetNode; } - inline const FCDSceneNode* GetTargetNode() const { return targetNode; } /**< See above. */ - - /** Sets the target visual scene node for this entity. - @param target The new target node. */ - void SetTargetNode(FCDSceneNode* target); - - /** Copies the entity target information into a entity clone. - All the overwriting functions of this function should call this function - to copy the target information. - The cloned entity may reside in another document. - @param clone The empty clone. If this pointer is NULL, a new entity - will be created and you will need to release the returned pointer manually. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - -}; - -#endif // _FCD_TARGETED_ENTITY_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDTargetedEntity.h + This file contains the FCDTargetedEntity class. +*/ + +#ifndef _FCD_TARGETED_ENTITY_H_ +#define _FCD_TARGETED_ENTITY_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDSceneNode; + +/** + A targeted entity. + + COLLADA doesn't have targeted entity. + Therefore: the behavior of a targeted entity is application-defined. + + This class is used to support 3dsMax's targeted cameras and lights + and we also plan to support Maya's targeted cameras and lights. + + @see FCDCamera FCDLight + @ingroup FCDEntity +*/ +class FCOLLADA_EXPORT FCDTargetedEntity : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + + // Target + DeclareParameterPtr(FCDSceneNode, targetNode, FC("Target Node")); + +public: + /** Constructor: do not use directly. + Instead, create objects of the up-classes. + @param document The COLLADA document that owns the targeted entity. + @param baseId The prefix COLLADA id to be used if no COLLADA id is provided. */ + FCDTargetedEntity(FCDocument* document, const char* baseId); + + /** Destructor. */ + virtual ~FCDTargetedEntity(); + + /** Retrieves whether a target is defined for this entity. + @return Whether a target is defined for this entity. */ + inline bool HasTarget() const { return targetNode != NULL; } + + /** Retrieves the target visual scene node for this entity. + @return The target visual scene node. */ + inline FCDSceneNode* GetTargetNode() { return targetNode; } + inline const FCDSceneNode* GetTargetNode() const { return targetNode; } /**< See above. */ + + /** Sets the target visual scene node for this entity. + @param target The new target node. */ + void SetTargetNode(FCDSceneNode* target); + + /** Copies the entity target information into a entity clone. + All the overwriting functions of this function should call this function + to copy the target information. + The cloned entity may reside in another document. + @param clone The empty clone. If this pointer is NULL, a new entity + will be created and you will need to release the returned pointer manually. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + +}; + +#endif // _FCD_TARGETED_ENTITY_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTargetedEntity.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleEmitter.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleEmitter.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleEmitter.h (revision 24247) @@ -1,19 +1,19 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDParticleEmitter.h - This file contains the FCDParticleModifier base class, and - its various definitions. -*/ - -#ifndef _FCD_PARTICLE_EMITTER_H_ -#define _FCD_PARTICLE_EMITTER_H_ - - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDParticleEmitter.h + This file contains the FCDParticleModifier base class, and + its various definitions. +*/ + +#ifndef _FCD_PARTICLE_EMITTER_H_ +#define _FCD_PARTICLE_EMITTER_H_ + + #endif // _FCD_PARTICLE_EMITTER_H_ \ No newline at end of file Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDParticleEmitter.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsAnalyticalGeometry.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsAnalyticalGeometry.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsAnalyticalGeometry.h (revision 24247) @@ -1,392 +1,392 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsAnalyticalGeometry.h - This file contains all the analytical geometry classes including Box, - Plane, Sphere, Cylinder, Capsule, Tapered Cylinder, and Tapered Capsule. -*/ - -#ifndef _FCD_PHYSICS_ANALYTICAL_GEOM_H_ -#define _FCD_PHYSICS_ANALYTICAL_GEOM_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDocument; -class FCDPhysicsShape; - -/** - A COLLADA physics analytical geometry. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPhysicsAnalyticalGeometry : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - -public: - /** The geometry type of the analytical geometry class. - Used this information to up-cast an entity instance. */ - enum GeomType { - BOX, /**< A box. */ - PLANE, /**< An infinate plane. */ - SPHERE, /**< A sphere. */ - CYLINDER, /**< A cylinder. */ - CAPSULE, /**< A cylinder with spheres at the end. */ - TAPERED_CYLINDER, /**< A cylinder with different sized flat faces. */ - TAPERED_CAPSULE /**< A capsule with different sized spheres. */ - }; - - /** Constructor: do not use directly. Create new analytical geometries by - using FCDPhysicsShape::CreateAnalyticalGeometry function. - @param document The COLLADA document that contains this physics scene. - */ - FCDPhysicsAnalyticalGeometry(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPhysicsAnalyticalGeometry(); - - /** Retrieves the entity type for this class. This function is part of the - FCDEntity interface. - @return The entity type: PHYSICS_ANALYTICAL_GEOMETRY. */ - virtual Type GetType() const {return PHYSICS_ANALYTICAL_GEOMETRY;} - - /** Retrieves the analytical geometry type for this class. - @return The analytical geometry type. */ - virtual GeomType GetGeomType() const = 0; - - /** Calculates the volume of this analytical geometry. - @return The volume. */ - virtual float CalculateVolume() const = 0; - - /** Copies the analytical geometry into a clone. - @param clone The empty clone. If this pointer is NULL, a analytical - geometry will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; -}; - -/** - A COLLADA physics box. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPASBox : public FCDPhysicsAnalyticalGeometry -{ -private: - DeclareObjectType(FCDPhysicsAnalyticalGeometry); - -public: - /** Constructor: do not use directly. Create new analytical geometries by - using FCDPhysicsShape::CreateAnalyticalGeometry function. - @param document The COLLADA document that contains this physics box. */ - FCDPASBox(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPASBox() {} - - /** Retrieves the analytical geometry type for this class. - @return The analytical geometry type: BOX. */ - virtual GeomType GetGeomType() const {return BOX;} - - /** Calculates the volume of this analytical geometry. - @return The volume. */ - virtual float CalculateVolume() const; - - /** Copies the physics box into a clone. - @param clone The empty clone. If this pointer is NULL, a analytical - geometry will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - -public: - FMVector3 halfExtents; /**< Half extents of the box in 3 dimensions. */ -}; - -/** - A COLLADA physics plane. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPASPlane : public FCDPhysicsAnalyticalGeometry -{ -private: - DeclareObjectType(FCDPhysicsAnalyticalGeometry); - -public: - /** Constructor: do not use directly. Create new analytical geometries by - using FCDPhysicsShape::CreateAnalyticalGeometry function. - @param document The COLLADA document that contains this physics plane. - */ - FCDPASPlane(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPASPlane() {} - - /** Retrieves the analytical geometry type for this class. - @return The analytical geometry type: PLANE. */ - virtual GeomType GetGeomType() const {return PLANE;} - - /** Calculates the volume of this analytical geometry. - @return The volume. */ - virtual float CalculateVolume() const; - - /** Copies the physics plane into a clone. - @param clone The empty clone. If this pointer is NULL, a analytical - geometry will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - -public: - FMVector3 normal; /**< The normal for the plane. */ - float d; /**< The value that positions the plane. If the normal of the plane is at (A, B, C), the equation of the plane is Ax + By + Cz + d = 0. */ -}; - -/** - A COLLADA physics sphere. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPASSphere : public FCDPhysicsAnalyticalGeometry -{ -private: - DeclareObjectType(FCDPhysicsAnalyticalGeometry); - -public: - /** Constructor: do not use directly. Create new analytical geometries by - using FCDPhysicsShape::CreateAnalyticalGeometry function. - @param document The COLLADA document that contains this physics sphere. - */ - FCDPASSphere(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPASSphere() {} - - /** Retrieves the analytical geometry type for this class. - @return The analytical geometry type: SPHERE. */ - virtual GeomType GetGeomType() const {return SPHERE;} - - /** Calculates the volume of this analytical geometry. - @return The volume. */ - virtual float CalculateVolume() const; - - /** Copies the physics sphere into a clone. - @param clone The empty clone. If this pointer is NULL, a analytical - geometry will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - -public: - float radius; /**< The radius of the sphere. */ -}; - -/** - A COLLADA physics cylinder. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPASCylinder : public FCDPhysicsAnalyticalGeometry -{ -private: - DeclareObjectType(FCDPhysicsAnalyticalGeometry); - -public: - /** Constructor: do not use directly. Create new analytical geometries by - using FCDPhysicsShape::CreateAnalyticalGeometry function. - @param document The COLLADA document that contains this physics - cylinder. */ - FCDPASCylinder(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPASCylinder() {} - - /** Retrieves the analytical geometry type for this class. - @return The analytical geometry type: CYLINDER. */ - virtual GeomType GetGeomType() const {return CYLINDER;} - - /** Calculates the volume of this analytical geometry. - @return The volume. */ - virtual float CalculateVolume() const; - - /** Copies the physics cylinder into a clone. - @param clone The empty clone. If this pointer is NULL, a analytical - geometry will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - -public: - float height; /**< The height of the cylinder. */ - FMVector2 radius; /**< The radius in the X direction and Z direction of the cylinder. */ -}; - -/** - A COLLADA physics capsule. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPASCapsule : public FCDPhysicsAnalyticalGeometry -{ -private: - DeclareObjectType(FCDPhysicsAnalyticalGeometry); - -public: - /** Constructor: do not use directly. Create new analytical geometries by - using FCDPhysicsShape::CreateAnalyticalGeometry function. - @param document The COLLADA document that contains this physics - capsule. */ - FCDPASCapsule(FCDocument* document); - - /** Desctructor. */ - virtual ~FCDPASCapsule() {} - - /** Retrieves the analytical geometry type for this class. - @return The analytical geometry type: CAPSULE. */ - virtual GeomType GetGeomType() const {return CAPSULE;} - - /** Calculates the volume of this analytical geometry. - @return The volume. */ - virtual float CalculateVolume() const; - - /** Copies the physics capsule into a clone. - @param clone The empty clone. If this pointer is NULL, a analytical - geometry will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - -public: - float height; /**< The height of the capsule. */ - FMVector2 radius; /**< The radius in the X direction and Z direction of the capsule. */ -}; - -/** - A COLLADA physics tapered capsule. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPASTaperedCapsule : public FCDPASCapsule -{ -private: - DeclareObjectType(FCDPASCapsule); - -public: - /** Constructor: do not use directly. Create new analytical geometries by - using FCDPhysicsShape::CreateAnalyticalGeometry function. - @param document The COLLADA document that contains this physics tapered - capsule. */ - FCDPASTaperedCapsule(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPASTaperedCapsule() {} - - /** Retrieves the analytical geometry type for this class. - @return The analytical geometry type: TAPERED_CAPSULE. */ - virtual GeomType GetGeomType() const {return TAPERED_CAPSULE;} - - /** Calculates the volume of this analytical geometry. - @return The volume. */ - virtual float CalculateVolume() const; - - /** Copies the physics tapered capsule into a clone. - @param clone The empty clone. If this pointer is NULL, a analytical - geometry will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDPhysicsAnalyticalGeometry* Clone(FCDPhysicsAnalyticalGeometry* clone = NULL, bool cloneChildren = false) const; - -public: - //inherits all other attributes from Capsule - FMVector2 radius2; /**< The second radius in the X direction and Z direction of the capsule. */ -}; - -/** - A COLLADA physics tapered cylinder. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPASTaperedCylinder : public FCDPASCylinder -{ -private: - DeclareObjectType(FCDPASCylinder); - -public: - /** Constructor: do not use directly. Create new analytical geometries by - using FCDPhysicsShape::CreateAnalyticalGeometry function. - @param document The COLLADA document that contains this physics tapered - cylinder. */ - FCDPASTaperedCylinder(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPASTaperedCylinder() {} - - /** Retrieves the analytical geometry type for this class. - @return The analytical geometry type: TAPERED_CYLINDER. */ - virtual GeomType GetGeomType() const {return TAPERED_CYLINDER;} - - /** Calculates the volume of this analytical geometry. - @return The volume. */ - virtual float CalculateVolume() const; - - /** Copies the physics tapered cylinder into a clone. - @param clone The empty clone. If this pointer is NULL, a analytical - geometry will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - -public: - //inherits all other attributes from Cylinder - FMVector2 radius2; /**< The second radius in the X direction and Z direction of the cylinder. */ -}; - -/** - [INTERNAL] The factory for COLLADA physics analytical shapes. - - Takes the type of analytical shape and returns a newly created one. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDPASFactory -{ -private: - FCDPASFactory() {} - -public: - /** Creates the physics analytical shape. - @param document The COLLADA document that contains the physics - analytical shape to create. - @param type The analytical geometry type of shape to dreate. - @return The newly created analytical shape. */ - static FCDPhysicsAnalyticalGeometry* CreatePAS(FCDocument* document, FCDPhysicsAnalyticalGeometry::GeomType type); -}; - -#endif // _FCD_PHYSICS_ANALYTICAL_GEOMETRY_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsAnalyticalGeometry.h + This file contains all the analytical geometry classes including Box, + Plane, Sphere, Cylinder, Capsule, Tapered Cylinder, and Tapered Capsule. +*/ + +#ifndef _FCD_PHYSICS_ANALYTICAL_GEOM_H_ +#define _FCD_PHYSICS_ANALYTICAL_GEOM_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDocument; +class FCDPhysicsShape; + +/** + A COLLADA physics analytical geometry. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPhysicsAnalyticalGeometry : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + +public: + /** The geometry type of the analytical geometry class. + Used this information to up-cast an entity instance. */ + enum GeomType { + BOX, /**< A box. */ + PLANE, /**< An infinate plane. */ + SPHERE, /**< A sphere. */ + CYLINDER, /**< A cylinder. */ + CAPSULE, /**< A cylinder with spheres at the end. */ + TAPERED_CYLINDER, /**< A cylinder with different sized flat faces. */ + TAPERED_CAPSULE /**< A capsule with different sized spheres. */ + }; + + /** Constructor: do not use directly. Create new analytical geometries by + using FCDPhysicsShape::CreateAnalyticalGeometry function. + @param document The COLLADA document that contains this physics scene. + */ + FCDPhysicsAnalyticalGeometry(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPhysicsAnalyticalGeometry(); + + /** Retrieves the entity type for this class. This function is part of the + FCDEntity interface. + @return The entity type: PHYSICS_ANALYTICAL_GEOMETRY. */ + virtual Type GetType() const {return PHYSICS_ANALYTICAL_GEOMETRY;} + + /** Retrieves the analytical geometry type for this class. + @return The analytical geometry type. */ + virtual GeomType GetGeomType() const = 0; + + /** Calculates the volume of this analytical geometry. + @return The volume. */ + virtual float CalculateVolume() const = 0; + + /** Copies the analytical geometry into a clone. + @param clone The empty clone. If this pointer is NULL, a analytical + geometry will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; +}; + +/** + A COLLADA physics box. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPASBox : public FCDPhysicsAnalyticalGeometry +{ +private: + DeclareObjectType(FCDPhysicsAnalyticalGeometry); + +public: + /** Constructor: do not use directly. Create new analytical geometries by + using FCDPhysicsShape::CreateAnalyticalGeometry function. + @param document The COLLADA document that contains this physics box. */ + FCDPASBox(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPASBox() {} + + /** Retrieves the analytical geometry type for this class. + @return The analytical geometry type: BOX. */ + virtual GeomType GetGeomType() const {return BOX;} + + /** Calculates the volume of this analytical geometry. + @return The volume. */ + virtual float CalculateVolume() const; + + /** Copies the physics box into a clone. + @param clone The empty clone. If this pointer is NULL, a analytical + geometry will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + +public: + FMVector3 halfExtents; /**< Half extents of the box in 3 dimensions. */ +}; + +/** + A COLLADA physics plane. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPASPlane : public FCDPhysicsAnalyticalGeometry +{ +private: + DeclareObjectType(FCDPhysicsAnalyticalGeometry); + +public: + /** Constructor: do not use directly. Create new analytical geometries by + using FCDPhysicsShape::CreateAnalyticalGeometry function. + @param document The COLLADA document that contains this physics plane. + */ + FCDPASPlane(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPASPlane() {} + + /** Retrieves the analytical geometry type for this class. + @return The analytical geometry type: PLANE. */ + virtual GeomType GetGeomType() const {return PLANE;} + + /** Calculates the volume of this analytical geometry. + @return The volume. */ + virtual float CalculateVolume() const; + + /** Copies the physics plane into a clone. + @param clone The empty clone. If this pointer is NULL, a analytical + geometry will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + +public: + FMVector3 normal; /**< The normal for the plane. */ + float d; /**< The value that positions the plane. If the normal of the plane is at (A, B, C), the equation of the plane is Ax + By + Cz + d = 0. */ +}; + +/** + A COLLADA physics sphere. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPASSphere : public FCDPhysicsAnalyticalGeometry +{ +private: + DeclareObjectType(FCDPhysicsAnalyticalGeometry); + +public: + /** Constructor: do not use directly. Create new analytical geometries by + using FCDPhysicsShape::CreateAnalyticalGeometry function. + @param document The COLLADA document that contains this physics sphere. + */ + FCDPASSphere(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPASSphere() {} + + /** Retrieves the analytical geometry type for this class. + @return The analytical geometry type: SPHERE. */ + virtual GeomType GetGeomType() const {return SPHERE;} + + /** Calculates the volume of this analytical geometry. + @return The volume. */ + virtual float CalculateVolume() const; + + /** Copies the physics sphere into a clone. + @param clone The empty clone. If this pointer is NULL, a analytical + geometry will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + +public: + float radius; /**< The radius of the sphere. */ +}; + +/** + A COLLADA physics cylinder. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPASCylinder : public FCDPhysicsAnalyticalGeometry +{ +private: + DeclareObjectType(FCDPhysicsAnalyticalGeometry); + +public: + /** Constructor: do not use directly. Create new analytical geometries by + using FCDPhysicsShape::CreateAnalyticalGeometry function. + @param document The COLLADA document that contains this physics + cylinder. */ + FCDPASCylinder(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPASCylinder() {} + + /** Retrieves the analytical geometry type for this class. + @return The analytical geometry type: CYLINDER. */ + virtual GeomType GetGeomType() const {return CYLINDER;} + + /** Calculates the volume of this analytical geometry. + @return The volume. */ + virtual float CalculateVolume() const; + + /** Copies the physics cylinder into a clone. + @param clone The empty clone. If this pointer is NULL, a analytical + geometry will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + +public: + float height; /**< The height of the cylinder. */ + FMVector2 radius; /**< The radius in the X direction and Z direction of the cylinder. */ +}; + +/** + A COLLADA physics capsule. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPASCapsule : public FCDPhysicsAnalyticalGeometry +{ +private: + DeclareObjectType(FCDPhysicsAnalyticalGeometry); + +public: + /** Constructor: do not use directly. Create new analytical geometries by + using FCDPhysicsShape::CreateAnalyticalGeometry function. + @param document The COLLADA document that contains this physics + capsule. */ + FCDPASCapsule(FCDocument* document); + + /** Desctructor. */ + virtual ~FCDPASCapsule() {} + + /** Retrieves the analytical geometry type for this class. + @return The analytical geometry type: CAPSULE. */ + virtual GeomType GetGeomType() const {return CAPSULE;} + + /** Calculates the volume of this analytical geometry. + @return The volume. */ + virtual float CalculateVolume() const; + + /** Copies the physics capsule into a clone. + @param clone The empty clone. If this pointer is NULL, a analytical + geometry will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + +public: + float height; /**< The height of the capsule. */ + FMVector2 radius; /**< The radius in the X direction and Z direction of the capsule. */ +}; + +/** + A COLLADA physics tapered capsule. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPASTaperedCapsule : public FCDPASCapsule +{ +private: + DeclareObjectType(FCDPASCapsule); + +public: + /** Constructor: do not use directly. Create new analytical geometries by + using FCDPhysicsShape::CreateAnalyticalGeometry function. + @param document The COLLADA document that contains this physics tapered + capsule. */ + FCDPASTaperedCapsule(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPASTaperedCapsule() {} + + /** Retrieves the analytical geometry type for this class. + @return The analytical geometry type: TAPERED_CAPSULE. */ + virtual GeomType GetGeomType() const {return TAPERED_CAPSULE;} + + /** Calculates the volume of this analytical geometry. + @return The volume. */ + virtual float CalculateVolume() const; + + /** Copies the physics tapered capsule into a clone. + @param clone The empty clone. If this pointer is NULL, a analytical + geometry will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDPhysicsAnalyticalGeometry* Clone(FCDPhysicsAnalyticalGeometry* clone = NULL, bool cloneChildren = false) const; + +public: + //inherits all other attributes from Capsule + FMVector2 radius2; /**< The second radius in the X direction and Z direction of the capsule. */ +}; + +/** + A COLLADA physics tapered cylinder. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPASTaperedCylinder : public FCDPASCylinder +{ +private: + DeclareObjectType(FCDPASCylinder); + +public: + /** Constructor: do not use directly. Create new analytical geometries by + using FCDPhysicsShape::CreateAnalyticalGeometry function. + @param document The COLLADA document that contains this physics tapered + cylinder. */ + FCDPASTaperedCylinder(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPASTaperedCylinder() {} + + /** Retrieves the analytical geometry type for this class. + @return The analytical geometry type: TAPERED_CYLINDER. */ + virtual GeomType GetGeomType() const {return TAPERED_CYLINDER;} + + /** Calculates the volume of this analytical geometry. + @return The volume. */ + virtual float CalculateVolume() const; + + /** Copies the physics tapered cylinder into a clone. + @param clone The empty clone. If this pointer is NULL, a analytical + geometry will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + +public: + //inherits all other attributes from Cylinder + FMVector2 radius2; /**< The second radius in the X direction and Z direction of the cylinder. */ +}; + +/** + [INTERNAL] The factory for COLLADA physics analytical shapes. + + Takes the type of analytical shape and returns a newly created one. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDPASFactory +{ +private: + FCDPASFactory() {} + +public: + /** Creates the physics analytical shape. + @param document The COLLADA document that contains the physics + analytical shape to create. + @param type The analytical geometry type of shape to dreate. + @return The newly created analytical shape. */ + static FCDPhysicsAnalyticalGeometry* CreatePAS(FCDocument* document, FCDPhysicsAnalyticalGeometry::GeomType type); +}; + +#endif // _FCD_PHYSICS_ANALYTICAL_GEOMETRY_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsAnalyticalGeometry.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsMaterial.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsMaterial.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsMaterial.h (revision 24247) @@ -1,87 +1,87 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsMaterial.h - This file contains the FCDPhysicsMaterial class. -*/ - -#ifndef _FCD_PHYSICSMATERIAL_H_ -#define _FCD_PHYSICSMATERIAL_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDocument; - -/** - A COLLADA physics material. - - A physics material contains physical properties for an object. Because - there isn't anything interesting in the physics material instance, this - class is used to represent that as well. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPhysicsMaterial : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - float staticFriction; - float dynamicFriction; - float restitution; - -public: - /** Constructor. - @param document The COLLADA document that contains this rigid body. */ - FCDPhysicsMaterial(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPhysicsMaterial(); - - /** Retrieves the entity type for this class. This function is part of the - FCDEntity interface. - @return The entity type: PHYSICS_MATERIAL. */ - virtual Type GetType() const { return FCDEntity::PHYSICS_MATERIAL; } - - /** Retrieves the static friction for this physics material. - @return The static friction. */ - float GetStaticFriction() const { return staticFriction; } - - /** Sets the static friction for this physics material. - @param _staticFriction The static friction. */ - void SetStaticFriction(float _staticFriction) { staticFriction = _staticFriction; SetDirtyFlag(); } - - /** Retrieves the dynamic friction for this physics material. - @return The dynamic friction. */ - float GetDynamicFriction() const { return dynamicFriction; } - - /** Sets the dynamic friction for this physics material. - @param _dynamicFriction The dynamic friction. */ - void SetDynamicFriction(float _dynamicFriction) { dynamicFriction = _dynamicFriction; SetDirtyFlag(); } - - /** Retrieves the restitution for this physics material. - @return The restitution. */ - float GetRestitution() const { return restitution; } - - /** Sets the restitution for this physics material. - @param _restitution The restitution. */ - void SetRestitution(float _restitution) { restitution = _restitution; SetDirtyFlag(); } - - /** Copies the physics material into a clone. - @param clone The empty clone. If this pointer is NULL, a new physics - material will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; -}; - -#endif // _FCD_MATERIAL_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsMaterial.h + This file contains the FCDPhysicsMaterial class. +*/ + +#ifndef _FCD_PHYSICSMATERIAL_H_ +#define _FCD_PHYSICSMATERIAL_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDocument; + +/** + A COLLADA physics material. + + A physics material contains physical properties for an object. Because + there isn't anything interesting in the physics material instance, this + class is used to represent that as well. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPhysicsMaterial : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + float staticFriction; + float dynamicFriction; + float restitution; + +public: + /** Constructor. + @param document The COLLADA document that contains this rigid body. */ + FCDPhysicsMaterial(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPhysicsMaterial(); + + /** Retrieves the entity type for this class. This function is part of the + FCDEntity interface. + @return The entity type: PHYSICS_MATERIAL. */ + virtual Type GetType() const { return FCDEntity::PHYSICS_MATERIAL; } + + /** Retrieves the static friction for this physics material. + @return The static friction. */ + float GetStaticFriction() const { return staticFriction; } + + /** Sets the static friction for this physics material. + @param _staticFriction The static friction. */ + void SetStaticFriction(float _staticFriction) { staticFriction = _staticFriction; SetDirtyFlag(); } + + /** Retrieves the dynamic friction for this physics material. + @return The dynamic friction. */ + float GetDynamicFriction() const { return dynamicFriction; } + + /** Sets the dynamic friction for this physics material. + @param _dynamicFriction The dynamic friction. */ + void SetDynamicFriction(float _dynamicFriction) { dynamicFriction = _dynamicFriction; SetDirtyFlag(); } + + /** Retrieves the restitution for this physics material. + @return The restitution. */ + float GetRestitution() const { return restitution; } + + /** Sets the restitution for this physics material. + @param _restitution The restitution. */ + void SetRestitution(float _restitution) { restitution = _restitution; SetDirtyFlag(); } + + /** Copies the physics material into a clone. + @param clone The empty clone. If this pointer is NULL, a new physics + material will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; +}; + +#endif // _FCD_MATERIAL_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsMaterial.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModelInstance.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModelInstance.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModelInstance.h (revision 24247) @@ -1,111 +1,111 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsModelInstance.h - This file contains the FCDPhysicsModelInstance class. -*/ - -#ifndef _FCD_PHYSICS_MODEL_ENTITY_H_ -#define _FCD_PHYSICS_MODEL_ENTITY_H_ - -#ifndef _FCD_ENTITY_INSTANCE_H_ -#include "FCDocument/FCDEntityInstance.h" -#endif // _FCD_ENTITY_INSTANCE_H_ - -class FCDocument; -class FCDForceField; -class FCDPhysicsForceFieldInstance; -class FCDPhysicsRigidBody; -class FCDPhysicsRigidBodyInstance; -class FCDPhysicsRigidConstraint; -class FCDPhysicsRigidConstraintInstance; - -/** - A COLLADA physics model instance. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPhysicsModelInstance : public FCDEntityInstance -{ -private: - DeclareObjectType(FCDEntityInstance); - - DeclareParameterContainer(FCDEntityInstance, instances, FC("Inner Instances")); - -public: - /** Constructor: do not use directly. Create new physics models using the - FCDPhysicsModel::AddPhysicsModelInstance function. - @param document The COLLADA document that contains this physics model - instance. */ - FCDPhysicsModelInstance(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPhysicsModelInstance(); - - /** Retrieves the entity type for this class. This function is part of the - FCDEntity interface. - @return The entity type: PHYSICS_MODEL. */ - virtual Type GetType() const { return FCDEntityInstance::PHYSICS_MODEL; } - - /** Retrieves all the instances from this physics model instance. - @return The instances. */ - DEPRECATED(3.05A, GetInstanceCount and GetInstance(index)) void GetInstances() const {} - - /** Retrieves the number of instances from this physics model instance. - @return The number of instances. */ - size_t GetInstanceCount() const { return instances.size(); } - - /** Retrieves a specified instance from this physics model instance by - index. - @param index The index. - @return The instance. */ - FCDEntityInstance* GetInstance(size_t index) { FUAssert(index < GetInstanceCount(), return NULL); return instances.at(index); } - const FCDEntityInstance* GetInstance(size_t index) const { FUAssert(index < GetInstanceCount(), return NULL); return instances.at(index); } /**< See above. */ - - /** Adds an instantiated rigid body to this physics model instance. - @param rigidBody The rigid body to be instanced in this physics model - instance. If this value is NULL, then there is no associated - rigid body for the instance yet. It should be filled in. - @return The new rigid body instance. */ - FCDPhysicsRigidBodyInstance* AddRigidBodyInstance(FCDPhysicsRigidBody* rigidBody = NULL); - - /** Adds an instantiated rigid constraint to this physics model instance. - @param rigidConstraint The rigid constraint to be instanced in this - physics model instance. If this value is NULL, then there is no - associated rigid constraint for the instance yet. It should be - filled in. - @return The new rigid constraint instance. */ - FCDPhysicsRigidConstraintInstance* AddRigidConstraintInstance(FCDPhysicsRigidConstraint* rigidConstraint = NULL); - - /** Adds an instantiated force field to this physics model instance. - @param forceField The force field to be instanced in this physics model - instance. If this value is NULL, then there is no associated - force field for the instance yet. It should be filled in. - @return The new force field instance. */ - FCDPhysicsForceFieldInstance* AddForceFieldInstance(FCDForceField* forceField = NULL); - - /** Removes and deletes the instance from the model. - @param instance The instance to remove. - @return True if the instance was removed. */ - DEPRECATED(3.05A, instance->Release() or SAFE_RELEASE(instance)) bool RemoveInstance(FCDEntityInstance* instance); - - /** Copies the physics model instance into a clone. - @param clone The empty clone. If this pointer is NULL, a new physics - model instance will be created and you will need to release the - returned pointer manually. - @return The clone. */ - virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; - - /** [INTERNAL] Cleans up the sub identifiers. - The sub identifiers must be unique with respect to its parent. This method corrects the sub ids if there are conflicts. - @param parentStringMap The string map from the parent of this instance in which the sub ids must be unique. */ - virtual void CleanSubId(FUSUniqueStringMap* parentStringMap); -}; - -#endif // _FCD_PHYSICS_MODEL_ENTITY_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsModelInstance.h + This file contains the FCDPhysicsModelInstance class. +*/ + +#ifndef _FCD_PHYSICS_MODEL_ENTITY_H_ +#define _FCD_PHYSICS_MODEL_ENTITY_H_ + +#ifndef _FCD_ENTITY_INSTANCE_H_ +#include "FCDocument/FCDEntityInstance.h" +#endif // _FCD_ENTITY_INSTANCE_H_ + +class FCDocument; +class FCDForceField; +class FCDPhysicsForceFieldInstance; +class FCDPhysicsRigidBody; +class FCDPhysicsRigidBodyInstance; +class FCDPhysicsRigidConstraint; +class FCDPhysicsRigidConstraintInstance; + +/** + A COLLADA physics model instance. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPhysicsModelInstance : public FCDEntityInstance +{ +private: + DeclareObjectType(FCDEntityInstance); + + DeclareParameterContainer(FCDEntityInstance, instances, FC("Inner Instances")); + +public: + /** Constructor: do not use directly. Create new physics models using the + FCDPhysicsModel::AddPhysicsModelInstance function. + @param document The COLLADA document that contains this physics model + instance. */ + FCDPhysicsModelInstance(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPhysicsModelInstance(); + + /** Retrieves the entity type for this class. This function is part of the + FCDEntity interface. + @return The entity type: PHYSICS_MODEL. */ + virtual Type GetType() const { return FCDEntityInstance::PHYSICS_MODEL; } + + /** Retrieves all the instances from this physics model instance. + @return The instances. */ + DEPRECATED(3.05A, GetInstanceCount and GetInstance(index)) void GetInstances() const {} + + /** Retrieves the number of instances from this physics model instance. + @return The number of instances. */ + size_t GetInstanceCount() const { return instances.size(); } + + /** Retrieves a specified instance from this physics model instance by + index. + @param index The index. + @return The instance. */ + FCDEntityInstance* GetInstance(size_t index) { FUAssert(index < GetInstanceCount(), return NULL); return instances.at(index); } + const FCDEntityInstance* GetInstance(size_t index) const { FUAssert(index < GetInstanceCount(), return NULL); return instances.at(index); } /**< See above. */ + + /** Adds an instantiated rigid body to this physics model instance. + @param rigidBody The rigid body to be instanced in this physics model + instance. If this value is NULL, then there is no associated + rigid body for the instance yet. It should be filled in. + @return The new rigid body instance. */ + FCDPhysicsRigidBodyInstance* AddRigidBodyInstance(FCDPhysicsRigidBody* rigidBody = NULL); + + /** Adds an instantiated rigid constraint to this physics model instance. + @param rigidConstraint The rigid constraint to be instanced in this + physics model instance. If this value is NULL, then there is no + associated rigid constraint for the instance yet. It should be + filled in. + @return The new rigid constraint instance. */ + FCDPhysicsRigidConstraintInstance* AddRigidConstraintInstance(FCDPhysicsRigidConstraint* rigidConstraint = NULL); + + /** Adds an instantiated force field to this physics model instance. + @param forceField The force field to be instanced in this physics model + instance. If this value is NULL, then there is no associated + force field for the instance yet. It should be filled in. + @return The new force field instance. */ + FCDPhysicsForceFieldInstance* AddForceFieldInstance(FCDForceField* forceField = NULL); + + /** Removes and deletes the instance from the model. + @param instance The instance to remove. + @return True if the instance was removed. */ + DEPRECATED(3.05A, instance->Release() or SAFE_RELEASE(instance)) bool RemoveInstance(FCDEntityInstance* instance); + + /** Copies the physics model instance into a clone. + @param clone The empty clone. If this pointer is NULL, a new physics + model instance will be created and you will need to release the + returned pointer manually. + @return The clone. */ + virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; + + /** [INTERNAL] Cleans up the sub identifiers. + The sub identifiers must be unique with respect to its parent. This method corrects the sub ids if there are conflicts. + @param parentStringMap The string map from the parent of this instance in which the sub ids must be unique. */ + virtual void CleanSubId(FUSUniqueStringMap* parentStringMap); +}; + +#endif // _FCD_PHYSICS_MODEL_ENTITY_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModelInstance.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyInstance.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyInstance.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyInstance.h (revision 24247) @@ -1,137 +1,137 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsRigidBodyInstance.h - This file contains the FCDPhysicsRigidBodyInstance class. -*/ - -#ifndef _FCD_PHYSICS_RIGID_BODY_ENTITY_H_ -#define _FCD_PHYSICS_RIGID_BODY_ENTITY_H_ - -#ifndef _FCD_ENTITY_INSTANCE_H_ -#include "FCDocument/FCDEntityInstance.h" -#endif // _FCD_ENTITY_INSTANCE_H_ -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -class FCDocument; -class FCDSceneNode; -class FCDPhysicsRigidBody; -class FCDPhysicsRigidBodyParameters; -class FCDPhysicsMaterial; -class FCDPhysicsModelInstance; -template class FUEvent2; - - -/** - An instance of a physics rigid body. - Allows you to overwrite the material of a rigid body - and attach the instance to a visual scene node. - - @ingroup FCDPhysics -*/ -class FCOLLADA_EXPORT FCDPhysicsRigidBodyInstance : public FCDEntityInstance -{ -private: - DeclareObjectType(FCDEntityInstance); - - FCDPhysicsModelInstance* parent; - typedef FUEvent2 CollisionEvent; - CollisionEvent* onCollisionEvent; - - DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, velocity, FC("Initial Linear Velocity")); - DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, angularVelocity, FC("Initial Angular Velocity")); - DeclareParameterRef(FCDPhysicsRigidBodyParameters, parameters, FC("Parameters")); - DeclareParameterPtr(FCDSceneNode, targetNode, FC("Target Node")); - - -public: - /** Constructor: do not use directly. Create new rigid bodies using the - FCDPhysicsModelInstance::AddRigidBodyInstance function. - @param document The COLLADA document that contains this rigid body - instance. - @param _parent The physics model instance holding this rigid body - instance. - @param body The rigid body to instance. Default values are taken from - here. This should not be NULL unless it is expected to be filled in - by LoadFromXML. */ - FCDPhysicsRigidBodyInstance(FCDocument* document, FCDPhysicsModelInstance* _parent, FCDPhysicsRigidBody* body); - - /** Destructor. */ - virtual ~FCDPhysicsRigidBodyInstance(); - - /** Retrieves the entity type for this class. This function is part of the - FCDEntity interface. - @return The entity type: PHYSICS_RIGID_BODY. */ - virtual Type GetType() const { return PHYSICS_RIGID_BODY; } - - /** [INTERNAL] Retrieve it's parent model instance. - @return The parent of the intance. - */ - FCDPhysicsModelInstance* GetModelParentInstance(){ return parent; } - - /** Retrieves the parameters of tihs rigid body. - @return The parameters. */ - FCDPhysicsRigidBodyParameters* GetParameters() { return parameters; } - const FCDPhysicsRigidBodyParameters* GetParameters() const { return parameters; } /**< See above. */ - - /** Retrieves the rigid body for this instance. - @return The rigid body. */ - inline FCDPhysicsRigidBody* GetRigidBody() { return (FCDPhysicsRigidBody*) GetEntity(); } - - /** Retrieves the angular velocity of this rigid body instance. - @return The angular velocity. */ - FCDParameterAnimatableVector3& GetAngularVelocity() { return angularVelocity; } - const FCDParameterAnimatableVector3& GetAngularVelocity() const { return angularVelocity; } /**< See above. */ - - /** Sets the angular velocity of this rigid body instance. - @param _angularVelocity The angular velocity. */ - inline void SetAngularVelocity(const FMVector3& _angularVelocity) { angularVelocity = _angularVelocity; SetDirtyFlag(); } - - /** Retrives the linear velocity of this rigid body instance. - @return The linear velocity. */ - FCDParameterAnimatableVector3& GetVelocity() { return velocity; } - const FCDParameterAnimatableVector3& GetVelocity() const { return velocity; } /**< See above. */ - - /** Sets the linear velocity of this rigid body instance. - @param _velocity The linear velocity. */ - inline void SetVelocity(const FMVector3& _velocity) { velocity = _velocity; SetDirtyFlag(); } - - /** Retrieves the target node influenced by this rigid body instance. - @return The target node. */ - FCDSceneNode* GetTargetNode() { return targetNode; } - const FCDSceneNode* GetTargetNode() const { return targetNode; } /**< See above. */ - - /** Sets the target node influenced by this rigid body instance. - @param target The target node. */ - void SetTargetNode(FCDSceneNode* target) { targetNode = target; SetDirtyFlag(); } - - /** Retrieves the collision event. - This event may be used by a physics plugin to call an applications' callback when a collision occured on this - rigid body. It should call it twice per collision, once for each object. The first parameter to the event - is the rigid body instance that was collided with, and the second parameter is the world position of the - collision. - @return The collision event. */ - CollisionEvent& GetCollisionEvent() { return *onCollisionEvent; } - - /** Clones the rigid body instance. - @param clone The rigid body instance to become the clone. - If this pointer is NULL, a new rigid body instance will be created - and you will need to release it. - @return The clone. */ - virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; - - /** [INTERNAL] Sets the rigid body for this rigid body instance. Default values are - taken from the rigid body. - @param body The rigid body. */ - void SetRigidBody(FCDPhysicsRigidBody* body); -}; - -#endif // _FCD_PHYSICS_RIGID_BODY_ENTITY_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsRigidBodyInstance.h + This file contains the FCDPhysicsRigidBodyInstance class. +*/ + +#ifndef _FCD_PHYSICS_RIGID_BODY_ENTITY_H_ +#define _FCD_PHYSICS_RIGID_BODY_ENTITY_H_ + +#ifndef _FCD_ENTITY_INSTANCE_H_ +#include "FCDocument/FCDEntityInstance.h" +#endif // _FCD_ENTITY_INSTANCE_H_ +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +class FCDocument; +class FCDSceneNode; +class FCDPhysicsRigidBody; +class FCDPhysicsRigidBodyParameters; +class FCDPhysicsMaterial; +class FCDPhysicsModelInstance; +template class FUEvent2; + + +/** + An instance of a physics rigid body. + Allows you to overwrite the material of a rigid body + and attach the instance to a visual scene node. + + @ingroup FCDPhysics +*/ +class FCOLLADA_EXPORT FCDPhysicsRigidBodyInstance : public FCDEntityInstance +{ +private: + DeclareObjectType(FCDEntityInstance); + + FCDPhysicsModelInstance* parent; + typedef FUEvent2 CollisionEvent; + CollisionEvent* onCollisionEvent; + + DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, velocity, FC("Initial Linear Velocity")); + DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, angularVelocity, FC("Initial Angular Velocity")); + DeclareParameterRef(FCDPhysicsRigidBodyParameters, parameters, FC("Parameters")); + DeclareParameterPtr(FCDSceneNode, targetNode, FC("Target Node")); + + +public: + /** Constructor: do not use directly. Create new rigid bodies using the + FCDPhysicsModelInstance::AddRigidBodyInstance function. + @param document The COLLADA document that contains this rigid body + instance. + @param _parent The physics model instance holding this rigid body + instance. + @param body The rigid body to instance. Default values are taken from + here. This should not be NULL unless it is expected to be filled in + by LoadFromXML. */ + FCDPhysicsRigidBodyInstance(FCDocument* document, FCDPhysicsModelInstance* _parent, FCDPhysicsRigidBody* body); + + /** Destructor. */ + virtual ~FCDPhysicsRigidBodyInstance(); + + /** Retrieves the entity type for this class. This function is part of the + FCDEntity interface. + @return The entity type: PHYSICS_RIGID_BODY. */ + virtual Type GetType() const { return PHYSICS_RIGID_BODY; } + + /** [INTERNAL] Retrieve it's parent model instance. + @return The parent of the intance. + */ + FCDPhysicsModelInstance* GetModelParentInstance(){ return parent; } + + /** Retrieves the parameters of tihs rigid body. + @return The parameters. */ + FCDPhysicsRigidBodyParameters* GetParameters() { return parameters; } + const FCDPhysicsRigidBodyParameters* GetParameters() const { return parameters; } /**< See above. */ + + /** Retrieves the rigid body for this instance. + @return The rigid body. */ + inline FCDPhysicsRigidBody* GetRigidBody() { return (FCDPhysicsRigidBody*) GetEntity(); } + + /** Retrieves the angular velocity of this rigid body instance. + @return The angular velocity. */ + FCDParameterAnimatableVector3& GetAngularVelocity() { return angularVelocity; } + const FCDParameterAnimatableVector3& GetAngularVelocity() const { return angularVelocity; } /**< See above. */ + + /** Sets the angular velocity of this rigid body instance. + @param _angularVelocity The angular velocity. */ + inline void SetAngularVelocity(const FMVector3& _angularVelocity) { angularVelocity = _angularVelocity; SetDirtyFlag(); } + + /** Retrives the linear velocity of this rigid body instance. + @return The linear velocity. */ + FCDParameterAnimatableVector3& GetVelocity() { return velocity; } + const FCDParameterAnimatableVector3& GetVelocity() const { return velocity; } /**< See above. */ + + /** Sets the linear velocity of this rigid body instance. + @param _velocity The linear velocity. */ + inline void SetVelocity(const FMVector3& _velocity) { velocity = _velocity; SetDirtyFlag(); } + + /** Retrieves the target node influenced by this rigid body instance. + @return The target node. */ + FCDSceneNode* GetTargetNode() { return targetNode; } + const FCDSceneNode* GetTargetNode() const { return targetNode; } /**< See above. */ + + /** Sets the target node influenced by this rigid body instance. + @param target The target node. */ + void SetTargetNode(FCDSceneNode* target) { targetNode = target; SetDirtyFlag(); } + + /** Retrieves the collision event. + This event may be used by a physics plugin to call an applications' callback when a collision occured on this + rigid body. It should call it twice per collision, once for each object. The first parameter to the event + is the rigid body instance that was collided with, and the second parameter is the world position of the + collision. + @return The collision event. */ + CollisionEvent& GetCollisionEvent() { return *onCollisionEvent; } + + /** Clones the rigid body instance. + @param clone The rigid body instance to become the clone. + If this pointer is NULL, a new rigid body instance will be created + and you will need to release it. + @return The clone. */ + virtual FCDEntityInstance* Clone(FCDEntityInstance* clone = NULL) const; + + /** [INTERNAL] Sets the rigid body for this rigid body instance. Default values are + taken from the rigid body. + @param body The rigid body. */ + void SetRigidBody(FCDPhysicsRigidBody* body); +}; + +#endif // _FCD_PHYSICS_RIGID_BODY_ENTITY_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyInstance.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraint.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraint.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraint.h (revision 24247) @@ -1,318 +1,318 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsRigidConstraint.h - This file contains the FCDPhysicsRigidConstraint class. -*/ - -#ifndef _FCD_PHYSICS_RIGID_CONSTRAINT_H_ -#define _FCD_PHYSICS_RIGID_CONSTRAINT_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ -#ifndef _FCD_TRANSFORM_H_ -#include "FCDocument/FCDTransform.h" /** @todo Remove this include by moving the FCDTransform::Type enum to FUDaeEnum.h. */ -#endif // _FCD_TRANSFORM_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ - -class FCDocument; -class FCDTransform; -class FCDPhysicsModel; -class FCDPhysicsRigidBody; -class FCDSceneNode; - -typedef FUObjectContainer FCDTransformContainer; /**< A dynamically-sized containment array for transforms. */ - -/** - A COLLADA rigid constraint. - - A rigid constraint attaches two rigid bodies together using springs, ball - joints, or other limitations. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPhysicsRigidConstraint : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - FCDPhysicsModel* parent; - - fm::string sid; - - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, enabled, FC("Enabled")); - DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, interpenetrate, FC("Inter-penetrate")); - - FUTrackedPtr referenceRigidBody; - FUTrackedPtr referenceNode; - FUTrackedPtr targetRigidBody; - FUTrackedPtr targetNode; - - DeclareParameter(FMVector3, FUParameterQualifiers::VECTOR, limitsLinearMin, FC("Minimum Linear Limit")); - DeclareParameter(FMVector3, FUParameterQualifiers::VECTOR, limitsLinearMax, FC("Maximum Linear Limit")); - DeclareParameter(FMVector3, FUParameterQualifiers::VECTOR, limitsSCTMin, FC("Minimum SCT? Limit")); - DeclareParameter(FMVector3, FUParameterQualifiers::VECTOR, limitsSCTMax, FC("Maximum SCT? Limit")); - - DeclareParameter(float, FUParameterQualifiers::SIMPLE, springLinearStiffness, FC("Spring Linear Stiffness")); - DeclareParameter(float, FUParameterQualifiers::SIMPLE, springLinearDamping, FC("Spring Linear Damping")); - DeclareParameter(float, FUParameterQualifiers::SIMPLE, springLinearTargetValue, FC("Spring Linear Target")); - - DeclareParameter(float, FUParameterQualifiers::SIMPLE, springAngularStiffness, FC("Spring Angular Stiffness")); - DeclareParameter(float, FUParameterQualifiers::SIMPLE, springAngularDamping, FC("Spring Angular Damping")); - DeclareParameter(float, FUParameterQualifiers::SIMPLE, springAngularTargetValue, FC("Spring Angular Target")); - - FCDTransformContainer transformsRef; - FCDTransformContainer transformsTar; - -public: - /** Constructor: do not use directly. Create new rigid constraints using - the FCDPhysicsModel::AddRigidConstraint function. - @param document The COLLADA document that contains this rigid - constraint. - @param _parent The physics model that contains this rigid constraint. - */ - FCDPhysicsRigidConstraint(FCDocument* document, FCDPhysicsModel* _parent); - - /** Destructor. */ - virtual ~FCDPhysicsRigidConstraint(); - - /** Retrieves the entity type for this class. This function is part of the - FCDEntity interface. - @return The entity type: PHYSICS_RIGID_CONSTRAINT. */ - virtual Type GetType() const { return PHYSICS_RIGID_CONSTRAINT; } - - /** Retrieves the physics model that contraints this rigid constraint. - @return The physics model. */ - FCDPhysicsModel* GetParent() { return parent; } - const FCDPhysicsModel* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the wanted sub-id for this transform. - A wanted sub-id will always be exported, even if the transform is not animated. - But the wanted sub-id may be modified if it isn't unique within the scope. - @return The sub-id. */ - inline const fm::string& GetSubId() const { return sid; } - - /** Sets the wanted sub-id for this transform. - A wanted sub-id will always be exported, even if the transform is not animated. - But the wanted sub-id may be modified if it isn't unique within the scope. - @param subId The wanted sub-id. */ - inline void SetSubId(const fm::string& subId) { sid = CleanSubId(subId); SetDirtyFlag(); } - inline void SetSubId(const char* subId) { sid = CleanSubId(subId); SetDirtyFlag(); } /**< See above. */ - - /** Retrieves the attached rigid body which is the reference. - @return The reference rigid body. */ - FCDPhysicsRigidBody* GetReferenceRigidBody() { return referenceRigidBody; } - const FCDPhysicsRigidBody* GetReferenceRigidBody() const { return referenceRigidBody; } /**< See above. */ - - /** Sets the attached rigid body which is the reference. - @param _referenceRigidBody The reference rigid body. */ - void SetReferenceRigidBody(FCDPhysicsRigidBody* _referenceRigidBody) { referenceRigidBody = _referenceRigidBody; referenceNode = NULL; SetNewChildFlag(); } - - /** Retrieves the attached rigid body which is not the reference. - @return The non reference rigid body. */ - FCDPhysicsRigidBody* GetTargetRigidBody() { return targetRigidBody; } - const FCDPhysicsRigidBody* GetTargetRigidBody() const { return targetRigidBody; } /**< See above. */ - - /** Sets the attached rigid body which is not the reference. - @param _targetRigidBody The non reference rigid body. */ - void SetTargetRigidBody(FCDPhysicsRigidBody* _targetRigidBody) { targetRigidBody = _targetRigidBody; targetNode = NULL; SetNewChildFlag(); } - - /** Retrieves the attached node which is the reference. This method should - be avoided as the specification says the attachment should be to a - rigid body. This value is only used if GetReferenceRigidBody is NULL. - @return The attached reference node. */ - FCDSceneNode* GetReferenceNode() { return referenceNode; } - const FCDSceneNode* GetReferenceNode() const { return referenceNode; } /**< See above. */ - - /** Sets the attached node which is the reference. This method should be - avoided as the specification says the attachment should be to a rigid - body. This value is only used if GetReferenceRigidBody is NULL. - @param _referenceNode The attached reference node. */ - void SetReferenceNode(FCDSceneNode* _referenceNode) { referenceNode = _referenceNode; referenceRigidBody = NULL; SetNewChildFlag(); } - - /** Retrieves the attached node which is not the reference. This method - should be avoided as the specification says the attachment should be to - a rigid body. This value is only used if GetTargetRigidBody is NULL. - @return The attached non reference node. */ - FCDSceneNode* GetTargetNode() { return targetNode; } - const FCDSceneNode* GetTargetNode() const { return targetNode; } /**< See above. */ - - /** Sets the attached node which is not the reference. This method should - be avoided as the specification says the attachment should be to a - rigid body. This value is only used if GetTargetRigidBody is NULL. - @param _targetNode The attached non reference node. */ - void SetTargetNode(FCDSceneNode* _targetNode) { targetNode = _targetNode; targetRigidBody = NULL; SetNewChildFlag(); } - - /** Retrieves the transforms for the attached rigid body which is the - reference. - @return The transforms. */ - FCDTransformContainer& GetTransformsRef() { return transformsRef; } - const FCDTransformContainer& GetTransformsRef() const { return transformsRef; } /**< See above. */ - - /** Retrieves the transforms for the attached rigid body which is not the - reference. - @return The transforms. */ - FCDTransformContainer& GetTransformsTar() { return transformsTar; } - const FCDTransformContainer& GetTransformsTar() const { return transformsTar; } /**< See above. */ - - /** Adds a transform for the attached rigid body which is the reference. - @param type The type of transform. - @param index The position to add the transform to. */ - FCDTransform* AddTransformRef(FCDTransform::Type type, size_t index = (size_t)-1); - - /** Adds a transform for the attached rigid body which is not the - reference. - @param type The type of transform. - @param index The position to add the transform to. */ - FCDTransform* AddTransformTar(FCDTransform::Type type, size_t index = (size_t)-1); - - /** Retrieves whether this rigid constraint is enabled. - @return True if enabled. */ - FCDParameterAnimatableFloat& GetEnabled() { return enabled; } - const FCDParameterAnimatableFloat& GetEnabled() const { return enabled; } /**< See above. */ - bool IsEnabled() const { return enabled > 0.5f; } /**< See above. */ - - /** Sets whether this rigid constraint is enabled. - @param _enabled True of enabled. */ - void SetEnabled(bool _enabled) { enabled = _enabled ? 1.0f : 0.0f; SetDirtyFlag(); } - - /** Retrieves whether the connected rigid bodies can penetrate eachother. - @return True of they can penetrate. */ - FCDParameterAnimatableFloat& GetInterpenetrate() { return interpenetrate; } - const FCDParameterAnimatableFloat& GetInterpenetrate() const { return interpenetrate; } /**< See above. */ - bool IsInterpenetrate() const { return interpenetrate > 0.5f; } /**< See above. */ - - /** Sets whether the connected rigid bodies can penetrate eachother. - @param _interpenetrate True of they can penetrate. */ - void SetInterpenetrate(bool _interpenetrate) { interpenetrate = _interpenetrate ? 1.0f : 0.0f; SetDirtyFlag(); } - - /** Retrieves the linear min limit of the degrees of freedom. - @return The linear min limit. */ - FUParameterVector3& GetLimitsLinearMin() { return limitsLinearMin; } - const FUParameterVector3& GetLimitsLinearMin() const { return limitsLinearMin; } /**< See above. */ - - /** Sets the linear min limit of the degrees of freedom. - @param _limitsLinearMin The linear min limit. */ - void SetLimitsLinearMin(const FMVector3& _limitsLinearMin) { limitsLinearMin = _limitsLinearMin; SetDirtyFlag(); } - - /** Retrieves the linear max limit of the degrees of freedom. - @return The linear max limit. */ - FUParameterVector3& GetLimitsLinearMax() { return limitsLinearMax; } - const FUParameterVector3& GetLimitsLinearMax() const { return limitsLinearMax; } /**< See above. */ - - /** Sets the linear max limit of the degrees of freedom. - @param _limitsLinearMax The linear max limit. */ - void SetLimitsLinearMax(const FMVector3& _limitsLinearMax) { limitsLinearMax = _limitsLinearMax; SetDirtyFlag(); } - - /** Retrieves the swing cone and twist min limit of the degrees of freedom. - @return The swing cone and twist min limit. */ - FUParameterVector3& GetLimitsSCTMin() { return limitsSCTMin; } - const FUParameterVector3& GetLimitsSCTMin() const { return limitsSCTMin; } /**< See above. */ - - /** Sets the swing cone and twist min limit of the degrees of freedom. - @param _limitsSCTMin The swing cone and twist min limit. */ - void SetLimitsSCTMin(const FMVector3& _limitsSCTMin) { limitsSCTMin = _limitsSCTMin; SetDirtyFlag(); } - - /** Retrieves the swing cone and twist max limit of the degrees of freedom. - @return The swing cone and twist max limit. */ - FUParameterVector3& GetLimitsSCTMax() { return limitsSCTMax; } - const FUParameterVector3& GetLimitsSCTMax() const { return limitsSCTMax; } /**< See above. */ - - /** Sets the swing cone and twist max limit of the degrees of freedom. - @param _limitsSCTMax The swing cone and twist max limit. */ - void SetLimitsSCTMax(const FMVector3& _limitsSCTMax) { limitsSCTMax = _limitsSCTMax; SetDirtyFlag(); } - - /** Retrieves the spring linear stiffness of the spring rigid constraint. - This is set to 1.0 if there is no spring. - @return The spring linear stiffness. */ - FUParameterFloat& GetSpringLinearStiffness() { return springLinearStiffness; } - const FUParameterFloat& GetSpringLinearStiffness() const { return springLinearStiffness; } /**< See above. */ - - /** Sets the spring linear stiffness of the spring rigid constraint. This - is set to 1.0 if there is no spring. - @param _springLinearStiffness The spring linear stiffness. */ - void SetSpringLinearStiffness(float _springLinearStiffness) { springLinearStiffness = _springLinearStiffness; SetDirtyFlag(); } - - /** Retrieves the spring linear damping of the spring rigid constraint. - This is set to 0.0 if there is no spring. - @return The spring linear damping. */ - FUParameterFloat& GetSpringLinearDamping() { return springLinearDamping; } - const FUParameterFloat& GetSpringLinearDamping() const { return springLinearDamping; } /**< See above. */ - - /** Sets the spring linear damping of the spring rigid constraint. This is - set to 0.0 if there is no spring. - @param _springLinearDamping The spring linear damping. */ - void SetSpringLinearDamping(float _springLinearDamping) { springLinearDamping = _springLinearDamping; SetDirtyFlag(); } - - /** Retrieves the sping linear target value of the spring rigid constraint. - This is set to 0.0 if there is no spring. - @return The spring linear target value. */ - FUParameterFloat& GetSpringLinearTargetValue() { return springLinearTargetValue; } - const FUParameterFloat& GetSpringLinearTargetValue() const { return springLinearTargetValue; } /**< See above. */ - - /** Sets the sping linear target value of the spring rigid constraint. This - is set to 0.0 if there is no spring. - @param _springLinearTargetValue The spring linear target value. */ - void SetSpringLinearTargetValue(float _springLinearTargetValue) { springLinearTargetValue = _springLinearTargetValue; SetDirtyFlag(); } - - /** Retrieves the spring angular stiffness of the spring rigid constraint. - This is set to 1.0 if there is no spring. - @return The spring angular stiffness. */ - FUParameterFloat& GetSpringAngularStiffness() { return springAngularStiffness; } - const FUParameterFloat& GetSpringAngularStiffness() const { return springAngularStiffness; } /**< See above. */ - - /** Sets the spring angular stiffness of the spring rigid constraint. This - is set to 1.0 if there is no spring. - @param _springAngularStiffness The spring angular stiffness. */ - void SetSpringAngularStiffness(float _springAngularStiffness) { springAngularStiffness = _springAngularStiffness; SetDirtyFlag(); } - - /** Retrieves the spring angular damping of the spring rigid constraint. - This is set to 0.0 if there is no spring. - @return The spring angular damping. */ - FUParameterFloat& GetSpringAngularDamping() { return springAngularDamping; } - const FUParameterFloat& GetSpringAngularDamping() const { return springAngularDamping; } /**< See above. */ - - /** Sets the spring angular damping of the spring rigid constraint. This is - set to 0.0 if there is no spring. - @param _springAngularDamping The spring angular damping. */ - void SetSpringAngularDamping(float _springAngularDamping) { springAngularDamping = _springAngularDamping; SetDirtyFlag(); } - - /** Retrieves the sping angular target value of the spring rigid - constraint. This is set to 0.0 if there is no spring. - @return The spring angular target value. */ - FUParameterFloat& GetSpringAngularTargetValue() { return springAngularTargetValue; } - const FUParameterFloat& GetSpringAngularTargetValue() const { return springAngularTargetValue; } /**< See above. */ - - /** Sets the sping angular target value of the spring rigid constraint. - This is set to 0.0 if there is no spring. - @param _springAngularTargetValue The spring angular target value. */ - void SetSpringAngularTargetValue(float _springAngularTargetValue) { springAngularTargetValue = _springAngularTargetValue; SetDirtyFlag(); } - - /** Retrieves the animated value for enabled. - @returns The animated value, or NULL if enabled is not animated. */ - DEPRECATED(3.05A, GetEnabled().GetAnimated) FCDAnimated* GetAnimatedEnabled() { return GetEnabled().GetAnimated(); } - DEPRECATED(3.05A, GetEnabled().GetAnimated) const FCDAnimated* GetAnimatedEnabled() const { return GetEnabled().GetAnimated(); } /**< See above. */ - - /** Retrieves the animated value for interpenetrate. - @returns The animated value, or NULL if interpenetrate is not animated. */ - DEPRECATED(3.05A, GetInterpenetrate().GetAnimated) FCDAnimated* GetAnimatedInterpenetrate() { return GetInterpenetrate().GetAnimated(); } - DEPRECATED(3.05A, GetInterpenetrate().GetAnimated) const FCDAnimated* GetAnimatedInterpenetrate() const { return GetInterpenetrate().GetAnimated(); } /**< See above. */ - - /** Copies the rigid constraint into a clone. - @param clone The empty clone. If this pointer is NULL, a new rigid - constraint will be created and you will need to release the - returned pointer manually. - @param cloneChildren Whether to recursively clone this entity's children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; -}; - -#endif // _FCD_PHYSICS_RIGID_CONSTRAINT_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsRigidConstraint.h + This file contains the FCDPhysicsRigidConstraint class. +*/ + +#ifndef _FCD_PHYSICS_RIGID_CONSTRAINT_H_ +#define _FCD_PHYSICS_RIGID_CONSTRAINT_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ +#ifndef _FCD_TRANSFORM_H_ +#include "FCDocument/FCDTransform.h" /** @todo Remove this include by moving the FCDTransform::Type enum to FUDaeEnum.h. */ +#endif // _FCD_TRANSFORM_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ + +class FCDocument; +class FCDTransform; +class FCDPhysicsModel; +class FCDPhysicsRigidBody; +class FCDSceneNode; + +typedef FUObjectContainer FCDTransformContainer; /**< A dynamically-sized containment array for transforms. */ + +/** + A COLLADA rigid constraint. + + A rigid constraint attaches two rigid bodies together using springs, ball + joints, or other limitations. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPhysicsRigidConstraint : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + FCDPhysicsModel* parent; + + fm::string sid; + + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, enabled, FC("Enabled")); + DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, interpenetrate, FC("Inter-penetrate")); + + FUTrackedPtr referenceRigidBody; + FUTrackedPtr referenceNode; + FUTrackedPtr targetRigidBody; + FUTrackedPtr targetNode; + + DeclareParameter(FMVector3, FUParameterQualifiers::VECTOR, limitsLinearMin, FC("Minimum Linear Limit")); + DeclareParameter(FMVector3, FUParameterQualifiers::VECTOR, limitsLinearMax, FC("Maximum Linear Limit")); + DeclareParameter(FMVector3, FUParameterQualifiers::VECTOR, limitsSCTMin, FC("Minimum SCT? Limit")); + DeclareParameter(FMVector3, FUParameterQualifiers::VECTOR, limitsSCTMax, FC("Maximum SCT? Limit")); + + DeclareParameter(float, FUParameterQualifiers::SIMPLE, springLinearStiffness, FC("Spring Linear Stiffness")); + DeclareParameter(float, FUParameterQualifiers::SIMPLE, springLinearDamping, FC("Spring Linear Damping")); + DeclareParameter(float, FUParameterQualifiers::SIMPLE, springLinearTargetValue, FC("Spring Linear Target")); + + DeclareParameter(float, FUParameterQualifiers::SIMPLE, springAngularStiffness, FC("Spring Angular Stiffness")); + DeclareParameter(float, FUParameterQualifiers::SIMPLE, springAngularDamping, FC("Spring Angular Damping")); + DeclareParameter(float, FUParameterQualifiers::SIMPLE, springAngularTargetValue, FC("Spring Angular Target")); + + FCDTransformContainer transformsRef; + FCDTransformContainer transformsTar; + +public: + /** Constructor: do not use directly. Create new rigid constraints using + the FCDPhysicsModel::AddRigidConstraint function. + @param document The COLLADA document that contains this rigid + constraint. + @param _parent The physics model that contains this rigid constraint. + */ + FCDPhysicsRigidConstraint(FCDocument* document, FCDPhysicsModel* _parent); + + /** Destructor. */ + virtual ~FCDPhysicsRigidConstraint(); + + /** Retrieves the entity type for this class. This function is part of the + FCDEntity interface. + @return The entity type: PHYSICS_RIGID_CONSTRAINT. */ + virtual Type GetType() const { return PHYSICS_RIGID_CONSTRAINT; } + + /** Retrieves the physics model that contraints this rigid constraint. + @return The physics model. */ + FCDPhysicsModel* GetParent() { return parent; } + const FCDPhysicsModel* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the wanted sub-id for this transform. + A wanted sub-id will always be exported, even if the transform is not animated. + But the wanted sub-id may be modified if it isn't unique within the scope. + @return The sub-id. */ + inline const fm::string& GetSubId() const { return sid; } + + /** Sets the wanted sub-id for this transform. + A wanted sub-id will always be exported, even if the transform is not animated. + But the wanted sub-id may be modified if it isn't unique within the scope. + @param subId The wanted sub-id. */ + inline void SetSubId(const fm::string& subId) { sid = CleanSubId(subId); SetDirtyFlag(); } + inline void SetSubId(const char* subId) { sid = CleanSubId(subId); SetDirtyFlag(); } /**< See above. */ + + /** Retrieves the attached rigid body which is the reference. + @return The reference rigid body. */ + FCDPhysicsRigidBody* GetReferenceRigidBody() { return referenceRigidBody; } + const FCDPhysicsRigidBody* GetReferenceRigidBody() const { return referenceRigidBody; } /**< See above. */ + + /** Sets the attached rigid body which is the reference. + @param _referenceRigidBody The reference rigid body. */ + void SetReferenceRigidBody(FCDPhysicsRigidBody* _referenceRigidBody) { referenceRigidBody = _referenceRigidBody; referenceNode = NULL; SetNewChildFlag(); } + + /** Retrieves the attached rigid body which is not the reference. + @return The non reference rigid body. */ + FCDPhysicsRigidBody* GetTargetRigidBody() { return targetRigidBody; } + const FCDPhysicsRigidBody* GetTargetRigidBody() const { return targetRigidBody; } /**< See above. */ + + /** Sets the attached rigid body which is not the reference. + @param _targetRigidBody The non reference rigid body. */ + void SetTargetRigidBody(FCDPhysicsRigidBody* _targetRigidBody) { targetRigidBody = _targetRigidBody; targetNode = NULL; SetNewChildFlag(); } + + /** Retrieves the attached node which is the reference. This method should + be avoided as the specification says the attachment should be to a + rigid body. This value is only used if GetReferenceRigidBody is NULL. + @return The attached reference node. */ + FCDSceneNode* GetReferenceNode() { return referenceNode; } + const FCDSceneNode* GetReferenceNode() const { return referenceNode; } /**< See above. */ + + /** Sets the attached node which is the reference. This method should be + avoided as the specification says the attachment should be to a rigid + body. This value is only used if GetReferenceRigidBody is NULL. + @param _referenceNode The attached reference node. */ + void SetReferenceNode(FCDSceneNode* _referenceNode) { referenceNode = _referenceNode; referenceRigidBody = NULL; SetNewChildFlag(); } + + /** Retrieves the attached node which is not the reference. This method + should be avoided as the specification says the attachment should be to + a rigid body. This value is only used if GetTargetRigidBody is NULL. + @return The attached non reference node. */ + FCDSceneNode* GetTargetNode() { return targetNode; } + const FCDSceneNode* GetTargetNode() const { return targetNode; } /**< See above. */ + + /** Sets the attached node which is not the reference. This method should + be avoided as the specification says the attachment should be to a + rigid body. This value is only used if GetTargetRigidBody is NULL. + @param _targetNode The attached non reference node. */ + void SetTargetNode(FCDSceneNode* _targetNode) { targetNode = _targetNode; targetRigidBody = NULL; SetNewChildFlag(); } + + /** Retrieves the transforms for the attached rigid body which is the + reference. + @return The transforms. */ + FCDTransformContainer& GetTransformsRef() { return transformsRef; } + const FCDTransformContainer& GetTransformsRef() const { return transformsRef; } /**< See above. */ + + /** Retrieves the transforms for the attached rigid body which is not the + reference. + @return The transforms. */ + FCDTransformContainer& GetTransformsTar() { return transformsTar; } + const FCDTransformContainer& GetTransformsTar() const { return transformsTar; } /**< See above. */ + + /** Adds a transform for the attached rigid body which is the reference. + @param type The type of transform. + @param index The position to add the transform to. */ + FCDTransform* AddTransformRef(FCDTransform::Type type, size_t index = (size_t)-1); + + /** Adds a transform for the attached rigid body which is not the + reference. + @param type The type of transform. + @param index The position to add the transform to. */ + FCDTransform* AddTransformTar(FCDTransform::Type type, size_t index = (size_t)-1); + + /** Retrieves whether this rigid constraint is enabled. + @return True if enabled. */ + FCDParameterAnimatableFloat& GetEnabled() { return enabled; } + const FCDParameterAnimatableFloat& GetEnabled() const { return enabled; } /**< See above. */ + bool IsEnabled() const { return enabled > 0.5f; } /**< See above. */ + + /** Sets whether this rigid constraint is enabled. + @param _enabled True of enabled. */ + void SetEnabled(bool _enabled) { enabled = _enabled ? 1.0f : 0.0f; SetDirtyFlag(); } + + /** Retrieves whether the connected rigid bodies can penetrate eachother. + @return True of they can penetrate. */ + FCDParameterAnimatableFloat& GetInterpenetrate() { return interpenetrate; } + const FCDParameterAnimatableFloat& GetInterpenetrate() const { return interpenetrate; } /**< See above. */ + bool IsInterpenetrate() const { return interpenetrate > 0.5f; } /**< See above. */ + + /** Sets whether the connected rigid bodies can penetrate eachother. + @param _interpenetrate True of they can penetrate. */ + void SetInterpenetrate(bool _interpenetrate) { interpenetrate = _interpenetrate ? 1.0f : 0.0f; SetDirtyFlag(); } + + /** Retrieves the linear min limit of the degrees of freedom. + @return The linear min limit. */ + FUParameterVector3& GetLimitsLinearMin() { return limitsLinearMin; } + const FUParameterVector3& GetLimitsLinearMin() const { return limitsLinearMin; } /**< See above. */ + + /** Sets the linear min limit of the degrees of freedom. + @param _limitsLinearMin The linear min limit. */ + void SetLimitsLinearMin(const FMVector3& _limitsLinearMin) { limitsLinearMin = _limitsLinearMin; SetDirtyFlag(); } + + /** Retrieves the linear max limit of the degrees of freedom. + @return The linear max limit. */ + FUParameterVector3& GetLimitsLinearMax() { return limitsLinearMax; } + const FUParameterVector3& GetLimitsLinearMax() const { return limitsLinearMax; } /**< See above. */ + + /** Sets the linear max limit of the degrees of freedom. + @param _limitsLinearMax The linear max limit. */ + void SetLimitsLinearMax(const FMVector3& _limitsLinearMax) { limitsLinearMax = _limitsLinearMax; SetDirtyFlag(); } + + /** Retrieves the swing cone and twist min limit of the degrees of freedom. + @return The swing cone and twist min limit. */ + FUParameterVector3& GetLimitsSCTMin() { return limitsSCTMin; } + const FUParameterVector3& GetLimitsSCTMin() const { return limitsSCTMin; } /**< See above. */ + + /** Sets the swing cone and twist min limit of the degrees of freedom. + @param _limitsSCTMin The swing cone and twist min limit. */ + void SetLimitsSCTMin(const FMVector3& _limitsSCTMin) { limitsSCTMin = _limitsSCTMin; SetDirtyFlag(); } + + /** Retrieves the swing cone and twist max limit of the degrees of freedom. + @return The swing cone and twist max limit. */ + FUParameterVector3& GetLimitsSCTMax() { return limitsSCTMax; } + const FUParameterVector3& GetLimitsSCTMax() const { return limitsSCTMax; } /**< See above. */ + + /** Sets the swing cone and twist max limit of the degrees of freedom. + @param _limitsSCTMax The swing cone and twist max limit. */ + void SetLimitsSCTMax(const FMVector3& _limitsSCTMax) { limitsSCTMax = _limitsSCTMax; SetDirtyFlag(); } + + /** Retrieves the spring linear stiffness of the spring rigid constraint. + This is set to 1.0 if there is no spring. + @return The spring linear stiffness. */ + FUParameterFloat& GetSpringLinearStiffness() { return springLinearStiffness; } + const FUParameterFloat& GetSpringLinearStiffness() const { return springLinearStiffness; } /**< See above. */ + + /** Sets the spring linear stiffness of the spring rigid constraint. This + is set to 1.0 if there is no spring. + @param _springLinearStiffness The spring linear stiffness. */ + void SetSpringLinearStiffness(float _springLinearStiffness) { springLinearStiffness = _springLinearStiffness; SetDirtyFlag(); } + + /** Retrieves the spring linear damping of the spring rigid constraint. + This is set to 0.0 if there is no spring. + @return The spring linear damping. */ + FUParameterFloat& GetSpringLinearDamping() { return springLinearDamping; } + const FUParameterFloat& GetSpringLinearDamping() const { return springLinearDamping; } /**< See above. */ + + /** Sets the spring linear damping of the spring rigid constraint. This is + set to 0.0 if there is no spring. + @param _springLinearDamping The spring linear damping. */ + void SetSpringLinearDamping(float _springLinearDamping) { springLinearDamping = _springLinearDamping; SetDirtyFlag(); } + + /** Retrieves the sping linear target value of the spring rigid constraint. + This is set to 0.0 if there is no spring. + @return The spring linear target value. */ + FUParameterFloat& GetSpringLinearTargetValue() { return springLinearTargetValue; } + const FUParameterFloat& GetSpringLinearTargetValue() const { return springLinearTargetValue; } /**< See above. */ + + /** Sets the sping linear target value of the spring rigid constraint. This + is set to 0.0 if there is no spring. + @param _springLinearTargetValue The spring linear target value. */ + void SetSpringLinearTargetValue(float _springLinearTargetValue) { springLinearTargetValue = _springLinearTargetValue; SetDirtyFlag(); } + + /** Retrieves the spring angular stiffness of the spring rigid constraint. + This is set to 1.0 if there is no spring. + @return The spring angular stiffness. */ + FUParameterFloat& GetSpringAngularStiffness() { return springAngularStiffness; } + const FUParameterFloat& GetSpringAngularStiffness() const { return springAngularStiffness; } /**< See above. */ + + /** Sets the spring angular stiffness of the spring rigid constraint. This + is set to 1.0 if there is no spring. + @param _springAngularStiffness The spring angular stiffness. */ + void SetSpringAngularStiffness(float _springAngularStiffness) { springAngularStiffness = _springAngularStiffness; SetDirtyFlag(); } + + /** Retrieves the spring angular damping of the spring rigid constraint. + This is set to 0.0 if there is no spring. + @return The spring angular damping. */ + FUParameterFloat& GetSpringAngularDamping() { return springAngularDamping; } + const FUParameterFloat& GetSpringAngularDamping() const { return springAngularDamping; } /**< See above. */ + + /** Sets the spring angular damping of the spring rigid constraint. This is + set to 0.0 if there is no spring. + @param _springAngularDamping The spring angular damping. */ + void SetSpringAngularDamping(float _springAngularDamping) { springAngularDamping = _springAngularDamping; SetDirtyFlag(); } + + /** Retrieves the sping angular target value of the spring rigid + constraint. This is set to 0.0 if there is no spring. + @return The spring angular target value. */ + FUParameterFloat& GetSpringAngularTargetValue() { return springAngularTargetValue; } + const FUParameterFloat& GetSpringAngularTargetValue() const { return springAngularTargetValue; } /**< See above. */ + + /** Sets the sping angular target value of the spring rigid constraint. + This is set to 0.0 if there is no spring. + @param _springAngularTargetValue The spring angular target value. */ + void SetSpringAngularTargetValue(float _springAngularTargetValue) { springAngularTargetValue = _springAngularTargetValue; SetDirtyFlag(); } + + /** Retrieves the animated value for enabled. + @returns The animated value, or NULL if enabled is not animated. */ + DEPRECATED(3.05A, GetEnabled().GetAnimated) FCDAnimated* GetAnimatedEnabled() { return GetEnabled().GetAnimated(); } + DEPRECATED(3.05A, GetEnabled().GetAnimated) const FCDAnimated* GetAnimatedEnabled() const { return GetEnabled().GetAnimated(); } /**< See above. */ + + /** Retrieves the animated value for interpenetrate. + @returns The animated value, or NULL if interpenetrate is not animated. */ + DEPRECATED(3.05A, GetInterpenetrate().GetAnimated) FCDAnimated* GetAnimatedInterpenetrate() { return GetInterpenetrate().GetAnimated(); } + DEPRECATED(3.05A, GetInterpenetrate().GetAnimated) const FCDAnimated* GetAnimatedInterpenetrate() const { return GetInterpenetrate().GetAnimated(); } /**< See above. */ + + /** Copies the rigid constraint into a clone. + @param clone The empty clone. If this pointer is NULL, a new rigid + constraint will be created and you will need to release the + returned pointer manually. + @param cloneChildren Whether to recursively clone this entity's children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; +}; + +#endif // _FCD_PHYSICS_RIGID_CONSTRAINT_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraint.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsScene.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsScene.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsScene.h (revision 24247) @@ -1,150 +1,150 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPhysicsScene.h - This file contains the FCDPhysicsScene class. -*/ - -#ifndef _FCD_PHYSICS_SCENE_NODE_ -#define _FCD_PHYSICS_SCENE_NODE_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ - -class FCDocument; -class FCDEntityInstance; -class FCDExtra; -class FCDPhysicsModel; -class FCDPhysicsModelInstance; -class FCDForceField; -class FCDPhysicsForceFieldInstance; - -typedef FUObjectContainer FCDPhysicsModelInstanceContainer; /**< A dynamically-sized containment array for physics model instances. */ -typedef FUObjectContainer FCDForceFieldInstanceContainer; /**< A dynamically-sized containment array for physics force field instances. */ - -/** - A COLLADA physics scene. - - A physics scene contains physics model instances that can run. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPhysicsScene : public FCDEntity -{ -private: - DeclareObjectType(FCDEntity); - FMVector3 gravity; - float timestep; - FCDPhysicsModelInstanceContainer physicsModelInstances; - FCDForceFieldInstanceContainer forceFieldInstances; - -public: - /** Constructor: do not use directly. Create new physics scenes by using - FCDocument::AddPhysicsScene function. - @param document The COLLADA document that contains this physics scene. - */ - FCDPhysicsScene(FCDocument* document); - - /** Destructor. */ - virtual ~FCDPhysicsScene(); - - /** Retrieves the entity type for this class. This function is part of the - FCDEntity interface. - @return The entity type: PHYSICS_SCENE_NODE. */ - virtual Type GetType() const { return PHYSICS_SCENE_NODE; } - - /** Retrieves the physics model instances that are a part of this physics - scene. - @return The physics model instances. */ - FCDPhysicsModelInstanceContainer& GetPhysicsModelInstances() { return physicsModelInstances; } - const FCDPhysicsModelInstanceContainer& GetPhysicsModelInstances() const { return physicsModelInstances; } /**< See above. */ - - /** Retrieves the number of physics model instances that are a part of this - physics scene. - @return The number of physics model instances. */ - size_t GetPhysicsModelInstancesCount() const { return physicsModelInstances.size(); }; - - /** Retrieves a specific physics model instance that is a part of tihs - physics scene by index. - @param index The index of the physics model instance. - @return The physics model instance. */ - FCDPhysicsModelInstance* GetPhysicsModelInstance(size_t index) { FUAssert(index < GetPhysicsModelInstancesCount(), return NULL); return physicsModelInstances.at(index); } - const FCDPhysicsModelInstance* GetPhysicsModelInstance(size_t index) const { FUAssert(index < GetPhysicsModelInstancesCount(), return NULL); return physicsModelInstances.at(index); } /**< See above. */ - - /** Retrieves the physics force field instances that are a part of this - physics scene. - @return The physics force fieldinstances. */ - FCDForceFieldInstanceContainer& GetForceFieldInstances() { return forceFieldInstances; } - const FCDForceFieldInstanceContainer& GetForceFieldInstances() const { return forceFieldInstances; } /**< See above. */ - - /** Retrieves the number of physics force field instances that are a part - of this physics scene. - @return The number of physics force field instances. */ - size_t GetForceFieldInstancesCount() const { return forceFieldInstances.size(); }; - - /** Retrieves a specific physics force field instance that is a part of - tihs physics scene by index. - @param index The index of the physics force field instance. - @return The physics force field instance. */ - FCDPhysicsForceFieldInstance* GetForceFieldInstance(size_t index) { FUAssert(index < GetForceFieldInstancesCount(), return NULL); return forceFieldInstances.at(index); } - const FCDPhysicsForceFieldInstance* GetForceFieldInstance(size_t index) const { FUAssert(index < GetForceFieldInstancesCount(), return NULL); return forceFieldInstances.at(index); } /**< See above. */ - - /** Adds an instantiated physics model to this physics model. - @param model The physics model to be instanced in this physics model. - If this value is NULL, then there is no associated physics model - for the instance yet. It should be filled in. - @return The new physics model instance. */ - FCDPhysicsModelInstance* AddPhysicsModelInstance(FCDPhysicsModel* model = NULL); - - /** Adds an instantiated force field to this physics model. - @param forceField The force field to be instanced in this physics - model. - @return The new force field instance. */ - FCDPhysicsForceFieldInstance* AddForceFieldInstance(FCDForceField* forceField = NULL); - - /** Retrieves the gravity magnitude and direction as a 3 dimensional - vector. - @return The gravity. */ - const FMVector3& GetGravity() const { return gravity; } - - /** Set the gravity magnitude and direction as a 3 dimensional vector. - @param _gravity The gravity. */ - void SetGravity(const FMVector3& _gravity) { gravity = _gravity; SetDirtyFlag(); } - - /** Retrieves the integration time step, in seconds. - @return The time step. */ - const float& GetTimestep() const { return timestep; } - - /** Set the integration time step, in seconds. - @param _timestep The time step. */ - void SetTimestep(float _timestep) { timestep = _timestep; SetDirtyFlag(); } - - /** Copies the physics scene into a clone. - @param clone The empty clone. If this pointer is NULL, a new physics - scene will be created and you will need to release the returned - pointer manually. - @param cloneChildren Whether to recursively clone this entity's - children. - @return The clone. */ - virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; - - /** [INTERNAL] Cleans up the sub identifiers. - The sub identifiers must be unique with respect to its parent. - This method corrects the sub ids if there are conflicts. */ - virtual void CleanSubId(); -}; - -#endif // _FCD_SCENE_NODE_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPhysicsScene.h + This file contains the FCDPhysicsScene class. +*/ + +#ifndef _FCD_PHYSICS_SCENE_NODE_ +#define _FCD_PHYSICS_SCENE_NODE_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ + +class FCDocument; +class FCDEntityInstance; +class FCDExtra; +class FCDPhysicsModel; +class FCDPhysicsModelInstance; +class FCDForceField; +class FCDPhysicsForceFieldInstance; + +typedef FUObjectContainer FCDPhysicsModelInstanceContainer; /**< A dynamically-sized containment array for physics model instances. */ +typedef FUObjectContainer FCDForceFieldInstanceContainer; /**< A dynamically-sized containment array for physics force field instances. */ + +/** + A COLLADA physics scene. + + A physics scene contains physics model instances that can run. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPhysicsScene : public FCDEntity +{ +private: + DeclareObjectType(FCDEntity); + FMVector3 gravity; + float timestep; + FCDPhysicsModelInstanceContainer physicsModelInstances; + FCDForceFieldInstanceContainer forceFieldInstances; + +public: + /** Constructor: do not use directly. Create new physics scenes by using + FCDocument::AddPhysicsScene function. + @param document The COLLADA document that contains this physics scene. + */ + FCDPhysicsScene(FCDocument* document); + + /** Destructor. */ + virtual ~FCDPhysicsScene(); + + /** Retrieves the entity type for this class. This function is part of the + FCDEntity interface. + @return The entity type: PHYSICS_SCENE_NODE. */ + virtual Type GetType() const { return PHYSICS_SCENE_NODE; } + + /** Retrieves the physics model instances that are a part of this physics + scene. + @return The physics model instances. */ + FCDPhysicsModelInstanceContainer& GetPhysicsModelInstances() { return physicsModelInstances; } + const FCDPhysicsModelInstanceContainer& GetPhysicsModelInstances() const { return physicsModelInstances; } /**< See above. */ + + /** Retrieves the number of physics model instances that are a part of this + physics scene. + @return The number of physics model instances. */ + size_t GetPhysicsModelInstancesCount() const { return physicsModelInstances.size(); }; + + /** Retrieves a specific physics model instance that is a part of tihs + physics scene by index. + @param index The index of the physics model instance. + @return The physics model instance. */ + FCDPhysicsModelInstance* GetPhysicsModelInstance(size_t index) { FUAssert(index < GetPhysicsModelInstancesCount(), return NULL); return physicsModelInstances.at(index); } + const FCDPhysicsModelInstance* GetPhysicsModelInstance(size_t index) const { FUAssert(index < GetPhysicsModelInstancesCount(), return NULL); return physicsModelInstances.at(index); } /**< See above. */ + + /** Retrieves the physics force field instances that are a part of this + physics scene. + @return The physics force fieldinstances. */ + FCDForceFieldInstanceContainer& GetForceFieldInstances() { return forceFieldInstances; } + const FCDForceFieldInstanceContainer& GetForceFieldInstances() const { return forceFieldInstances; } /**< See above. */ + + /** Retrieves the number of physics force field instances that are a part + of this physics scene. + @return The number of physics force field instances. */ + size_t GetForceFieldInstancesCount() const { return forceFieldInstances.size(); }; + + /** Retrieves a specific physics force field instance that is a part of + tihs physics scene by index. + @param index The index of the physics force field instance. + @return The physics force field instance. */ + FCDPhysicsForceFieldInstance* GetForceFieldInstance(size_t index) { FUAssert(index < GetForceFieldInstancesCount(), return NULL); return forceFieldInstances.at(index); } + const FCDPhysicsForceFieldInstance* GetForceFieldInstance(size_t index) const { FUAssert(index < GetForceFieldInstancesCount(), return NULL); return forceFieldInstances.at(index); } /**< See above. */ + + /** Adds an instantiated physics model to this physics model. + @param model The physics model to be instanced in this physics model. + If this value is NULL, then there is no associated physics model + for the instance yet. It should be filled in. + @return The new physics model instance. */ + FCDPhysicsModelInstance* AddPhysicsModelInstance(FCDPhysicsModel* model = NULL); + + /** Adds an instantiated force field to this physics model. + @param forceField The force field to be instanced in this physics + model. + @return The new force field instance. */ + FCDPhysicsForceFieldInstance* AddForceFieldInstance(FCDForceField* forceField = NULL); + + /** Retrieves the gravity magnitude and direction as a 3 dimensional + vector. + @return The gravity. */ + const FMVector3& GetGravity() const { return gravity; } + + /** Set the gravity magnitude and direction as a 3 dimensional vector. + @param _gravity The gravity. */ + void SetGravity(const FMVector3& _gravity) { gravity = _gravity; SetDirtyFlag(); } + + /** Retrieves the integration time step, in seconds. + @return The time step. */ + const float& GetTimestep() const { return timestep; } + + /** Set the integration time step, in seconds. + @param _timestep The time step. */ + void SetTimestep(float _timestep) { timestep = _timestep; SetDirtyFlag(); } + + /** Copies the physics scene into a clone. + @param clone The empty clone. If this pointer is NULL, a new physics + scene will be created and you will need to release the returned + pointer manually. + @param cloneChildren Whether to recursively clone this entity's + children. + @return The clone. */ + virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const; + + /** [INTERNAL] Cleans up the sub identifiers. + The sub identifiers must be unique with respect to its parent. + This method corrects the sub ids if there are conflicts. */ + virtual void CleanSubId(); +}; + +#endif // _FCD_SCENE_NODE_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsScene.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPlaceHolder.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPlaceHolder.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPlaceHolder.h (revision 24247) @@ -1,114 +1,114 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDPlaceHolder.h - This file contains the FCDPlaceHolder class. -*/ - -#ifndef _FCD_PLACEHOLDER_H_ -#define _FCD_PLACEHOLDER_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ - -class FCDEntityReference; - -/** - A FCollada document placeholder. - - This class is used to correctly support deferred external references. - It contains the information necessary to find and open referenced - FCollada documents and (re-)bind entity instances that use entities within - the referenced FCollada document. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDPlaceHolder : public FCDObject, FUTracker -{ -private: - DeclareObjectType(FCDPlaceHolder); - - FCDocument* target; - FUTrackedList references; - fstring fileUrl; - -public: - /** Constructor. - @param document The FCollada document that owns the placeholder. - @param target The FCollada document referenced by the placeholder. */ - FCDPlaceHolder(FCDocument* document, FCDocument* target = NULL); - - /** Destructor. */ - virtual ~FCDPlaceHolder(); - - /** Retrieves the referenced FCollada document. - @return The referenced FCollada document. The NULL pointer will - be returned when the referenced FCollada document is not loaded. */ - inline FCDocument* GetTarget() const { return target; } - - /** Retrieves the referenced FCollada document. - @param loadIfMissing Whether the referenced document should be loaded when - it is not already loaded. - @return The referenced FCollada document. The NULL pointer will - be returned when the referenced FCollada document could not be opened. */ - FCDocument* GetTarget(bool loadIfMissing = true); - - /** [INTERNAL] Loads the referenced FCollada document. - @param _target The FCollada document referenced by this placeholder. - This pointer will be NULL to let the placeholder load the FCollada document it - knows about. */ - void LoadTarget(FCDocument* _target = NULL); - - /** Unloads and releases the referenced FCollada document. */ - void UnloadTarget(); - - /** Retrieves whether the FCollada document referenced by this placeholder - is currently loaded and available. - @return Whether the referenced document is available. */ - inline bool IsTargetLoaded() const { return target != NULL; } - - /** Retrieves the URL of the referenced FCollada document. - @return The URL of the referenced FCollada document. */ - const fstring& GetFileUrl() const; - - /** Sets the URL of the referenced FCollada document. - @param url The URL of the referenced FCollada document. */ - void SetFileUrl(const fstring& url); - - /** [INTERNAL] Registers an entity reference into out document. - This external reference will be updated as the - referenced FCollada document is loaded and unloaded. - @param reference An external reference. */ - inline void AddExternalReference(FCDEntityReference* reference) { references.push_back(reference); SetNewChildFlag(); } - - /** [INTERNAL] Removes an external reference from - this placeholder's management list. - @param reference An external reference currently managed by this placeholder. */ - inline void RemoveExternalReference(FCDEntityReference* reference) { references.erase(reference); SetNewChildFlag(); } - - /** Retrieves the number of external references that references entities - contained within the referenced FCollada document. - @return The number of external references. */ - inline size_t GetExternalReferenceCount() const { return references.size(); } - - /** Retrieves an indexed external reference. - @param index The index of the external reference. - @return The external reference at the given index. */ - const FCDEntityReference* GetExternalReference(size_t index) const { FUAssert(index < GetExternalReferenceCount(), return NULL); return references.at(index); } - -protected: - /** [INTERNAL] Callback for the manual release of a - loaded referenced FCollada document. - @param object The released object pointer. */ - void OnObjectReleased(FUTrackable* object); -}; - -#endif // _FCD_PLACEHOLDER_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDPlaceHolder.h + This file contains the FCDPlaceHolder class. +*/ + +#ifndef _FCD_PLACEHOLDER_H_ +#define _FCD_PLACEHOLDER_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ + +class FCDEntityReference; + +/** + A FCollada document placeholder. + + This class is used to correctly support deferred external references. + It contains the information necessary to find and open referenced + FCollada documents and (re-)bind entity instances that use entities within + the referenced FCollada document. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDPlaceHolder : public FCDObject, FUTracker +{ +private: + DeclareObjectType(FCDPlaceHolder); + + FCDocument* target; + FUTrackedList references; + fstring fileUrl; + +public: + /** Constructor. + @param document The FCollada document that owns the placeholder. + @param target The FCollada document referenced by the placeholder. */ + FCDPlaceHolder(FCDocument* document, FCDocument* target = NULL); + + /** Destructor. */ + virtual ~FCDPlaceHolder(); + + /** Retrieves the referenced FCollada document. + @return The referenced FCollada document. The NULL pointer will + be returned when the referenced FCollada document is not loaded. */ + inline FCDocument* GetTarget() const { return target; } + + /** Retrieves the referenced FCollada document. + @param loadIfMissing Whether the referenced document should be loaded when + it is not already loaded. + @return The referenced FCollada document. The NULL pointer will + be returned when the referenced FCollada document could not be opened. */ + FCDocument* GetTarget(bool loadIfMissing = true); + + /** [INTERNAL] Loads the referenced FCollada document. + @param _target The FCollada document referenced by this placeholder. + This pointer will be NULL to let the placeholder load the FCollada document it + knows about. */ + void LoadTarget(FCDocument* _target = NULL); + + /** Unloads and releases the referenced FCollada document. */ + void UnloadTarget(); + + /** Retrieves whether the FCollada document referenced by this placeholder + is currently loaded and available. + @return Whether the referenced document is available. */ + inline bool IsTargetLoaded() const { return target != NULL; } + + /** Retrieves the URL of the referenced FCollada document. + @return The URL of the referenced FCollada document. */ + const fstring& GetFileUrl() const; + + /** Sets the URL of the referenced FCollada document. + @param url The URL of the referenced FCollada document. */ + void SetFileUrl(const fstring& url); + + /** [INTERNAL] Registers an entity reference into out document. + This external reference will be updated as the + referenced FCollada document is loaded and unloaded. + @param reference An external reference. */ + inline void AddExternalReference(FCDEntityReference* reference) { references.push_back(reference); SetNewChildFlag(); } + + /** [INTERNAL] Removes an external reference from + this placeholder's management list. + @param reference An external reference currently managed by this placeholder. */ + inline void RemoveExternalReference(FCDEntityReference* reference) { references.erase(reference); SetNewChildFlag(); } + + /** Retrieves the number of external references that references entities + contained within the referenced FCollada document. + @return The number of external references. */ + inline size_t GetExternalReferenceCount() const { return references.size(); } + + /** Retrieves an indexed external reference. + @param index The index of the external reference. + @return The external reference at the given index. */ + const FCDEntityReference* GetExternalReference(size_t index) const { FUAssert(index < GetExternalReferenceCount(), return NULL); return references.at(index); } + +protected: + /** [INTERNAL] Callback for the manual release of a + loaded referenced FCollada document. + @param object The released object pointer. */ + void OnObjectReleased(FUTrackable* object); +}; + +#endif // _FCD_PLACEHOLDER_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPlaceHolder.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeTools.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeTools.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeTools.cpp (revision 24247) @@ -1,158 +1,158 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDSceneNode.h" -#include "FCDocument/FCDSceneNodeTools.h" -#include "FCDocument/FCDTransform.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDAnimationCurve.h" -#include "FCDocument/FCDAnimationKey.h" - -namespace FCDSceneNodeTools -{ - static FloatList sampleKeys; - static FMMatrix44List sampleValues; - - void GenerateSampledAnimation(FCDSceneNode* node) - { - sampleKeys.clear(); - sampleValues.clear(); - - FCDAnimatedList animateds; - // Special case for rotation angles: need to check for changes that are greater than 180 degrees. - Int32List angleIndices; - - // Collect all the animation curves - size_t transformCount = node->GetTransformCount(); - for (size_t t = 0; t < transformCount; ++t) - { - FCDTransform* transform = node->GetTransform(t); - FCDAnimated* animated = transform->GetAnimated(); - if (animated != NULL) - { - if (animated->HasCurve()) animateds.push_back(animated); - - // Figure out whether this is a rotation and then, which animated value contains the angle. - if (!transform->HasType(FCDTRotation::GetClassType())) angleIndices.push_back(-1); - else angleIndices.push_back((int32) animated->FindQualifier(".ANGLE")); - } - } - if (animateds.empty()) return; - - // Make a list of the ordered key times to sample - size_t animatedsCount = animateds.size(); - for (size_t i = 0; i < animatedsCount; ++i) - { - FCDAnimated* animated = animateds[i]; - int32 angleIndex = angleIndices[i]; - - const FCDAnimationCurveListList& allCurves = animated->GetCurves(); - size_t valueCount = allCurves.size(); - for (size_t curveIndex = 0; curveIndex < valueCount; ++curveIndex) - { - const FCDAnimationCurveTrackList& curves = allCurves[curveIndex]; - if (curves.empty()) continue; - - size_t curveKeyCount = curves.front()->GetKeyCount(); - const FCDAnimationKey** curveKeys = curves.front()->GetKeys(); - size_t sampleKeyCount = sampleKeys.size(); - - // Merge this curve's keys in with the sample keys - // This assumes both key lists are in increasing order - size_t s = 0, c = 0; - while (s < sampleKeyCount && c < curveKeyCount) - { - float sampleKey = sampleKeys[s], curveKey = curveKeys[c]->input; - if (IsEquivalent(sampleKey, curveKey)) { ++s; ++c; } - else if (sampleKey < curveKey) { ++s; } - else - { - // Add this curve key to the sampling key list - sampleKeys.insert(sampleKeys.begin() + (s++), curveKeys[c++]->input); - sampleKeyCount++; - } - } - - // Add all the left-over curve keys to the sampling key list - while (c < curveKeyCount) sampleKeys.push_back(curveKeys[c++]->input); - - // Check for large angular rotations.. - if (angleIndex == (intptr_t) curveIndex) - { - for (size_t c = 1; c < curveKeyCount; ++c) - { - const FCDAnimationKey* previousKey = curveKeys[c - 1]; - const FCDAnimationKey* currentKey = curveKeys[c]; - float halfWrapAmount = (currentKey->output - previousKey->output) / 180.0f; - halfWrapAmount *= FMath::Sign(halfWrapAmount); - if (halfWrapAmount >= 1.0f) - { - // Need to add sample times. - size_t addSampleCount = (size_t) floorf(halfWrapAmount); - for (size_t d = 1; d <= addSampleCount; ++d) - { - float fd = (float) d; - float fid = (float) (addSampleCount + 1 - d); - float addSampleTime = (currentKey->input * fd + previousKey->input * fid) / (fd + fid); - - // Sorted insert. - float* endIt = sampleKeys.end(); - for (float* sampleKeyTime = sampleKeys.begin(); sampleKeyTime != endIt; ++sampleKeyTime) - { - if (IsEquivalent(*sampleKeyTime, addSampleTime)) break; - else if (*sampleKeyTime > addSampleTime) - { - sampleKeys.insert(sampleKeyTime, addSampleTime); - break; - } - } - } - } - } - } - } - } - size_t sampleKeyCount = sampleKeys.size(); - if (sampleKeyCount == 0) return; - - // Pre-allocate the value array; - sampleValues.reserve(sampleKeyCount); - - // Sample the scene node transform - for (size_t i = 0; i < sampleKeyCount; ++i) - { - float sampleTime = sampleKeys[i]; - for (FCDAnimatedList::iterator it = animateds.begin(); it != animateds.end(); ++it) - { - // Sample each animated, which changes the transform values directly - (*it)->Evaluate(sampleTime); - } - - // Retrieve the new transform matrix for the COLLADA scene node - sampleValues.push_back(node->ToMatrix()); - } - } - - const FloatList& GetSampledAnimationKeys() - { - return sampleKeys; - } - - const FMMatrix44List& GetSampledAnimationMatrices() - { - return sampleValues; - } - - void ClearSampledAnimation() - { - sampleKeys.clear(); - sampleValues.clear(); - } -}; - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDSceneNode.h" +#include "FCDocument/FCDSceneNodeTools.h" +#include "FCDocument/FCDTransform.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDAnimationCurve.h" +#include "FCDocument/FCDAnimationKey.h" + +namespace FCDSceneNodeTools +{ + static FloatList sampleKeys; + static FMMatrix44List sampleValues; + + void GenerateSampledAnimation(FCDSceneNode* node) + { + sampleKeys.clear(); + sampleValues.clear(); + + FCDAnimatedList animateds; + // Special case for rotation angles: need to check for changes that are greater than 180 degrees. + Int32List angleIndices; + + // Collect all the animation curves + size_t transformCount = node->GetTransformCount(); + for (size_t t = 0; t < transformCount; ++t) + { + FCDTransform* transform = node->GetTransform(t); + FCDAnimated* animated = transform->GetAnimated(); + if (animated != NULL) + { + if (animated->HasCurve()) animateds.push_back(animated); + + // Figure out whether this is a rotation and then, which animated value contains the angle. + if (!transform->HasType(FCDTRotation::GetClassType())) angleIndices.push_back(-1); + else angleIndices.push_back((int32) animated->FindQualifier(".ANGLE")); + } + } + if (animateds.empty()) return; + + // Make a list of the ordered key times to sample + size_t animatedsCount = animateds.size(); + for (size_t i = 0; i < animatedsCount; ++i) + { + FCDAnimated* animated = animateds[i]; + int32 angleIndex = angleIndices[i]; + + const FCDAnimationCurveListList& allCurves = animated->GetCurves(); + size_t valueCount = allCurves.size(); + for (size_t curveIndex = 0; curveIndex < valueCount; ++curveIndex) + { + const FCDAnimationCurveTrackList& curves = allCurves[curveIndex]; + if (curves.empty()) continue; + + size_t curveKeyCount = curves.front()->GetKeyCount(); + const FCDAnimationKey** curveKeys = curves.front()->GetKeys(); + size_t sampleKeyCount = sampleKeys.size(); + + // Merge this curve's keys in with the sample keys + // This assumes both key lists are in increasing order + size_t s = 0, c = 0; + while (s < sampleKeyCount && c < curveKeyCount) + { + float sampleKey = sampleKeys[s], curveKey = curveKeys[c]->input; + if (IsEquivalent(sampleKey, curveKey)) { ++s; ++c; } + else if (sampleKey < curveKey) { ++s; } + else + { + // Add this curve key to the sampling key list + sampleKeys.insert(sampleKeys.begin() + (s++), curveKeys[c++]->input); + sampleKeyCount++; + } + } + + // Add all the left-over curve keys to the sampling key list + while (c < curveKeyCount) sampleKeys.push_back(curveKeys[c++]->input); + + // Check for large angular rotations.. + if (angleIndex == (intptr_t) curveIndex) + { + for (size_t c = 1; c < curveKeyCount; ++c) + { + const FCDAnimationKey* previousKey = curveKeys[c - 1]; + const FCDAnimationKey* currentKey = curveKeys[c]; + float halfWrapAmount = (currentKey->output - previousKey->output) / 180.0f; + halfWrapAmount *= FMath::Sign(halfWrapAmount); + if (halfWrapAmount >= 1.0f) + { + // Need to add sample times. + size_t addSampleCount = (size_t) floorf(halfWrapAmount); + for (size_t d = 1; d <= addSampleCount; ++d) + { + float fd = (float) d; + float fid = (float) (addSampleCount + 1 - d); + float addSampleTime = (currentKey->input * fd + previousKey->input * fid) / (fd + fid); + + // Sorted insert. + float* endIt = sampleKeys.end(); + for (float* sampleKeyTime = sampleKeys.begin(); sampleKeyTime != endIt; ++sampleKeyTime) + { + if (IsEquivalent(*sampleKeyTime, addSampleTime)) break; + else if (*sampleKeyTime > addSampleTime) + { + sampleKeys.insert(sampleKeyTime, addSampleTime); + break; + } + } + } + } + } + } + } + } + size_t sampleKeyCount = sampleKeys.size(); + if (sampleKeyCount == 0) return; + + // Pre-allocate the value array; + sampleValues.reserve(sampleKeyCount); + + // Sample the scene node transform + for (size_t i = 0; i < sampleKeyCount; ++i) + { + float sampleTime = sampleKeys[i]; + for (FCDAnimatedList::iterator it = animateds.begin(); it != animateds.end(); ++it) + { + // Sample each animated, which changes the transform values directly + (*it)->Evaluate(sampleTime); + } + + // Retrieve the new transform matrix for the COLLADA scene node + sampleValues.push_back(node->ToMatrix()); + } + } + + const FloatList& GetSampledAnimationKeys() + { + return sampleKeys; + } + + const FMMatrix44List& GetSampledAnimationMatrices() + { + return sampleValues; + } + + void ClearSampledAnimation() + { + sampleKeys.clear(); + sampleValues.clear(); + } +}; + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeTools.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTargetedEntity.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTargetedEntity.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTargetedEntity.cpp (revision 24247) @@ -1,74 +1,74 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDSceneNode.h" -#include "FCDocument/FCDTargetedEntity.h" - -// -// FCDTargetedEntity -// - -ImplementObjectType(FCDTargetedEntity); -ImplementParameterObjectNoCtr(FCDTargetedEntity, FCDSceneNode, targetNode) - -FCDTargetedEntity::FCDTargetedEntity(FCDocument* document, const char* className) -: FCDEntity(document, className) -, InitializeParameterNoArg(targetNode) -{ -} - -FCDTargetedEntity::~FCDTargetedEntity() -{ -} - -// Sets a new target -void FCDTargetedEntity::SetTargetNode(FCDSceneNode* target) -{ - if (targetNode != NULL) - { - targetNode->DecrementTargetCount(); - } - - targetNode = target; - - if (targetNode != NULL) - { - targetNode->IncrementTargetCount(); - } - - SetNewChildFlag(); -} - -FCDEntity* FCDTargetedEntity::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - if (_clone == NULL) - { - _clone = new FCDTargetedEntity(const_cast(GetDocument()), "TargetedEntity"); - } - - // Clone the base class variables - FCDEntity::Clone(_clone, cloneChildren); - - if (_clone->HasType(FCDTargetedEntity::GetClassType())) - { - FCDTargetedEntity* clone = (FCDTargetedEntity*) _clone; - // Copy the target information over. - clone->SetTargetNode(const_cast((const FCDSceneNode*)targetNode)); - } - - return _clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDSceneNode.h" +#include "FCDocument/FCDTargetedEntity.h" + +// +// FCDTargetedEntity +// + +ImplementObjectType(FCDTargetedEntity); +ImplementParameterObjectNoCtr(FCDTargetedEntity, FCDSceneNode, targetNode) + +FCDTargetedEntity::FCDTargetedEntity(FCDocument* document, const char* className) +: FCDEntity(document, className) +, InitializeParameterNoArg(targetNode) +{ +} + +FCDTargetedEntity::~FCDTargetedEntity() +{ +} + +// Sets a new target +void FCDTargetedEntity::SetTargetNode(FCDSceneNode* target) +{ + if (targetNode != NULL) + { + targetNode->DecrementTargetCount(); + } + + targetNode = target; + + if (targetNode != NULL) + { + targetNode->IncrementTargetCount(); + } + + SetNewChildFlag(); +} + +FCDEntity* FCDTargetedEntity::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + if (_clone == NULL) + { + _clone = new FCDTargetedEntity(const_cast(GetDocument()), "TargetedEntity"); + } + + // Clone the base class variables + FCDEntity::Clone(_clone, cloneChildren); + + if (_clone->HasType(FCDTargetedEntity::GetClassType())) + { + FCDTargetedEntity* clone = (FCDTargetedEntity*) _clone; + // Copy the target information over. + clone->SetTargetNode(const_cast((const FCDSceneNode*)targetNode)); + } + + return _clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTargetedEntity.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsAnalyticalGeometry.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsAnalyticalGeometry.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsAnalyticalGeometry.cpp (revision 24247) @@ -1,292 +1,292 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDPhysicsAnalyticalGeometry.h" -#include "FCDocument/FCDocument.h" -#include "FMath/FMVolume.h" - -// -// FCDPhysicsAnalyticalGeometry -// - -ImplementObjectType(FCDPhysicsAnalyticalGeometry); - -FCDPhysicsAnalyticalGeometry::FCDPhysicsAnalyticalGeometry(FCDocument* document) -: FCDEntity(document, "AnalyticalGeometry") -{ -} - -FCDPhysicsAnalyticalGeometry::~FCDPhysicsAnalyticalGeometry() -{ -} - -FCDEntity* FCDPhysicsAnalyticalGeometry::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - // FCDPhysicsAnalyticalGeometry has no data values to clone. - // It is also abstract and cannot be created if (_clone == NULL). - return Parent::Clone(_clone, cloneChildren); -} - -// -// FCDPASBox -// - -ImplementObjectType(FCDPASBox); - -FCDPASBox::FCDPASBox(FCDocument* document) -: FCDPhysicsAnalyticalGeometry(document) -{ - halfExtents.x = halfExtents.y = halfExtents.z = 0.f; -} - -FCDEntity* FCDPASBox::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPASBox* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPASBox(const_cast(GetDocument())); - else if (_clone->HasType(FCDPASBox::GetClassType())) clone = (FCDPASBox*) _clone; - - Parent::Clone(clone, cloneChildren); - - if (clone != NULL) - { - clone->halfExtents = halfExtents; - } - return _clone; -} - -float FCDPASBox::CalculateVolume() const -{ - return FMVolume::CalculateBoxVolume(halfExtents); -} - -// -// FCDPASPlane -// - -ImplementObjectType(FCDPASPlane); - -FCDPASPlane::FCDPASPlane(FCDocument* document) : FCDPhysicsAnalyticalGeometry(document) -{ - normal.x = normal.y = normal.z = d = 0.f; -} - -FCDEntity* FCDPASPlane::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPASPlane* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPASPlane(const_cast(GetDocument())); - else if (_clone->HasType(FCDPASPlane::GetClassType())) clone = (FCDPASPlane*) _clone; - - Parent::Clone(clone, cloneChildren); - - if (clone != NULL) - { - clone->normal = normal; - } - return _clone; -} - -float FCDPASPlane::CalculateVolume() const -{ - return 1.0f; -} - -// -// FCDPASSphere -// - -ImplementObjectType(FCDPASSphere); - -FCDPASSphere::FCDPASSphere(FCDocument* document) : FCDPhysicsAnalyticalGeometry(document) -{ - radius = 0.f; -} - -FCDEntity* FCDPASSphere::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPASSphere* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPASSphere(const_cast(GetDocument())); - else if (_clone->HasType(FCDPASSphere::GetClassType())) clone = (FCDPASSphere*) _clone; - - Parent::Clone(clone, cloneChildren); - - if (clone != NULL) - { - clone->radius = radius; - } - return _clone; -} - -float FCDPASSphere::CalculateVolume() const -{ - return FMVolume::CalculateSphereVolume(radius); -} - -// -// FCDPASCylinder -// - -ImplementObjectType(FCDPASCylinder); - -FCDPASCylinder::FCDPASCylinder(FCDocument* document) : FCDPhysicsAnalyticalGeometry(document) -{ - height = 0.f; - radius.x = 0.f; - radius.y = 0.f; -} - -FCDEntity* FCDPASCylinder::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPASCylinder* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPASCylinder(const_cast(GetDocument())); - else if (_clone->HasType(FCDPASCylinder::GetClassType())) clone = (FCDPASCylinder*) _clone; - - Parent::Clone(clone, cloneChildren); - - if (clone != NULL) - { - clone->radius = radius; - clone->height = height; - } - return _clone; -} - -float FCDPASCylinder::CalculateVolume() const -{ - return FMVolume::CalculateCylinderVolume(radius, height); -} - -// -// FCDPASCapsule -// - -ImplementObjectType(FCDPASCapsule); - -FCDPASCapsule::FCDPASCapsule(FCDocument* document) : FCDPhysicsAnalyticalGeometry(document) -{ - height = 0.f; - radius.x = 0.f; - radius.y = 0.f; -} - -FCDEntity* FCDPASCapsule::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPASCapsule* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPASCapsule(const_cast(GetDocument())); - else if (_clone->HasType(FCDPASCapsule::GetClassType())) clone = (FCDPASCapsule*) _clone; - - Parent::Clone(clone, cloneChildren); - - if (clone != NULL) - { - clone->radius = radius; - clone->height = height; - } - return _clone; -} - -float FCDPASCapsule::CalculateVolume() const -{ - return FMVolume::CalculateCapsuleVolume(radius, height); -} - -// -// FCDPASTaperedCapsule -// - -ImplementObjectType(FCDPASTaperedCapsule); - -FCDPASTaperedCapsule::FCDPASTaperedCapsule(FCDocument* document) : FCDPASCapsule(document) -{ - radius2.x = 0.f; - radius2.y = 0.f; -} - -FCDPhysicsAnalyticalGeometry* FCDPASTaperedCapsule::Clone(FCDPhysicsAnalyticalGeometry* _clone, bool cloneChildren) const -{ - FCDPASTaperedCapsule* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPASTaperedCapsule(const_cast(GetDocument())); - else if (_clone->HasType(FCDPASTaperedCapsule::GetClassType())) clone = (FCDPASTaperedCapsule*) _clone; - - Parent::Clone(clone, cloneChildren); - - if (clone != NULL) - { - clone->radius2 = radius2; - } - return _clone; -} - -float FCDPASTaperedCapsule::CalculateVolume() const -{ - if (IsEquivalent(radius, radius2)) // this is a capsule - { - return FMVolume::CalculateCapsuleVolume(radius, height); - } - - // 1 tapered cylinder + 1/2 ellipsoid + 1/2 other ellipsoid - return FMVolume::CalculateTaperedCylinderVolume(radius, radius2, height) - + FMVolume::CalculateEllipsoidEndVolume(radius) / 2.0f + - FMVolume::CalculateEllipsoidEndVolume(radius2) / 2.0f; -} - -// -// FCDPASTaperedCylinder -// - -ImplementObjectType(FCDPASTaperedCylinder); - -FCDPASTaperedCylinder::FCDPASTaperedCylinder(FCDocument* document) : FCDPASCylinder(document) -{ - radius2.x = 0.f; - radius2.y = 0.f; -} - -FCDEntity* FCDPASTaperedCylinder::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPASTaperedCylinder* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPASTaperedCylinder(const_cast(GetDocument())); - else if (_clone->HasType(FCDPASTaperedCylinder::GetClassType())) clone = (FCDPASTaperedCylinder*) _clone; - - Parent::Clone(clone, cloneChildren); - - if (clone != NULL) - { - clone->radius2 = radius2; - } - return _clone; -} - -float FCDPASTaperedCylinder::CalculateVolume() const -{ - if (IsEquivalent(radius, radius2)) // this is a cylinder - { - return FMVolume::CalculateCylinderVolume(radius, height); - } - - return FMVolume::CalculateTaperedCylinderVolume(radius, radius2, height); -} - -// -// FCDPASFactory -// - -FCDPhysicsAnalyticalGeometry* FCDPASFactory::CreatePAS(FCDocument* document, FCDPhysicsAnalyticalGeometry::GeomType type) -{ - switch (type) - { - case FCDPhysicsAnalyticalGeometry::BOX: return new FCDPASBox(document); - case FCDPhysicsAnalyticalGeometry::PLANE: return new FCDPASPlane(document); - case FCDPhysicsAnalyticalGeometry::SPHERE: return new FCDPASSphere(document); - case FCDPhysicsAnalyticalGeometry::CYLINDER: return new FCDPASCylinder(document); - case FCDPhysicsAnalyticalGeometry::CAPSULE: return new FCDPASCapsule(document); - case FCDPhysicsAnalyticalGeometry::TAPERED_CYLINDER: return new FCDPASTaperedCylinder(document); - case FCDPhysicsAnalyticalGeometry::TAPERED_CAPSULE: return new FCDPASTaperedCapsule(document); - default: return NULL; - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDPhysicsAnalyticalGeometry.h" +#include "FCDocument/FCDocument.h" +#include "FMath/FMVolume.h" + +// +// FCDPhysicsAnalyticalGeometry +// + +ImplementObjectType(FCDPhysicsAnalyticalGeometry); + +FCDPhysicsAnalyticalGeometry::FCDPhysicsAnalyticalGeometry(FCDocument* document) +: FCDEntity(document, "AnalyticalGeometry") +{ +} + +FCDPhysicsAnalyticalGeometry::~FCDPhysicsAnalyticalGeometry() +{ +} + +FCDEntity* FCDPhysicsAnalyticalGeometry::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + // FCDPhysicsAnalyticalGeometry has no data values to clone. + // It is also abstract and cannot be created if (_clone == NULL). + return Parent::Clone(_clone, cloneChildren); +} + +// +// FCDPASBox +// + +ImplementObjectType(FCDPASBox); + +FCDPASBox::FCDPASBox(FCDocument* document) +: FCDPhysicsAnalyticalGeometry(document) +{ + halfExtents.x = halfExtents.y = halfExtents.z = 0.f; +} + +FCDEntity* FCDPASBox::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPASBox* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPASBox(const_cast(GetDocument())); + else if (_clone->HasType(FCDPASBox::GetClassType())) clone = (FCDPASBox*) _clone; + + Parent::Clone(clone, cloneChildren); + + if (clone != NULL) + { + clone->halfExtents = halfExtents; + } + return _clone; +} + +float FCDPASBox::CalculateVolume() const +{ + return FMVolume::CalculateBoxVolume(halfExtents); +} + +// +// FCDPASPlane +// + +ImplementObjectType(FCDPASPlane); + +FCDPASPlane::FCDPASPlane(FCDocument* document) : FCDPhysicsAnalyticalGeometry(document) +{ + normal.x = normal.y = normal.z = d = 0.f; +} + +FCDEntity* FCDPASPlane::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPASPlane* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPASPlane(const_cast(GetDocument())); + else if (_clone->HasType(FCDPASPlane::GetClassType())) clone = (FCDPASPlane*) _clone; + + Parent::Clone(clone, cloneChildren); + + if (clone != NULL) + { + clone->normal = normal; + } + return _clone; +} + +float FCDPASPlane::CalculateVolume() const +{ + return 1.0f; +} + +// +// FCDPASSphere +// + +ImplementObjectType(FCDPASSphere); + +FCDPASSphere::FCDPASSphere(FCDocument* document) : FCDPhysicsAnalyticalGeometry(document) +{ + radius = 0.f; +} + +FCDEntity* FCDPASSphere::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPASSphere* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPASSphere(const_cast(GetDocument())); + else if (_clone->HasType(FCDPASSphere::GetClassType())) clone = (FCDPASSphere*) _clone; + + Parent::Clone(clone, cloneChildren); + + if (clone != NULL) + { + clone->radius = radius; + } + return _clone; +} + +float FCDPASSphere::CalculateVolume() const +{ + return FMVolume::CalculateSphereVolume(radius); +} + +// +// FCDPASCylinder +// + +ImplementObjectType(FCDPASCylinder); + +FCDPASCylinder::FCDPASCylinder(FCDocument* document) : FCDPhysicsAnalyticalGeometry(document) +{ + height = 0.f; + radius.x = 0.f; + radius.y = 0.f; +} + +FCDEntity* FCDPASCylinder::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPASCylinder* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPASCylinder(const_cast(GetDocument())); + else if (_clone->HasType(FCDPASCylinder::GetClassType())) clone = (FCDPASCylinder*) _clone; + + Parent::Clone(clone, cloneChildren); + + if (clone != NULL) + { + clone->radius = radius; + clone->height = height; + } + return _clone; +} + +float FCDPASCylinder::CalculateVolume() const +{ + return FMVolume::CalculateCylinderVolume(radius, height); +} + +// +// FCDPASCapsule +// + +ImplementObjectType(FCDPASCapsule); + +FCDPASCapsule::FCDPASCapsule(FCDocument* document) : FCDPhysicsAnalyticalGeometry(document) +{ + height = 0.f; + radius.x = 0.f; + radius.y = 0.f; +} + +FCDEntity* FCDPASCapsule::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPASCapsule* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPASCapsule(const_cast(GetDocument())); + else if (_clone->HasType(FCDPASCapsule::GetClassType())) clone = (FCDPASCapsule*) _clone; + + Parent::Clone(clone, cloneChildren); + + if (clone != NULL) + { + clone->radius = radius; + clone->height = height; + } + return _clone; +} + +float FCDPASCapsule::CalculateVolume() const +{ + return FMVolume::CalculateCapsuleVolume(radius, height); +} + +// +// FCDPASTaperedCapsule +// + +ImplementObjectType(FCDPASTaperedCapsule); + +FCDPASTaperedCapsule::FCDPASTaperedCapsule(FCDocument* document) : FCDPASCapsule(document) +{ + radius2.x = 0.f; + radius2.y = 0.f; +} + +FCDPhysicsAnalyticalGeometry* FCDPASTaperedCapsule::Clone(FCDPhysicsAnalyticalGeometry* _clone, bool cloneChildren) const +{ + FCDPASTaperedCapsule* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPASTaperedCapsule(const_cast(GetDocument())); + else if (_clone->HasType(FCDPASTaperedCapsule::GetClassType())) clone = (FCDPASTaperedCapsule*) _clone; + + Parent::Clone(clone, cloneChildren); + + if (clone != NULL) + { + clone->radius2 = radius2; + } + return _clone; +} + +float FCDPASTaperedCapsule::CalculateVolume() const +{ + if (IsEquivalent(radius, radius2)) // this is a capsule + { + return FMVolume::CalculateCapsuleVolume(radius, height); + } + + // 1 tapered cylinder + 1/2 ellipsoid + 1/2 other ellipsoid + return FMVolume::CalculateTaperedCylinderVolume(radius, radius2, height) + + FMVolume::CalculateEllipsoidEndVolume(radius) / 2.0f + + FMVolume::CalculateEllipsoidEndVolume(radius2) / 2.0f; +} + +// +// FCDPASTaperedCylinder +// + +ImplementObjectType(FCDPASTaperedCylinder); + +FCDPASTaperedCylinder::FCDPASTaperedCylinder(FCDocument* document) : FCDPASCylinder(document) +{ + radius2.x = 0.f; + radius2.y = 0.f; +} + +FCDEntity* FCDPASTaperedCylinder::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPASTaperedCylinder* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPASTaperedCylinder(const_cast(GetDocument())); + else if (_clone->HasType(FCDPASTaperedCylinder::GetClassType())) clone = (FCDPASTaperedCylinder*) _clone; + + Parent::Clone(clone, cloneChildren); + + if (clone != NULL) + { + clone->radius2 = radius2; + } + return _clone; +} + +float FCDPASTaperedCylinder::CalculateVolume() const +{ + if (IsEquivalent(radius, radius2)) // this is a cylinder + { + return FMVolume::CalculateCylinderVolume(radius, height); + } + + return FMVolume::CalculateTaperedCylinderVolume(radius, radius2, height); +} + +// +// FCDPASFactory +// + +FCDPhysicsAnalyticalGeometry* FCDPASFactory::CreatePAS(FCDocument* document, FCDPhysicsAnalyticalGeometry::GeomType type) +{ + switch (type) + { + case FCDPhysicsAnalyticalGeometry::BOX: return new FCDPASBox(document); + case FCDPhysicsAnalyticalGeometry::PLANE: return new FCDPASPlane(document); + case FCDPhysicsAnalyticalGeometry::SPHERE: return new FCDPASSphere(document); + case FCDPhysicsAnalyticalGeometry::CYLINDER: return new FCDPASCylinder(document); + case FCDPhysicsAnalyticalGeometry::CAPSULE: return new FCDPASCapsule(document); + case FCDPhysicsAnalyticalGeometry::TAPERED_CYLINDER: return new FCDPASTaperedCylinder(document); + case FCDPhysicsAnalyticalGeometry::TAPERED_CAPSULE: return new FCDPASTaperedCapsule(document); + default: return NULL; + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsAnalyticalGeometry.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsMaterial.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsMaterial.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsMaterial.cpp (revision 24247) @@ -1,43 +1,43 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDPhysicsMaterial.h" -#include "FUtils/FUStringConversion.h" - -ImplementObjectType(FCDPhysicsMaterial); - -FCDPhysicsMaterial::FCDPhysicsMaterial(FCDocument* document) : FCDEntity(document, "PhysicsMaterial") -{ - staticFriction = 0.f; - dynamicFriction = 0.f; - restitution = 0.f; -} - -FCDPhysicsMaterial::~FCDPhysicsMaterial() -{ -} - -// Cloning -FCDEntity* FCDPhysicsMaterial::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPhysicsMaterial* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPhysicsMaterial(const_cast(GetDocument())); - else if (_clone->HasType(FCDPhysicsMaterial::GetClassType())) clone = (FCDPhysicsMaterial*) _clone; - - Parent::Clone(clone, cloneChildren); - - if (clone != NULL) - { - clone->SetStaticFriction(staticFriction); - clone->SetDynamicFriction(dynamicFriction); - clone->SetRestitution(restitution); - } - return _clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDPhysicsMaterial.h" +#include "FUtils/FUStringConversion.h" + +ImplementObjectType(FCDPhysicsMaterial); + +FCDPhysicsMaterial::FCDPhysicsMaterial(FCDocument* document) : FCDEntity(document, "PhysicsMaterial") +{ + staticFriction = 0.f; + dynamicFriction = 0.f; + restitution = 0.f; +} + +FCDPhysicsMaterial::~FCDPhysicsMaterial() +{ +} + +// Cloning +FCDEntity* FCDPhysicsMaterial::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPhysicsMaterial* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPhysicsMaterial(const_cast(GetDocument())); + else if (_clone->HasType(FCDPhysicsMaterial::GetClassType())) clone = (FCDPhysicsMaterial*) _clone; + + Parent::Clone(clone, cloneChildren); + + if (clone != NULL) + { + clone->SetStaticFriction(staticFriction); + clone->SetDynamicFriction(dynamicFriction); + clone->SetRestitution(restitution); + } + return _clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsMaterial.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModelInstance.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModelInstance.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModelInstance.cpp (revision 24247) @@ -1,106 +1,106 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDEntity.h" -#include "FCDocument/FCDForceField.h" -#include "FCDocument/FCDPhysicsForceFieldInstance.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDPhysicsModel.h" -#include "FCDocument/FCDPhysicsModelInstance.h" -#include "FCDocument/FCDPhysicsRigidBodyInstance.h" -#include "FCDocument/FCDPhysicsRigidConstraintInstance.h" -#include "FUtils/FUUniqueStringMap.h" -#include "FUtils/FUUri.h" - -// -// FCDPhysicsModelInstance -// - -ImplementObjectType(FCDPhysicsModelInstance); -ImplementParameterObjectNoCtr(FCDPhysicsModelInstance, FCDEntityInstance, instances); - -FCDPhysicsModelInstance::FCDPhysicsModelInstance(FCDocument* document) -: FCDEntityInstance(document, NULL, FCDEntity::PHYSICS_MODEL) -, InitializeParameterNoArg(instances) -{ -} - -FCDPhysicsModelInstance::~FCDPhysicsModelInstance() -{ -} - -FCDPhysicsRigidBodyInstance* FCDPhysicsModelInstance::AddRigidBodyInstance(FCDPhysicsRigidBody* rigidBody) -{ - FCDPhysicsRigidBodyInstance* instance = new FCDPhysicsRigidBodyInstance(GetDocument(), this, rigidBody); - instances.push_back(instance); - SetNewChildFlag(); - return instance; -} - -FCDPhysicsRigidConstraintInstance* FCDPhysicsModelInstance::AddRigidConstraintInstance(FCDPhysicsRigidConstraint* rigidConstraint) -{ - FCDPhysicsRigidConstraintInstance* instance = new FCDPhysicsRigidConstraintInstance(GetDocument(), this, rigidConstraint); - instances.push_back(instance); - SetNewChildFlag(); - return instance; -} - -FCDPhysicsForceFieldInstance* FCDPhysicsModelInstance::AddForceFieldInstance(FCDForceField* forceField) -{ - FCDEntityInstance* instance = FCDEntityInstanceFactory::CreateInstance(GetDocument(), (FCDSceneNode*) NULL, forceField); - instances.push_back(instance); - SetNewChildFlag(); - return (FCDPhysicsForceFieldInstance*)instance; -} - -bool FCDPhysicsModelInstance::RemoveInstance(FCDEntityInstance* instance) -{ - SAFE_RELEASE(instance); - return true; -} - -FCDEntityInstance* FCDPhysicsModelInstance::Clone(FCDEntityInstance* _clone) const -{ - FCDPhysicsModelInstance* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPhysicsModelInstance(const_cast(GetDocument())); - else if (_clone->HasType(FCDPhysicsModelInstance::GetClassType())) clone = (FCDPhysicsModelInstance*) _clone; - - Parent::Clone(_clone); - - if (clone != NULL) - { - for (const FCDEntityInstance** it = instances.begin(); it != instances.end(); ++it) - { - FCDEntityInstance* clonedInstance = NULL; - switch ((*it)->GetEntityType()) - { - case FCDEntity::PHYSICS_RIGID_BODY: clonedInstance = clone->AddRigidBodyInstance(); break; - case FCDEntity::PHYSICS_RIGID_CONSTRAINT: clonedInstance = clone->AddRigidConstraintInstance(); break; - case FCDEntity::FORCE_FIELD: clonedInstance = clone->AddForceFieldInstance(); break; - default: FUFail(break); - } - if (clonedInstance != NULL) (*it)->Clone(clonedInstance); - } - } - return _clone; -} - -void FCDPhysicsModelInstance::CleanSubId(FUSUniqueStringMap* parentStringMap) -{ - Parent::CleanSubId(parentStringMap); - FUSUniqueStringMap myStringMap; - - size_t subInstanceCount = instances.size(); - for (size_t i = 0; i < subInstanceCount; ++i) - { - instances[i]->CleanSubId(&myStringMap); - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDEntity.h" +#include "FCDocument/FCDForceField.h" +#include "FCDocument/FCDPhysicsForceFieldInstance.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDPhysicsModel.h" +#include "FCDocument/FCDPhysicsModelInstance.h" +#include "FCDocument/FCDPhysicsRigidBodyInstance.h" +#include "FCDocument/FCDPhysicsRigidConstraintInstance.h" +#include "FUtils/FUUniqueStringMap.h" +#include "FUtils/FUUri.h" + +// +// FCDPhysicsModelInstance +// + +ImplementObjectType(FCDPhysicsModelInstance); +ImplementParameterObjectNoCtr(FCDPhysicsModelInstance, FCDEntityInstance, instances); + +FCDPhysicsModelInstance::FCDPhysicsModelInstance(FCDocument* document) +: FCDEntityInstance(document, NULL, FCDEntity::PHYSICS_MODEL) +, InitializeParameterNoArg(instances) +{ +} + +FCDPhysicsModelInstance::~FCDPhysicsModelInstance() +{ +} + +FCDPhysicsRigidBodyInstance* FCDPhysicsModelInstance::AddRigidBodyInstance(FCDPhysicsRigidBody* rigidBody) +{ + FCDPhysicsRigidBodyInstance* instance = new FCDPhysicsRigidBodyInstance(GetDocument(), this, rigidBody); + instances.push_back(instance); + SetNewChildFlag(); + return instance; +} + +FCDPhysicsRigidConstraintInstance* FCDPhysicsModelInstance::AddRigidConstraintInstance(FCDPhysicsRigidConstraint* rigidConstraint) +{ + FCDPhysicsRigidConstraintInstance* instance = new FCDPhysicsRigidConstraintInstance(GetDocument(), this, rigidConstraint); + instances.push_back(instance); + SetNewChildFlag(); + return instance; +} + +FCDPhysicsForceFieldInstance* FCDPhysicsModelInstance::AddForceFieldInstance(FCDForceField* forceField) +{ + FCDEntityInstance* instance = FCDEntityInstanceFactory::CreateInstance(GetDocument(), (FCDSceneNode*) NULL, forceField); + instances.push_back(instance); + SetNewChildFlag(); + return (FCDPhysicsForceFieldInstance*)instance; +} + +bool FCDPhysicsModelInstance::RemoveInstance(FCDEntityInstance* instance) +{ + SAFE_RELEASE(instance); + return true; +} + +FCDEntityInstance* FCDPhysicsModelInstance::Clone(FCDEntityInstance* _clone) const +{ + FCDPhysicsModelInstance* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPhysicsModelInstance(const_cast(GetDocument())); + else if (_clone->HasType(FCDPhysicsModelInstance::GetClassType())) clone = (FCDPhysicsModelInstance*) _clone; + + Parent::Clone(_clone); + + if (clone != NULL) + { + for (const FCDEntityInstance** it = instances.begin(); it != instances.end(); ++it) + { + FCDEntityInstance* clonedInstance = NULL; + switch ((*it)->GetEntityType()) + { + case FCDEntity::PHYSICS_RIGID_BODY: clonedInstance = clone->AddRigidBodyInstance(); break; + case FCDEntity::PHYSICS_RIGID_CONSTRAINT: clonedInstance = clone->AddRigidConstraintInstance(); break; + case FCDEntity::FORCE_FIELD: clonedInstance = clone->AddForceFieldInstance(); break; + default: FUFail(break); + } + if (clonedInstance != NULL) (*it)->Clone(clonedInstance); + } + } + return _clone; +} + +void FCDPhysicsModelInstance::CleanSubId(FUSUniqueStringMap* parentStringMap) +{ + Parent::CleanSubId(parentStringMap); + FUSUniqueStringMap myStringMap; + + size_t subInstanceCount = instances.size(); + for (size_t i = 0; i < subInstanceCount; ++i) + { + instances[i]->CleanSubId(&myStringMap); + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsModelInstance.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyInstance.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyInstance.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyInstance.cpp (revision 24247) @@ -1,83 +1,83 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDPhysicsModel.h" -#include "FCDocument/FCDPhysicsModelInstance.h" -#include "FCDocument/FCDPhysicsRigidBody.h" -#include "FCDocument/FCDPhysicsRigidBodyInstance.h" -#include "FCDocument/FCDPhysicsRigidBodyParameters.h" -#include "FCDocument/FCDSceneNode.h" -#include "FUtils/FUEvent.h" -#include "FUtils/FUUri.h" - -// -// FCDPhysicsRigidBodyInstance -// - -ImplementObjectType(FCDPhysicsRigidBodyInstance); -ImplementParameterObject(FCDPhysicsRigidBodyInstance, FCDPhysicsRigidBodyParameters, parameters, new FCDPhysicsRigidBodyParameters(parent->GetDocument(), parent)); -ImplementParameterObjectNoCtr(FCDPhysicsRigidBodyInstance, FCDSceneNode, targetNode); - -FCDPhysicsRigidBodyInstance::FCDPhysicsRigidBodyInstance(FCDocument* document, FCDPhysicsModelInstance* _parent, FCDPhysicsRigidBody* body) -: FCDEntityInstance(document, NULL, FCDEntity::PHYSICS_RIGID_BODY) -, parent(_parent), onCollisionEvent(NULL) -, InitializeParameterAnimatable(velocity, FMVector3::Zero) -, InitializeParameterAnimatable(angularVelocity, FMVector3::Zero) -, InitializeParameterNoArg(parameters) -, InitializeParameterNoArg(targetNode) -{ - onCollisionEvent = new CollisionEvent(); - parameters = new FCDPhysicsRigidBodyParameters(document, this); - if (body != NULL) SetRigidBody(body); -} - -FCDPhysicsRigidBodyInstance::~FCDPhysicsRigidBodyInstance() -{ - parent = NULL; - SAFE_DELETE(onCollisionEvent); -} - -FCDEntityInstance* FCDPhysicsRigidBodyInstance::Clone(FCDEntityInstance* _clone) const -{ - FCDPhysicsRigidBodyInstance* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPhysicsRigidBodyInstance(const_cast(GetDocument()), NULL, NULL); - else clone = DynamicCast(_clone); - - Parent::Clone(_clone); - - if (clone != NULL) - { - clone->angularVelocity = angularVelocity; - clone->velocity = velocity; - clone->GetParameters()->CopyFrom(*parameters); - - // Intentionally leave the target scene node as NULL. - } - return _clone; -} - -void FCDPhysicsRigidBodyInstance::SetRigidBody(FCDPhysicsRigidBody* body) -{ - FUAssert(body != NULL, return); - - SetEntity(body); - - // copy some of the default values from the body - FCDPhysicsRigidBodyParameters* bodyParams = body->GetParameters(); - parameters->SetDynamic(bodyParams->IsDynamic()); - parameters->SetMass(bodyParams->GetMass()); - parameters->SetMassFrameTranslate(bodyParams->GetMassFrameTranslate()); - parameters->SetMassFrameRotateAxis(bodyParams->GetMassFrameRotateAxis()); - parameters->SetMassFrameRotateAngle(bodyParams->GetMassFrameRotateAngle()); - parameters->SetInertia(bodyParams->GetInertia()); - parameters->SetDensity(bodyParams->GetDensity()); - parameters->SetDensityMoreAccurate(bodyParams->IsDensityMoreAccurate()); - parameters->SetInertiaAccurate(bodyParams->IsInertiaAccurate()); -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDPhysicsModel.h" +#include "FCDocument/FCDPhysicsModelInstance.h" +#include "FCDocument/FCDPhysicsRigidBody.h" +#include "FCDocument/FCDPhysicsRigidBodyInstance.h" +#include "FCDocument/FCDPhysicsRigidBodyParameters.h" +#include "FCDocument/FCDSceneNode.h" +#include "FUtils/FUEvent.h" +#include "FUtils/FUUri.h" + +// +// FCDPhysicsRigidBodyInstance +// + +ImplementObjectType(FCDPhysicsRigidBodyInstance); +ImplementParameterObject(FCDPhysicsRigidBodyInstance, FCDPhysicsRigidBodyParameters, parameters, new FCDPhysicsRigidBodyParameters(parent->GetDocument(), parent)); +ImplementParameterObjectNoCtr(FCDPhysicsRigidBodyInstance, FCDSceneNode, targetNode); + +FCDPhysicsRigidBodyInstance::FCDPhysicsRigidBodyInstance(FCDocument* document, FCDPhysicsModelInstance* _parent, FCDPhysicsRigidBody* body) +: FCDEntityInstance(document, NULL, FCDEntity::PHYSICS_RIGID_BODY) +, parent(_parent), onCollisionEvent(NULL) +, InitializeParameterAnimatable(velocity, FMVector3::Zero) +, InitializeParameterAnimatable(angularVelocity, FMVector3::Zero) +, InitializeParameterNoArg(parameters) +, InitializeParameterNoArg(targetNode) +{ + onCollisionEvent = new CollisionEvent(); + parameters = new FCDPhysicsRigidBodyParameters(document, this); + if (body != NULL) SetRigidBody(body); +} + +FCDPhysicsRigidBodyInstance::~FCDPhysicsRigidBodyInstance() +{ + parent = NULL; + SAFE_DELETE(onCollisionEvent); +} + +FCDEntityInstance* FCDPhysicsRigidBodyInstance::Clone(FCDEntityInstance* _clone) const +{ + FCDPhysicsRigidBodyInstance* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPhysicsRigidBodyInstance(const_cast(GetDocument()), NULL, NULL); + else clone = DynamicCast(_clone); + + Parent::Clone(_clone); + + if (clone != NULL) + { + clone->angularVelocity = angularVelocity; + clone->velocity = velocity; + clone->GetParameters()->CopyFrom(*parameters); + + // Intentionally leave the target scene node as NULL. + } + return _clone; +} + +void FCDPhysicsRigidBodyInstance::SetRigidBody(FCDPhysicsRigidBody* body) +{ + FUAssert(body != NULL, return); + + SetEntity(body); + + // copy some of the default values from the body + FCDPhysicsRigidBodyParameters* bodyParams = body->GetParameters(); + parameters->SetDynamic(bodyParams->IsDynamic()); + parameters->SetMass(bodyParams->GetMass()); + parameters->SetMassFrameTranslate(bodyParams->GetMassFrameTranslate()); + parameters->SetMassFrameRotateAxis(bodyParams->GetMassFrameRotateAxis()); + parameters->SetMassFrameRotateAngle(bodyParams->GetMassFrameRotateAngle()); + parameters->SetInertia(bodyParams->GetInertia()); + parameters->SetDensity(bodyParams->GetDensity()); + parameters->SetDensityMoreAccurate(bodyParams->IsDensityMoreAccurate()); + parameters->SetInertiaAccurate(bodyParams->IsInertiaAccurate()); +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidBodyInstance.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraint.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraint.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraint.cpp (revision 24247) @@ -1,116 +1,116 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDPhysicsModel.h" -#include "FCDocument/FCDPhysicsRigidConstraint.h" -#include "FCDocument/FCDPhysicsRigidBody.h" -#include "FCDocument/FCDTransform.h" -#include "FCDocument/FCDSceneNode.h" -#include "FCDocument/FCDAnimated.h" -#include "FUtils/FUStringConversion.h" - -// -// FCDPhysicsRigidConstraint -// - -ImplementObjectType(FCDPhysicsRigidConstraint); - -FCDPhysicsRigidConstraint::FCDPhysicsRigidConstraint(FCDocument* document, FCDPhysicsModel* _parent) -: FCDEntity(document, "PhysicsRigidConstraint") -, parent(_parent) -, InitializeParameterAnimatable(enabled, 1.0f) -, InitializeParameterAnimatable(interpenetrate, 0.0f) -, InitializeParameter(limitsLinearMin, FMVector3::Zero) -, InitializeParameter(limitsLinearMax, FMVector3::Zero) -, InitializeParameter(limitsSCTMin, FMVector3::Zero) -, InitializeParameter(limitsSCTMax, FMVector3::Zero) -, InitializeParameter(springLinearStiffness, 1.0f) -, InitializeParameter(springLinearDamping, 0.0f) -, InitializeParameter(springLinearTargetValue, 0.0f) -, InitializeParameter(springAngularStiffness, 1.0f) -, InitializeParameter(springAngularDamping, 0.0f) -, InitializeParameter(springAngularTargetValue, 0.0f) -{ -} - -FCDPhysicsRigidConstraint::~FCDPhysicsRigidConstraint() -{ - referenceRigidBody = NULL; - targetRigidBody = NULL; - transformsTar.clear(); - transformsRef.clear(); -} - -FCDTransform* FCDPhysicsRigidConstraint::AddTransformRef(FCDTransform::Type type, size_t index) -{ - FCDTransform* transform = FCDTFactory::CreateTransform(GetDocument(), NULL, type); - if (transform != NULL) - { - if (index > transformsRef.size()) transformsRef.push_back(transform); - else transformsRef.insert(transformsRef.begin() + index, transform); - } - SetNewChildFlag(); - return transform; -} - -FCDTransform* FCDPhysicsRigidConstraint::AddTransformTar(FCDTransform::Type type, size_t index) -{ - FCDTransform* transform = FCDTFactory::CreateTransform(GetDocument(), NULL, type); - if (transform != NULL) - { - if (index > transformsTar.size()) transformsTar.push_back(transform); - else transformsTar.insert(transformsTar.begin() + index, transform); - } - SetNewChildFlag(); - return transform; -} - -// Create a copy of this physicsRigidConstraint, with the vertices overwritten -FCDEntity* FCDPhysicsRigidConstraint::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPhysicsRigidConstraint* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPhysicsRigidConstraint(const_cast(GetDocument()), NULL); - else if (_clone->HasType(FCDPhysicsRigidConstraint::GetClassType())) clone = (FCDPhysicsRigidConstraint*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone != NULL) - { - clone->enabled = enabled; - clone->interpenetrate = interpenetrate; - clone->referenceRigidBody = referenceRigidBody; - clone->referenceNode = referenceNode; - clone->targetRigidBody = targetRigidBody; - clone->targetNode = targetNode; - clone->limitsLinearMax = limitsLinearMax; - clone->limitsLinearMin = limitsLinearMin; - clone->limitsSCTMax = limitsSCTMax; - clone->limitsSCTMin = limitsSCTMin; - clone->springAngularDamping = springAngularDamping; - clone->springAngularStiffness = springAngularStiffness; - clone->springAngularTargetValue = springAngularTargetValue; - clone->springLinearDamping = springLinearDamping; - clone->springLinearStiffness = springLinearStiffness; - clone->springLinearTargetValue = springLinearTargetValue; - - // Clone the transforms - for (FCDTransformContainer::const_iterator it = transformsRef.begin(); it != transformsRef.end(); ++it) - { - FCDTransform* clonedTransform = clone->AddTransformRef((*it)->GetType()); - (*it)->Clone(clonedTransform); - } - for (FCDTransformContainer::const_iterator it = transformsTar.begin(); it != transformsTar.end(); ++it) - { - FCDTransform* clonedTransform = clone->AddTransformTar((*it)->GetType()); - (*it)->Clone(clonedTransform); - } - } - return _clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDPhysicsModel.h" +#include "FCDocument/FCDPhysicsRigidConstraint.h" +#include "FCDocument/FCDPhysicsRigidBody.h" +#include "FCDocument/FCDTransform.h" +#include "FCDocument/FCDSceneNode.h" +#include "FCDocument/FCDAnimated.h" +#include "FUtils/FUStringConversion.h" + +// +// FCDPhysicsRigidConstraint +// + +ImplementObjectType(FCDPhysicsRigidConstraint); + +FCDPhysicsRigidConstraint::FCDPhysicsRigidConstraint(FCDocument* document, FCDPhysicsModel* _parent) +: FCDEntity(document, "PhysicsRigidConstraint") +, parent(_parent) +, InitializeParameterAnimatable(enabled, 1.0f) +, InitializeParameterAnimatable(interpenetrate, 0.0f) +, InitializeParameter(limitsLinearMin, FMVector3::Zero) +, InitializeParameter(limitsLinearMax, FMVector3::Zero) +, InitializeParameter(limitsSCTMin, FMVector3::Zero) +, InitializeParameter(limitsSCTMax, FMVector3::Zero) +, InitializeParameter(springLinearStiffness, 1.0f) +, InitializeParameter(springLinearDamping, 0.0f) +, InitializeParameter(springLinearTargetValue, 0.0f) +, InitializeParameter(springAngularStiffness, 1.0f) +, InitializeParameter(springAngularDamping, 0.0f) +, InitializeParameter(springAngularTargetValue, 0.0f) +{ +} + +FCDPhysicsRigidConstraint::~FCDPhysicsRigidConstraint() +{ + referenceRigidBody = NULL; + targetRigidBody = NULL; + transformsTar.clear(); + transformsRef.clear(); +} + +FCDTransform* FCDPhysicsRigidConstraint::AddTransformRef(FCDTransform::Type type, size_t index) +{ + FCDTransform* transform = FCDTFactory::CreateTransform(GetDocument(), NULL, type); + if (transform != NULL) + { + if (index > transformsRef.size()) transformsRef.push_back(transform); + else transformsRef.insert(transformsRef.begin() + index, transform); + } + SetNewChildFlag(); + return transform; +} + +FCDTransform* FCDPhysicsRigidConstraint::AddTransformTar(FCDTransform::Type type, size_t index) +{ + FCDTransform* transform = FCDTFactory::CreateTransform(GetDocument(), NULL, type); + if (transform != NULL) + { + if (index > transformsTar.size()) transformsTar.push_back(transform); + else transformsTar.insert(transformsTar.begin() + index, transform); + } + SetNewChildFlag(); + return transform; +} + +// Create a copy of this physicsRigidConstraint, with the vertices overwritten +FCDEntity* FCDPhysicsRigidConstraint::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPhysicsRigidConstraint* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPhysicsRigidConstraint(const_cast(GetDocument()), NULL); + else if (_clone->HasType(FCDPhysicsRigidConstraint::GetClassType())) clone = (FCDPhysicsRigidConstraint*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone != NULL) + { + clone->enabled = enabled; + clone->interpenetrate = interpenetrate; + clone->referenceRigidBody = referenceRigidBody; + clone->referenceNode = referenceNode; + clone->targetRigidBody = targetRigidBody; + clone->targetNode = targetNode; + clone->limitsLinearMax = limitsLinearMax; + clone->limitsLinearMin = limitsLinearMin; + clone->limitsSCTMax = limitsSCTMax; + clone->limitsSCTMin = limitsSCTMin; + clone->springAngularDamping = springAngularDamping; + clone->springAngularStiffness = springAngularStiffness; + clone->springAngularTargetValue = springAngularTargetValue; + clone->springLinearDamping = springLinearDamping; + clone->springLinearStiffness = springLinearStiffness; + clone->springLinearTargetValue = springLinearTargetValue; + + // Clone the transforms + for (FCDTransformContainer::const_iterator it = transformsRef.begin(); it != transformsRef.end(); ++it) + { + FCDTransform* clonedTransform = clone->AddTransformRef((*it)->GetType()); + (*it)->Clone(clonedTransform); + } + for (FCDTransformContainer::const_iterator it = transformsTar.begin(); it != transformsTar.end(); ++it) + { + FCDTransform* clonedTransform = clone->AddTransformTar((*it)->GetType()); + (*it)->Clone(clonedTransform); + } + } + return _clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsRigidConstraint.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsScene.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsScene.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsScene.cpp (revision 24247) @@ -1,101 +1,101 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDPhysicsModel.h" -#include "FCDocument/FCDPhysicsModelInstance.h" -#include "FCDocument/FCDForceField.h" -#include "FCDocument/FCDPhysicsForceFieldInstance.h" -#include "FCDocument/FCDPhysicsScene.h" -#include "FUtils/FUFileManager.h" -#include "FUtils/FUStringConversion.h" -#include "FUtils/FUUniqueStringMap.h" -#include "FCDocument/FCDExtra.h" - -ImplementObjectType(FCDPhysicsScene); - -FCDPhysicsScene::FCDPhysicsScene(FCDocument* document) -: FCDEntity(document, "PhysicsSceneNode") -, gravity(0.0f, -9.8f, 0.0f), timestep(1.0f) -{ -} - -FCDPhysicsScene::~FCDPhysicsScene() -{ -} - -FCDEntity* FCDPhysicsScene::Clone(FCDEntity* _clone, bool cloneChildren) const -{ - FCDPhysicsScene* clone = NULL; - if (_clone == NULL) _clone = clone = new FCDPhysicsScene(const_cast(GetDocument())); - else if (_clone->HasType(FCDPhysicsScene::GetClassType())) clone = (FCDPhysicsScene*) _clone; - - Parent::Clone(_clone, cloneChildren); - - if (clone == NULL) - { - // Clone the miscellaneous parameters - clone->gravity = gravity; - clone->timestep = timestep; - - // Clone the physics model instances - for (FCDPhysicsModelInstanceContainer::const_iterator it = physicsModelInstances.begin(); it != physicsModelInstances.end(); ++it) - { - FCDPhysicsModelInstance* clonedInstance = clone->AddPhysicsModelInstance(); - (*it)->Clone(clonedInstance); - } - - // Clone the force field instances - for (FCDForceFieldInstanceContainer::const_iterator it = forceFieldInstances.begin(); it != forceFieldInstances.end(); ++it) - { - FCDPhysicsForceFieldInstance* clonedInstance = clone->AddForceFieldInstance(); - (*it)->Clone(clonedInstance); - } - } - return _clone; -} - -FCDPhysicsModelInstance* FCDPhysicsScene::AddPhysicsModelInstance(FCDPhysicsModel* model) -{ - FCDPhysicsModelInstance* instance = physicsModelInstances.Add(GetDocument()); - instance->SetEntity(model); - SetNewChildFlag(); - return instance; -} - -FCDPhysicsForceFieldInstance* FCDPhysicsScene::AddForceFieldInstance(FCDForceField* forceField) -{ - FCDPhysicsForceFieldInstance* instance = (FCDPhysicsForceFieldInstance*) - FCDEntityInstanceFactory::CreateInstance( - GetDocument(), (FCDSceneNode*) NULL, forceField); - forceFieldInstances.push_back(instance); - SetNewChildFlag(); - return instance; -} - -void FCDPhysicsScene::CleanSubId() -{ - FUSUniqueStringMap myStringMap; - - for (FCDForceFieldInstanceContainer::iterator itI = forceFieldInstances.begin(); itI != forceFieldInstances.end(); ++itI) - { - (*itI)->CleanSubId(&myStringMap); - } - - for (FCDPhysicsModelInstanceContainer::iterator itI = physicsModelInstances.begin(); itI != physicsModelInstances.end(); ++itI) - { - (*itI)->CleanSubId(&myStringMap); - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDPhysicsModel.h" +#include "FCDocument/FCDPhysicsModelInstance.h" +#include "FCDocument/FCDForceField.h" +#include "FCDocument/FCDPhysicsForceFieldInstance.h" +#include "FCDocument/FCDPhysicsScene.h" +#include "FUtils/FUFileManager.h" +#include "FUtils/FUStringConversion.h" +#include "FUtils/FUUniqueStringMap.h" +#include "FCDocument/FCDExtra.h" + +ImplementObjectType(FCDPhysicsScene); + +FCDPhysicsScene::FCDPhysicsScene(FCDocument* document) +: FCDEntity(document, "PhysicsSceneNode") +, gravity(0.0f, -9.8f, 0.0f), timestep(1.0f) +{ +} + +FCDPhysicsScene::~FCDPhysicsScene() +{ +} + +FCDEntity* FCDPhysicsScene::Clone(FCDEntity* _clone, bool cloneChildren) const +{ + FCDPhysicsScene* clone = NULL; + if (_clone == NULL) _clone = clone = new FCDPhysicsScene(const_cast(GetDocument())); + else if (_clone->HasType(FCDPhysicsScene::GetClassType())) clone = (FCDPhysicsScene*) _clone; + + Parent::Clone(_clone, cloneChildren); + + if (clone == NULL) + { + // Clone the miscellaneous parameters + clone->gravity = gravity; + clone->timestep = timestep; + + // Clone the physics model instances + for (FCDPhysicsModelInstanceContainer::const_iterator it = physicsModelInstances.begin(); it != physicsModelInstances.end(); ++it) + { + FCDPhysicsModelInstance* clonedInstance = clone->AddPhysicsModelInstance(); + (*it)->Clone(clonedInstance); + } + + // Clone the force field instances + for (FCDForceFieldInstanceContainer::const_iterator it = forceFieldInstances.begin(); it != forceFieldInstances.end(); ++it) + { + FCDPhysicsForceFieldInstance* clonedInstance = clone->AddForceFieldInstance(); + (*it)->Clone(clonedInstance); + } + } + return _clone; +} + +FCDPhysicsModelInstance* FCDPhysicsScene::AddPhysicsModelInstance(FCDPhysicsModel* model) +{ + FCDPhysicsModelInstance* instance = physicsModelInstances.Add(GetDocument()); + instance->SetEntity(model); + SetNewChildFlag(); + return instance; +} + +FCDPhysicsForceFieldInstance* FCDPhysicsScene::AddForceFieldInstance(FCDForceField* forceField) +{ + FCDPhysicsForceFieldInstance* instance = (FCDPhysicsForceFieldInstance*) + FCDEntityInstanceFactory::CreateInstance( + GetDocument(), (FCDSceneNode*) NULL, forceField); + forceFieldInstances.push_back(instance); + SetNewChildFlag(); + return instance; +} + +void FCDPhysicsScene::CleanSubId() +{ + FUSUniqueStringMap myStringMap; + + for (FCDForceFieldInstanceContainer::iterator itI = forceFieldInstances.begin(); itI != forceFieldInstances.end(); ++itI) + { + (*itI)->CleanSubId(&myStringMap); + } + + for (FCDPhysicsModelInstanceContainer::iterator itI = physicsModelInstances.begin(); itI != physicsModelInstances.end(); ++itI) + { + (*itI)->CleanSubId(&myStringMap); + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPhysicsScene.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPlaceHolder.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPlaceHolder.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPlaceHolder.cpp (revision 24247) @@ -1,124 +1,124 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEntityInstance.h" -#include "FCDocument/FCDEntityReference.h" -#include "FCDocument/FCDExternalReferenceManager.h" -#include "FCDocument/FCDPlaceHolder.h" -#include "FUtils/FUFileManager.h" - -// -// FCDPlaceHolder -// - -ImplementObjectType(FCDPlaceHolder); - -FCDPlaceHolder::FCDPlaceHolder(FCDocument* document, FCDocument* _target) -: FCDObject(document) -, target(_target) -{ - if (target != NULL) - { - TrackObject(target); - fileUrl = target->GetFileUrl(); - } -} - -FCDPlaceHolder::~FCDPlaceHolder() -{ - if (target != NULL) - { - UntrackObject(target); - if (target->GetTrackerCount() == 0) - { - target->Release(); - } - } -} - -const fstring& FCDPlaceHolder::GetFileUrl() const -{ - return (target != NULL) ? target->GetFileUrl() : fileUrl; -} - -void FCDPlaceHolder::SetFileUrl(const fstring& url) -{ - fileUrl = url; - SetDirtyFlag(); -} - -FCDocument* FCDPlaceHolder::GetTarget(bool loadIfMissing) -{ - if (target == NULL && loadIfMissing) LoadTarget(NULL); - return target; -} - -void FCDPlaceHolder::LoadTarget(FCDocument* newTarget) -{ - if (target == NULL) - { - if (newTarget == NULL) - { - newTarget = new FCDocument(); - FUUri uri(GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(fileUrl)); - fstring filename = uri.GetAbsolutePath(); - -#ifdef _DEBUG - // Check for circular dependencies. - FCDocumentList documents; - FCollada::GetAllDocuments(documents); - for (FCDocument** it = documents.begin(); it != documents.end(); ++it) - { - // If the following asset triggers, you are wrongly forcing XRefs to load during archiving ? - FUAssert(!IsEquivalent((*it)->GetFileUrl(), fileUrl),); - } -#endif // _DEBUG - - // Now, we have to copy over our callback schemes from our document to the new - // one (to ensure that the new document can handle the scheme we was loaded under) - FCDocument* curDoc = GetDocument(); - newTarget->GetFileManager()->CloneSchemeCallbacks(curDoc->GetFileManager()); - - bool loadStatus = FCollada::LoadDocumentFromFile(newTarget, filename.c_str()); - if (!loadStatus) - { - SAFE_DELETE(newTarget); - } - } - - if (newTarget != NULL) - { - if (target != NULL) - { - fileUrl = target->GetFileUrl(); - UntrackObject(target); - target = NULL; - } - target = newTarget; - TrackObject(target); - } - SetNewChildFlag(); - } -} - -void FCDPlaceHolder::UnloadTarget() -{ - SAFE_RELEASE(target); - SetNewChildFlag(); -} - -void FCDPlaceHolder::OnObjectReleased(FUTrackable* object) -{ - if (object == target) - { - fileUrl = target->GetFileUrl(); - target = NULL; - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEntityInstance.h" +#include "FCDocument/FCDEntityReference.h" +#include "FCDocument/FCDExternalReferenceManager.h" +#include "FCDocument/FCDPlaceHolder.h" +#include "FUtils/FUFileManager.h" + +// +// FCDPlaceHolder +// + +ImplementObjectType(FCDPlaceHolder); + +FCDPlaceHolder::FCDPlaceHolder(FCDocument* document, FCDocument* _target) +: FCDObject(document) +, target(_target) +{ + if (target != NULL) + { + TrackObject(target); + fileUrl = target->GetFileUrl(); + } +} + +FCDPlaceHolder::~FCDPlaceHolder() +{ + if (target != NULL) + { + UntrackObject(target); + if (target->GetTrackerCount() == 0) + { + target->Release(); + } + } +} + +const fstring& FCDPlaceHolder::GetFileUrl() const +{ + return (target != NULL) ? target->GetFileUrl() : fileUrl; +} + +void FCDPlaceHolder::SetFileUrl(const fstring& url) +{ + fileUrl = url; + SetDirtyFlag(); +} + +FCDocument* FCDPlaceHolder::GetTarget(bool loadIfMissing) +{ + if (target == NULL && loadIfMissing) LoadTarget(NULL); + return target; +} + +void FCDPlaceHolder::LoadTarget(FCDocument* newTarget) +{ + if (target == NULL) + { + if (newTarget == NULL) + { + newTarget = new FCDocument(); + FUUri uri(GetDocument()->GetFileManager()->GetCurrentUri().MakeAbsolute(fileUrl)); + fstring filename = uri.GetAbsolutePath(); + +#ifdef _DEBUG + // Check for circular dependencies. + FCDocumentList documents; + FCollada::GetAllDocuments(documents); + for (FCDocument** it = documents.begin(); it != documents.end(); ++it) + { + // If the following asset triggers, you are wrongly forcing XRefs to load during archiving ? + FUAssert(!IsEquivalent((*it)->GetFileUrl(), fileUrl),); + } +#endif // _DEBUG + + // Now, we have to copy over our callback schemes from our document to the new + // one (to ensure that the new document can handle the scheme we was loaded under) + FCDocument* curDoc = GetDocument(); + newTarget->GetFileManager()->CloneSchemeCallbacks(curDoc->GetFileManager()); + + bool loadStatus = FCollada::LoadDocumentFromFile(newTarget, filename.c_str()); + if (!loadStatus) + { + SAFE_DELETE(newTarget); + } + } + + if (newTarget != NULL) + { + if (target != NULL) + { + fileUrl = target->GetFileUrl(); + UntrackObject(target); + target = NULL; + } + target = newTarget; + TrackObject(target); + } + SetNewChildFlag(); + } +} + +void FCDPlaceHolder::UnloadTarget() +{ + SAFE_RELEASE(target); + SetNewChildFlag(); +} + +void FCDPlaceHolder::OnObjectReleased(FUTrackable* object) +{ + if (object == target) + { + fileUrl = target->GetFileUrl(); + target = NULL; + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDPlaceHolder.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.h (revision 24247) @@ -1,93 +1,93 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/** - @file FCDSceneNodeIterator.h - This file contains the FCDSceneNodeIteratorT template - and its two definitions: FCDSceneNodeIterator and FCDSceneNodeConstIterator. -*/ - -#ifndef _FCD_SCENE_NODE_ITERATOR_H_ -#define _FCD_SCENE_NODE_ITERATOR_H_ - -class FCDSceneNode; - -/** - This template is used to process a given scene node and its full sub-tree. - We use a template here in order to easily support both const - and non-const scene node data, with the same code. - - Do not use this template directly, instead use the - FCDSceneNodeIterator and FCDSceneNodeConstIterator definitions. - - This template does not care whether multiple instances of the same node is processed. -*/ -template -class FCOLLADA_EXPORT FCDSceneNodeIteratorT -{ -private: - fm::pvector<_NODE> queue; - size_t iterator; - -public: - /** The order in which the scene nodes should be iterated. */ - enum SearchType - { - /** Iterate over the scene nodes one level at a time. Starts from the root - and terminates with the leaves. Each node level is processed fully - before processing the next one. */ - BREADTH_FIRST, - - /** Standard tree traversal. Processes the root, the first child of the root, - then the child's first child... until a leaf is reached. Then, the leaf's siblings - are iterated over before iterating over the leaf's parent's siblings. */ - DEPTH_FIRST_PREORDER, - - /** Iterate over the scene nodes one level at a time. Starts at the leaves - and terminates with the root. Each node level is processed fully - before processing the next one. */ - DEPTH_FIRST_POSTORDER, - }; - - /** Constructor. - @param root The scene root of the sub-tree to iterate over. - @param searchType The search type determines the ordering of the scene nodes returned by Next. - @param pureChildOnly Only process nodes that are direct children of the root. All node - instances will be discarded. */ - FCDSceneNodeIteratorT(_NODE* root, SearchType searchType=BREADTH_FIRST, bool pureChildOnly=false); - - /** Destructor. */ - ~FCDSceneNodeIteratorT(); - - /** Retrieves the current node to process. - @return The current node. */ - _NODE* GetNode(); - - /** Advances the iteration pointer and retrieves the next node to process. - @return The node to process. */ - _NODE* Next(); - - /** Retrieves whether the full sub-tree has been processed. */ - inline bool IsDone() { return iterator >= queue.size(); } - - /** Advances the iteration pointer. - @return The iterator. */ - inline FCDSceneNodeIteratorT& operator++() { Next(); return (*this); } - - /** Retrieves the current node to process. - @return The current node. */ - inline _NODE* operator*() { return GetNode(); } -}; - -typedef FCDSceneNodeIteratorT FCDSceneNodeIterator; /**< A scene node iterator. */ -typedef FCDSceneNodeIteratorT FCDSceneNodeConstIterator; /**< A constant scene node iterator. */ - -#ifdef __APPLE__ -#include "FCDocument/FCDSceneNodeIterator.hpp" -#endif // __APPLE__ - -#endif // _FCD_SCENE_NODE_ITERATOR_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/** + @file FCDSceneNodeIterator.h + This file contains the FCDSceneNodeIteratorT template + and its two definitions: FCDSceneNodeIterator and FCDSceneNodeConstIterator. +*/ + +#ifndef _FCD_SCENE_NODE_ITERATOR_H_ +#define _FCD_SCENE_NODE_ITERATOR_H_ + +class FCDSceneNode; + +/** + This template is used to process a given scene node and its full sub-tree. + We use a template here in order to easily support both const + and non-const scene node data, with the same code. + + Do not use this template directly, instead use the + FCDSceneNodeIterator and FCDSceneNodeConstIterator definitions. + + This template does not care whether multiple instances of the same node is processed. +*/ +template +class FCOLLADA_EXPORT FCDSceneNodeIteratorT +{ +private: + fm::pvector<_NODE> queue; + size_t iterator; + +public: + /** The order in which the scene nodes should be iterated. */ + enum SearchType + { + /** Iterate over the scene nodes one level at a time. Starts from the root + and terminates with the leaves. Each node level is processed fully + before processing the next one. */ + BREADTH_FIRST, + + /** Standard tree traversal. Processes the root, the first child of the root, + then the child's first child... until a leaf is reached. Then, the leaf's siblings + are iterated over before iterating over the leaf's parent's siblings. */ + DEPTH_FIRST_PREORDER, + + /** Iterate over the scene nodes one level at a time. Starts at the leaves + and terminates with the root. Each node level is processed fully + before processing the next one. */ + DEPTH_FIRST_POSTORDER, + }; + + /** Constructor. + @param root The scene root of the sub-tree to iterate over. + @param searchType The search type determines the ordering of the scene nodes returned by Next. + @param pureChildOnly Only process nodes that are direct children of the root. All node + instances will be discarded. */ + FCDSceneNodeIteratorT(_NODE* root, SearchType searchType=BREADTH_FIRST, bool pureChildOnly=false); + + /** Destructor. */ + ~FCDSceneNodeIteratorT(); + + /** Retrieves the current node to process. + @return The current node. */ + _NODE* GetNode(); + + /** Advances the iteration pointer and retrieves the next node to process. + @return The node to process. */ + _NODE* Next(); + + /** Retrieves whether the full sub-tree has been processed. */ + inline bool IsDone() { return iterator >= queue.size(); } + + /** Advances the iteration pointer. + @return The iterator. */ + inline FCDSceneNodeIteratorT& operator++() { Next(); return (*this); } + + /** Retrieves the current node to process. + @return The current node. */ + inline _NODE* operator*() { return GetNode(); } +}; + +typedef FCDSceneNodeIteratorT FCDSceneNodeIterator; /**< A scene node iterator. */ +typedef FCDSceneNodeIteratorT FCDSceneNodeConstIterator; /**< A constant scene node iterator. */ + +#ifdef __APPLE__ +#include "FCDocument/FCDSceneNodeIterator.hpp" +#endif // __APPLE__ + +#endif // _FCD_SCENE_NODE_ITERATOR_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSceneNodeIterator.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSkinController.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSkinController.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSkinController.h (revision 24247) @@ -1,250 +1,250 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDSkinController.h - This file contains the FCDSkinController class. -*/ - -#ifndef _FCD_SKIN_CONTROLLER_H_ -#define _FCD_SKIN_CONTROLLER_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -class FCDocument; -class FCDController; -class FCDGeometry; -class FCDSceneNode; -class FCDEntityReference; -class FUUri; - -/** - A COLLADA weighted vertex-joint binding used in skinning. - @ingroup FCDGeometry -*/ -struct FCOLLADA_EXPORT FCDJointWeightPair -{ - /** Default constructor: sets both the joint index and the weight to zero. */ - FCDJointWeightPair() { jointIndex = -1; weight = 0.0f; } - - /** Constructor: sets the joint index and the weight to the given values. - @param _jointIndex The jointIndex. - @param _weight Its weight. */ - FCDJointWeightPair(int32 _jointIndex, float _weight) { jointIndex = _jointIndex; weight = _weight; } - - /** A joint index. - Use this index within the skin's joint list. - Look-out for the special joint index: -1. It indicates that - the bind-shape position should be used. */ - int32 jointIndex; - - /** The weight of this influence on the vertex. */ - float weight; -}; - -/** - A COLLADA skin controller vertex. - This structure contains a list of joint-weight pairs that defines - how to modify a given mesh vertex in order to skin it properly. - @ingroup FCDGeometry -*/ -class FCOLLADA_EXPORT FCDSkinControllerVertex -{ -private: - fm::vector pairs; - -public: - /** Retrieve the number of joint-weight pairs defined for this vertex. - @return The number of joint-weight pairs. */ - inline size_t GetPairCount() const { return pairs.size(); } - - /** Sets the number of joint-weight pairs defined for this vertex. - @param count The number of joint-weight pairs defined for this vertex. */ - void SetPairCount(size_t count); - - /** Retrieves a joint-weight pair. - @param index The index of the joint-weight pair. - @return The joint-weight pair at the given index. */ - inline FCDJointWeightPair* GetPair(size_t index) { FUAssert(index < pairs.size(), return NULL); return &(pairs.at(index)); } - inline const FCDJointWeightPair* GetPair(size_t index) const { FUAssert(index < pairs.size(), return NULL); return &(pairs.at(index)); } /**< See above. */ - - /** Adds a new joint-weight pair to this vertex. - No verification will be made to ensure that the sum of the weights equal 1.0. - @param jointIndex The index of the joint within the skin controller's joint list. - @param weight The influence weight for this joint, on this vertex. */ - void AddPair(int32 jointIndex, float weight); -}; - -/** - A COLLADA skin controller joint. - The controller does not reference the scene nodes directly: that's the instance's job. - Instead, the skin controllers keeps track of the sub-ids of the scene nodes and their - bind poses. - @ingroup FCDGeometry -*/ -class FCOLLADA_EXPORT FCDSkinControllerJoint -{ -private: - fm::string id; - FMMatrix44 bindPoseInverse; - -public: - /** Retrieves the identifier of the scene node(s) representing this joint. - @return The identifier of the joint. */ - inline const fm::string& GetId() const { return id; } - - /** Sets the identifier of the scene node(s) representing this joint. - @param id The identifier of the joint. */ - void SetId(const fm::string& id); - - /** Retrieves the inverse bind-pose matrix of the joint. - @return The inverse bind-pose matrix. */ - inline const FMMatrix44& GetBindPoseInverse() const { return bindPoseInverse; } - - /** Sets the inverse bind-pose matrix of the joint. - @param inverseBindPose The inverse bind-pose matrix. */ - inline void SetBindPoseInverse(const FMMatrix44& inverseBindPose) { bindPoseInverse = inverseBindPose; } -}; - -/** - A COLLADA skin controller. - - The skin controller holds the information to skin a geometric object. - That information includes a target/base entity and its bind-pose matrix, - a list of joints and their bind pose and the influences for the joints. - - The influences are a list, for each vertex of the target entity, of which - joints affect the vertex and by how much. - - @ingroup FCDGeometry -*/ - -class FCOLLADA_EXPORT FCDSkinController : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - FCDController* parent; - - FUObjectRef target; - DeclareParameter(FMMatrix44, FUParameterQualifiers::SIMPLE, bindShapeTransform, FC("Base Mesh Bind-pose Transform")); - - fm::vector joints; - fm::vector influences; - -public: - /** Constructor: do not use directly. - Instead, use the FCDController::CreateSkinController function. - @param document The COLLADA document that owns the skin. - @param parent The COLLADA controller that contains this skin. */ - FCDSkinController(FCDocument* document, FCDController* parent); - - /** Destructor. */ - virtual ~FCDSkinController(); - - /** Retrieves the parent entity for the morpher. - @return The parent controller entity. */ - inline FCDController* GetParent() { return parent; } - inline const FCDController* GetParent() const { return parent; } /**< See above. */ - - /** Retrieves the target entity. - This entity may be a geometric entity or another controller. - @return The target entity. */ - FCDEntity* GetTarget(); - const FCDEntity* GetTarget() const; - - /** Retrieves the Uri to the skin target. - This can be an internal or external link - @return The uri to the target */ - FUUri GetTargetUri() const; - - /** Sets the URI of the target mesh. - @param uri The Uri to a local or external controller or geometry */ - void SetTargetUri(const FUUri& uri); - - /** Sets the target entity. - This function has very important ramifications, as the number - of vertices may change. The influences list will be modified to - follow the number of vertices. - This entity may be a geometric entity or another controller. - @param _target The target entity. */ - void SetTarget(FCDEntity* _target); - - /** Retrieves the bind-pose transform of the target entity. - @return The bind-pose transform. */ - const FMMatrix44& GetBindShapeTransform() const { return *bindShapeTransform; } - - /** Sets the bind-pose transform of the target entity. - @param bindPose The bind-pose transform. */ - void SetBindShapeTransform(const FMMatrix44& bindPose) { bindShapeTransform = bindPose; SetDirtyFlag(); } - - /** Retrieves the number of joints that influence the skin. - @return The number of joints. */ - inline size_t GetJointCount() const { return joints.size(); } - - /** Sets the number of joints that influence the skin. - @param count The number of joints that influence the skin. */ - void SetJointCount(size_t count); - - /** Retrieves the list of joints that influence the skin. - @return The list of joints that influence the skin. */ - inline FCDSkinControllerJoint* GetJoints() { return !joints.empty() ? &(joints.front()) : NULL; } - inline const FCDSkinControllerJoint* GetJoints() const { return !joints.empty() ? &(joints.front()) : NULL; } /**< See above. */ - - /** Retrieves an indexed joint from the list of joints that influence this skin. - @param index The index of the joint. - @return The joint at the given index. */ - inline FCDSkinControllerJoint* GetJoint(size_t index) { FUAssert(index < joints.size(), return NULL); return &joints.at(index); } - inline const FCDSkinControllerJoint* GetJoint(size_t index) const { FUAssert(index < joints.size(), return NULL); return &joints.at(index); } /**< See above. */ - - /** Adds a joint to influence the skin. - @param jSubId The sub-id of the scene node(s) that represent the joint. - @param inverseBindPose The inverse bind-pose of the joint. */ - FCDSkinControllerJoint* AddJoint(const fm::string jSubId = "", const FMMatrix44& inverseBindPose = FMMatrix44::Identity); - - /** Retrieves the number of vertices with influences defined in the skin controller. - @return The number of influenced vertices. */ - inline size_t GetInfluenceCount() const { return influences.size(); } - - /** Sets the number of vertices with influences defined in the skin controller. - @param count The number of influences vertices. */ - void SetInfluenceCount(size_t count); - - /** Retrieves a list of the per-vertex influences for the skin. - @return The list of per-vertex influences. */ - inline FCDSkinControllerVertex* GetVertexInfluences() { return influences.size() > 0 ? &(influences.front()) : NULL; } - inline const FCDSkinControllerVertex* GetVertexInfluences() const { return influences.size() > 0 ? &(influences.front()) : NULL; } /**< See above. */ - - /** Retrieves the per-vertex influences for a given vertex. - @param index The vertex index. - @return The per-vertex influences. */ - inline FCDSkinControllerVertex* GetVertexInfluence(size_t index) { FUAssert(index < influences.size(), return NULL); return &influences.at(index); } - inline const FCDSkinControllerVertex* GetVertexInfluence(size_t index) const { FUAssert(index < influences.size(), return NULL); return &influences.at(index); } /**< See above. */ - - /** Reduces the number of joints influencing each vertex. - 1) All the influences with a weight less than the minimum will be removed. - 2) If a vertex has more influences than the given maximum, they will be sorted and the - most important influences will be kept. - If some of the influences for a vertex are removed, the weight will be normalized. - @param maxInfluenceCount The maximum number of influence to keep for each vertex. - @param minimumWeight The smallest weight to keep. */ - void ReduceInfluences(uint32 maxInfluenceCount, float minimumWeight=0.0f); -}; - -#endif // _FCD_SKIN_CONTROLLER_H_ - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDSkinController.h + This file contains the FCDSkinController class. +*/ + +#ifndef _FCD_SKIN_CONTROLLER_H_ +#define _FCD_SKIN_CONTROLLER_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +class FCDocument; +class FCDController; +class FCDGeometry; +class FCDSceneNode; +class FCDEntityReference; +class FUUri; + +/** + A COLLADA weighted vertex-joint binding used in skinning. + @ingroup FCDGeometry +*/ +struct FCOLLADA_EXPORT FCDJointWeightPair +{ + /** Default constructor: sets both the joint index and the weight to zero. */ + FCDJointWeightPair() { jointIndex = -1; weight = 0.0f; } + + /** Constructor: sets the joint index and the weight to the given values. + @param _jointIndex The jointIndex. + @param _weight Its weight. */ + FCDJointWeightPair(int32 _jointIndex, float _weight) { jointIndex = _jointIndex; weight = _weight; } + + /** A joint index. + Use this index within the skin's joint list. + Look-out for the special joint index: -1. It indicates that + the bind-shape position should be used. */ + int32 jointIndex; + + /** The weight of this influence on the vertex. */ + float weight; +}; + +/** + A COLLADA skin controller vertex. + This structure contains a list of joint-weight pairs that defines + how to modify a given mesh vertex in order to skin it properly. + @ingroup FCDGeometry +*/ +class FCOLLADA_EXPORT FCDSkinControllerVertex +{ +private: + fm::vector pairs; + +public: + /** Retrieve the number of joint-weight pairs defined for this vertex. + @return The number of joint-weight pairs. */ + inline size_t GetPairCount() const { return pairs.size(); } + + /** Sets the number of joint-weight pairs defined for this vertex. + @param count The number of joint-weight pairs defined for this vertex. */ + void SetPairCount(size_t count); + + /** Retrieves a joint-weight pair. + @param index The index of the joint-weight pair. + @return The joint-weight pair at the given index. */ + inline FCDJointWeightPair* GetPair(size_t index) { FUAssert(index < pairs.size(), return NULL); return &(pairs.at(index)); } + inline const FCDJointWeightPair* GetPair(size_t index) const { FUAssert(index < pairs.size(), return NULL); return &(pairs.at(index)); } /**< See above. */ + + /** Adds a new joint-weight pair to this vertex. + No verification will be made to ensure that the sum of the weights equal 1.0. + @param jointIndex The index of the joint within the skin controller's joint list. + @param weight The influence weight for this joint, on this vertex. */ + void AddPair(int32 jointIndex, float weight); +}; + +/** + A COLLADA skin controller joint. + The controller does not reference the scene nodes directly: that's the instance's job. + Instead, the skin controllers keeps track of the sub-ids of the scene nodes and their + bind poses. + @ingroup FCDGeometry +*/ +class FCOLLADA_EXPORT FCDSkinControllerJoint +{ +private: + fm::string id; + FMMatrix44 bindPoseInverse; + +public: + /** Retrieves the identifier of the scene node(s) representing this joint. + @return The identifier of the joint. */ + inline const fm::string& GetId() const { return id; } + + /** Sets the identifier of the scene node(s) representing this joint. + @param id The identifier of the joint. */ + void SetId(const fm::string& id); + + /** Retrieves the inverse bind-pose matrix of the joint. + @return The inverse bind-pose matrix. */ + inline const FMMatrix44& GetBindPoseInverse() const { return bindPoseInverse; } + + /** Sets the inverse bind-pose matrix of the joint. + @param inverseBindPose The inverse bind-pose matrix. */ + inline void SetBindPoseInverse(const FMMatrix44& inverseBindPose) { bindPoseInverse = inverseBindPose; } +}; + +/** + A COLLADA skin controller. + + The skin controller holds the information to skin a geometric object. + That information includes a target/base entity and its bind-pose matrix, + a list of joints and their bind pose and the influences for the joints. + + The influences are a list, for each vertex of the target entity, of which + joints affect the vertex and by how much. + + @ingroup FCDGeometry +*/ + +class FCOLLADA_EXPORT FCDSkinController : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + FCDController* parent; + + FUObjectRef target; + DeclareParameter(FMMatrix44, FUParameterQualifiers::SIMPLE, bindShapeTransform, FC("Base Mesh Bind-pose Transform")); + + fm::vector joints; + fm::vector influences; + +public: + /** Constructor: do not use directly. + Instead, use the FCDController::CreateSkinController function. + @param document The COLLADA document that owns the skin. + @param parent The COLLADA controller that contains this skin. */ + FCDSkinController(FCDocument* document, FCDController* parent); + + /** Destructor. */ + virtual ~FCDSkinController(); + + /** Retrieves the parent entity for the morpher. + @return The parent controller entity. */ + inline FCDController* GetParent() { return parent; } + inline const FCDController* GetParent() const { return parent; } /**< See above. */ + + /** Retrieves the target entity. + This entity may be a geometric entity or another controller. + @return The target entity. */ + FCDEntity* GetTarget(); + const FCDEntity* GetTarget() const; + + /** Retrieves the Uri to the skin target. + This can be an internal or external link + @return The uri to the target */ + FUUri GetTargetUri() const; + + /** Sets the URI of the target mesh. + @param uri The Uri to a local or external controller or geometry */ + void SetTargetUri(const FUUri& uri); + + /** Sets the target entity. + This function has very important ramifications, as the number + of vertices may change. The influences list will be modified to + follow the number of vertices. + This entity may be a geometric entity or another controller. + @param _target The target entity. */ + void SetTarget(FCDEntity* _target); + + /** Retrieves the bind-pose transform of the target entity. + @return The bind-pose transform. */ + const FMMatrix44& GetBindShapeTransform() const { return *bindShapeTransform; } + + /** Sets the bind-pose transform of the target entity. + @param bindPose The bind-pose transform. */ + void SetBindShapeTransform(const FMMatrix44& bindPose) { bindShapeTransform = bindPose; SetDirtyFlag(); } + + /** Retrieves the number of joints that influence the skin. + @return The number of joints. */ + inline size_t GetJointCount() const { return joints.size(); } + + /** Sets the number of joints that influence the skin. + @param count The number of joints that influence the skin. */ + void SetJointCount(size_t count); + + /** Retrieves the list of joints that influence the skin. + @return The list of joints that influence the skin. */ + inline FCDSkinControllerJoint* GetJoints() { return !joints.empty() ? &(joints.front()) : NULL; } + inline const FCDSkinControllerJoint* GetJoints() const { return !joints.empty() ? &(joints.front()) : NULL; } /**< See above. */ + + /** Retrieves an indexed joint from the list of joints that influence this skin. + @param index The index of the joint. + @return The joint at the given index. */ + inline FCDSkinControllerJoint* GetJoint(size_t index) { FUAssert(index < joints.size(), return NULL); return &joints.at(index); } + inline const FCDSkinControllerJoint* GetJoint(size_t index) const { FUAssert(index < joints.size(), return NULL); return &joints.at(index); } /**< See above. */ + + /** Adds a joint to influence the skin. + @param jSubId The sub-id of the scene node(s) that represent the joint. + @param inverseBindPose The inverse bind-pose of the joint. */ + FCDSkinControllerJoint* AddJoint(const fm::string jSubId = "", const FMMatrix44& inverseBindPose = FMMatrix44::Identity); + + /** Retrieves the number of vertices with influences defined in the skin controller. + @return The number of influenced vertices. */ + inline size_t GetInfluenceCount() const { return influences.size(); } + + /** Sets the number of vertices with influences defined in the skin controller. + @param count The number of influences vertices. */ + void SetInfluenceCount(size_t count); + + /** Retrieves a list of the per-vertex influences for the skin. + @return The list of per-vertex influences. */ + inline FCDSkinControllerVertex* GetVertexInfluences() { return influences.size() > 0 ? &(influences.front()) : NULL; } + inline const FCDSkinControllerVertex* GetVertexInfluences() const { return influences.size() > 0 ? &(influences.front()) : NULL; } /**< See above. */ + + /** Retrieves the per-vertex influences for a given vertex. + @param index The vertex index. + @return The per-vertex influences. */ + inline FCDSkinControllerVertex* GetVertexInfluence(size_t index) { FUAssert(index < influences.size(), return NULL); return &influences.at(index); } + inline const FCDSkinControllerVertex* GetVertexInfluence(size_t index) const { FUAssert(index < influences.size(), return NULL); return &influences.at(index); } /**< See above. */ + + /** Reduces the number of joints influencing each vertex. + 1) All the influences with a weight less than the minimum will be removed. + 2) If a vertex has more influences than the given maximum, they will be sorted and the + most important influences will be kept. + If some of the influences for a vertex are removed, the weight will be normalized. + @param maxInfluenceCount The maximum number of influence to keep for each vertex. + @param minimumWeight The smallest weight to keep. */ + void ReduceInfluences(uint32 maxInfluenceCount, float minimumWeight=0.0f); +}; + +#endif // _FCD_SKIN_CONTROLLER_H_ + Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDSkinController.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTexture.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTexture.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTexture.cpp (revision 24247) @@ -1,133 +1,133 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDEffect.h" -#include "FCDocument/FCDEffectParameter.h" -#include "FCDocument/FCDEffectParameterFactory.h" -#include "FCDocument/FCDEffectParameterSurface.h" -#include "FCDocument/FCDEffectParameterSampler.h" -#include "FCDocument/FCDEffectStandard.h" -#include "FCDocument/FCDEffectTools.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDImage.h" -#include "FCDocument/FCDTexture.h" -#include "FUtils/FUStringConversion.h" - -// -// FCDTexture -// - -ImplementObjectType(FCDTexture); -ImplementParameterObjectNoCtr(FCDTexture, FCDEffectParameterSampler, sampler); -ImplementParameterObject(FCDTexture, FCDEffectParameterInt, set, new FCDEffectParameterInt(parent->GetDocument())); -ImplementParameterObject(FCDTexture, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); - -FCDTexture::FCDTexture(FCDocument* document, FCDEffectStandard* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(sampler) -, InitializeParameterNoArg(set) -, InitializeParameterNoArg(extra) -{ - set = new FCDEffectParameterInt(document); - set->SetValue(-1); - extra = new FCDExtra(document, this); -} - -FCDTexture::~FCDTexture() -{ - parent = NULL; -} - -// Retrieves the sampler parameter: creates one if none are attached. -FCDEffectParameterSampler* FCDTexture::GetSampler() -{ - if (parent == NULL && sampler == NULL) return NULL; - if (sampler == NULL) - { - sampler = (FCDEffectParameterSampler*) parent->AddEffectParameter(FCDEffectParameter::SAMPLER); - } - return sampler; -} - -// Retrieves the image information for this texture. -const FCDImage* FCDTexture::GetImage() const -{ - if (sampler == NULL) return NULL; - const FCDEffectParameterSurface* surface = sampler->GetSurface(); - if (surface == NULL) return NULL; - return surface->GetImage(); -} - -// Set the image information for this texture. -void FCDTexture::SetImage(FCDImage* image) -{ - // TODO: No parameter re-use for now. - SAFE_RELEASE(sampler); - if (image != NULL && parent != NULL) - { - // Look for a surface with the expected sid. - fm::string surfaceSid = image->GetDaeId() + "-surface"; - FCDEffectParameter* _surface = FCDEffectTools::FindEffectParameterByReference(parent, surfaceSid); - FCDEffectParameterSurface* surface = NULL; - if (_surface == NULL) - { - // Create the surface parameter - surface = (FCDEffectParameterSurface*) parent->AddEffectParameter(FCDEffectParameter::SURFACE); - surface->SetInitMethod(new FCDEffectParameterSurfaceInitFrom()); - surface->AddImage(image); - surface->SetGenerator(); - surface->SetReference(surfaceSid); - } - else if (_surface->HasType(FCDEffectParameterSurface::GetClassType())) - { - surface = (FCDEffectParameterSurface*) _surface; - } - else return; - - // Look for a sampler with the expected sid. - fm::string samplerSid = image->GetDaeId() + "-sampler"; - const FCDEffectParameter* _sampler = FCDEffectTools::FindEffectParameterByReference(parent, samplerSid); - if (_sampler == NULL) - { - sampler = (FCDEffectParameterSampler*) parent->AddEffectParameter(FCDEffectParameter::SAMPLER); - sampler->SetSurface(surface); - sampler->SetGenerator(); - sampler->SetReference(samplerSid); - } - else if (_sampler->GetObjectType().Includes(FCDEffectParameterSampler::GetClassType())) - { - sampler = (FCDEffectParameterSampler*) const_cast(_sampler); - } - } - - SetNewChildFlag(); -} - -// Returns a copy of the texture/sampler, with all the animations attached -FCDTexture* FCDTexture::Clone(FCDTexture* clone) const -{ - if (clone == NULL) clone = new FCDTexture(const_cast(this)->GetDocument(), parent); - - set->Clone(clone->set); - extra->Clone(clone->extra); - - if (sampler != NULL) - { - sampler->Clone(clone->GetSampler()); - } - - return clone; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDEffect.h" +#include "FCDocument/FCDEffectParameter.h" +#include "FCDocument/FCDEffectParameterFactory.h" +#include "FCDocument/FCDEffectParameterSurface.h" +#include "FCDocument/FCDEffectParameterSampler.h" +#include "FCDocument/FCDEffectStandard.h" +#include "FCDocument/FCDEffectTools.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDImage.h" +#include "FCDocument/FCDTexture.h" +#include "FUtils/FUStringConversion.h" + +// +// FCDTexture +// + +ImplementObjectType(FCDTexture); +ImplementParameterObjectNoCtr(FCDTexture, FCDEffectParameterSampler, sampler); +ImplementParameterObject(FCDTexture, FCDEffectParameterInt, set, new FCDEffectParameterInt(parent->GetDocument())); +ImplementParameterObject(FCDTexture, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); + +FCDTexture::FCDTexture(FCDocument* document, FCDEffectStandard* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(sampler) +, InitializeParameterNoArg(set) +, InitializeParameterNoArg(extra) +{ + set = new FCDEffectParameterInt(document); + set->SetValue(-1); + extra = new FCDExtra(document, this); +} + +FCDTexture::~FCDTexture() +{ + parent = NULL; +} + +// Retrieves the sampler parameter: creates one if none are attached. +FCDEffectParameterSampler* FCDTexture::GetSampler() +{ + if (parent == NULL && sampler == NULL) return NULL; + if (sampler == NULL) + { + sampler = (FCDEffectParameterSampler*) parent->AddEffectParameter(FCDEffectParameter::SAMPLER); + } + return sampler; +} + +// Retrieves the image information for this texture. +const FCDImage* FCDTexture::GetImage() const +{ + if (sampler == NULL) return NULL; + const FCDEffectParameterSurface* surface = sampler->GetSurface(); + if (surface == NULL) return NULL; + return surface->GetImage(); +} + +// Set the image information for this texture. +void FCDTexture::SetImage(FCDImage* image) +{ + // TODO: No parameter re-use for now. + SAFE_RELEASE(sampler); + if (image != NULL && parent != NULL) + { + // Look for a surface with the expected sid. + fm::string surfaceSid = image->GetDaeId() + "-surface"; + FCDEffectParameter* _surface = FCDEffectTools::FindEffectParameterByReference(parent, surfaceSid); + FCDEffectParameterSurface* surface = NULL; + if (_surface == NULL) + { + // Create the surface parameter + surface = (FCDEffectParameterSurface*) parent->AddEffectParameter(FCDEffectParameter::SURFACE); + surface->SetInitMethod(new FCDEffectParameterSurfaceInitFrom()); + surface->AddImage(image); + surface->SetGenerator(); + surface->SetReference(surfaceSid); + } + else if (_surface->HasType(FCDEffectParameterSurface::GetClassType())) + { + surface = (FCDEffectParameterSurface*) _surface; + } + else return; + + // Look for a sampler with the expected sid. + fm::string samplerSid = image->GetDaeId() + "-sampler"; + const FCDEffectParameter* _sampler = FCDEffectTools::FindEffectParameterByReference(parent, samplerSid); + if (_sampler == NULL) + { + sampler = (FCDEffectParameterSampler*) parent->AddEffectParameter(FCDEffectParameter::SAMPLER); + sampler->SetSurface(surface); + sampler->SetGenerator(); + sampler->SetReference(samplerSid); + } + else if (_sampler->GetObjectType().Includes(FCDEffectParameterSampler::GetClassType())) + { + sampler = (FCDEffectParameterSampler*) const_cast(_sampler); + } + } + + SetNewChildFlag(); +} + +// Returns a copy of the texture/sampler, with all the animations attached +FCDTexture* FCDTexture::Clone(FCDTexture* clone) const +{ + if (clone == NULL) clone = new FCDTexture(const_cast(this)->GetDocument(), parent); + + set->Clone(clone->set); + extra->Clone(clone->extra); + + if (sampler != NULL) + { + sampler->Clone(clone->GetSampler()); + } + + return clone; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTexture.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDVersion.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDVersion.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDVersion.cpp (revision 24247) @@ -1,61 +1,61 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDVersion.h" - -// -// FCDVersion -// -FCDVersion::FCDVersion() -: major(0), minor(0), revision(0) -{ -} - -FCDVersion::FCDVersion(const fm::string& v) -{ - ParseVersionNumbers(v); -} - -FCDVersion::FCDVersion(uint32 _major, uint32 _minor, uint32 _revision) -: major(_major), minor(_minor), revision(_revision) -{ -} - -void FCDVersion::ParseVersionNumbers(const fm::string& _v) -{ - const char* v = _v.c_str(); - major = FUStringConversion::ToUInt32(v); - while (*v != 0 && *v != '.') { ++v; } if (*v != 0) ++v; // skip the '.' - minor = FUStringConversion::ToUInt32(v); - while (*v != 0 && *v != '.') { ++v; } if (*v != 0) ++v; // skip the '.' - revision = FUStringConversion::ToUInt32(v); -} - -bool IsEquivalent(const FCDVersion& a, const FCDVersion& b) -{ - return a.major == b.major && a.minor == b.minor && a.revision == b.revision; -} - -bool FCDVersion::operator< (const FCDVersion& b) const -{ - if (major < b.major) return true; - if (major > b.major) return false; - if (minor < b.minor) return true; - if (minor > b.minor) return false; - return revision < b.revision; -} - -bool FCDVersion::operator<= (const FCDVersion& b) const -{ - if (major < b.major) return true; - if (major > b.major) return false; - if (minor < b.minor) return true; - if (minor > b.minor) return false; - return revision <= b.revision; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDVersion.h" + +// +// FCDVersion +// +FCDVersion::FCDVersion() +: major(0), minor(0), revision(0) +{ +} + +FCDVersion::FCDVersion(const fm::string& v) +{ + ParseVersionNumbers(v); +} + +FCDVersion::FCDVersion(uint32 _major, uint32 _minor, uint32 _revision) +: major(_major), minor(_minor), revision(_revision) +{ +} + +void FCDVersion::ParseVersionNumbers(const fm::string& _v) +{ + const char* v = _v.c_str(); + major = FUStringConversion::ToUInt32(v); + while (*v != 0 && *v != '.') { ++v; } if (*v != 0) ++v; // skip the '.' + minor = FUStringConversion::ToUInt32(v); + while (*v != 0 && *v != '.') { ++v; } if (*v != 0) ++v; // skip the '.' + revision = FUStringConversion::ToUInt32(v); +} + +bool IsEquivalent(const FCDVersion& a, const FCDVersion& b) +{ + return a.major == b.major && a.minor == b.minor && a.revision == b.revision; +} + +bool FCDVersion::operator< (const FCDVersion& b) const +{ + if (major < b.major) return true; + if (major > b.major) return false; + if (minor < b.minor) return true; + if (minor > b.minor) return false; + return revision < b.revision; +} + +bool FCDVersion::operator<= (const FCDVersion& b) const +{ + if (major < b.major) return true; + if (major > b.major) return false; + if (minor < b.minor) return true; + if (minor > b.minor) return false; + return revision <= b.revision; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDVersion.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTransform.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTransform.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTransform.h (revision 24247) @@ -1,648 +1,648 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDTransform.h - This file contains the FCDTransform class and its up-classes: - FCDTTranslation, FCDTScale, FCDTRotation, FCDTMatrix, FCDTLookAt and FCDTSkew. -*/ - -#ifndef _FCD_TRANSFORM_H_ -#define _FCD_TRANSFORM_H_ - -class FCDocument; -class FCDAnimated; -class FCDSceneNode; -class FCDTransform; - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FM_QUATERNION_H_ -#include "FMath/FMQuaternion.h" -#endif // _FM_QUATERNION_H_ -#ifndef _FCD_PARAMETER_ANIMATABLE_H_ -#include "FCDocument/FCDParameterAnimatable.h" -#endif // _FCD_PARAMETER_ANIMATABLE_H_ - -/** - A COLLADA transform. - - COLLADA supports six transformation types: translations(FCDTTranslation), - rotations(FCDTRotation), scales(FCDTScale), matrices(FCDTMatrix), - skews(FCDTSkew) and the 'look-at' transform(FCDTLookAt). - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDTransform : public FCDObject -{ -public: - /** The COLLADA transform types. */ - enum Type - { - TRANSLATION, /**< A translation(FCDTTranslation). */ - ROTATION, /**< A rotation(FCDTRotation). */ - SCALE, /**< A non-uniform scale(FCDTScale). */ - MATRIX, /**< A matrix multiplication(FCDTMatrix). */ - LOOKAT, /**< A targeted, 'look-at' transformation(FCDTLookAt). */ - SKEW, /**< A skew(FCDTSkew). */ - TYPE_COUNT - }; - -private: - DeclareObjectType(FCDObject); - FCDSceneNode* parent; - DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, sid, FC("Sub-id")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDSceneNode::AddTransform function. - @param document The COLLADA document that owns the transform. - @param parent The visual scene node that contains the transform. - Set this pointer to NULL if this transform is not owned by a - visual scene node. */ - FCDTransform(FCDocument* document, FCDSceneNode* parent); - - /** Destructor. */ - virtual ~FCDTransform(); - - /** Retrieves the visual scene node that contains this transformation. - @return The parent visual scene node. This pointer will be NULL - if the transformation is not contained by a visual scene node. */ - FCDSceneNode* GetParent() { return parent; } - const FCDSceneNode* GetParent() const { return parent; } /**< See above. */ - - /** [DEPRECATED] Sets on a scene node parent, the transform dirty flag. */ - DEPRECATED(3.05, SetValueChange) - void SetTransformsDirtyFlag(); - - /** Creates a copy of a transformation. - @param clone The transform that will be the clone. - @return The cloned transformation. */ - virtual FCDTransform* Clone(FCDTransform* clone = NULL) const = 0; - - /** Retrieves the class type of the transformation. - The class type should be used to up-case the transformation pointer. - @return The class type. */ - virtual Type GetType() const = 0; - - /** Converts the transformation into a matrix. - Useful for visual scene nodes with a weird transformation stack. - @return A matrix equivalent of the transformation. */ - virtual FMMatrix44 ToMatrix() const = 0; - - /** Retrieves the wanted sub-id for this transform. - A wanted sub-id will always be exported, even if the transform is not animated. - But the wanted sub-id may be modified if it isn't unique within the scope. - @return The sub-id. */ - inline FUParameterString& GetSubId() { return sid; } - inline const FUParameterString& GetSubId() const { return sid; } /**< See above. */ - - /** Sets the wanted sub-id for this transform. - A wanted sub-id will always be exported, even if the transform is not animated. - But the wanted sub-id may be modified if it isn't unique within the scope. - @param subId The wanted sub-id. */ - void SetSubId(const fm::string& subId); - - /** Retrieves whether this transformation has an animation tied to its values. - @return Whether the transformation is animated. */ - virtual bool IsAnimated() const = 0; - - /** Retrieves the animated element for the transformation. - @return The animated element. This pointer will be NULL if the transformation - is not animated. */ - inline FCDAnimated* GetAnimated() { return const_cast(const_cast(this)->GetAnimated()); } - virtual const FCDAnimated* GetAnimated() const = 0; /**< See above. */ - - /** Retrieves whether a given transformation is the exact opposite of - this transformation. Executing two opposite transformations, one after the - other will not give any resulting transformation. This function is useful - to detect pivots within the transform stack. - @param transform A second transformation. - @return Whether the two transformations are opposites. */ - virtual bool IsInverse(const FCDTransform* transform) const; - - /** Set Value changed flag. When this happens, notify our parent */ - virtual void SetValueChange(); -}; - -/** - A COLLADA translation. - A translation is a simple 3D displacement. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDTTranslation : public FCDTransform -{ -private: - DeclareObjectType(FCDTransform); - DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, translation, FC("Translation")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDSceneNode::AddTransform function with - the TRANSLATION transformation type. - @param document The COLLADA document that owns the translation. - @param parent The visual scene node that contains the translation. - Set this pointer to NULL if the translation is not owned - by a visual scene node. */ - FCDTTranslation(FCDocument* document, FCDSceneNode* parent); - - /** Destructor. */ - virtual ~FCDTTranslation(); - - /** Retrieves the transformation class type for the translation. - @return The transformation class type: TRANSLATION. */ - virtual Type GetType() const { return TRANSLATION; } - - /** Retrieves the translation 3D displacement vector. - This displacement vector may be animated. - @return The displacement vector. */ - inline FCDParameterAnimatableVector3& GetTranslation() { return translation; } - inline const FCDParameterAnimatableVector3& GetTranslation() const { return translation; } /**< See above. */ - - /** Sets the translation 3D displacement vector. - @param _translation The displacement vector. */ - inline void SetTranslation(const FMVector3& _translation) { translation = _translation; SetValueChange(); } - - /** Sets the translation 3D displacement vector. - @param x The x-component displacement. - @param y The y-component displacement. - @param z The z-component displacement. */ - inline void SetTranslation(float x, float y, float z) { translation = FMVector3(x, y, z); SetValueChange(); } - - /** Converts the translation into a matrix. - @return A matrix equivalent of the translation. */ - virtual FMMatrix44 ToMatrix() const; - - /** Retrieves whether this translation is affected by an animation. - @return Whether the translation is animated. */ - virtual bool IsAnimated() const; - - /** Retrieves the animated element for the translation. - @return The animated element. This pointer will be NULL if the translation - is not animated. */ - inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } - virtual const FCDAnimated* GetAnimated() const; /**< See above. */ - - /** Retrieves whether a given transform is the exact opposite of - this translation. The opposite of a translation has a displacement - vector with all the components multiplied by -1. - @param transform A second transformation. - @return Whether the two transformations are opposites. */ - virtual bool IsInverse(const FCDTransform* transform) const; - - /** Creates a copy of a translation. - @param clone The transform that will be the clone. - @return The cloned transformation. */ - virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; -}; - -/** - A COLLADA non-uniform scale. - A non-uniform scale contains three scale factors. - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDTScale : public FCDTransform -{ -private: - DeclareObjectType(FCDTransform); - DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, scale, FC("Scale")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDSceneNode::AddTransform function with - the SCALE transformation type. - @param document The COLLADA document that owns the non-uniform scale. - @param parent The visual scene node that contains the non-uniform scale. - Set this pointer to NULL if the non-uniform scale is not owned - by a visual scene node. */ - FCDTScale(FCDocument* document, FCDSceneNode* parent); - - /** Destructor. */ - virtual ~FCDTScale(); - - /** Retrieves the transformation class type for the non-uniform scale. - @return The class type: SCALE. */ - virtual Type GetType() const { return SCALE; } - - /** Retrieves the factors of the non-uniform scale. - These factors may be animated. - @return The scale factors. */ - inline FCDParameterAnimatableVector3& GetScale() { return scale; } - inline const FCDParameterAnimatableVector3& GetScale() const { return scale; } /**< See above. */ - - /** Sets the factors of the non-uniform scale. - @param _scale The scale factors. */ - inline void SetScale(const FMVector3& _scale) { scale = _scale; SetValueChange(); } - - /** Sets the factors of the non-uniform scale. - @param x The x-component scale factor. - @param y The y-component scale factor. - @param z The z-component scale factor. */ - inline void SetScale(float x, float y, float z) { scale = FMVector3(x, y, z); SetValueChange(); } - - /** Converts the non-uniform scale into a matrix. - @return A matrix equivalent of the non-uniform scale. */ - virtual FMMatrix44 ToMatrix() const; - - /** Retrieves whether the factors of the non-uniform scale are animated. - @return Whether the scale factors are animated. */ - virtual bool IsAnimated() const; - - /** Retrieves the animated element for the non-uniform scale factors. - @return The animated element. This pointer will be NULL if the - scale factors are not animated. */ - inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } - virtual const FCDAnimated* GetAnimated() const; /**< See above. */ - - /** Creates a copy of a non-uniform scale. - @param clone The transform that will be the clone. - @return The cloned transformation. */ - virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; -}; - -/** - A COLLADA angle-axis rotation. - This rotation defines an axis around which the 3D points - are rotated by a given angle. - @todo (clock-wise/counter-clock-wise?) - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDTRotation : public FCDTransform -{ -private: - DeclareObjectType(FCDTransform); - DeclareParameterAnimatable(FMAngleAxis, FUParameterQualifiers::SIMPLE, angleAxis, FC("Angle-axis")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDSceneNode::AddTransform function with - the transformation type: ROTATION. - @param document The COLLADA document that owns the rotation. - @param parent The visual scene node that contains the rotation. - Set this pointer to NULL if the rotation is not owned - by a visual scene node. */ - FCDTRotation(FCDocument* document, FCDSceneNode* parent); - - /** Destructor. */ - virtual ~FCDTRotation(); - - /** Retrieves the transformation class type for the rotation. - @return The class type: ROTATION. */ - virtual Type GetType() const { return ROTATION; } - - /** Retrieves the angle-axis value of the rotation. - @return The angle-axis value. */ - inline FCDParameterAnimatableAngleAxis& GetAngleAxis() { return angleAxis; } - inline const FCDParameterAnimatableAngleAxis& GetAngleAxis() const { return angleAxis; } /**< See above. */ - - /** Sets the angle-axis value of the rotation. - @param aa The new angle-axis value. */ - inline void SetAngleAxis(const FMAngleAxis& aa) { angleAxis = aa; SetValueChange(); } - - /** Retrieves the rotation axis. - This 3D vector may be animated. - @return The rotation axis. */ - inline FMVector3& GetAxis() { return angleAxis->axis; } - inline const FMVector3& GetAxis() const { return angleAxis->axis; } /**< See above. */ - - /** Sets the rotation axis. - @param axis The rotation axis. */ - inline void SetAxis(const FMVector3& axis) { angleAxis->axis = axis; SetValueChange(); } - - /** Sets the rotation axis. - @param x The x-component of the rotation axis. - @param y The y-component of the rotation axis. - @param z The z-component of the rotation axis. */ - inline void SetAxis(float x, float y, float z) { angleAxis->axis = FMVector3(x, y, z); SetValueChange(); } - - /** Retrieves the rotation angle. - This angle may be animated. - @return The rotation angle, in degrees. */ - inline float& GetAngle() { return angleAxis->angle; } - inline const float& GetAngle() const { return angleAxis->angle; } /**< See above. */ - - /** Sets the rotation angle. - @param a The rotation angle, in degrees. */ - inline void SetAngle(float a) { angleAxis->angle = a; SetValueChange(); } - - /** Sets the rotation components - @param axis The rotation axis. - @param angle The rotation angle, in degrees. */ - inline void SetRotation(const FMVector3& axis, float angle) { angleAxis = FMAngleAxis(axis, angle); SetValueChange(); } - - /** Retrieves the rotation orientation. - @return The rotation orientation quaternion. */ - inline FMQuaternion GetOrientation() { return FMQuaternion(angleAxis->axis, FMath::DegToRad(angleAxis->angle)); } - - /** Sets the rotation orientation. - @param q The rotation orientation quaternion. */ - inline void SetOrientation(const FMQuaternion& q) { q.ToAngleAxis(angleAxis->axis, angleAxis->angle); angleAxis->angle = FMath::RadToDeg(angleAxis->angle); SetValueChange(); } - - /** Converts the rotation into a matrix. - @return A matrix equivalent of the rotation. */ - virtual FMMatrix44 ToMatrix() const; - - /** Retrieves whether the axis or the angle of the rotation are animated. - @return Whether the rotation is animated. */ - virtual bool IsAnimated() const; - - /** Retrieves the animated element for the angle-axis rotation. - @see FCDAnimatedAngleAxis - @return The animated element. This pointer will be NULL if the - rotation is not animated. */ - inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } - virtual const FCDAnimated* GetAnimated() const; /**< See above. */ - - /** Retrieves whether a given transform is the exact opposite of - this rotation. The opposite of an angle-axis rotation has the - same axis as this rotation but the angle is multiplied by -1. - @param transform A second transformation. - @return Whether the two rotation are opposites. */ - virtual bool IsInverse(const FCDTransform* transform) const; - - /** Creates a copy of a rotation. - @param clone The transform that will be the clone. - @return The cloned transformation. */ - virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; -}; - -/** - A COLLADA matrix transformation. - This transformation contains a matrix that should be - multiplied to the local transformation matrix. - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDTMatrix : public FCDTransform -{ -private: - DeclareObjectType(FCDTransform); - DeclareParameterAnimatable(FMMatrix44, FUParameterQualifiers::SIMPLE, transform, FC("Transform")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDSceneNode::AddTransform function with - the transformation type: MATRIX. - @param document The COLLADA document that owns the transformation. - @param parent The visual scene node that contains the transformation. */ - FCDTMatrix(FCDocument* document, FCDSceneNode* parent); - - /** Destructor. */ - virtual ~FCDTMatrix(); - - /** Retrieves the transformation class type for the transformation. - @return The class type: MATRIX. */ - virtual Type GetType() const { return MATRIX; } - - /** Retrieves the matrix for the transformation. - All 16 values of the matrix may be animated. - @return The transformation matrix. */ - inline FCDParameterAnimatableMatrix44& GetTransform() { return transform; } - inline const FCDParameterAnimatableMatrix44& GetTransform() const { return transform; } /**< See above. */ - - /** Sets the matrix for the transformation. - @param mx The transformation matrix. */ - inline void SetTransform(const FMMatrix44& mx) { transform = mx; SetValueChange(); } - - /** Converts the transformation into a matrix. - For matrix transformations, that's simply the transformation matrix. - @return The transformation matrix. */ - virtual FMMatrix44 ToMatrix() const { return transform; } - - /** Retrieves whether the transformation matrix is animated. - @return Whether the transformation matrix is animated. */ - virtual bool IsAnimated() const; - - /** Retrieves the animated element for the transformation matrix. - @see FCDAnimatedMatrix - @return The animated element. This pointer will be NULL if the - transformation matrix is not animated. */ - inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } - virtual const FCDAnimated* GetAnimated() const; /**< See above. */ - - /** Creates a copy of a matrix transformation. - @param clone The transform that will be the clone. - @return The cloned transformation. */ - virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; -}; - -/** - A COLLADA 'look-at' transformation. - This transformation type fully defines a position - and an orientation with a 3D world by using three - 3D vectors: the viewer's position, the position - that the viewer is looking at, and the up-vector - for camera rolls. */ -class FCOLLADA_EXPORT FCDTLookAt : public FCDTransform -{ -private: - DeclareObjectType(FCDTransform); - DeclareParameterAnimatable(FMLookAt, FUParameterQualifiers::SIMPLE, lookAt, FC("LookAt")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDSceneNode::AddTransform function with - the transformation type: LOOKAT. - @param document The COLLADA document that owns the transformation. - @param parent The visual scene node that contains the transformation. */ - FCDTLookAt(FCDocument* document, FCDSceneNode* parent); - - /** Destructor. */ - virtual ~FCDTLookAt(); - - /** Retrieves the transformation class type for the transformation. - @return The class type: LOOKAT. */ - virtual Type GetType() const { return LOOKAT; } - - /** Retrieves the look-at value for this transformation. - @return The local look-at. */ - inline FCDParameterAnimatableLookAt& GetLookAt() { return lookAt; } - inline const FCDParameterAnimatableLookAt& GetLookAt() const { return lookAt; } /**< See above. */ - - /** Sets the look-at value for this transformation. - @param _lookAt A look-at. */ - inline void SetLookAt(const FMLookAt& _lookAt) { lookAt = _lookAt; SetValueChange(); } - - /** Retrieves the viewer's position. - @return The viewer's position. */ - FMVector3& GetPosition() { return lookAt->position; } - const FMVector3& GetPosition() const { return lookAt->position; } /**< See above. */ - - /** Sets the viewer's position. - @param pos The viewer's position. */ - inline void SetPosition(const FMVector3& pos) { lookAt->position = pos; SetValueChange(); } - - /** Sets the viewer's position. - @param x The x-component of the position. - @param y The y-component of the position. - @param z The z-component of the position. */ - inline void SetPosition(float x, float y, float z) { lookAt->position = FMVector3(x, y, z); SetValueChange(); } - - /** Retrieves the position that the viewer is looking at. - @return The viewer's target. */ - FMVector3& GetTarget() { return lookAt->target; } - const FMVector3& GetTarget() const { return lookAt->target; } /**< See above. */ - - /** Sets the position that the viewer is looking at. - @param target The target position. */ - inline void SetTarget(const FMVector3& target) { lookAt->target = target; SetValueChange(); } - - /** Sets the position that the viewer is looking at. - @param x The x-component of the target position. - @param y The y-component of the target position. - @param z The z-component of the target position. */ - inline void SetTarget(float x, float y, float z) { lookAt->target = FMVector3(x, y, z); SetValueChange(); } - - /** Retrieves the viewer's up-vector. - @return The up-vector. */ - FMVector3& GetUp() { return lookAt->up; } - const FMVector3& GetUp() const { return lookAt->up; } /**< See above. */ - - /** Sets the viewer's up-vector. - @param up The up-vector. */ - inline void SetUp(const FMVector3& up) { lookAt->up = up; SetValueChange(); } - - /** Sets the viewer's up-vector. - @param x The x-component of the up-vector. - @param y The y-component of the up-vector. - @param z The z-component of the up-vector. */ - inline void SetUp(float x, float y, float z) { lookAt->up = FMVector3(x, y, z); SetValueChange(); } - - /** Converts the transformation into a matrix. - @return The transformation matrix. */ - virtual FMMatrix44 ToMatrix() const; - - /** Retrieves whether the transformation is animated. - FCollada now supports animated look-at transforms, through the FCDAnimatedCustom. - @return Whether the transform is animated. */ - virtual bool IsAnimated() const; - - /** Retrieves the animated element for the transformation matrix. - FCollada now supports animated look-at transforms. - @see FCDAnimatedCustom - @return the animated element, containing 9 values. */ - inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } - virtual const FCDAnimated* GetAnimated() const; /**< See above. */ - - /** Creates a copy of a look-at transformation. - @param clone The transform that will be the clone. - @return The cloned transformation. */ - virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; -}; - -/** - A COLLADA skew. - In COLLADA, the skew transformation follows the Renderman convention. - A skew is defined by two axis and one angle: the axis which is rotated, the axis around - which the rotation is done and the angle of the rotation. - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDTSkew : public FCDTransform -{ -private: - DeclareObjectType(FCDTransform); - DeclareParameterAnimatable(FMSkew, FUParameterQualifiers::SIMPLE, skew, FC("Skew")); - -public: - /** Constructor: do not use directly. - Instead, use the FCDSceneNode::AddTransform function with - the transformation type: SKEW. - @param document The COLLADA document that owns the skew. - @param parent The visual scene node that contains the skew. */ - FCDTSkew(FCDocument* document, FCDSceneNode* parent); - - /** Destructor. */ - virtual ~FCDTSkew(); - - /** Retrieves the transformation class type for the transformation. - @return The class type: SKEW. */ - virtual Type GetType() const { return SKEW; } - - /** Retrieves the skew value for this transformation. - @return The skew value. */ - inline FCDParameterAnimatableSkew& GetSkew() { return skew; } - inline const FCDParameterAnimatableSkew& GetSkew() const { return skew; } - - /** Sets the skew value for this transformation. - @param _skew A skew value. */ - inline void SetSkew(const FMSkew& _skew) { skew = _skew; SetValueChange(); } - - /** Retrieves the axis which is rotated. - @return The rotated axis. */ - const FMVector3& GetRotateAxis() const { return skew->rotateAxis; } - FMVector3& GetRotateAxis() { return skew->rotateAxis; } /**< See above. */ - - /** Sets the axis which is rotated. - @param axis The rotated axis. */ - inline void SetRotateAxis(const FMVector3& axis) { skew->rotateAxis = axis; SetValueChange(); } - - /** Retrieves the axis around which the rotation is done. - @return The rotation axis. */ - inline const FMVector3& GetAroundAxis() const { return skew->aroundAxis; } - inline FMVector3& GetAroundAxis() { return skew->aroundAxis; } /**< See above. */ - - /** Sets the axis around which the rotation is done. - @param axis The rotation axis. */ - inline void SetAroundAxis(const FMVector3& axis) { skew->aroundAxis = axis; SetValueChange(); } - - /** Retrieves the rotation angle. - @return The rotation angle. */ - inline const float& GetAngle() const { return skew->angle; } - inline float& GetAngle() { return skew->angle; } /**< See above. */ - - /** Sets the rotation angle. - @param _angle The rotation angle. */ - inline void SetAngle(float angle) { skew->angle = angle; SetValueChange(); } - - /** Converts the skew into a matrix. - @return The transformation matrix. */ - virtual FMMatrix44 ToMatrix() const; - - /** Retrieves whether the transformation is animated. - @return FCollada doesn't support animated skews: false. */ - virtual bool IsAnimated() const; - - /** Retrieves the animated element for the skew. - @return FCollada doesn't support animated skews: NULL. */ - inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } - virtual const FCDAnimated* GetAnimated() const; /**< See above. */ - - /** Creates a copy of a skew transformation. - @param clone The transform that will be the clone. - @return The cloned transformation. */ - virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; -}; - -/** - [INTERNAL] A factory for COLLADA transforms. - Creates the correct transform object for a given transform type/XML tree node. - To create new transforms, use the FCDSceneNode::AddTransform function. -*/ -class FCOLLADA_EXPORT FCDTFactory -{ -private: - FCDTFactory() {} // Static class: do not instantiate. - -public: - /** Creates a new COLLADA transform, given a transform type. - @param document The COLLADA document that will own the new transform. - @param parent The visual scene node that will contain the transform. - @param type The type of transform object to create. - @return The new COLLADA transform. This pointer will be NULL - if the given type is invalid. */ - static FCDTransform* CreateTransform(FCDocument* document, FCDSceneNode* parent, FCDTransform::Type type); -}; - -#endif // _FR_TRANSFORM_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDTransform.h + This file contains the FCDTransform class and its up-classes: + FCDTTranslation, FCDTScale, FCDTRotation, FCDTMatrix, FCDTLookAt and FCDTSkew. +*/ + +#ifndef _FCD_TRANSFORM_H_ +#define _FCD_TRANSFORM_H_ + +class FCDocument; +class FCDAnimated; +class FCDSceneNode; +class FCDTransform; + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FM_QUATERNION_H_ +#include "FMath/FMQuaternion.h" +#endif // _FM_QUATERNION_H_ +#ifndef _FCD_PARAMETER_ANIMATABLE_H_ +#include "FCDocument/FCDParameterAnimatable.h" +#endif // _FCD_PARAMETER_ANIMATABLE_H_ + +/** + A COLLADA transform. + + COLLADA supports six transformation types: translations(FCDTTranslation), + rotations(FCDTRotation), scales(FCDTScale), matrices(FCDTMatrix), + skews(FCDTSkew) and the 'look-at' transform(FCDTLookAt). + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDTransform : public FCDObject +{ +public: + /** The COLLADA transform types. */ + enum Type + { + TRANSLATION, /**< A translation(FCDTTranslation). */ + ROTATION, /**< A rotation(FCDTRotation). */ + SCALE, /**< A non-uniform scale(FCDTScale). */ + MATRIX, /**< A matrix multiplication(FCDTMatrix). */ + LOOKAT, /**< A targeted, 'look-at' transformation(FCDTLookAt). */ + SKEW, /**< A skew(FCDTSkew). */ + TYPE_COUNT + }; + +private: + DeclareObjectType(FCDObject); + FCDSceneNode* parent; + DeclareParameter(fm::string, FUParameterQualifiers::SIMPLE, sid, FC("Sub-id")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDSceneNode::AddTransform function. + @param document The COLLADA document that owns the transform. + @param parent The visual scene node that contains the transform. + Set this pointer to NULL if this transform is not owned by a + visual scene node. */ + FCDTransform(FCDocument* document, FCDSceneNode* parent); + + /** Destructor. */ + virtual ~FCDTransform(); + + /** Retrieves the visual scene node that contains this transformation. + @return The parent visual scene node. This pointer will be NULL + if the transformation is not contained by a visual scene node. */ + FCDSceneNode* GetParent() { return parent; } + const FCDSceneNode* GetParent() const { return parent; } /**< See above. */ + + /** [DEPRECATED] Sets on a scene node parent, the transform dirty flag. */ + DEPRECATED(3.05, SetValueChange) + void SetTransformsDirtyFlag(); + + /** Creates a copy of a transformation. + @param clone The transform that will be the clone. + @return The cloned transformation. */ + virtual FCDTransform* Clone(FCDTransform* clone = NULL) const = 0; + + /** Retrieves the class type of the transformation. + The class type should be used to up-case the transformation pointer. + @return The class type. */ + virtual Type GetType() const = 0; + + /** Converts the transformation into a matrix. + Useful for visual scene nodes with a weird transformation stack. + @return A matrix equivalent of the transformation. */ + virtual FMMatrix44 ToMatrix() const = 0; + + /** Retrieves the wanted sub-id for this transform. + A wanted sub-id will always be exported, even if the transform is not animated. + But the wanted sub-id may be modified if it isn't unique within the scope. + @return The sub-id. */ + inline FUParameterString& GetSubId() { return sid; } + inline const FUParameterString& GetSubId() const { return sid; } /**< See above. */ + + /** Sets the wanted sub-id for this transform. + A wanted sub-id will always be exported, even if the transform is not animated. + But the wanted sub-id may be modified if it isn't unique within the scope. + @param subId The wanted sub-id. */ + void SetSubId(const fm::string& subId); + + /** Retrieves whether this transformation has an animation tied to its values. + @return Whether the transformation is animated. */ + virtual bool IsAnimated() const = 0; + + /** Retrieves the animated element for the transformation. + @return The animated element. This pointer will be NULL if the transformation + is not animated. */ + inline FCDAnimated* GetAnimated() { return const_cast(const_cast(this)->GetAnimated()); } + virtual const FCDAnimated* GetAnimated() const = 0; /**< See above. */ + + /** Retrieves whether a given transformation is the exact opposite of + this transformation. Executing two opposite transformations, one after the + other will not give any resulting transformation. This function is useful + to detect pivots within the transform stack. + @param transform A second transformation. + @return Whether the two transformations are opposites. */ + virtual bool IsInverse(const FCDTransform* transform) const; + + /** Set Value changed flag. When this happens, notify our parent */ + virtual void SetValueChange(); +}; + +/** + A COLLADA translation. + A translation is a simple 3D displacement. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDTTranslation : public FCDTransform +{ +private: + DeclareObjectType(FCDTransform); + DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, translation, FC("Translation")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDSceneNode::AddTransform function with + the TRANSLATION transformation type. + @param document The COLLADA document that owns the translation. + @param parent The visual scene node that contains the translation. + Set this pointer to NULL if the translation is not owned + by a visual scene node. */ + FCDTTranslation(FCDocument* document, FCDSceneNode* parent); + + /** Destructor. */ + virtual ~FCDTTranslation(); + + /** Retrieves the transformation class type for the translation. + @return The transformation class type: TRANSLATION. */ + virtual Type GetType() const { return TRANSLATION; } + + /** Retrieves the translation 3D displacement vector. + This displacement vector may be animated. + @return The displacement vector. */ + inline FCDParameterAnimatableVector3& GetTranslation() { return translation; } + inline const FCDParameterAnimatableVector3& GetTranslation() const { return translation; } /**< See above. */ + + /** Sets the translation 3D displacement vector. + @param _translation The displacement vector. */ + inline void SetTranslation(const FMVector3& _translation) { translation = _translation; SetValueChange(); } + + /** Sets the translation 3D displacement vector. + @param x The x-component displacement. + @param y The y-component displacement. + @param z The z-component displacement. */ + inline void SetTranslation(float x, float y, float z) { translation = FMVector3(x, y, z); SetValueChange(); } + + /** Converts the translation into a matrix. + @return A matrix equivalent of the translation. */ + virtual FMMatrix44 ToMatrix() const; + + /** Retrieves whether this translation is affected by an animation. + @return Whether the translation is animated. */ + virtual bool IsAnimated() const; + + /** Retrieves the animated element for the translation. + @return The animated element. This pointer will be NULL if the translation + is not animated. */ + inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } + virtual const FCDAnimated* GetAnimated() const; /**< See above. */ + + /** Retrieves whether a given transform is the exact opposite of + this translation. The opposite of a translation has a displacement + vector with all the components multiplied by -1. + @param transform A second transformation. + @return Whether the two transformations are opposites. */ + virtual bool IsInverse(const FCDTransform* transform) const; + + /** Creates a copy of a translation. + @param clone The transform that will be the clone. + @return The cloned transformation. */ + virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; +}; + +/** + A COLLADA non-uniform scale. + A non-uniform scale contains three scale factors. + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDTScale : public FCDTransform +{ +private: + DeclareObjectType(FCDTransform); + DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::VECTOR, scale, FC("Scale")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDSceneNode::AddTransform function with + the SCALE transformation type. + @param document The COLLADA document that owns the non-uniform scale. + @param parent The visual scene node that contains the non-uniform scale. + Set this pointer to NULL if the non-uniform scale is not owned + by a visual scene node. */ + FCDTScale(FCDocument* document, FCDSceneNode* parent); + + /** Destructor. */ + virtual ~FCDTScale(); + + /** Retrieves the transformation class type for the non-uniform scale. + @return The class type: SCALE. */ + virtual Type GetType() const { return SCALE; } + + /** Retrieves the factors of the non-uniform scale. + These factors may be animated. + @return The scale factors. */ + inline FCDParameterAnimatableVector3& GetScale() { return scale; } + inline const FCDParameterAnimatableVector3& GetScale() const { return scale; } /**< See above. */ + + /** Sets the factors of the non-uniform scale. + @param _scale The scale factors. */ + inline void SetScale(const FMVector3& _scale) { scale = _scale; SetValueChange(); } + + /** Sets the factors of the non-uniform scale. + @param x The x-component scale factor. + @param y The y-component scale factor. + @param z The z-component scale factor. */ + inline void SetScale(float x, float y, float z) { scale = FMVector3(x, y, z); SetValueChange(); } + + /** Converts the non-uniform scale into a matrix. + @return A matrix equivalent of the non-uniform scale. */ + virtual FMMatrix44 ToMatrix() const; + + /** Retrieves whether the factors of the non-uniform scale are animated. + @return Whether the scale factors are animated. */ + virtual bool IsAnimated() const; + + /** Retrieves the animated element for the non-uniform scale factors. + @return The animated element. This pointer will be NULL if the + scale factors are not animated. */ + inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } + virtual const FCDAnimated* GetAnimated() const; /**< See above. */ + + /** Creates a copy of a non-uniform scale. + @param clone The transform that will be the clone. + @return The cloned transformation. */ + virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; +}; + +/** + A COLLADA angle-axis rotation. + This rotation defines an axis around which the 3D points + are rotated by a given angle. + @todo (clock-wise/counter-clock-wise?) + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDTRotation : public FCDTransform +{ +private: + DeclareObjectType(FCDTransform); + DeclareParameterAnimatable(FMAngleAxis, FUParameterQualifiers::SIMPLE, angleAxis, FC("Angle-axis")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDSceneNode::AddTransform function with + the transformation type: ROTATION. + @param document The COLLADA document that owns the rotation. + @param parent The visual scene node that contains the rotation. + Set this pointer to NULL if the rotation is not owned + by a visual scene node. */ + FCDTRotation(FCDocument* document, FCDSceneNode* parent); + + /** Destructor. */ + virtual ~FCDTRotation(); + + /** Retrieves the transformation class type for the rotation. + @return The class type: ROTATION. */ + virtual Type GetType() const { return ROTATION; } + + /** Retrieves the angle-axis value of the rotation. + @return The angle-axis value. */ + inline FCDParameterAnimatableAngleAxis& GetAngleAxis() { return angleAxis; } + inline const FCDParameterAnimatableAngleAxis& GetAngleAxis() const { return angleAxis; } /**< See above. */ + + /** Sets the angle-axis value of the rotation. + @param aa The new angle-axis value. */ + inline void SetAngleAxis(const FMAngleAxis& aa) { angleAxis = aa; SetValueChange(); } + + /** Retrieves the rotation axis. + This 3D vector may be animated. + @return The rotation axis. */ + inline FMVector3& GetAxis() { return angleAxis->axis; } + inline const FMVector3& GetAxis() const { return angleAxis->axis; } /**< See above. */ + + /** Sets the rotation axis. + @param axis The rotation axis. */ + inline void SetAxis(const FMVector3& axis) { angleAxis->axis = axis; SetValueChange(); } + + /** Sets the rotation axis. + @param x The x-component of the rotation axis. + @param y The y-component of the rotation axis. + @param z The z-component of the rotation axis. */ + inline void SetAxis(float x, float y, float z) { angleAxis->axis = FMVector3(x, y, z); SetValueChange(); } + + /** Retrieves the rotation angle. + This angle may be animated. + @return The rotation angle, in degrees. */ + inline float& GetAngle() { return angleAxis->angle; } + inline const float& GetAngle() const { return angleAxis->angle; } /**< See above. */ + + /** Sets the rotation angle. + @param a The rotation angle, in degrees. */ + inline void SetAngle(float a) { angleAxis->angle = a; SetValueChange(); } + + /** Sets the rotation components + @param axis The rotation axis. + @param angle The rotation angle, in degrees. */ + inline void SetRotation(const FMVector3& axis, float angle) { angleAxis = FMAngleAxis(axis, angle); SetValueChange(); } + + /** Retrieves the rotation orientation. + @return The rotation orientation quaternion. */ + inline FMQuaternion GetOrientation() { return FMQuaternion(angleAxis->axis, FMath::DegToRad(angleAxis->angle)); } + + /** Sets the rotation orientation. + @param q The rotation orientation quaternion. */ + inline void SetOrientation(const FMQuaternion& q) { q.ToAngleAxis(angleAxis->axis, angleAxis->angle); angleAxis->angle = FMath::RadToDeg(angleAxis->angle); SetValueChange(); } + + /** Converts the rotation into a matrix. + @return A matrix equivalent of the rotation. */ + virtual FMMatrix44 ToMatrix() const; + + /** Retrieves whether the axis or the angle of the rotation are animated. + @return Whether the rotation is animated. */ + virtual bool IsAnimated() const; + + /** Retrieves the animated element for the angle-axis rotation. + @see FCDAnimatedAngleAxis + @return The animated element. This pointer will be NULL if the + rotation is not animated. */ + inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } + virtual const FCDAnimated* GetAnimated() const; /**< See above. */ + + /** Retrieves whether a given transform is the exact opposite of + this rotation. The opposite of an angle-axis rotation has the + same axis as this rotation but the angle is multiplied by -1. + @param transform A second transformation. + @return Whether the two rotation are opposites. */ + virtual bool IsInverse(const FCDTransform* transform) const; + + /** Creates a copy of a rotation. + @param clone The transform that will be the clone. + @return The cloned transformation. */ + virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; +}; + +/** + A COLLADA matrix transformation. + This transformation contains a matrix that should be + multiplied to the local transformation matrix. + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDTMatrix : public FCDTransform +{ +private: + DeclareObjectType(FCDTransform); + DeclareParameterAnimatable(FMMatrix44, FUParameterQualifiers::SIMPLE, transform, FC("Transform")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDSceneNode::AddTransform function with + the transformation type: MATRIX. + @param document The COLLADA document that owns the transformation. + @param parent The visual scene node that contains the transformation. */ + FCDTMatrix(FCDocument* document, FCDSceneNode* parent); + + /** Destructor. */ + virtual ~FCDTMatrix(); + + /** Retrieves the transformation class type for the transformation. + @return The class type: MATRIX. */ + virtual Type GetType() const { return MATRIX; } + + /** Retrieves the matrix for the transformation. + All 16 values of the matrix may be animated. + @return The transformation matrix. */ + inline FCDParameterAnimatableMatrix44& GetTransform() { return transform; } + inline const FCDParameterAnimatableMatrix44& GetTransform() const { return transform; } /**< See above. */ + + /** Sets the matrix for the transformation. + @param mx The transformation matrix. */ + inline void SetTransform(const FMMatrix44& mx) { transform = mx; SetValueChange(); } + + /** Converts the transformation into a matrix. + For matrix transformations, that's simply the transformation matrix. + @return The transformation matrix. */ + virtual FMMatrix44 ToMatrix() const { return transform; } + + /** Retrieves whether the transformation matrix is animated. + @return Whether the transformation matrix is animated. */ + virtual bool IsAnimated() const; + + /** Retrieves the animated element for the transformation matrix. + @see FCDAnimatedMatrix + @return The animated element. This pointer will be NULL if the + transformation matrix is not animated. */ + inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } + virtual const FCDAnimated* GetAnimated() const; /**< See above. */ + + /** Creates a copy of a matrix transformation. + @param clone The transform that will be the clone. + @return The cloned transformation. */ + virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; +}; + +/** + A COLLADA 'look-at' transformation. + This transformation type fully defines a position + and an orientation with a 3D world by using three + 3D vectors: the viewer's position, the position + that the viewer is looking at, and the up-vector + for camera rolls. */ +class FCOLLADA_EXPORT FCDTLookAt : public FCDTransform +{ +private: + DeclareObjectType(FCDTransform); + DeclareParameterAnimatable(FMLookAt, FUParameterQualifiers::SIMPLE, lookAt, FC("LookAt")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDSceneNode::AddTransform function with + the transformation type: LOOKAT. + @param document The COLLADA document that owns the transformation. + @param parent The visual scene node that contains the transformation. */ + FCDTLookAt(FCDocument* document, FCDSceneNode* parent); + + /** Destructor. */ + virtual ~FCDTLookAt(); + + /** Retrieves the transformation class type for the transformation. + @return The class type: LOOKAT. */ + virtual Type GetType() const { return LOOKAT; } + + /** Retrieves the look-at value for this transformation. + @return The local look-at. */ + inline FCDParameterAnimatableLookAt& GetLookAt() { return lookAt; } + inline const FCDParameterAnimatableLookAt& GetLookAt() const { return lookAt; } /**< See above. */ + + /** Sets the look-at value for this transformation. + @param _lookAt A look-at. */ + inline void SetLookAt(const FMLookAt& _lookAt) { lookAt = _lookAt; SetValueChange(); } + + /** Retrieves the viewer's position. + @return The viewer's position. */ + FMVector3& GetPosition() { return lookAt->position; } + const FMVector3& GetPosition() const { return lookAt->position; } /**< See above. */ + + /** Sets the viewer's position. + @param pos The viewer's position. */ + inline void SetPosition(const FMVector3& pos) { lookAt->position = pos; SetValueChange(); } + + /** Sets the viewer's position. + @param x The x-component of the position. + @param y The y-component of the position. + @param z The z-component of the position. */ + inline void SetPosition(float x, float y, float z) { lookAt->position = FMVector3(x, y, z); SetValueChange(); } + + /** Retrieves the position that the viewer is looking at. + @return The viewer's target. */ + FMVector3& GetTarget() { return lookAt->target; } + const FMVector3& GetTarget() const { return lookAt->target; } /**< See above. */ + + /** Sets the position that the viewer is looking at. + @param target The target position. */ + inline void SetTarget(const FMVector3& target) { lookAt->target = target; SetValueChange(); } + + /** Sets the position that the viewer is looking at. + @param x The x-component of the target position. + @param y The y-component of the target position. + @param z The z-component of the target position. */ + inline void SetTarget(float x, float y, float z) { lookAt->target = FMVector3(x, y, z); SetValueChange(); } + + /** Retrieves the viewer's up-vector. + @return The up-vector. */ + FMVector3& GetUp() { return lookAt->up; } + const FMVector3& GetUp() const { return lookAt->up; } /**< See above. */ + + /** Sets the viewer's up-vector. + @param up The up-vector. */ + inline void SetUp(const FMVector3& up) { lookAt->up = up; SetValueChange(); } + + /** Sets the viewer's up-vector. + @param x The x-component of the up-vector. + @param y The y-component of the up-vector. + @param z The z-component of the up-vector. */ + inline void SetUp(float x, float y, float z) { lookAt->up = FMVector3(x, y, z); SetValueChange(); } + + /** Converts the transformation into a matrix. + @return The transformation matrix. */ + virtual FMMatrix44 ToMatrix() const; + + /** Retrieves whether the transformation is animated. + FCollada now supports animated look-at transforms, through the FCDAnimatedCustom. + @return Whether the transform is animated. */ + virtual bool IsAnimated() const; + + /** Retrieves the animated element for the transformation matrix. + FCollada now supports animated look-at transforms. + @see FCDAnimatedCustom + @return the animated element, containing 9 values. */ + inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } + virtual const FCDAnimated* GetAnimated() const; /**< See above. */ + + /** Creates a copy of a look-at transformation. + @param clone The transform that will be the clone. + @return The cloned transformation. */ + virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; +}; + +/** + A COLLADA skew. + In COLLADA, the skew transformation follows the Renderman convention. + A skew is defined by two axis and one angle: the axis which is rotated, the axis around + which the rotation is done and the angle of the rotation. + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDTSkew : public FCDTransform +{ +private: + DeclareObjectType(FCDTransform); + DeclareParameterAnimatable(FMSkew, FUParameterQualifiers::SIMPLE, skew, FC("Skew")); + +public: + /** Constructor: do not use directly. + Instead, use the FCDSceneNode::AddTransform function with + the transformation type: SKEW. + @param document The COLLADA document that owns the skew. + @param parent The visual scene node that contains the skew. */ + FCDTSkew(FCDocument* document, FCDSceneNode* parent); + + /** Destructor. */ + virtual ~FCDTSkew(); + + /** Retrieves the transformation class type for the transformation. + @return The class type: SKEW. */ + virtual Type GetType() const { return SKEW; } + + /** Retrieves the skew value for this transformation. + @return The skew value. */ + inline FCDParameterAnimatableSkew& GetSkew() { return skew; } + inline const FCDParameterAnimatableSkew& GetSkew() const { return skew; } + + /** Sets the skew value for this transformation. + @param _skew A skew value. */ + inline void SetSkew(const FMSkew& _skew) { skew = _skew; SetValueChange(); } + + /** Retrieves the axis which is rotated. + @return The rotated axis. */ + const FMVector3& GetRotateAxis() const { return skew->rotateAxis; } + FMVector3& GetRotateAxis() { return skew->rotateAxis; } /**< See above. */ + + /** Sets the axis which is rotated. + @param axis The rotated axis. */ + inline void SetRotateAxis(const FMVector3& axis) { skew->rotateAxis = axis; SetValueChange(); } + + /** Retrieves the axis around which the rotation is done. + @return The rotation axis. */ + inline const FMVector3& GetAroundAxis() const { return skew->aroundAxis; } + inline FMVector3& GetAroundAxis() { return skew->aroundAxis; } /**< See above. */ + + /** Sets the axis around which the rotation is done. + @param axis The rotation axis. */ + inline void SetAroundAxis(const FMVector3& axis) { skew->aroundAxis = axis; SetValueChange(); } + + /** Retrieves the rotation angle. + @return The rotation angle. */ + inline const float& GetAngle() const { return skew->angle; } + inline float& GetAngle() { return skew->angle; } /**< See above. */ + + /** Sets the rotation angle. + @param _angle The rotation angle. */ + inline void SetAngle(float angle) { skew->angle = angle; SetValueChange(); } + + /** Converts the skew into a matrix. + @return The transformation matrix. */ + virtual FMMatrix44 ToMatrix() const; + + /** Retrieves whether the transformation is animated. + @return FCollada doesn't support animated skews: false. */ + virtual bool IsAnimated() const; + + /** Retrieves the animated element for the skew. + @return FCollada doesn't support animated skews: NULL. */ + inline FCDAnimated* GetAnimated() { return Parent::GetAnimated(); } + virtual const FCDAnimated* GetAnimated() const; /**< See above. */ + + /** Creates a copy of a skew transformation. + @param clone The transform that will be the clone. + @return The cloned transformation. */ + virtual FCDTransform* Clone(FCDTransform* clone = NULL) const; +}; + +/** + [INTERNAL] A factory for COLLADA transforms. + Creates the correct transform object for a given transform type/XML tree node. + To create new transforms, use the FCDSceneNode::AddTransform function. +*/ +class FCOLLADA_EXPORT FCDTFactory +{ +private: + FCDTFactory() {} // Static class: do not instantiate. + +public: + /** Creates a new COLLADA transform, given a transform type. + @param document The COLLADA document that will own the new transform. + @param parent The visual scene node that will contain the transform. + @param type The type of transform object to create. + @return The new COLLADA transform. This pointer will be NULL + if the given type is invalid. */ + static FCDTransform* CreateTransform(FCDocument* document, FCDSceneNode* parent, FCDTransform::Type type); +}; + +#endif // _FR_TRANSFORM_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTransform.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTransform.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTransform.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTransform.cpp (revision 24247) @@ -1,339 +1,339 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument.h" -#include "FCDSceneNode.h" -#include "FCDTransform.h" -#include -#include -#include - -// -// FCDTransform -// - -ImplementObjectType(FCDTransform); - -FCDTransform::FCDTransform(FCDocument* document, FCDSceneNode* _parent) -: FCDObject(document), parent(_parent) -, InitializeParameterNoArg(sid) -{} - -FCDTransform::~FCDTransform() -{ - parent = NULL; -} - -bool FCDTransform::IsInverse(const FCDTransform* UNUSED(transform)) const -{ - return false; -} - -void FCDTransform::SetSubId(const fm::string& subId) -{ - sid = FCDObjectWithId::CleanSubId(subId); - SetDirtyFlag(); -} - -void FCDTransform::SetValueChange() -{ - SetValueChangedFlag(); - // parent == NULL is a valid value in ColladaPhysics. - if (parent != NULL) parent->SetTransformsDirtyFlag(); -} - -// -// FCDTTranslation -// - -ImplementObjectType(FCDTTranslation); - -FCDTTranslation::FCDTTranslation(FCDocument* document, FCDSceneNode* parent) -: FCDTransform(document, parent) -, InitializeParameterAnimatable(translation, FMVector3::Zero) -{ -} - -FCDTTranslation::~FCDTTranslation() {} - -FCDTransform* FCDTTranslation::Clone(FCDTransform* _clone) const -{ - FCDTTranslation* clone = NULL; - if (_clone == NULL) clone = new FCDTTranslation(const_cast(GetDocument()), const_cast(GetParent())); - else if (!_clone->HasType(FCDTTranslation::GetClassType())) return _clone; - else clone = (FCDTTranslation*) _clone; - - clone->translation = translation; - return clone; -} - -FMMatrix44 FCDTTranslation::ToMatrix() const -{ - return FMMatrix44::TranslationMatrix(translation); -} - -const FCDAnimated* FCDTTranslation::GetAnimated() const -{ - return translation.GetAnimated(); -} - -bool FCDTTranslation::IsAnimated() const -{ - return translation.IsAnimated(); -} - -bool FCDTTranslation::IsInverse(const FCDTransform* transform) const -{ - return transform->GetType() == FCDTransform::TRANSLATION - && IsEquivalent(-1.0f * translation, ((const FCDTTranslation*)transform)->translation); -} - -// -// FCDTRotation -// - -ImplementObjectType(FCDTRotation); - -FCDTRotation::FCDTRotation(FCDocument* document, FCDSceneNode* parent) -: FCDTransform(document, parent) -, InitializeParameterAnimatable(angleAxis, FMAngleAxis(FMVector3::XAxis, 0.0f)) -{ -} - -FCDTRotation::~FCDTRotation() {} - -FCDTransform* FCDTRotation::Clone(FCDTransform* _clone) const -{ - FCDTRotation* clone = NULL; - if (_clone == NULL) clone = new FCDTRotation(const_cast(GetDocument()), const_cast(GetParent())); - else if (!_clone->HasType(FCDTRotation::GetClassType())) return _clone; - else clone = (FCDTRotation*) _clone; - - clone->angleAxis = angleAxis; - return clone; -} - -FMMatrix44 FCDTRotation::ToMatrix() const -{ - return FMMatrix44::AxisRotationMatrix(angleAxis->axis, FMath::DegToRad(angleAxis->angle)); -} - -const FCDAnimated* FCDTRotation::GetAnimated() const -{ - return angleAxis.GetAnimated(); -} - -bool FCDTRotation::IsAnimated() const -{ - return angleAxis.IsAnimated(); -} - -bool FCDTRotation::IsInverse(const FCDTransform* transform) const -{ - return transform->GetType() == FCDTransform::ROTATION - && ((IsEquivalent(angleAxis->axis, ((const FCDTRotation*)transform)->angleAxis->axis) - && IsEquivalent(-angleAxis->angle, ((const FCDTRotation*)transform)->angleAxis->angle)) - || (IsEquivalent(-angleAxis->axis, ((const FCDTRotation*)transform)->angleAxis->axis) - && IsEquivalent(angleAxis->angle, ((const FCDTRotation*)transform)->angleAxis->angle))); -} - -// -// FCDTScale -// - -ImplementObjectType(FCDTScale); - -FCDTScale::FCDTScale(FCDocument* document, FCDSceneNode* parent) -: FCDTransform(document, parent) -, InitializeParameterAnimatable(scale, FMVector3::One) -{ -} - -FCDTScale::~FCDTScale() {} - -FCDTransform* FCDTScale::Clone(FCDTransform* _clone) const -{ - FCDTScale* clone = NULL; - if (_clone == NULL) clone = new FCDTScale(const_cast(GetDocument()), const_cast(GetParent())); - else if (!_clone->HasType(FCDTScale::GetClassType())) return _clone; - else clone = (FCDTScale*) _clone; - - clone->scale = scale; - return clone; -} - -FMMatrix44 FCDTScale::ToMatrix() const -{ - return FMMatrix44::ScaleMatrix(scale); -} - -const FCDAnimated* FCDTScale::GetAnimated() const -{ - return scale.GetAnimated(); -} - -bool FCDTScale::IsAnimated() const -{ - return scale.IsAnimated(); -} - -// -// FCDTMatrix -// - -ImplementObjectType(FCDTMatrix); - -FCDTMatrix::FCDTMatrix(FCDocument* document, FCDSceneNode* parent) -: FCDTransform(document, parent) -, InitializeParameterAnimatable(transform, FMMatrix44::Identity) -{ -} - -FCDTMatrix::~FCDTMatrix() {} - -FCDTransform* FCDTMatrix::Clone(FCDTransform* _clone) const -{ - FCDTMatrix* clone = NULL; - if (_clone == NULL) clone = new FCDTMatrix(const_cast(GetDocument()), const_cast(GetParent())); - else if (!_clone->HasType(FCDTMatrix::GetClassType())) return _clone; - else clone = (FCDTMatrix*) _clone; - - clone->transform = transform; - return clone; -} - -const FCDAnimated* FCDTMatrix::GetAnimated() const -{ - return transform.GetAnimated(); -} - -bool FCDTMatrix::IsAnimated() const -{ - return transform.IsAnimated(); -} - -// -// FCDTLookAt -// - -ImplementObjectType(FCDTLookAt); - -FCDTLookAt::FCDTLookAt(FCDocument* document, FCDSceneNode* parent) -: FCDTransform(document, parent) -, InitializeParameterAnimatable(lookAt, FMLookAt(FMVector3::Zero, -FMVector3::ZAxis, FMVector3::YAxis)) -{ -} - -FCDTLookAt::~FCDTLookAt() {} - -FCDTransform* FCDTLookAt::Clone(FCDTransform* _clone) const -{ - FCDTLookAt* clone = NULL; - if (_clone == NULL) clone = new FCDTLookAt(const_cast(GetDocument()), const_cast(GetParent())); - else if (!_clone->HasType(FCDTLookAt::GetClassType())) return _clone; - else clone = (FCDTLookAt*) _clone; - - clone->lookAt = lookAt; - return clone; -} - -FMMatrix44 FCDTLookAt::ToMatrix() const -{ - return FMMatrix44::LookAtMatrix(lookAt->position, lookAt->target, lookAt->up); -} - -const FCDAnimated* FCDTLookAt::GetAnimated() const -{ - return lookAt.GetAnimated(); -} - -bool FCDTLookAt::IsAnimated() const -{ - return lookAt.IsAnimated(); -} - -// -// FCDTSkew -// - -ImplementObjectType(FCDTSkew); - -FCDTSkew::FCDTSkew(FCDocument* document, FCDSceneNode* parent) -: FCDTransform(document, parent) -, InitializeParameterAnimatable(skew, FMSkew(FMVector3::XAxis, FMVector3::YAxis, 0.0f)) -{ -} - -FCDTSkew::~FCDTSkew() -{ -} - -FCDTransform* FCDTSkew::Clone(FCDTransform* _clone) const -{ - FCDTSkew* clone = NULL; - if (_clone == NULL) clone = new FCDTSkew(const_cast(GetDocument()), const_cast(GetParent())); - else if (!_clone->HasType(FCDTSkew::GetClassType())) return _clone; - else clone = (FCDTSkew*) _clone; - - clone->skew = skew; - return clone; -} - -FMMatrix44 FCDTSkew::ToMatrix() const -{ - float v[4][4]; - - float s = tanf(FMath::DegToRad(skew->angle)); - - for (int row = 0; row < 3; ++row) - { - for (int col = 0; col < 3; ++col) - { - v[col][row] = ((row == col) ? 1.0f : 0.0f) + s * skew->rotateAxis[col] * skew->aroundAxis[row]; - } - } - - v[0][3] = v[1][3] = v[2][3] = 0.0f; - v[3][0] = v[3][1] = v[3][2] = 0.0f; - v[3][3] = 1.0f; - - return FMMatrix44((float*) v); -} - -const FCDAnimated* FCDTSkew::GetAnimated() const -{ - return skew.GetAnimated(); -} - -bool FCDTSkew::IsAnimated() const -{ - // Only angle may be animated for now. - return skew.IsAnimated(); -} - -// Creates a new COLLADA transform, given a transform type. -FCDTransform* FCDTFactory::CreateTransform(FCDocument* document, FCDSceneNode* parent, FCDTransform::Type type) -{ - switch (type) - { - case FCDTransform::TRANSLATION: return new FCDTTranslation(document, parent); - case FCDTransform::ROTATION: return new FCDTRotation(document, parent); - case FCDTransform::SCALE: return new FCDTScale(document, parent); - case FCDTransform::SKEW: return new FCDTSkew(document, parent); - case FCDTransform::MATRIX: return new FCDTMatrix(document, parent); - case FCDTransform::LOOKAT: return new FCDTLookAt(document, parent); - default: return NULL; - } -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument.h" +#include "FCDSceneNode.h" +#include "FCDTransform.h" +#include +#include +#include + +// +// FCDTransform +// + +ImplementObjectType(FCDTransform); + +FCDTransform::FCDTransform(FCDocument* document, FCDSceneNode* _parent) +: FCDObject(document), parent(_parent) +, InitializeParameterNoArg(sid) +{} + +FCDTransform::~FCDTransform() +{ + parent = NULL; +} + +bool FCDTransform::IsInverse(const FCDTransform* UNUSED(transform)) const +{ + return false; +} + +void FCDTransform::SetSubId(const fm::string& subId) +{ + sid = FCDObjectWithId::CleanSubId(subId); + SetDirtyFlag(); +} + +void FCDTransform::SetValueChange() +{ + SetValueChangedFlag(); + // parent == NULL is a valid value in ColladaPhysics. + if (parent != NULL) parent->SetTransformsDirtyFlag(); +} + +// +// FCDTTranslation +// + +ImplementObjectType(FCDTTranslation); + +FCDTTranslation::FCDTTranslation(FCDocument* document, FCDSceneNode* parent) +: FCDTransform(document, parent) +, InitializeParameterAnimatable(translation, FMVector3::Zero) +{ +} + +FCDTTranslation::~FCDTTranslation() {} + +FCDTransform* FCDTTranslation::Clone(FCDTransform* _clone) const +{ + FCDTTranslation* clone = NULL; + if (_clone == NULL) clone = new FCDTTranslation(const_cast(GetDocument()), const_cast(GetParent())); + else if (!_clone->HasType(FCDTTranslation::GetClassType())) return _clone; + else clone = (FCDTTranslation*) _clone; + + clone->translation = translation; + return clone; +} + +FMMatrix44 FCDTTranslation::ToMatrix() const +{ + return FMMatrix44::TranslationMatrix(translation); +} + +const FCDAnimated* FCDTTranslation::GetAnimated() const +{ + return translation.GetAnimated(); +} + +bool FCDTTranslation::IsAnimated() const +{ + return translation.IsAnimated(); +} + +bool FCDTTranslation::IsInverse(const FCDTransform* transform) const +{ + return transform->GetType() == FCDTransform::TRANSLATION + && IsEquivalent(-1.0f * translation, ((const FCDTTranslation*)transform)->translation); +} + +// +// FCDTRotation +// + +ImplementObjectType(FCDTRotation); + +FCDTRotation::FCDTRotation(FCDocument* document, FCDSceneNode* parent) +: FCDTransform(document, parent) +, InitializeParameterAnimatable(angleAxis, FMAngleAxis(FMVector3::XAxis, 0.0f)) +{ +} + +FCDTRotation::~FCDTRotation() {} + +FCDTransform* FCDTRotation::Clone(FCDTransform* _clone) const +{ + FCDTRotation* clone = NULL; + if (_clone == NULL) clone = new FCDTRotation(const_cast(GetDocument()), const_cast(GetParent())); + else if (!_clone->HasType(FCDTRotation::GetClassType())) return _clone; + else clone = (FCDTRotation*) _clone; + + clone->angleAxis = angleAxis; + return clone; +} + +FMMatrix44 FCDTRotation::ToMatrix() const +{ + return FMMatrix44::AxisRotationMatrix(angleAxis->axis, FMath::DegToRad(angleAxis->angle)); +} + +const FCDAnimated* FCDTRotation::GetAnimated() const +{ + return angleAxis.GetAnimated(); +} + +bool FCDTRotation::IsAnimated() const +{ + return angleAxis.IsAnimated(); +} + +bool FCDTRotation::IsInverse(const FCDTransform* transform) const +{ + return transform->GetType() == FCDTransform::ROTATION + && ((IsEquivalent(angleAxis->axis, ((const FCDTRotation*)transform)->angleAxis->axis) + && IsEquivalent(-angleAxis->angle, ((const FCDTRotation*)transform)->angleAxis->angle)) + || (IsEquivalent(-angleAxis->axis, ((const FCDTRotation*)transform)->angleAxis->axis) + && IsEquivalent(angleAxis->angle, ((const FCDTRotation*)transform)->angleAxis->angle))); +} + +// +// FCDTScale +// + +ImplementObjectType(FCDTScale); + +FCDTScale::FCDTScale(FCDocument* document, FCDSceneNode* parent) +: FCDTransform(document, parent) +, InitializeParameterAnimatable(scale, FMVector3::One) +{ +} + +FCDTScale::~FCDTScale() {} + +FCDTransform* FCDTScale::Clone(FCDTransform* _clone) const +{ + FCDTScale* clone = NULL; + if (_clone == NULL) clone = new FCDTScale(const_cast(GetDocument()), const_cast(GetParent())); + else if (!_clone->HasType(FCDTScale::GetClassType())) return _clone; + else clone = (FCDTScale*) _clone; + + clone->scale = scale; + return clone; +} + +FMMatrix44 FCDTScale::ToMatrix() const +{ + return FMMatrix44::ScaleMatrix(scale); +} + +const FCDAnimated* FCDTScale::GetAnimated() const +{ + return scale.GetAnimated(); +} + +bool FCDTScale::IsAnimated() const +{ + return scale.IsAnimated(); +} + +// +// FCDTMatrix +// + +ImplementObjectType(FCDTMatrix); + +FCDTMatrix::FCDTMatrix(FCDocument* document, FCDSceneNode* parent) +: FCDTransform(document, parent) +, InitializeParameterAnimatable(transform, FMMatrix44::Identity) +{ +} + +FCDTMatrix::~FCDTMatrix() {} + +FCDTransform* FCDTMatrix::Clone(FCDTransform* _clone) const +{ + FCDTMatrix* clone = NULL; + if (_clone == NULL) clone = new FCDTMatrix(const_cast(GetDocument()), const_cast(GetParent())); + else if (!_clone->HasType(FCDTMatrix::GetClassType())) return _clone; + else clone = (FCDTMatrix*) _clone; + + clone->transform = transform; + return clone; +} + +const FCDAnimated* FCDTMatrix::GetAnimated() const +{ + return transform.GetAnimated(); +} + +bool FCDTMatrix::IsAnimated() const +{ + return transform.IsAnimated(); +} + +// +// FCDTLookAt +// + +ImplementObjectType(FCDTLookAt); + +FCDTLookAt::FCDTLookAt(FCDocument* document, FCDSceneNode* parent) +: FCDTransform(document, parent) +, InitializeParameterAnimatable(lookAt, FMLookAt(FMVector3::Zero, -FMVector3::ZAxis, FMVector3::YAxis)) +{ +} + +FCDTLookAt::~FCDTLookAt() {} + +FCDTransform* FCDTLookAt::Clone(FCDTransform* _clone) const +{ + FCDTLookAt* clone = NULL; + if (_clone == NULL) clone = new FCDTLookAt(const_cast(GetDocument()), const_cast(GetParent())); + else if (!_clone->HasType(FCDTLookAt::GetClassType())) return _clone; + else clone = (FCDTLookAt*) _clone; + + clone->lookAt = lookAt; + return clone; +} + +FMMatrix44 FCDTLookAt::ToMatrix() const +{ + return FMMatrix44::LookAtMatrix(lookAt->position, lookAt->target, lookAt->up); +} + +const FCDAnimated* FCDTLookAt::GetAnimated() const +{ + return lookAt.GetAnimated(); +} + +bool FCDTLookAt::IsAnimated() const +{ + return lookAt.IsAnimated(); +} + +// +// FCDTSkew +// + +ImplementObjectType(FCDTSkew); + +FCDTSkew::FCDTSkew(FCDocument* document, FCDSceneNode* parent) +: FCDTransform(document, parent) +, InitializeParameterAnimatable(skew, FMSkew(FMVector3::XAxis, FMVector3::YAxis, 0.0f)) +{ +} + +FCDTSkew::~FCDTSkew() +{ +} + +FCDTransform* FCDTSkew::Clone(FCDTransform* _clone) const +{ + FCDTSkew* clone = NULL; + if (_clone == NULL) clone = new FCDTSkew(const_cast(GetDocument()), const_cast(GetParent())); + else if (!_clone->HasType(FCDTSkew::GetClassType())) return _clone; + else clone = (FCDTSkew*) _clone; + + clone->skew = skew; + return clone; +} + +FMMatrix44 FCDTSkew::ToMatrix() const +{ + float v[4][4]; + + float s = tanf(FMath::DegToRad(skew->angle)); + + for (int row = 0; row < 3; ++row) + { + for (int col = 0; col < 3; ++col) + { + v[col][row] = ((row == col) ? 1.0f : 0.0f) + s * skew->rotateAxis[col] * skew->aroundAxis[row]; + } + } + + v[0][3] = v[1][3] = v[2][3] = 0.0f; + v[3][0] = v[3][1] = v[3][2] = 0.0f; + v[3][3] = 1.0f; + + return FMMatrix44((float*) v); +} + +const FCDAnimated* FCDTSkew::GetAnimated() const +{ + return skew.GetAnimated(); +} + +bool FCDTSkew::IsAnimated() const +{ + // Only angle may be animated for now. + return skew.IsAnimated(); +} + +// Creates a new COLLADA transform, given a transform type. +FCDTransform* FCDTFactory::CreateTransform(FCDocument* document, FCDSceneNode* parent, FCDTransform::Type type) +{ + switch (type) + { + case FCDTransform::TRANSLATION: return new FCDTTranslation(document, parent); + case FCDTransform::ROTATION: return new FCDTRotation(document, parent); + case FCDTransform::SCALE: return new FCDTScale(document, parent); + case FCDTransform::SKEW: return new FCDTSkew(document, parent); + case FCDTransform::MATRIX: return new FCDTMatrix(document, parent); + case FCDTransform::LOOKAT: return new FCDTLookAt(document, parent); + default: return NULL; + } +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTransform.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTexture.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTexture.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTexture.h (revision 24247) @@ -1,126 +1,126 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDTexture.h - This file contains the FCDTexture class. -*/ - -#ifndef _FCD_TEXTURE_H_ -#define _FCD_TEXTURE_H_ - -#ifndef _FCD_ENTITY_H_ -#include "FCDocument/FCDEntity.h" -#endif // _FCD_ENTITY_H_ -#ifndef _FU_DAE_ENUM_H_ -#include "FUtils/FUDaeEnum.h" -#endif // _FU_DAE_ENUM_H_ - -class FCDocument; -class FCDEffectParameter; -class FCDEffectParameterSampler; -class FCDEffectStandard; -class FCDImage; - +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDTexture.h + This file contains the FCDTexture class. +*/ + +#ifndef _FCD_TEXTURE_H_ +#define _FCD_TEXTURE_H_ + +#ifndef _FCD_ENTITY_H_ +#include "FCDocument/FCDEntity.h" +#endif // _FCD_ENTITY_H_ +#ifndef _FU_DAE_ENUM_H_ +#include "FUtils/FUDaeEnum.h" +#endif // _FU_DAE_ENUM_H_ + +class FCDocument; +class FCDEffectParameter; +class FCDEffectParameterSampler; +class FCDEffectStandard; +class FCDImage; + #if defined(WIN32) -template class FCOLLADA_EXPORT FCDEffectParameterT; /**< Trick Doxygen. */ +template class FCOLLADA_EXPORT FCDEffectParameterT; /**< Trick Doxygen. */ #elif defined(LINUX) || defined(__APPLE__) -template class FCDEffectParameterT; /**< Trick Doxygen. */ -#endif // LINUX -typedef FCDEffectParameterT FCDEffectParameterInt; /**< An integer effect parameter. */ - -/** - A COLLADA texture. - - Textures are used by the COMMON profile materials. - As per the COLLADA 1.4 specification, a texture is - used to match some texture coordinates with a surface sampler, on a given - texturing channel. - - Therefore: textures hold the extra information necessary to place an image correctly onto - polygon sets. This extra information includes the texturing coordinate transformations and - the blend mode. - - @ingroup FCDEffect -*/ -class FCOLLADA_EXPORT FCDTexture : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - FCDEffectStandard* parent; - DeclareParameterPtr(FCDEffectParameterSampler, sampler, FC("Sampler")); // Points to the surface, which points to the image. - DeclareParameterRef(FCDEffectParameterInt, set, FC("Set")); // Always preset, this parameter hold the map channel/uv set index - DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); - -public: - /** Constructor. Do not use directly. - Instead, use the FCDEffectStandard::AddTexture function. - @param document The COLLADA document that owns this texture. - @param parent The standard effect that contains this texture. */ - FCDTexture(FCDocument* document, FCDEffectStandard* parent = NULL); - - /** Destructor. */ - virtual ~FCDTexture(); - - /** Access the parent standard effect or this texture. - @return The parent effect.*/ - FCDEffectStandard* GetParent() const { return parent; } - - /** Retrieves the image information for this texture. - @return The image. This pointer will be NULL if this texture is not yet - tied to a valid image. */ - inline FCDImage* GetImage() { return const_cast(const_cast(this)->GetImage()); } - const FCDImage* GetImage() const; /**< See above. */ - - /** Set the image information for this texture. - This is a shortcut that generates the sampler/surface parameters - to access the given image. - @param image The image information. This pointer may be - NULL to disconnect an image. */ - void SetImage(FCDImage* image); - - /** Retrieves the surface sampler for this texture. - @return The sampler. In the non-const method: the sampler - will be created if it is currently missing and the parent is available. */ - FCDEffectParameterSampler* GetSampler(); - inline const FCDEffectParameterSampler* GetSampler() const { return sampler; } /**< See above. */ - - /** Sets the targeted sampler. - @param _sampler The new sampler. */ - inline void SetSampler(FCDEffectParameterSampler* _sampler) { sampler = _sampler; } - - /** Determines whether this texture targets a sampler. - @return Whether the texture targets a sampler. */ - inline bool HasSampler() { return sampler != NULL; } - - /** Retrieves the texture coordinate set to use with this texture. - This information is duplicated from the material instance abstraction level. - @return The effect parameter containing the set. */ - inline FCDEffectParameterInt* GetSet() { return set; } - inline const FCDEffectParameterInt* GetSet() const { return set; } /**< See above. */ - - /** Retrieves the extra information tied to this texture. - @return The extra tree. */ - inline FCDExtra* GetExtra() { return extra; } - inline const FCDExtra* GetExtra() const { return extra; } /**< See above. */ - - /** Clones the texture. - @param clone The cloned texture. If this pointer is NULL, - a new texture is created and you will need to release this new texture. - @return The cloned texture. This pointer will never be NULL. */ - virtual FCDTexture* Clone(FCDTexture* clone = NULL) const; -}; - -#endif // _FCD_TEXTURE_H_ +template class FCDEffectParameterT; /**< Trick Doxygen. */ +#endif // LINUX +typedef FCDEffectParameterT FCDEffectParameterInt; /**< An integer effect parameter. */ + +/** + A COLLADA texture. + + Textures are used by the COMMON profile materials. + As per the COLLADA 1.4 specification, a texture is + used to match some texture coordinates with a surface sampler, on a given + texturing channel. + + Therefore: textures hold the extra information necessary to place an image correctly onto + polygon sets. This extra information includes the texturing coordinate transformations and + the blend mode. + + @ingroup FCDEffect +*/ +class FCOLLADA_EXPORT FCDTexture : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + FCDEffectStandard* parent; + DeclareParameterPtr(FCDEffectParameterSampler, sampler, FC("Sampler")); // Points to the surface, which points to the image. + DeclareParameterRef(FCDEffectParameterInt, set, FC("Set")); // Always preset, this parameter hold the map channel/uv set index + DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); + +public: + /** Constructor. Do not use directly. + Instead, use the FCDEffectStandard::AddTexture function. + @param document The COLLADA document that owns this texture. + @param parent The standard effect that contains this texture. */ + FCDTexture(FCDocument* document, FCDEffectStandard* parent = NULL); + + /** Destructor. */ + virtual ~FCDTexture(); + + /** Access the parent standard effect or this texture. + @return The parent effect.*/ + FCDEffectStandard* GetParent() const { return parent; } + + /** Retrieves the image information for this texture. + @return The image. This pointer will be NULL if this texture is not yet + tied to a valid image. */ + inline FCDImage* GetImage() { return const_cast(const_cast(this)->GetImage()); } + const FCDImage* GetImage() const; /**< See above. */ + + /** Set the image information for this texture. + This is a shortcut that generates the sampler/surface parameters + to access the given image. + @param image The image information. This pointer may be + NULL to disconnect an image. */ + void SetImage(FCDImage* image); + + /** Retrieves the surface sampler for this texture. + @return The sampler. In the non-const method: the sampler + will be created if it is currently missing and the parent is available. */ + FCDEffectParameterSampler* GetSampler(); + inline const FCDEffectParameterSampler* GetSampler() const { return sampler; } /**< See above. */ + + /** Sets the targeted sampler. + @param _sampler The new sampler. */ + inline void SetSampler(FCDEffectParameterSampler* _sampler) { sampler = _sampler; } + + /** Determines whether this texture targets a sampler. + @return Whether the texture targets a sampler. */ + inline bool HasSampler() { return sampler != NULL; } + + /** Retrieves the texture coordinate set to use with this texture. + This information is duplicated from the material instance abstraction level. + @return The effect parameter containing the set. */ + inline FCDEffectParameterInt* GetSet() { return set; } + inline const FCDEffectParameterInt* GetSet() const { return set; } /**< See above. */ + + /** Retrieves the extra information tied to this texture. + @return The extra tree. */ + inline FCDExtra* GetExtra() { return extra; } + inline const FCDExtra* GetExtra() const { return extra; } /**< See above. */ + + /** Clones the texture. + @param clone The cloned texture. If this pointer is NULL, + a new texture is created and you will need to release this new texture. + @return The cloned texture. This pointer will never be NULL. */ + virtual FCDTexture* Clone(FCDTexture* clone = NULL) const; +}; + +#endif // _FCD_TEXTURE_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDTexture.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDVersion.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDVersion.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDVersion.h (revision 24247) @@ -1,85 +1,85 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDVersion.h - This file declares the FCDVersion class. -*/ - -#ifndef _FCD_VERSION_H_ -#define _FCD_VERSION_H_ - -#ifdef major -#undef major -#endif -#ifdef minor -#undef minor -#endif - -/** - A COLLADA document verison. - Format is major.minor.revision. - - @ingroup FCDocument -*/ -class FCOLLADA_EXPORT FCDVersion -{ -public: - uint32 major; /**< The major release number of the version. */ - uint32 minor; /**< The minor release number of the version. */ - uint32 revision; /**< The revision number of the release. */ - - /** Default Constructor. Leaves all the numbers at zero. */ - FCDVersion(); - - /** Constructs a version number structure from a string. - @param v A string containing the version numbers. */ - FCDVersion(const fm::string& v); - - /** Constructs a version number structure from a series of numbers. - @param major The major version number. - @param minor The minor version number. - @param revision The revision version number. */ - FCDVersion(uint32 major, uint32 minor, uint32 revision); - - /** Destructor. */ - ~FCDVersion() {} - - /** Extracts the version number from a string in the form of - major.minor.revision (ex: 1.4.1) - @param v A string containing the version numbers */ - void ParseVersionNumbers(const fm::string& v); - - /** Returns whether two versions are equivalent. - @param a A first version. - @param b A second version. - @return Whether the two versions are equivalent. */ - friend FCOLLADA_EXPORT bool IsEquivalent(const FCDVersion& a, const FCDVersion& b); - - /** Returns whether this version is older than a second version. - @param b A second version. - @return Whether this version is older than the second version. */ - bool operator< (const FCDVersion& b) const; - - /** Returns whether this version is older than or equal to a second version. - @param b A second version. - @return Whether this version is older than or equal to a second version. */ - bool operator<= (const FCDVersion& b) const; - - /** Returns whether this version is newer than a second version. - @param b A second version. - @return Whether this version is newer than the second version. */ - inline bool operator> (const FCDVersion& b) const { return b <= *this; } - - /** Returns whether this version is newer or equal to a second version. - @param b A second version. - @return Whether this version is newer or equal to a second version. */ - inline bool operator>= (const FCDVersion& b) const { return b < *this; } -}; - -#endif // _FCD_VERSION_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDVersion.h + This file declares the FCDVersion class. +*/ + +#ifndef _FCD_VERSION_H_ +#define _FCD_VERSION_H_ + +#ifdef major +#undef major +#endif +#ifdef minor +#undef minor +#endif + +/** + A COLLADA document verison. + Format is major.minor.revision. + + @ingroup FCDocument +*/ +class FCOLLADA_EXPORT FCDVersion +{ +public: + uint32 major; /**< The major release number of the version. */ + uint32 minor; /**< The minor release number of the version. */ + uint32 revision; /**< The revision number of the release. */ + + /** Default Constructor. Leaves all the numbers at zero. */ + FCDVersion(); + + /** Constructs a version number structure from a string. + @param v A string containing the version numbers. */ + FCDVersion(const fm::string& v); + + /** Constructs a version number structure from a series of numbers. + @param major The major version number. + @param minor The minor version number. + @param revision The revision version number. */ + FCDVersion(uint32 major, uint32 minor, uint32 revision); + + /** Destructor. */ + ~FCDVersion() {} + + /** Extracts the version number from a string in the form of + major.minor.revision (ex: 1.4.1) + @param v A string containing the version numbers */ + void ParseVersionNumbers(const fm::string& v); + + /** Returns whether two versions are equivalent. + @param a A first version. + @param b A second version. + @return Whether the two versions are equivalent. */ + friend FCOLLADA_EXPORT bool IsEquivalent(const FCDVersion& a, const FCDVersion& b); + + /** Returns whether this version is older than a second version. + @param b A second version. + @return Whether this version is older than the second version. */ + bool operator< (const FCDVersion& b) const; + + /** Returns whether this version is older than or equal to a second version. + @param b A second version. + @return Whether this version is older than or equal to a second version. */ + bool operator<= (const FCDVersion& b) const; + + /** Returns whether this version is newer than a second version. + @param b A second version. + @return Whether this version is newer than the second version. */ + inline bool operator> (const FCDVersion& b) const { return b <= *this; } + + /** Returns whether this version is newer or equal to a second version. + @param b A second version. + @return Whether this version is newer or equal to a second version. */ + inline bool operator>= (const FCDVersion& b) const { return b < *this; } +}; + +#endif // _FCD_VERSION_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDVersion.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocumentTools.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocumentTools.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocumentTools.cpp (revision 24247) @@ -1,710 +1,710 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDocumentTools.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDAnimation.h" -#include "FCDocument/FCDAnimationChannel.h" -#include "FCDocument/FCDAnimationCurve.h" -#include "FCDocument/FCDAnimationKey.h" -#include "FCDocument/FCDAsset.h" -#include "FCDocument/FCDCamera.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDGeometryMesh.h" -#include "FCDocument/FCDGeometryPolygons.h" -#include "FCDocument/FCDGeometrySource.h" -#include "FCDocument/FCDGeometrySpline.h" -#include "FCDocument/FCDGeometryNURBSSurface.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDSceneNode.h" -#include "FCDocument/FCDSkinController.h" -#include "FCDocument/FCDTargetedEntity.h" -#include "FCDocument/FCDTransform.h" -#include "FCDocument/FCDExternalReferenceManager.h" -#include "FCDocument/FCDPlaceHolder.h" -#include "FCDocument/FCDSceneNodeIterator.h" -#include "FCDocument/FCDControllerInstance.h" -#include "FCDocument/FCDMorphController.h" -#include "FCDocument/FCDAnimationCurveTools.h" -#include "FCDocument/FCDAnimationMultiCurve.h" - -// -// FCDocumentTools -// - -namespace FCDocumentTools -{ - class FCDConversionSwapFunctor - { - private: - enum Axis { X, Y, Z, UNKNOWN } current, target; - Axis ConvertVector(const FMVector3& v) - { - if (IsEquivalent(v, FMVector3::XAxis)) return X; - else if (IsEquivalent(v, FMVector3::YAxis)) return Y; - else if (IsEquivalent(v, FMVector3::ZAxis)) return Z; - else return UNKNOWN; - } - - typedef void (*ConversionFn) (FMVector3& data, int32 sign); - ConversionFn functor; - - public: - FCDConversionSwapFunctor(const FMVector3& targetAxis) - : current(UNKNOWN), target(UNKNOWN) - { - target = ConvertVector(targetAxis); - }; - - inline void SetCurrent(const FMVector3& axis) - { - current = ConvertVector(axis); - PrepareFunctor(); - } - - inline bool HasConversion() { return functor != Identity; } - - static FCDTRotation* GetLastTransformForPivot(FCDSceneNode* node) - { - // Verify whether the last transform on this node's stack is a rotation transform. - if (node->GetTransformCount() > 0) - { - FCDTransform* transform = node->GetTransform(node->GetTransformCount() - 1); - if (transform->HasType(FCDTRotation::GetClassType())) - { - FCDAnimated* animated = transform->GetAnimated(); - if (animated != NULL && !animated->HasCurve()) animated = NULL; - if (animated == NULL) return (FCDTRotation*) transform; - } - } - return NULL; - } - - static void SmartAddRotationPivot(FCDSceneNode* node, const FMVector3& axis, float angle) - { - // Check for an old rotation pivot to remove. - FCDTRotation* lastRotation = GetLastTransformForPivot(node); - if (lastRotation != NULL && IsEquivalent(lastRotation->GetAxis(), axis) && IsEquivalent(lastRotation->GetAngle(), -1.0f * angle)) - { - SAFE_RELEASE(lastRotation); - lastRotation = GetLastTransformForPivot(node); - } - else - { - // Add this rotation to pivot the entity instance. - FCDTRotation* rotate = (FCDTRotation*) node->AddTransform(FCDTransform::ROTATION); - rotate->SetAxis(axis); - rotate->SetAngle(angle); - } - } - - void SetPivotTransform(FCDSceneNode* node, bool rollOnly) - { - if (functor == Identity) return; - - - // Change out of the current up-axis into Y-up. - if (current == X && !rollOnly) - { - SmartAddRotationPivot(node, FMVector3::ZAxis, 90.0f); - } - else if (current == Z) - { - SmartAddRotationPivot(node, rollOnly ? FMVector3::ZAxis : FMVector3::XAxis, rollOnly ? 90.0f : -90.0f); - } - - // Change into the target up-axis. - if (target == X && !rollOnly) - { - SmartAddRotationPivot(node, FMVector3::ZAxis, -90.0f); - } - else if (target == Z) - { - SmartAddRotationPivot(node, rollOnly ? FMVector3::ZAxis : FMVector3::XAxis, rollOnly ? -90.0f : 90.0f); - } - } - - void operator() (FMVector3& data, bool isScale = false) { (*functor)(data, (isScale ? 1 : -1)); } - - private: - void PrepareFunctor() - { - if (target == UNKNOWN || current == UNKNOWN || target == current) functor = Identity; - else - { - switch (target) - { - case X: functor = (current == Y) ? XtoY : XtoZ; break; - case Y: functor = (current == X) ? YtoX : YtoZ; break; - case Z: functor = (current == X) ? ZtoX : ZtoY; break; - case UNKNOWN: - default: FUFail(break); - } - } - } - - static void Identity(FMVector3& UNUSED(data), int32 UNUSED(sign)) {} - static void XtoY(FMVector3& data, int32 sign) { float t = sign * data.x; data.x = data.y; data.y = t; } - static void XtoZ(FMVector3& data, int32 UNUSED(sign)) { float t = data.x; data.x = data.y; data.y = data.z; data.z = t; } - static void YtoX(FMVector3& data, int32 sign) { float t = data.x; data.x = sign * data.y; data.y = t; } - static void YtoZ(FMVector3& data, int32 sign) { float t = sign * data.y; data.y = data.z; data.z = t; } - static void ZtoX(FMVector3& data, int32 UNUSED(sign)) { float t = data.z; data.z = data.y; data.y = data.x; data.x = t; } - static void ZtoY(FMVector3& data, int32 sign) { float t = data.y; data.y = sign * data.z; data.z = t; } - }; - - class FCDConversionUnitFunctor - { - private: - float factor, target; - - public: - FCDConversionUnitFunctor(float _target) - : factor(1.0f), target(_target) {} - - bool HasConversion() { return !IsEquivalent(factor, 1.0f); } - void SetCurrent(float current) { factor = ((current <= 0.0f) ? 1.0f : (current / target)); } - float GetConversionFactor() { return factor; } - void operator() (float& data) { data *= factor; } - void operator() (FMVector3& data) { data *= factor; } - }; - - typedef fm::pvector FCDSceneNodeIteratorList; - class VisualSceneNodeIterator - { - private: - FCDSceneNodeIteratorList queue; - - public: - VisualSceneNodeIterator(FCDVisualSceneNodeLibrary* visualSceneLibrary) - { - for (size_t i = 0; i < visualSceneLibrary->GetEntityCount(); ++i) - { - // use depth first to make sure node instancing in StandardizeScale works - queue.push_back(new FCDSceneNodeIterator(visualSceneLibrary->GetEntity(i), FCDSceneNodeIterator::DEPTH_FIRST_PREORDER, true)); - } - } - - virtual ~VisualSceneNodeIterator() - { - while (!queue.empty()) - { - SAFE_DELETE(queue.back()); - queue.pop_back(); - } - } - - FCDSceneNode* Next() - { - CleanQueue(); - if (queue.empty()) return NULL; - - FCDSceneNode* node = queue.back()->GetNode(); - queue.back()->Next(); - - return node; - } - - bool IsDone() - { - CleanQueue(); - return queue.empty(); - } - private: - void CleanQueue() // makes sure we can get the next node easily - { - while (!queue.empty()) - { - FCDSceneNodeIterator* sceneNodeIterator = queue.back(); - if (!sceneNodeIterator->IsDone()) return; - - SAFE_DELETE(sceneNodeIterator); - queue.pop_back(); - } - } - }; - - void GetAssetFunctors(FCDEntity* entity, FCDAsset* libraryAsset, FCDConversionUnitFunctor& lengthFunctor, FCDConversionSwapFunctor& upAxisFunctor) - { - FCDAssetList assets; assets.reserve(3); - entity->GetHierarchicalAssets(assets); - if (libraryAsset != NULL) assets.push_back(libraryAsset); - bool hasLength = false; - bool hasAxis = false; - for (FCDAssetList::iterator it = assets.begin(); it != assets.end(); ++it) - { - if (!hasLength && (*it)->GetHasUnitsFlag()) { hasLength = true; lengthFunctor.SetCurrent((*it)->GetUnitConversionFactor()); } - if (!hasAxis && (*it)->GetHasUpAxisFlag()) { hasAxis = true; upAxisFunctor.SetCurrent((*it)->GetUpAxis()); } - } - if (!hasLength) lengthFunctor.SetCurrent(-1.0f); - if (!hasAxis) upAxisFunctor.SetCurrent(FMVector3::Origin); - } - - inline void ResetAsset(FCDEntity* entity) - { - FCDAsset* asset = const_cast(const_cast(entity)->GetAsset()); - if (asset != NULL) - { - asset->ResetHasUnitsFlag(); - asset->ResetHasUpAxisFlag(); - } - } - - void ConvertAnimationVector3(FCDAnimated* animated1, FCDAnimated* animated2, FCDAnimated* animated3, float* v1, float* v2, float* v3, FCDocument* document, FCDConversionUnitFunctor& lengthFunctor, FCDConversionSwapFunctor& upAxisFunctor, bool convertLength, bool isScale = false) - { - FUAssert(animated1 != NULL && animated2 != NULL && animated3 != NULL, return); - - size_t indices[3] = { animated1->FindValue(v1), animated2->FindValue(v2), animated3->FindValue(v3) }; - if (indices[0] == ~(size_t)0 && indices[1] == ~(size_t)0 && indices[2] == ~(size_t)0) return; // no animations on the vector - FCDAnimated* animateds[3] = { animated1, animated2, animated3 }; - FMVector3 localAxes[3] = { FMVector3::XAxis, FMVector3::YAxis, FMVector3::ZAxis }; - - // save the curves and remove them from the animated - size_t curvesCount[3]; - FCDAnimationCurve** curves[3]; - for (size_t i = 0; i < 3; ++i) - { - FCDAnimationCurveTrackList& curvesList = animateds[i]->GetCurves()[indices[i]]; - curvesCount[i] = curvesList.size(); - if (curvesCount[i] > 0) - { - curves[i] = new FCDAnimationCurve*[curvesCount[i]]; - for (size_t j = 0; j < curvesCount[i]; j++) - { - curves[i][j] = curvesList.at(j); - } - animateds[i]->RemoveCurve(indices[i]); - } - else curves[i] = NULL; - } - - // transform the keys' outputs - for (size_t i = 0; i < 3; ++i) - { - for (size_t curvesCounter = 0; curvesCounter < curvesCount[i]; curvesCounter++) - { - FCDAnimationCurve* currentCurve = curves[i][curvesCounter]; - FCDAnimation* animation = currentCurve->GetParent()->GetParent(); - - FCDConversionUnitFunctor savedLengthFunctor(lengthFunctor); - FCDConversionSwapFunctor savedUpAxisFunctor(upAxisFunctor); - GetAssetFunctors(animation, document->GetAnimationLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); - - // convert the up axes and update the factor if we need to negate signs - FMVector3 savedLocalAxes(localAxes[i]); - upAxisFunctor(localAxes[i], isScale); - - float factor = 1.0f; - FUAssert(IsEquivalent(localAxes[i].LengthSquared(), 1.0f), continue;); - if (IsEquivalent(fabsf(localAxes[i].x), 1.0f)) - { - animateds[0]->AddCurve(indices[0], currentCurve); - factor = localAxes[i].x; - } - else if (IsEquivalent(fabsf(localAxes[i].y), 1.0f)) - { - animateds[1]->AddCurve(indices[1], currentCurve); - factor = localAxes[i].y; - } - else if (IsEquivalent(fabsf(localAxes[i].z), 1.0f)) - { - animateds[2]->AddCurve(indices[2], currentCurve); - factor = localAxes[i].z; - } - - // convert the unit lengths - FCDConversionScaleFunctor functor(factor * (convertLength ? lengthFunctor.GetConversionFactor() : 1.0f)); - currentCurve->ConvertValues(&functor, &functor); - - localAxes[i] = savedLocalAxes; - lengthFunctor = savedLengthFunctor; - upAxisFunctor = savedUpAxisFunctor; - } - } - - for (size_t i = 0; i < 3; ++i) - { - SAFE_DELETE_ARRAY(curves[i]); - } - } - inline void ConvertAnimationVector3(FCDAnimated* animated1, FCDAnimated* animated2, FCDAnimated* animated3, FMVector3& v, FCDocument* document, FCDConversionUnitFunctor& lengthFunctor, - FCDConversionSwapFunctor& upAxisFunctor, bool convertLength, bool isScale = false) - { - ConvertAnimationVector3(animated1, animated2, animated3, &v.x, &v.y, &v.z, document, lengthFunctor, upAxisFunctor, convertLength, isScale); - } - inline void ConvertAnimationVector3(FCDAnimated* animated, float* x, float* y, float* z, FCDocument* document, FCDConversionUnitFunctor& lengthFunctor, - FCDConversionSwapFunctor& upAxisFunctor, bool convertLength, bool isScale = false) - { - ConvertAnimationVector3(animated, animated, animated, x, y, z, document, lengthFunctor, upAxisFunctor, convertLength, isScale); - } - inline void ConvertAnimationVector3(FCDAnimated* animated, FMVector3& v, FCDocument* document, FCDConversionUnitFunctor& lengthFunctor, - FCDConversionSwapFunctor& upAxisFunctor, bool convertLength, bool isScale = false) - { - ConvertAnimationVector3(animated, &v.x, &v.y, &v.z, document, lengthFunctor, upAxisFunctor, convertLength, isScale); - } - - void ConvertAnimationFloat(FCDAnimated* animated, float& f, FCDocument* document, FCDConversionUnitFunctor& lengthFunctor, FCDConversionSwapFunctor& upAxisFunctor) - { - if (animated != NULL) - { - size_t index = animated->FindValue(&f); - if (index == ~(size_t)0) return; // no animations on the float - - FCDAnimationCurveListList& curvesListList = animated->GetCurves(); - if (index >= curvesListList.size()) return; // no animations on the float - FCDAnimationCurveTrackList& curves = curvesListList.at(index); - - // transform the keys' outputs - size_t curvesCount = curves.size(); - for (size_t curvesCounter = 0; curvesCounter < curvesCount; curvesCounter++) - { - FCDAnimationCurve* currentCurve = curves[curvesCounter]; - FCDAnimation* animation = currentCurve->GetParent()->GetParent(); - - FCDConversionUnitFunctor savedLengthFunctor(lengthFunctor); - FCDConversionSwapFunctor savedUpAxisFunctor(upAxisFunctor); - GetAssetFunctors(animation, document->GetAnimationLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); - - // convert the unit lengths - FCDConversionScaleFunctor functor(lengthFunctor.GetConversionFactor()); - currentCurve->ConvertValues(&functor, &functor); - - lengthFunctor = savedLengthFunctor; - upAxisFunctor = savedUpAxisFunctor; - } - } - } - -#define CONVERT_FL(parameter, f) { lengthFunctor(f); if (parameter.IsAnimated()) { ConvertAnimationFloat(parameter.GetAnimated(), f, document, lengthFunctor, upAxisFunctor); } } -#define CONVERT_VECT3(parameter, v) { upAxisFunctor(v); if (parameter.IsAnimated()) { ConvertAnimationVector3(parameter.GetAnimated(), v, document, lengthFunctor, upAxisFunctor, false); } } -#define CONVERT_SCALE(parameter, v) { upAxisFunctor(v, true); if (parameter.IsAnimated()) { ConvertAnimationVector3(parameter.GetAnimated(), v, document, lengthFunctor, upAxisFunctor, false, true); } } -#define CONVERT_VECT3L(parameter, v) { upAxisFunctor(v); lengthFunctor(v); if (parameter.IsAnimated()) { ConvertAnimationVector3(parameter.GetAnimated(), v, document, lengthFunctor, upAxisFunctor, true); } } -#define CONVERT_MAT44(parameter, m) { \ - FMMatrix44& _m = (m); \ - /* Rotation/Scale. */ \ - CONVERT_VECT3(parameter, *(FMVector3*) _m[0]); \ - CONVERT_VECT3(parameter, *(FMVector3*) _m[1]); \ - CONVERT_VECT3(parameter, *(FMVector3*) _m[2]); \ - for (int i = 0; i < 3; ++i) { \ - FMVector3 v = FMVector3(_m[0][i], _m[1][i], _m[2][i]); \ - upAxisFunctor(v); _m[0][i] = v.x; _m[1][i] = v.y; _m[2][i] = v.z; \ - /* Handle the animation carefully... */ \ - if (parameter.IsAnimated()) { \ - ConvertAnimationVector3(parameter.GetAnimated(), &_m[0][i], &_m[1][i], &_m[2][i], document, lengthFunctor, upAxisFunctor, false); } } \ - /* Translation.. */ \ - CONVERT_VECT3(parameter, *(FMVector3*) _m[3]); \ - CONVERT_FL(parameter, _m[3][0]); CONVERT_FL(parameter, _m[3][1]); CONVERT_FL(parameter, _m[3][2]); } - -#define CONVERT_MAT44_NONANIMATABLE(m) { \ - FMMatrix44& _m = (m); \ - /* Rotation/Scale. */ \ - upAxisFunctor(*(FMVector3*) _m[0]); \ - upAxisFunctor(*(FMVector3*) _m[1]); \ - upAxisFunctor(*(FMVector3*) _m[2]); \ - for (int i = 0; i < 3; ++i) { \ - FMVector3 v(_m[0][i], _m[1][i], _m[2][i]); \ - upAxisFunctor(v); _m[0][i] = v.x; _m[1][i] = v.y; _m[2][i] = v.z; } \ - /* Translation.. */ \ - upAxisFunctor(*(FMVector3*) _m[3]); \ - lengthFunctor(_m[3][0]); lengthFunctor(_m[3][1]); lengthFunctor(_m[3][2]); } - - void StandardizeUpAxisAndLength(FCDocument* document, const FMVector3& upAxis, float unitInMeters, bool handleTargets) - { - if (document == NULL) return; - - // Figure out the wanted up_axis and unit values, if they are not provided. - FCDAsset* baseAsset = document->GetAsset(); - if (IsEquivalent(unitInMeters, 0.0f) || unitInMeters < 0.0f) - { - if (baseAsset->GetHasUnitsFlag()) unitInMeters = baseAsset->GetUnitConversionFactor(); - else unitInMeters = 1.0f; // COLLADA specification default. - } - FMVector3 _upAxis = upAxis; - if (!IsEquivalent(upAxis, FMVector3::Origin)) _upAxis = upAxis; - else - { - if (baseAsset->GetHasUpAxisFlag()) _upAxis = baseAsset->GetUpAxis(); - else _upAxis = FMVector3::YAxis; // COLLADA specification default. - } - - // Setup the modification functors. - FCDConversionUnitFunctor lengthFunctor(unitInMeters); - FCDConversionSwapFunctor upAxisFunctor(_upAxis); - - FCDocumentList documentQueue; - documentQueue.push_back(document); - - // documentQueue grows while we are accessing! - for (size_t documentCounter = 0; documentCounter < documentQueue.size(); documentCounter++) - { - FCDocument* document = documentQueue.at(documentCounter); - FCDExternalReferenceManager* referenceManager = document->GetExternalReferenceManager(); - size_t placeHolderCount = referenceManager->GetPlaceHolderCount(); - for (size_t i = 0; i < placeHolderCount; ++i) - { - FCDPlaceHolder* placeHolder = referenceManager->GetPlaceHolder(i); - - if (!placeHolder->IsTargetLoaded()) - { - if (FCollada::GetDereferenceFlag()) - { - placeHolder->LoadTarget(); - if (!placeHolder->IsTargetLoaded()) continue; - } - else - { - // we don't want to load the external reference - continue; - } - } - FUAssert(placeHolder->IsTargetLoaded(), continue); - - FCDocument* targetDocument = placeHolder->GetTarget(); - if (documentQueue.find(targetDocument) == documentQueue.end()) - { - documentQueue.push_back(targetDocument); - } - } - } - - // Iterate over all the documents, modifying their elements - while (!documentQueue.empty()) - { - FCDocument* document = documentQueue.back(); documentQueue.pop_back(); - - // Iterate over the scene graph, modifying the transforms. - VisualSceneNodeIterator visualSceneNodeIt(document->GetVisualSceneLibrary()); - while (!visualSceneNodeIt.IsDone()) - { - FCDSceneNode* node = visualSceneNodeIt.Next(); - GetAssetFunctors(node, document->GetVisualSceneLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); - if (lengthFunctor.HasConversion() || upAxisFunctor.HasConversion()) - { - size_t transformCount = node->GetTransformCount(); - for (size_t t = 0; t < transformCount; ++t) - { - FCDTransform* transform = node->GetTransform(t); - if (transform->HasType(FCDTTranslation::GetClassType())) CONVERT_VECT3L(((FCDTTranslation*) transform)->GetTranslation(), ((FCDTTranslation*) transform)->GetTranslation()) - else if (transform->HasType(FCDTRotation::GetClassType())) CONVERT_VECT3(((FCDTRotation*) transform)->GetAngleAxis(), ((FCDTRotation*) transform)->GetAxis()) - else if (transform->HasType(FCDTScale::GetClassType())) CONVERT_SCALE(((FCDTScale*) transform)->GetScale(), ((FCDTScale*) transform)->GetScale()) - else if (transform->HasType(FCDTSkew::GetClassType())) { CONVERT_VECT3(((FCDTSkew*) transform)->GetSkew(), ((FCDTSkew*) transform)->GetRotateAxis()); CONVERT_VECT3(((FCDTSkew*) transform)->GetSkew(), ((FCDTSkew*) transform)->GetAroundAxis()); } - else if (transform->HasType(FCDTLookAt::GetClassType())) { CONVERT_VECT3L(((FCDTLookAt*) transform)->GetLookAt(), ((FCDTLookAt*) transform)->GetPosition()); CONVERT_VECT3L(((FCDTLookAt*) transform)->GetLookAt(), ((FCDTLookAt*) transform)->GetTarget()); CONVERT_VECT3(((FCDTLookAt*) transform)->GetLookAt(), ((FCDTLookAt*) transform)->GetUp()); } - else if (transform->HasType(FCDTMatrix::GetClassType())) { CONVERT_MAT44(((FCDTMatrix*) transform)->GetTransform(), ((FCDTMatrix*) transform)->GetTransform()); } - } - } - - if (upAxisFunctor.HasConversion()) - { - // Unfortunately, some of the entity types do not survive very well on up-axis changes. - // Check for cameras, lights, emitters, force fields - fm::pvector toRemove; - size_t nodeInstanceCount = node->GetInstanceCount(); - for (size_t n = 0; n < nodeInstanceCount; ++n) - { - FCDEntityInstance* nodeInstance = node->GetInstance(n); - if (nodeInstance->GetEntityType() == FCDEntity::CAMERA || nodeInstance->GetEntityType() == FCDEntity::LIGHT - || nodeInstance->GetEntityType() == FCDEntity::FORCE_FIELD || nodeInstance->GetEntityType() == FCDEntity::EMITTER) - { - // Targeted entities should still point in the correct direction: do only roll up-axis changes. - bool rollOnly = false; - if (handleTargets && nodeInstance->GetEntity() != NULL && nodeInstance->GetEntity()->HasType(FCDTargetedEntity::GetClassType())) - { - FCDTargetedEntity* targetedEntity = (FCDTargetedEntity*) nodeInstance->GetEntity(); - rollOnly = targetedEntity->HasTarget(); // Don't pivot fully. - } - - // Do not create a pivot node unless necessary. - FCDSceneNode* pivotedNode = node; - if (node->GetChildrenCount() == 0 && node->GetInstanceCount() == 1) - { - pivotedNode = node; - } - else - { - // Create a pivot node. - pivotedNode = node->AddChildNode(); - pivotedNode->SetName(node->GetName() + FC("_pivot")); - pivotedNode->SetDaeId(node->GetDaeId() + "_pivot"); - - // Need to clone the instance and remove the original one, then. - FCDEntityInstance* clone = pivotedNode->AddInstance(nodeInstance->GetEntityType()); - nodeInstance->Clone(clone); - toRemove.push_back(nodeInstance); - } - - // Do the 'pivoting'. - upAxisFunctor.SetPivotTransform(pivotedNode, rollOnly); - } - } - CLEAR_POINTER_VECTOR(toRemove); - } - - ResetAsset(node); - } - - // Iterate over the skin controllers: need to convert the bind-poses. - size_t controllerCount = document->GetControllerLibrary()->GetEntityCount(); - for (size_t i = 0; i < controllerCount; ++i) - { - FCDController* controller = document->GetControllerLibrary()->GetEntity(i); - if (controller->IsSkin()) - { - GetAssetFunctors(controller, document->GetControllerLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); - if (lengthFunctor.HasConversion() || upAxisFunctor.HasConversion()) - { - FCDSkinController* skin = controller->GetSkinController(); - FMMatrix44 mx = skin->GetBindShapeTransform(); - CONVERT_MAT44_NONANIMATABLE(mx); - skin->SetBindShapeTransform(mx); - size_t jointCount = skin->GetJointCount(); - for (size_t j = 0; j < jointCount; ++j) - { - FMMatrix44 bindPose = skin->GetJoint(j)->GetBindPoseInverse().Inverted(); - CONVERT_MAT44_NONANIMATABLE(bindPose); - skin->GetJoint(j)->SetBindPoseInverse(bindPose.Inverted()); - } - } - ResetAsset(controller); - } - } - - // Iterate over the geometries. Depending on the type, convert the control points, the normals and all other 3D data. - size_t geometryCount = document->GetGeometryLibrary()->GetEntityCount(); - for (size_t i = 0; i < geometryCount; ++i) - { - FCDGeometry* geometry = document->GetGeometryLibrary()->GetEntity(i); - GetAssetFunctors(geometry, document->GetGeometryLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); - if (lengthFunctor.HasConversion() || upAxisFunctor.HasConversion()) - { - if (geometry->IsMesh()) - { - // Iterate over the sources. Convert the source data depending on the stride and the type. - FCDGeometryMesh* mesh = geometry->GetMesh(); - size_t sourceCount = mesh->GetSourceCount(); - for (size_t s = 0; s < sourceCount; ++s) - { - FCDGeometrySource* source = mesh->GetSource(s); - uint32 stride = source->GetStride(); - size_t count = source->GetValueCount(); - if (count == 0) continue; - - float* ptr = source->GetData(); - switch (source->GetType()) - { - case FUDaeGeometryInput::POSITION: - if (upAxisFunctor.HasConversion() && stride >= 3) - { - for (uint32 j = 0; j < count; ++j) - { - FMVector3& v = *(FMVector3*) (ptr + j * stride); - upAxisFunctor(v); - if (source->GetSourceData().IsAnimated(stride * j) || source->GetSourceData().IsAnimated(stride * j + 1) || source->GetSourceData().IsAnimated(stride * j + 2)) - { - ConvertAnimationVector3(source->GetSourceData().GetAnimated(stride * j), source->GetSourceData().GetAnimated(stride * j + 1), source->GetSourceData().GetAnimated(stride * j + 2), v, document, lengthFunctor, upAxisFunctor, false); - } - } - } - if (lengthFunctor.HasConversion()) - { - for (uint32 j = 0; j < count * stride; ++j) - { - lengthFunctor(ptr[j]); - if (source->GetSourceData().IsAnimated(j)) - { - ConvertAnimationFloat(source->GetSourceData().GetAnimated(j), ptr[j], document, lengthFunctor, upAxisFunctor); - } - } - } - break; - - case FUDaeGeometryInput::NORMAL: - case FUDaeGeometryInput::GEOTANGENT: - case FUDaeGeometryInput::GEOBINORMAL: - case FUDaeGeometryInput::TEXTANGENT: - case FUDaeGeometryInput::TEXBINORMAL: - if (upAxisFunctor.HasConversion() && stride >= 3) - { - for (uint32 j = 0; j < count; ++j) - { - FMVector3& v = *(FMVector3*) (ptr + j * stride); - upAxisFunctor(v); - if (source->GetSourceData().IsAnimated(j) || source->GetSourceData().IsAnimated(j + 1) || source->GetSourceData().IsAnimated(j + 2)) - { - ConvertAnimationVector3(source->GetSourceData().GetAnimated(j), source->GetSourceData().GetAnimated(j+1), source->GetSourceData().GetAnimated(j+2), v, document, lengthFunctor, upAxisFunctor, false); - } - } - } - break; - case FUDaeGeometryInput::TEXCOORD: - case FUDaeGeometryInput::UV: - case FUDaeGeometryInput::EXTRA: - case FUDaeGeometryInput::UNKNOWN: - case FUDaeGeometryInput::COLOR: - case FUDaeGeometryInput::POINT_SIZE: - case FUDaeGeometryInput::POINT_ROTATION: - case FUDaeGeometryInput::VERTEX: - default: - break; // No work to do on these data types. - } - } - } - else if (geometry->IsSpline()) - { - FCDGeometrySpline* spline = geometry->GetSpline(); - size_t elementCount = spline->GetSplineCount(); - for (size_t j = 0; j < elementCount; ++j) - { - FCDSpline* element = spline->GetSpline(j); - for (FMVector3List::iterator it2 = element->GetCVs().begin(); it2 != element->GetCVs().end(); ++it2) - { - // 3D positions - upAxisFunctor(*it2); lengthFunctor(*it2); - } - } - } - } - - ResetAsset(geometry); - } - - // Iterate over the cameras: need to convert the far/near clip planes. - size_t cameraCount = document->GetCameraLibrary()->GetEntityCount(); - for (size_t i = 0; i < cameraCount; ++i) - { - FCDCamera* camera = document->GetCameraLibrary()->GetEntity(i); - GetAssetFunctors(camera, document->GetCameraLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); - if (lengthFunctor.HasConversion()) - { - CONVERT_FL(camera->GetFarZ(), camera->GetFarZ()); - CONVERT_FL(camera->GetNearZ(), camera->GetNearZ()); - } - ResetAsset(camera); - } - - // Iterate over the animations resetting their assets since its been taken care of. - FCDAnimationLibrary* library = document->GetAnimationLibrary(); - size_t animationCount = library->GetEntityCount(); - for (size_t i = 0; i < animationCount; ++i) - { - ResetAsset(library->GetEntity(i)); - } - - document->GetAsset()->SetUnitConversionFactor(unitInMeters); - document->GetAsset()->SetUpAxis(_upAxis); - } - } - -#undef CONVERT_FL -#undef CONVERT_VECT3 -#undef CONVERT_SCALE -#undef CONVERT_VECT3L -#undef CONVERT_MAT44 - -}; +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDocumentTools.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDAnimation.h" +#include "FCDocument/FCDAnimationChannel.h" +#include "FCDocument/FCDAnimationCurve.h" +#include "FCDocument/FCDAnimationKey.h" +#include "FCDocument/FCDAsset.h" +#include "FCDocument/FCDCamera.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDGeometryMesh.h" +#include "FCDocument/FCDGeometryPolygons.h" +#include "FCDocument/FCDGeometrySource.h" +#include "FCDocument/FCDGeometrySpline.h" +#include "FCDocument/FCDGeometryNURBSSurface.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDSceneNode.h" +#include "FCDocument/FCDSkinController.h" +#include "FCDocument/FCDTargetedEntity.h" +#include "FCDocument/FCDTransform.h" +#include "FCDocument/FCDExternalReferenceManager.h" +#include "FCDocument/FCDPlaceHolder.h" +#include "FCDocument/FCDSceneNodeIterator.h" +#include "FCDocument/FCDControllerInstance.h" +#include "FCDocument/FCDMorphController.h" +#include "FCDocument/FCDAnimationCurveTools.h" +#include "FCDocument/FCDAnimationMultiCurve.h" + +// +// FCDocumentTools +// + +namespace FCDocumentTools +{ + class FCDConversionSwapFunctor + { + private: + enum Axis { X, Y, Z, UNKNOWN } current, target; + Axis ConvertVector(const FMVector3& v) + { + if (IsEquivalent(v, FMVector3::XAxis)) return X; + else if (IsEquivalent(v, FMVector3::YAxis)) return Y; + else if (IsEquivalent(v, FMVector3::ZAxis)) return Z; + else return UNKNOWN; + } + + typedef void (*ConversionFn) (FMVector3& data, int32 sign); + ConversionFn functor; + + public: + FCDConversionSwapFunctor(const FMVector3& targetAxis) + : current(UNKNOWN), target(UNKNOWN) + { + target = ConvertVector(targetAxis); + }; + + inline void SetCurrent(const FMVector3& axis) + { + current = ConvertVector(axis); + PrepareFunctor(); + } + + inline bool HasConversion() { return functor != Identity; } + + static FCDTRotation* GetLastTransformForPivot(FCDSceneNode* node) + { + // Verify whether the last transform on this node's stack is a rotation transform. + if (node->GetTransformCount() > 0) + { + FCDTransform* transform = node->GetTransform(node->GetTransformCount() - 1); + if (transform->HasType(FCDTRotation::GetClassType())) + { + FCDAnimated* animated = transform->GetAnimated(); + if (animated != NULL && !animated->HasCurve()) animated = NULL; + if (animated == NULL) return (FCDTRotation*) transform; + } + } + return NULL; + } + + static void SmartAddRotationPivot(FCDSceneNode* node, const FMVector3& axis, float angle) + { + // Check for an old rotation pivot to remove. + FCDTRotation* lastRotation = GetLastTransformForPivot(node); + if (lastRotation != NULL && IsEquivalent(lastRotation->GetAxis(), axis) && IsEquivalent(lastRotation->GetAngle(), -1.0f * angle)) + { + SAFE_RELEASE(lastRotation); + lastRotation = GetLastTransformForPivot(node); + } + else + { + // Add this rotation to pivot the entity instance. + FCDTRotation* rotate = (FCDTRotation*) node->AddTransform(FCDTransform::ROTATION); + rotate->SetAxis(axis); + rotate->SetAngle(angle); + } + } + + void SetPivotTransform(FCDSceneNode* node, bool rollOnly) + { + if (functor == Identity) return; + + + // Change out of the current up-axis into Y-up. + if (current == X && !rollOnly) + { + SmartAddRotationPivot(node, FMVector3::ZAxis, 90.0f); + } + else if (current == Z) + { + SmartAddRotationPivot(node, rollOnly ? FMVector3::ZAxis : FMVector3::XAxis, rollOnly ? 90.0f : -90.0f); + } + + // Change into the target up-axis. + if (target == X && !rollOnly) + { + SmartAddRotationPivot(node, FMVector3::ZAxis, -90.0f); + } + else if (target == Z) + { + SmartAddRotationPivot(node, rollOnly ? FMVector3::ZAxis : FMVector3::XAxis, rollOnly ? -90.0f : 90.0f); + } + } + + void operator() (FMVector3& data, bool isScale = false) { (*functor)(data, (isScale ? 1 : -1)); } + + private: + void PrepareFunctor() + { + if (target == UNKNOWN || current == UNKNOWN || target == current) functor = Identity; + else + { + switch (target) + { + case X: functor = (current == Y) ? XtoY : XtoZ; break; + case Y: functor = (current == X) ? YtoX : YtoZ; break; + case Z: functor = (current == X) ? ZtoX : ZtoY; break; + case UNKNOWN: + default: FUFail(break); + } + } + } + + static void Identity(FMVector3& UNUSED(data), int32 UNUSED(sign)) {} + static void XtoY(FMVector3& data, int32 sign) { float t = sign * data.x; data.x = data.y; data.y = t; } + static void XtoZ(FMVector3& data, int32 UNUSED(sign)) { float t = data.x; data.x = data.y; data.y = data.z; data.z = t; } + static void YtoX(FMVector3& data, int32 sign) { float t = data.x; data.x = sign * data.y; data.y = t; } + static void YtoZ(FMVector3& data, int32 sign) { float t = sign * data.y; data.y = data.z; data.z = t; } + static void ZtoX(FMVector3& data, int32 UNUSED(sign)) { float t = data.z; data.z = data.y; data.y = data.x; data.x = t; } + static void ZtoY(FMVector3& data, int32 sign) { float t = data.y; data.y = sign * data.z; data.z = t; } + }; + + class FCDConversionUnitFunctor + { + private: + float factor, target; + + public: + FCDConversionUnitFunctor(float _target) + : factor(1.0f), target(_target) {} + + bool HasConversion() { return !IsEquivalent(factor, 1.0f); } + void SetCurrent(float current) { factor = ((current <= 0.0f) ? 1.0f : (current / target)); } + float GetConversionFactor() { return factor; } + void operator() (float& data) { data *= factor; } + void operator() (FMVector3& data) { data *= factor; } + }; + + typedef fm::pvector FCDSceneNodeIteratorList; + class VisualSceneNodeIterator + { + private: + FCDSceneNodeIteratorList queue; + + public: + VisualSceneNodeIterator(FCDVisualSceneNodeLibrary* visualSceneLibrary) + { + for (size_t i = 0; i < visualSceneLibrary->GetEntityCount(); ++i) + { + // use depth first to make sure node instancing in StandardizeScale works + queue.push_back(new FCDSceneNodeIterator(visualSceneLibrary->GetEntity(i), FCDSceneNodeIterator::DEPTH_FIRST_PREORDER, true)); + } + } + + virtual ~VisualSceneNodeIterator() + { + while (!queue.empty()) + { + SAFE_DELETE(queue.back()); + queue.pop_back(); + } + } + + FCDSceneNode* Next() + { + CleanQueue(); + if (queue.empty()) return NULL; + + FCDSceneNode* node = queue.back()->GetNode(); + queue.back()->Next(); + + return node; + } + + bool IsDone() + { + CleanQueue(); + return queue.empty(); + } + private: + void CleanQueue() // makes sure we can get the next node easily + { + while (!queue.empty()) + { + FCDSceneNodeIterator* sceneNodeIterator = queue.back(); + if (!sceneNodeIterator->IsDone()) return; + + SAFE_DELETE(sceneNodeIterator); + queue.pop_back(); + } + } + }; + + void GetAssetFunctors(FCDEntity* entity, FCDAsset* libraryAsset, FCDConversionUnitFunctor& lengthFunctor, FCDConversionSwapFunctor& upAxisFunctor) + { + FCDAssetList assets; assets.reserve(3); + entity->GetHierarchicalAssets(assets); + if (libraryAsset != NULL) assets.push_back(libraryAsset); + bool hasLength = false; + bool hasAxis = false; + for (FCDAssetList::iterator it = assets.begin(); it != assets.end(); ++it) + { + if (!hasLength && (*it)->GetHasUnitsFlag()) { hasLength = true; lengthFunctor.SetCurrent((*it)->GetUnitConversionFactor()); } + if (!hasAxis && (*it)->GetHasUpAxisFlag()) { hasAxis = true; upAxisFunctor.SetCurrent((*it)->GetUpAxis()); } + } + if (!hasLength) lengthFunctor.SetCurrent(-1.0f); + if (!hasAxis) upAxisFunctor.SetCurrent(FMVector3::Origin); + } + + inline void ResetAsset(FCDEntity* entity) + { + FCDAsset* asset = const_cast(const_cast(entity)->GetAsset()); + if (asset != NULL) + { + asset->ResetHasUnitsFlag(); + asset->ResetHasUpAxisFlag(); + } + } + + void ConvertAnimationVector3(FCDAnimated* animated1, FCDAnimated* animated2, FCDAnimated* animated3, float* v1, float* v2, float* v3, FCDocument* document, FCDConversionUnitFunctor& lengthFunctor, FCDConversionSwapFunctor& upAxisFunctor, bool convertLength, bool isScale = false) + { + FUAssert(animated1 != NULL && animated2 != NULL && animated3 != NULL, return); + + size_t indices[3] = { animated1->FindValue(v1), animated2->FindValue(v2), animated3->FindValue(v3) }; + if (indices[0] == ~(size_t)0 && indices[1] == ~(size_t)0 && indices[2] == ~(size_t)0) return; // no animations on the vector + FCDAnimated* animateds[3] = { animated1, animated2, animated3 }; + FMVector3 localAxes[3] = { FMVector3::XAxis, FMVector3::YAxis, FMVector3::ZAxis }; + + // save the curves and remove them from the animated + size_t curvesCount[3]; + FCDAnimationCurve** curves[3]; + for (size_t i = 0; i < 3; ++i) + { + FCDAnimationCurveTrackList& curvesList = animateds[i]->GetCurves()[indices[i]]; + curvesCount[i] = curvesList.size(); + if (curvesCount[i] > 0) + { + curves[i] = new FCDAnimationCurve*[curvesCount[i]]; + for (size_t j = 0; j < curvesCount[i]; j++) + { + curves[i][j] = curvesList.at(j); + } + animateds[i]->RemoveCurve(indices[i]); + } + else curves[i] = NULL; + } + + // transform the keys' outputs + for (size_t i = 0; i < 3; ++i) + { + for (size_t curvesCounter = 0; curvesCounter < curvesCount[i]; curvesCounter++) + { + FCDAnimationCurve* currentCurve = curves[i][curvesCounter]; + FCDAnimation* animation = currentCurve->GetParent()->GetParent(); + + FCDConversionUnitFunctor savedLengthFunctor(lengthFunctor); + FCDConversionSwapFunctor savedUpAxisFunctor(upAxisFunctor); + GetAssetFunctors(animation, document->GetAnimationLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); + + // convert the up axes and update the factor if we need to negate signs + FMVector3 savedLocalAxes(localAxes[i]); + upAxisFunctor(localAxes[i], isScale); + + float factor = 1.0f; + FUAssert(IsEquivalent(localAxes[i].LengthSquared(), 1.0f), continue;); + if (IsEquivalent(fabsf(localAxes[i].x), 1.0f)) + { + animateds[0]->AddCurve(indices[0], currentCurve); + factor = localAxes[i].x; + } + else if (IsEquivalent(fabsf(localAxes[i].y), 1.0f)) + { + animateds[1]->AddCurve(indices[1], currentCurve); + factor = localAxes[i].y; + } + else if (IsEquivalent(fabsf(localAxes[i].z), 1.0f)) + { + animateds[2]->AddCurve(indices[2], currentCurve); + factor = localAxes[i].z; + } + + // convert the unit lengths + FCDConversionScaleFunctor functor(factor * (convertLength ? lengthFunctor.GetConversionFactor() : 1.0f)); + currentCurve->ConvertValues(&functor, &functor); + + localAxes[i] = savedLocalAxes; + lengthFunctor = savedLengthFunctor; + upAxisFunctor = savedUpAxisFunctor; + } + } + + for (size_t i = 0; i < 3; ++i) + { + SAFE_DELETE_ARRAY(curves[i]); + } + } + inline void ConvertAnimationVector3(FCDAnimated* animated1, FCDAnimated* animated2, FCDAnimated* animated3, FMVector3& v, FCDocument* document, FCDConversionUnitFunctor& lengthFunctor, + FCDConversionSwapFunctor& upAxisFunctor, bool convertLength, bool isScale = false) + { + ConvertAnimationVector3(animated1, animated2, animated3, &v.x, &v.y, &v.z, document, lengthFunctor, upAxisFunctor, convertLength, isScale); + } + inline void ConvertAnimationVector3(FCDAnimated* animated, float* x, float* y, float* z, FCDocument* document, FCDConversionUnitFunctor& lengthFunctor, + FCDConversionSwapFunctor& upAxisFunctor, bool convertLength, bool isScale = false) + { + ConvertAnimationVector3(animated, animated, animated, x, y, z, document, lengthFunctor, upAxisFunctor, convertLength, isScale); + } + inline void ConvertAnimationVector3(FCDAnimated* animated, FMVector3& v, FCDocument* document, FCDConversionUnitFunctor& lengthFunctor, + FCDConversionSwapFunctor& upAxisFunctor, bool convertLength, bool isScale = false) + { + ConvertAnimationVector3(animated, &v.x, &v.y, &v.z, document, lengthFunctor, upAxisFunctor, convertLength, isScale); + } + + void ConvertAnimationFloat(FCDAnimated* animated, float& f, FCDocument* document, FCDConversionUnitFunctor& lengthFunctor, FCDConversionSwapFunctor& upAxisFunctor) + { + if (animated != NULL) + { + size_t index = animated->FindValue(&f); + if (index == ~(size_t)0) return; // no animations on the float + + FCDAnimationCurveListList& curvesListList = animated->GetCurves(); + if (index >= curvesListList.size()) return; // no animations on the float + FCDAnimationCurveTrackList& curves = curvesListList.at(index); + + // transform the keys' outputs + size_t curvesCount = curves.size(); + for (size_t curvesCounter = 0; curvesCounter < curvesCount; curvesCounter++) + { + FCDAnimationCurve* currentCurve = curves[curvesCounter]; + FCDAnimation* animation = currentCurve->GetParent()->GetParent(); + + FCDConversionUnitFunctor savedLengthFunctor(lengthFunctor); + FCDConversionSwapFunctor savedUpAxisFunctor(upAxisFunctor); + GetAssetFunctors(animation, document->GetAnimationLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); + + // convert the unit lengths + FCDConversionScaleFunctor functor(lengthFunctor.GetConversionFactor()); + currentCurve->ConvertValues(&functor, &functor); + + lengthFunctor = savedLengthFunctor; + upAxisFunctor = savedUpAxisFunctor; + } + } + } + +#define CONVERT_FL(parameter, f) { lengthFunctor(f); if (parameter.IsAnimated()) { ConvertAnimationFloat(parameter.GetAnimated(), f, document, lengthFunctor, upAxisFunctor); } } +#define CONVERT_VECT3(parameter, v) { upAxisFunctor(v); if (parameter.IsAnimated()) { ConvertAnimationVector3(parameter.GetAnimated(), v, document, lengthFunctor, upAxisFunctor, false); } } +#define CONVERT_SCALE(parameter, v) { upAxisFunctor(v, true); if (parameter.IsAnimated()) { ConvertAnimationVector3(parameter.GetAnimated(), v, document, lengthFunctor, upAxisFunctor, false, true); } } +#define CONVERT_VECT3L(parameter, v) { upAxisFunctor(v); lengthFunctor(v); if (parameter.IsAnimated()) { ConvertAnimationVector3(parameter.GetAnimated(), v, document, lengthFunctor, upAxisFunctor, true); } } +#define CONVERT_MAT44(parameter, m) { \ + FMMatrix44& _m = (m); \ + /* Rotation/Scale. */ \ + CONVERT_VECT3(parameter, *(FMVector3*) _m[0]); \ + CONVERT_VECT3(parameter, *(FMVector3*) _m[1]); \ + CONVERT_VECT3(parameter, *(FMVector3*) _m[2]); \ + for (int i = 0; i < 3; ++i) { \ + FMVector3 v = FMVector3(_m[0][i], _m[1][i], _m[2][i]); \ + upAxisFunctor(v); _m[0][i] = v.x; _m[1][i] = v.y; _m[2][i] = v.z; \ + /* Handle the animation carefully... */ \ + if (parameter.IsAnimated()) { \ + ConvertAnimationVector3(parameter.GetAnimated(), &_m[0][i], &_m[1][i], &_m[2][i], document, lengthFunctor, upAxisFunctor, false); } } \ + /* Translation.. */ \ + CONVERT_VECT3(parameter, *(FMVector3*) _m[3]); \ + CONVERT_FL(parameter, _m[3][0]); CONVERT_FL(parameter, _m[3][1]); CONVERT_FL(parameter, _m[3][2]); } + +#define CONVERT_MAT44_NONANIMATABLE(m) { \ + FMMatrix44& _m = (m); \ + /* Rotation/Scale. */ \ + upAxisFunctor(*(FMVector3*) _m[0]); \ + upAxisFunctor(*(FMVector3*) _m[1]); \ + upAxisFunctor(*(FMVector3*) _m[2]); \ + for (int i = 0; i < 3; ++i) { \ + FMVector3 v(_m[0][i], _m[1][i], _m[2][i]); \ + upAxisFunctor(v); _m[0][i] = v.x; _m[1][i] = v.y; _m[2][i] = v.z; } \ + /* Translation.. */ \ + upAxisFunctor(*(FMVector3*) _m[3]); \ + lengthFunctor(_m[3][0]); lengthFunctor(_m[3][1]); lengthFunctor(_m[3][2]); } + + void StandardizeUpAxisAndLength(FCDocument* document, const FMVector3& upAxis, float unitInMeters, bool handleTargets) + { + if (document == NULL) return; + + // Figure out the wanted up_axis and unit values, if they are not provided. + FCDAsset* baseAsset = document->GetAsset(); + if (IsEquivalent(unitInMeters, 0.0f) || unitInMeters < 0.0f) + { + if (baseAsset->GetHasUnitsFlag()) unitInMeters = baseAsset->GetUnitConversionFactor(); + else unitInMeters = 1.0f; // COLLADA specification default. + } + FMVector3 _upAxis = upAxis; + if (!IsEquivalent(upAxis, FMVector3::Origin)) _upAxis = upAxis; + else + { + if (baseAsset->GetHasUpAxisFlag()) _upAxis = baseAsset->GetUpAxis(); + else _upAxis = FMVector3::YAxis; // COLLADA specification default. + } + + // Setup the modification functors. + FCDConversionUnitFunctor lengthFunctor(unitInMeters); + FCDConversionSwapFunctor upAxisFunctor(_upAxis); + + FCDocumentList documentQueue; + documentQueue.push_back(document); + + // documentQueue grows while we are accessing! + for (size_t documentCounter = 0; documentCounter < documentQueue.size(); documentCounter++) + { + FCDocument* document = documentQueue.at(documentCounter); + FCDExternalReferenceManager* referenceManager = document->GetExternalReferenceManager(); + size_t placeHolderCount = referenceManager->GetPlaceHolderCount(); + for (size_t i = 0; i < placeHolderCount; ++i) + { + FCDPlaceHolder* placeHolder = referenceManager->GetPlaceHolder(i); + + if (!placeHolder->IsTargetLoaded()) + { + if (FCollada::GetDereferenceFlag()) + { + placeHolder->LoadTarget(); + if (!placeHolder->IsTargetLoaded()) continue; + } + else + { + // we don't want to load the external reference + continue; + } + } + FUAssert(placeHolder->IsTargetLoaded(), continue); + + FCDocument* targetDocument = placeHolder->GetTarget(); + if (documentQueue.find(targetDocument) == documentQueue.end()) + { + documentQueue.push_back(targetDocument); + } + } + } + + // Iterate over all the documents, modifying their elements + while (!documentQueue.empty()) + { + FCDocument* document = documentQueue.back(); documentQueue.pop_back(); + + // Iterate over the scene graph, modifying the transforms. + VisualSceneNodeIterator visualSceneNodeIt(document->GetVisualSceneLibrary()); + while (!visualSceneNodeIt.IsDone()) + { + FCDSceneNode* node = visualSceneNodeIt.Next(); + GetAssetFunctors(node, document->GetVisualSceneLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); + if (lengthFunctor.HasConversion() || upAxisFunctor.HasConversion()) + { + size_t transformCount = node->GetTransformCount(); + for (size_t t = 0; t < transformCount; ++t) + { + FCDTransform* transform = node->GetTransform(t); + if (transform->HasType(FCDTTranslation::GetClassType())) CONVERT_VECT3L(((FCDTTranslation*) transform)->GetTranslation(), ((FCDTTranslation*) transform)->GetTranslation()) + else if (transform->HasType(FCDTRotation::GetClassType())) CONVERT_VECT3(((FCDTRotation*) transform)->GetAngleAxis(), ((FCDTRotation*) transform)->GetAxis()) + else if (transform->HasType(FCDTScale::GetClassType())) CONVERT_SCALE(((FCDTScale*) transform)->GetScale(), ((FCDTScale*) transform)->GetScale()) + else if (transform->HasType(FCDTSkew::GetClassType())) { CONVERT_VECT3(((FCDTSkew*) transform)->GetSkew(), ((FCDTSkew*) transform)->GetRotateAxis()); CONVERT_VECT3(((FCDTSkew*) transform)->GetSkew(), ((FCDTSkew*) transform)->GetAroundAxis()); } + else if (transform->HasType(FCDTLookAt::GetClassType())) { CONVERT_VECT3L(((FCDTLookAt*) transform)->GetLookAt(), ((FCDTLookAt*) transform)->GetPosition()); CONVERT_VECT3L(((FCDTLookAt*) transform)->GetLookAt(), ((FCDTLookAt*) transform)->GetTarget()); CONVERT_VECT3(((FCDTLookAt*) transform)->GetLookAt(), ((FCDTLookAt*) transform)->GetUp()); } + else if (transform->HasType(FCDTMatrix::GetClassType())) { CONVERT_MAT44(((FCDTMatrix*) transform)->GetTransform(), ((FCDTMatrix*) transform)->GetTransform()); } + } + } + + if (upAxisFunctor.HasConversion()) + { + // Unfortunately, some of the entity types do not survive very well on up-axis changes. + // Check for cameras, lights, emitters, force fields + fm::pvector toRemove; + size_t nodeInstanceCount = node->GetInstanceCount(); + for (size_t n = 0; n < nodeInstanceCount; ++n) + { + FCDEntityInstance* nodeInstance = node->GetInstance(n); + if (nodeInstance->GetEntityType() == FCDEntity::CAMERA || nodeInstance->GetEntityType() == FCDEntity::LIGHT + || nodeInstance->GetEntityType() == FCDEntity::FORCE_FIELD || nodeInstance->GetEntityType() == FCDEntity::EMITTER) + { + // Targeted entities should still point in the correct direction: do only roll up-axis changes. + bool rollOnly = false; + if (handleTargets && nodeInstance->GetEntity() != NULL && nodeInstance->GetEntity()->HasType(FCDTargetedEntity::GetClassType())) + { + FCDTargetedEntity* targetedEntity = (FCDTargetedEntity*) nodeInstance->GetEntity(); + rollOnly = targetedEntity->HasTarget(); // Don't pivot fully. + } + + // Do not create a pivot node unless necessary. + FCDSceneNode* pivotedNode = node; + if (node->GetChildrenCount() == 0 && node->GetInstanceCount() == 1) + { + pivotedNode = node; + } + else + { + // Create a pivot node. + pivotedNode = node->AddChildNode(); + pivotedNode->SetName(node->GetName() + FC("_pivot")); + pivotedNode->SetDaeId(node->GetDaeId() + "_pivot"); + + // Need to clone the instance and remove the original one, then. + FCDEntityInstance* clone = pivotedNode->AddInstance(nodeInstance->GetEntityType()); + nodeInstance->Clone(clone); + toRemove.push_back(nodeInstance); + } + + // Do the 'pivoting'. + upAxisFunctor.SetPivotTransform(pivotedNode, rollOnly); + } + } + CLEAR_POINTER_VECTOR(toRemove); + } + + ResetAsset(node); + } + + // Iterate over the skin controllers: need to convert the bind-poses. + size_t controllerCount = document->GetControllerLibrary()->GetEntityCount(); + for (size_t i = 0; i < controllerCount; ++i) + { + FCDController* controller = document->GetControllerLibrary()->GetEntity(i); + if (controller->IsSkin()) + { + GetAssetFunctors(controller, document->GetControllerLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); + if (lengthFunctor.HasConversion() || upAxisFunctor.HasConversion()) + { + FCDSkinController* skin = controller->GetSkinController(); + FMMatrix44 mx = skin->GetBindShapeTransform(); + CONVERT_MAT44_NONANIMATABLE(mx); + skin->SetBindShapeTransform(mx); + size_t jointCount = skin->GetJointCount(); + for (size_t j = 0; j < jointCount; ++j) + { + FMMatrix44 bindPose = skin->GetJoint(j)->GetBindPoseInverse().Inverted(); + CONVERT_MAT44_NONANIMATABLE(bindPose); + skin->GetJoint(j)->SetBindPoseInverse(bindPose.Inverted()); + } + } + ResetAsset(controller); + } + } + + // Iterate over the geometries. Depending on the type, convert the control points, the normals and all other 3D data. + size_t geometryCount = document->GetGeometryLibrary()->GetEntityCount(); + for (size_t i = 0; i < geometryCount; ++i) + { + FCDGeometry* geometry = document->GetGeometryLibrary()->GetEntity(i); + GetAssetFunctors(geometry, document->GetGeometryLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); + if (lengthFunctor.HasConversion() || upAxisFunctor.HasConversion()) + { + if (geometry->IsMesh()) + { + // Iterate over the sources. Convert the source data depending on the stride and the type. + FCDGeometryMesh* mesh = geometry->GetMesh(); + size_t sourceCount = mesh->GetSourceCount(); + for (size_t s = 0; s < sourceCount; ++s) + { + FCDGeometrySource* source = mesh->GetSource(s); + uint32 stride = source->GetStride(); + size_t count = source->GetValueCount(); + if (count == 0) continue; + + float* ptr = source->GetData(); + switch (source->GetType()) + { + case FUDaeGeometryInput::POSITION: + if (upAxisFunctor.HasConversion() && stride >= 3) + { + for (uint32 j = 0; j < count; ++j) + { + FMVector3& v = *(FMVector3*) (ptr + j * stride); + upAxisFunctor(v); + if (source->GetSourceData().IsAnimated(stride * j) || source->GetSourceData().IsAnimated(stride * j + 1) || source->GetSourceData().IsAnimated(stride * j + 2)) + { + ConvertAnimationVector3(source->GetSourceData().GetAnimated(stride * j), source->GetSourceData().GetAnimated(stride * j + 1), source->GetSourceData().GetAnimated(stride * j + 2), v, document, lengthFunctor, upAxisFunctor, false); + } + } + } + if (lengthFunctor.HasConversion()) + { + for (uint32 j = 0; j < count * stride; ++j) + { + lengthFunctor(ptr[j]); + if (source->GetSourceData().IsAnimated(j)) + { + ConvertAnimationFloat(source->GetSourceData().GetAnimated(j), ptr[j], document, lengthFunctor, upAxisFunctor); + } + } + } + break; + + case FUDaeGeometryInput::NORMAL: + case FUDaeGeometryInput::GEOTANGENT: + case FUDaeGeometryInput::GEOBINORMAL: + case FUDaeGeometryInput::TEXTANGENT: + case FUDaeGeometryInput::TEXBINORMAL: + if (upAxisFunctor.HasConversion() && stride >= 3) + { + for (uint32 j = 0; j < count; ++j) + { + FMVector3& v = *(FMVector3*) (ptr + j * stride); + upAxisFunctor(v); + if (source->GetSourceData().IsAnimated(j) || source->GetSourceData().IsAnimated(j + 1) || source->GetSourceData().IsAnimated(j + 2)) + { + ConvertAnimationVector3(source->GetSourceData().GetAnimated(j), source->GetSourceData().GetAnimated(j+1), source->GetSourceData().GetAnimated(j+2), v, document, lengthFunctor, upAxisFunctor, false); + } + } + } + break; + case FUDaeGeometryInput::TEXCOORD: + case FUDaeGeometryInput::UV: + case FUDaeGeometryInput::EXTRA: + case FUDaeGeometryInput::UNKNOWN: + case FUDaeGeometryInput::COLOR: + case FUDaeGeometryInput::POINT_SIZE: + case FUDaeGeometryInput::POINT_ROTATION: + case FUDaeGeometryInput::VERTEX: + default: + break; // No work to do on these data types. + } + } + } + else if (geometry->IsSpline()) + { + FCDGeometrySpline* spline = geometry->GetSpline(); + size_t elementCount = spline->GetSplineCount(); + for (size_t j = 0; j < elementCount; ++j) + { + FCDSpline* element = spline->GetSpline(j); + for (FMVector3List::iterator it2 = element->GetCVs().begin(); it2 != element->GetCVs().end(); ++it2) + { + // 3D positions + upAxisFunctor(*it2); lengthFunctor(*it2); + } + } + } + } + + ResetAsset(geometry); + } + + // Iterate over the cameras: need to convert the far/near clip planes. + size_t cameraCount = document->GetCameraLibrary()->GetEntityCount(); + for (size_t i = 0; i < cameraCount; ++i) + { + FCDCamera* camera = document->GetCameraLibrary()->GetEntity(i); + GetAssetFunctors(camera, document->GetCameraLibrary()->GetAsset(false), lengthFunctor, upAxisFunctor); + if (lengthFunctor.HasConversion()) + { + CONVERT_FL(camera->GetFarZ(), camera->GetFarZ()); + CONVERT_FL(camera->GetNearZ(), camera->GetNearZ()); + } + ResetAsset(camera); + } + + // Iterate over the animations resetting their assets since its been taken care of. + FCDAnimationLibrary* library = document->GetAnimationLibrary(); + size_t animationCount = library->GetEntityCount(); + for (size_t i = 0; i < animationCount; ++i) + { + ResetAsset(library->GetEntity(i)); + } + + document->GetAsset()->SetUnitConversionFactor(unitInMeters); + document->GetAsset()->SetUpAxis(_upAxis); + } + } + +#undef CONVERT_FL +#undef CONVERT_VECT3 +#undef CONVERT_SCALE +#undef CONVERT_VECT3L +#undef CONVERT_MAT44 + +}; Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocumentTools.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocument.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocument.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocument.h (revision 24247) @@ -1,525 +1,525 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDocument.h - This file declares the COLLADA document object model top class: FCDocument. -*/ - -#ifndef _FC_DOCUMENT_H_ -#define _FC_DOCUMENT_H_ - -#ifndef __FCD_OBJECT_H_ -#include "FCDocument/FCDObject.h" -#endif // __FCD_OBJECT_H_ -#ifndef _FU_PARAMETER_H_ -#include "FUtils/FUParameter.h" -#endif // _FU_PARAMETER_H_ - -#if defined(WIN32) -template class FCOLLADA_EXPORT FCDLibrary; /**< Trick Doxygen. */ -template class FCOLLADA_EXPORT FUUniqueStringMapT; /**< Trick Doxygen. */ -#elif defined(LINUX) || defined(__APPLE__) || defined (__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) -template class FCDLibrary; /**< Trick Doxygen. */ -template class FUUniqueStringMapT; /**< Trick Doxygen. */ -#endif // LINUX - -class FCDAnimated; -class FCDAnimation; -class FCDAnimationChannel; -class FCDAnimationClip; -class FCDAsset; -class FCDCamera; -class FCDController; -class FCDEffect; -class FCDEntity; -class FCDEntityReference; -class FCDEmitter; -class FCDExternalReferenceManager; -class FCDExtra; -class FCDForceField; -class FCDGeometry; -class FCDImage; -class FCDLight; -class FCDMaterial; -class FCDObject; -class FCDPhysicsMaterial; -class FCDPhysicsModel; -class FCDPhysicsScene; -class FCDTexture; -class FCDSceneNode; -class FCDVersion; -class FUFileManager; - -/** - A layer declaration. - Contains a name for the layer and the ids of all the entities within the layer. -*/ -class FCOLLADA_EXPORT FCDLayer -{ -public: - fm::string name; /**< The layer name. There is no guarantee of uniqueness. */ - StringList objects; /**< The list of COLLADA entity ids which are contained by this layer. */ -}; - -typedef fm::pvector FCDLayerList; /**< A dynamically-sized array of layer declarations. */ - -typedef FCDLibrary FCDAnimationLibrary; /**< A COLLADA library of animation entities. */ -typedef FCDLibrary FCDAnimationClipLibrary; /**< A COLLADA library of animation clip entities. */ -typedef FCDLibrary FCDCameraLibrary; /**< A COLLADA library of camera entities. */ -typedef FCDLibrary FCDControllerLibrary; /**< A COLLADA library of controller entities. */ -typedef FCDLibrary FCDEffectLibrary; /**< A COLLADA library of effect entities. */ -typedef FCDLibrary FCDEmitterLibrary; /**< A non-standard library of generic emitters. */ -typedef FCDLibrary FCDForceFieldLibrary; /**< A COLLADA library of force fields. */ -typedef FCDLibrary FCDGeometryLibrary; /**< A COLLADA library of geometric entities. */ -typedef FCDLibrary FCDImageLibrary; /**< A COLLADA library of images. */ -typedef FCDLibrary FCDLightLibrary; /**< A COLLADA library of light entities. */ -typedef FCDLibrary FCDMaterialLibrary; /**< A COLLADA library of visual material entities. */ -typedef FCDLibrary FCDVisualSceneNodeLibrary; /**< A COLLADA library of visual scene nodes. */ -typedef FCDLibrary FCDPhysicsModelLibrary; /**< A COLLADA library of physics model entities. */ -typedef FCDLibrary FCDPhysicsMaterialLibrary; /**< A COLLADA library of physics material entities. */ -typedef FCDLibrary FCDPhysicsSceneLibrary; /**< A COLLADA library of physics scene nodes. */ -typedef FUUniqueStringMapT FUSUniqueStringMap; /**< A set of unique strings. */ -typedef fm::map FCDExtraSet; /**< A set of extra trees. */ - -/** @defgroup FCDocument COLLADA Document Object Model. */ - -/** The top class for the COLLADA object model. - - This class holds all the COLLADA libraries, the scene graphs and the - document's asset tag. - - It also holds some global information, such as the animation start and end - time and the layers. This global information is only exported by ColladaMaya - right now. - - @ingroup FCDocument COLLADA Document Object Model -*/ -class FCOLLADA_EXPORT FCDocument : public FCDObject -{ -private: - DeclareObjectType(FCDObject); - - FUFileManager* fileManager; - FUObjectRef externalReferenceManager; - fstring fileUrl; - FCDVersion* version; - FCDExtraSet extraTrees; - - FUSUniqueStringMap* uniqueNameMap; - DeclareParameterRef(FCDEntityReference, visualSceneRoot, FC("Root Visual Scene")); - DeclareParameterContainer(FCDEntityReference, physicsSceneRoots, FC("Root Physics Scenes")); - - // Document parameters - DeclareParameterRef(FCDAsset, asset, FC("Asset Tag")); - DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); - bool hasStartTime, hasEndTime; - DeclareParameter(float, FUParameterQualifiers::SIMPLE, startTime, FC("Start Time")); - DeclareParameter(float, FUParameterQualifiers::SIMPLE, endTime, FC("End Time")); - FCDLayerList layers; // Maya-only - - // Parsed and merged libraries - DeclareParameterRef(FCDAnimationLibrary, animationLibrary, FC("Animation Library")); - DeclareParameterRef(FCDAnimationClipLibrary, animationClipLibrary, FC("Animation Clip Library")); - DeclareParameterRef(FCDCameraLibrary, cameraLibrary, FC("Camera Library")); - DeclareParameterRef(FCDControllerLibrary, controllerLibrary, FC("Controller Library")); - DeclareParameterRef(FCDEffectLibrary, effectLibrary, FC("Effect Library")); - DeclareParameterRef(FCDForceFieldLibrary, forceFieldLibrary, FC("Force-field Library")); - DeclareParameterRef(FCDGeometryLibrary, geometryLibrary, FC("Geometry Library")); - DeclareParameterRef(FCDImageLibrary, imageLibrary, FC("Image Library")); - DeclareParameterRef(FCDLightLibrary, lightLibrary, FC("Light Library")); - DeclareParameterRef(FCDMaterialLibrary, materialLibrary, FC("Material Library")); - DeclareParameterRef(FCDPhysicsModelLibrary, physicsModelLibrary, FC("Physics Model Library")); - DeclareParameterRef(FCDPhysicsMaterialLibrary, physicsMaterialLibrary, FC("Physics Material Library")); - DeclareParameterRef(FCDPhysicsSceneLibrary, physicsSceneLibrary, FC("Physics Scene Library")); - DeclareParameterRef(FCDVisualSceneNodeLibrary, visualSceneLibrary, FC("Visual Scene Library")); - DeclareParameterRef(FCDEmitterLibrary, emitterLibrary, FC("Emitter Library")); - - // Animated values - typedef fm::map FCDAnimatedSet; - FCDAnimatedSet animatedValues; - -public: - /** Construct a new COLLADA document. */ - FCDocument(); - - /** COLLADA document destructor. This clears out all the memory related to the document. */ - virtual ~FCDocument(); - - /** Retrieves the asset information for this COLLADA document. The asset information should always be present. - @return A pointer to the asset information structure. This pointer should never be NULL. */ - inline FCDAsset* GetAsset() { return asset; } - inline const FCDAsset* GetAsset() const { return asset; } /**< See above. */ - - /** Retrieves the base extra tree for this COLLADA document. An extra tree should always be present, - but is likely to be empty. - @return A pointer to the base extra tree. This pointer should never be NULL. */ - inline FCDExtra* GetExtra() { return extra; } - inline const FCDExtra* GetExtra() const { return extra; } /**< See above. */ - - /** Retrieves the version numbers for this COLLADA document. The version numbers should always be present. - @return The version number structure.*/ - inline FCDVersion& GetVersion() { return *version; } - inline const FCDVersion& GetVersion() const { return *version; } /**< See above. */ - - /** [INTERNAL] Retrieves the local file manager for the COLLADA document. Used to resolve URIs and transform file - paths into their relative or absolute equivalent. May be deprecated in future versions. - @return The file manager for this COLLADA document. This pointer should never be NULL. */ - inline FUFileManager* GetFileManager() { return fileManager; } - inline const FUFileManager* GetFileManager() const { return fileManager; } /**< See above. */ - - /** Retrieves the currently instanced visual scene. - NOTE: GetVisualSceneRoot is deprecated. Please start using GetVisualSceneInstance. - @return The currently instanced visual scene. */ - inline FCDSceneNode* GetVisualSceneInstance() { return const_cast(const_cast(this)->GetVisualSceneInstance()); } - const FCDSceneNode* GetVisualSceneInstance() const; /**< See above. */ - DEPRECATED(3.04A, FCDocument::GetVisualSceneInstance) inline FCDSceneNode* GetVisualSceneRoot() { return GetVisualSceneInstance(); } /**< See above. */ - DEPRECATED(3.04A, FCDocument::GetVisualSceneInstance) inline const FCDSceneNode* GetVisualSceneRoot() const { return GetVisualSceneInstance(); } /**< See above. */ - - /** Retrieves the reference to the currently instanced visual scene. - @return The instanced visual scene reference. */ - inline FCDEntityReference* GetVisualSceneInstanceReference() { return visualSceneRoot; } - inline const FCDEntityReference* GetVisualSceneInstanceReference() const { return visualSceneRoot; } /**< See above. */ - - /** Retrieves the number of instanced physics scenes. - @return The number of instanced physics scenes. */ - inline size_t GetPhysicsSceneInstanceCount() const { return physicsSceneRoots.size(); } - - /** Retrieves one instanced physics scene. - @param index The index of the physics scene to retrieve. - If the index is out-of-bounds, NULL is returned. - @return A currently instanced physics scene. */ - inline FCDPhysicsScene* GetPhysicsSceneInstance(size_t index = 0) { return const_cast(const_cast(this)->GetPhysicsSceneInstance(index)); } - const FCDPhysicsScene* GetPhysicsSceneInstance(size_t index = 0) const; /**< See above. */ - DEPRECATED(3.04A, FCDocument::GetPhysicsSceneInstance) inline FCDPhysicsScene* GetPhysicsSceneRoot(size_t index = 0) { return GetPhysicsSceneInstance(index); } /**< See above. */ - DEPRECATED(3.04A, FCDocument::GetPhysicsSceneInstance) inline const FCDPhysicsScene* GetPhysicsSceneRoot(size_t index = 0) const { return GetPhysicsSceneInstance(index); } /**< See above. */ - - /** Adds one instanced physics scene to the document. - @param scene The newly instanced physics scene. */ - void AddPhysicsSceneInstance(FCDPhysicsScene* scene); - - /** Retrieves a reference to the instanced physics scene. - @param index The index of the physics scene instance reference to - retrieve. If the index is out-of-bounds, NULL is returned. - @return The reference to the index physics scene reference. */ - inline FCDEntityReference* GetPhysicsSceneInstanceReference(size_t index = 0) { if (index == 0 && physicsSceneRoots.empty()) return NULL; FUAssert(index < physicsSceneRoots.size(), return NULL); return physicsSceneRoots[index]; } - inline const FCDEntityReference* GetPhysicsSceneInstanceReference(size_t index = 0) const { if (index == 0 && physicsSceneRoots.empty()) return NULL; FUAssert(index < physicsSceneRoots.size(), return NULL); return physicsSceneRoots[index]; } - - /** Adds an empty reference in the list of instanced physics scenes. - @return The new, empty, reference. */ - FCDEntityReference* AddPhysicsSceneInstanceReference(); - - /** [INTERNAL] Retrieves the map of unique ids for this document. - @return The map of unique ids for this document. */ - inline FUSUniqueStringMap* GetUniqueNameMap() { return uniqueNameMap; } - inline const FUSUniqueStringMap* GetUniqueNameMap() const { return uniqueNameMap; } /**< See above. */ - - /** Retrieves the external reference manager. - @return The external reference manager. */ - inline FCDExternalReferenceManager* GetExternalReferenceManager() { return externalReferenceManager; } - inline const FCDExternalReferenceManager* GetExternalReferenceManager() const { return externalReferenceManager; } /**< See above. */ - - /** Retrieves the file URL for this document. - @return The file URL for the document. */ - const fstring& GetFileUrl() const { return fileUrl; } - - /** Sets the file URL for this document. - Useful when working with external references. - @param filename The filename for the document. */ - void SetFileUrl(const fstring& filename); - - /** Returns whether a start time is being enforced for the document. - @return Whether the document has a start time. */ - inline bool HasStartTime() const { return hasStartTime; } - /** Retrieves the start time set for the document. - @return The document start time. */ - inline float GetStartTime() const { return startTime; } - /** Enforces a certain time as the start time for the document. - @param time The document start time. */ - inline void SetStartTime(float time) { startTime = time; hasStartTime = true; } - - /** Returns whether a end time is being enforced for the document. - @return Whether the document has a end time. */ - inline bool HasEndTime() const { return hasEndTime; } - /** Retrieves the end time set for the document. - @return The document end time. */ - inline float GetEndTime() const { return endTime; } - /** Enforces a certain time as the end time for the document. - @param time The document end time. */ - inline void SetEndTime(float time) { endTime = time; hasEndTime = true; } - - /** Evaluate the animation objects at the given time - @param time The time to evaluate the objects at */ - inline void SetCurrentTime(float time); - - /** Retrieves the list of entity layers. - @return The list of entity layers. */ - inline FCDLayerList& GetLayers() { return layers; } - inline const FCDLayerList& GetLayers() const { return layers; } /**< See above. */ - - /** Retrieves the number of entity layers contained within the document. - @return The number of layers. */ - inline size_t GetLayerCount() const { return layers.size(); } - - /** Retrieves a specific entity layer contained within the document. - @param index The index of the layer. - @return The entity layer. This pointer will be NULL if the index - is out-of-bounds. */ - inline FCDLayer* GetLayer(size_t index) { FUAssert(index < GetLayerCount(), return NULL); return layers.at(index); } - inline const FCDLayer* GetLayer(size_t index) const { FUAssert(index < GetLayerCount(), return NULL); return layers.at(index); } /**< See above. */ - - /** Adds an entity layer to the document. - @return The new layer. */ - FCDLayer* AddLayer(); - - /** Releases an entity layer from the document - @param layer The layer to release. */ - void ReleaseLayer(FCDLayer* layer); - - /** Retrieves the animation library. The animation library contains the animation curves - within a tree structure. To create and find animation curves, do not use the animation - library directly: use the FCDAnimated class, the FindAnimatedValue() function and the - RegisterAnimatedValue() function. - @return The animation library. */ - inline FCDAnimationLibrary* GetAnimationLibrary() { return animationLibrary; } - inline const FCDAnimationLibrary* GetAnimationLibrary() const { return animationLibrary; } /**< See above. */ - - /** Retrieves the animation clip library. The animation clip library contains a list of animation clips. - Each animation clip instantiates nodes from the animation library. Sections of the animation curves - belonging to the instantiated animation nodes are thereby packaged together as animation clips. - @return The animation clip library. */ - inline FCDAnimationClipLibrary* GetAnimationClipLibrary() { return animationClipLibrary; } - inline const FCDAnimationClipLibrary* GetAnimationClipLibrary() const { return animationClipLibrary; } /**< See above. */ - - /** Retrieves the camera library. The camera library contains a list of cameras, which may be - instantiated within the scene graph. COLLADA supports two camera types: perspective and orthographic. - @return The camera library. */ - inline FCDCameraLibrary* GetCameraLibrary() { return cameraLibrary; } - inline const FCDCameraLibrary* GetCameraLibrary() const { return cameraLibrary; } /**< See above. */ - - /** Retrieves the controller library. The controller library contains a list of controllers, which may - be instantiated within the scene graph. COLLADA supports two controller types: skin and morph. - @return The controller library. */ - inline FCDControllerLibrary* GetControllerLibrary() { return controllerLibrary; } - inline const FCDControllerLibrary* GetControllerLibrary() const { return controllerLibrary; } /**< See above. */ - - /** Retrieves the geometry library. The geometry library contains a list of basic geometries, which may - be instantiated within the scene graph and may be used by controllers. - COLLADA supports two geometry types: mesh and spline. - @return The geometry library. */ - inline FCDGeometryLibrary* GetGeometryLibrary() { return geometryLibrary; } - inline const FCDGeometryLibrary* GetGeometryLibrary() const { return geometryLibrary; } /**< See above. */ - - /** Retrieves the physics force field library. - Force fields are emitters of physical force and have no COMMON profile in COLLADA. - @return The force field library. */ - inline FCDForceFieldLibrary* GetForceFieldLibrary() { return forceFieldLibrary; } - inline const FCDForceFieldLibrary* GetForceFieldLibrary() const { return forceFieldLibrary; } /**< See above. */ - - /** Retrieves the image library. The image library contains a list of images. Images are used - by effects for textures. - @return The image library. */ - inline FCDImageLibrary* GetImageLibrary() { return imageLibrary; } - inline const FCDImageLibrary* GetImageLibrary() const { return imageLibrary; } /**< See above. */ - - /** Retrieves the light library. The light library contains a list of light, which may be - instantiated within the scene graph. COLLADA supports four light types: ambient, directional, - point and spot lights. - @return The light library. */ - inline FCDLightLibrary* GetLightLibrary() { return lightLibrary; } - inline const FCDLightLibrary* GetLightLibrary() const { return lightLibrary; } /**< See above. */ - - /** Retrieves the visual material library. The visual material library contains a list of visual materials, - which are bound to mesh polygons within the scene graph. A visual material instantiates an effect and - presets the effect parameters for a given visual result. - @return The visual material library. */ - inline FCDMaterialLibrary* GetMaterialLibrary() { return materialLibrary; } - inline const FCDMaterialLibrary* GetMaterialLibrary() const { return materialLibrary; } /**< See above. */ - - /** Retrieves the effect library. The effect library contains a list of effects, which may be instantiated - by materials. An effect defines an interface for a rendering shader. A ColladaFX effect may contain multiple - passes and techniques for different platforms or level of details. - @return The effect library. */ - inline FCDEffectLibrary* GetEffectLibrary() { return effectLibrary; } - inline const FCDEffectLibrary* GetEffectLibrary() const { return effectLibrary; } /**< See above. */ - - /** Retrieves the visual scene library. The visual scene library contains an acyclic directed graph of - visual scene nodes: a visual scene node contains one or more parent nodes and zero or more child nodes. - A visual scene node also contains 3D transformations: translation, rotation, scale, skew, as well as - the compound transformations: lookAt and matrix. A visual scene node also contains instances of - geometries, controllers, cameras and/or lights. Only one visual scene should be used at one time - by the global scene. - @return The visual scene library. */ - inline FCDVisualSceneNodeLibrary* GetVisualSceneLibrary() { return visualSceneLibrary; } - inline const FCDVisualSceneNodeLibrary* GetVisualSceneLibrary() const { return visualSceneLibrary; } /**< See above. */ - - /** Retrieves the physics model library. - The physics model library contains a list of physics models. - @return The physics model library. */ - inline FCDPhysicsModelLibrary* GetPhysicsModelLibrary() { return physicsModelLibrary; } - inline const FCDPhysicsModelLibrary* GetPhysicsModelLibrary() const { return physicsModelLibrary; } /**< See above. */ - - /** Retrieves the physics material library. - The physics material library contains a list of physics material. - @return The physics material library. */ - inline FCDPhysicsMaterialLibrary* GetPhysicsMaterialLibrary() { return physicsMaterialLibrary; } - inline const FCDPhysicsMaterialLibrary* GetPhysicsMaterialLibrary() const { return physicsMaterialLibrary; } /**< See above. */ - - /** Retrieves the physics scene library. - The physics scene library contains a list of physics scene nodes. - @return The physics scene library. */ - inline FCDPhysicsSceneLibrary* GetPhysicsSceneLibrary() { return physicsSceneLibrary; } - inline const FCDPhysicsSceneLibrary* GetPhysicsSceneLibrary() const { return physicsSceneLibrary; } /**< See above. */ - - /** Retrieves the emitter library. - The emitter library contains a list of emitter definitions. - @return The emitter library. */ - inline FCDEmitterLibrary* GetEmitterLibrary() { return emitterLibrary; } - inline const FCDEmitterLibrary* GetEmitterLibrary() const { return emitterLibrary; } /**< See above. */ - - /** Insert a new visual scene within the visual scene library. - The new visual scene will be used as the root visual scene. - @return The newly created visual scene. */ - FCDSceneNode* AddVisualScene(); - - /** Insert a new physics scene within the physics material library. - The new physics scene will be used as the root physics scene. - @return The newly created physics scene. */ - FCDPhysicsScene* AddPhysicsScene(); - - /** Retrieves the animation tree node that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The animation tree node. This pointer will be NULL if - no matching animation tree node was found. */ - FCDAnimation* FindAnimation(const fm::string& daeId); - - /** Retrieves the animation clip that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The animation clip. This pointer will be NULL if - no matching animation clip was found. */ - FCDAnimationClip* FindAnimationClip(const fm::string& daeId); - - /** Retrieves the camera that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The camera. This pointer will be NULL if no matching camera was found. */ - FCDCamera* FindCamera(const fm::string& daeId); - - /** Retrieves the controller that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The controller. This pointer will be NULL if no matching controller was found. */ - FCDController* FindController(const fm::string& daeId); - - /** Retrieves the effect that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The effect. This pointer will be NULL if no matching effect was found. */ - FCDEffect* FindEffect(const fm::string& daeId); - - /** Retrieves the entity that matches the given COLLADA id. - This function will look through all the libraries for any entity - with the given COLLADA id. - @param daeId A valid COLLADA id. - @return The entity. This pointer will be NULL if no matching entity was found. */ - FCDEntity* FindEntity(const fm::string& daeId); - - /** Retrieves the emitter that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The emitter. This pointer will be NULL if no matching emitter was found. */ - FCDEmitter* FindEmitter(const fm::string& daeId); - - /** Retrieves the force field that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The force field. This pointer will be NULL if no matching force field was found. */ - FCDForceField* FindForceField(const fm::string& daeId); - - /** Retrieves the geometry that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The geometry. This pointer will be NULL if no matching geometry was found. */ - FCDGeometry* FindGeometry(const fm::string& daeId); - - /** Retrieves the image that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The image. This pointer will be NULL if no matching image was found. */ - FCDImage* FindImage(const fm::string& daeId); - - /** Retrieves the layer that matches the given name. - Note that there are no checks for uniqueness in layer names. - @param name A layer name. - @return The layer. This pointer will be NULL if no matching layer was found. */ - FCDLayer* FindLayer(const fm::string& name); - - /** Retrieves the light that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The light. This pointer will be NULL if no matching light was found. */ - FCDLight* FindLight(const fm::string& daeId); - - /** Retrieves the visual material that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The visual material. This pointer will be NULL if no matching visual material was found. */ - FCDMaterial* FindMaterial(const fm::string& daeId); - - /** Retrieves the visual scene that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The visual scene. This pointer will be NULL if no matching visual scene was found. */ - FCDSceneNode* FindVisualScene(const fm::string& daeId); - - /** Retrieves the physics scene that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The physics scene. This pointer will be NULL if no matching physics scene was found. */ - FCDPhysicsScene* FindPhysicsScene(const fm::string& daeId); - - /** Retrieves the physics material that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The physics material. This pointer will be NULL if no matching physics material was found. */ - FCDPhysicsMaterial* FindPhysicsMaterial(const fm::string& daeId); - - /** Retrieves the physics model that matches the given COLLADA id. - @param daeId A valid COLLADA id. - @return The physics model. This pointer will be NULL if no matching physics model was found. */ - FCDPhysicsModel* FindPhysicsModel(const fm::string& daeId); - - /** Retrieves the visual scene node that matches the given COLLADA id. - This method searches through all the visual scenes within the visual scene library and - their child visual scene nodes to find the correct visual scene node. - @param daeId A valid COLLADA id. - @return The visual scene node. This pointer will be NULL if no matching visual scene node was found. */ - const FCDSceneNode* FindSceneNode(const char* daeId) const; - inline FCDSceneNode* FindSceneNode(const char* daeId) { return const_cast(const_cast(this)->FindSceneNode(daeId)); } - - /** [INTERNAL] Registers an animated value with the document. All animated values are - listed within the document. - @param animated The new animated value to list within the document. */ - void RegisterAnimatedValue(FCDAnimated* animated); - - /** [INTERNAL] Unregisters an animated value of the document. All animated values are - listed within the document. This function must be called before deleting an animated value. - @param animated The animated value to un-list from the document. */ - void UnregisterAnimatedValue(FCDAnimated* animated); - - /** [INTERNAL] Registers an extra tree with the document. - All extra trees are listed within the document to support extra-technique plug-ins. - @param tree The new extra tree to list within the document. */ - inline void RegisterExtraTree(FCDExtra* tree) { extraTrees.insert(tree, tree); } - - /** [INTERNAL] Unregisters an extra tree of the document. - All extra trees are listed within the document to support extra-technique plug-ins. - @param tree The extra tree to un-list from the document. */ - inline void UnregisterExtraTree(FCDExtra* tree) { FUAssert(extraTrees.find(tree) != extraTrees.end(), return); extraTrees.erase(tree); } - - /** [INTERNAL] Retrieves the set of extra trees. - This function is meant only to be used for supporting the extra-technique plug-ins. - @return The set of extra trees for this document. */ - inline FCDExtraSet& GetExtraTrees() { return extraTrees; } -}; - -#endif //_FC_DOCUMENT_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDocument.h + This file declares the COLLADA document object model top class: FCDocument. +*/ + +#ifndef _FC_DOCUMENT_H_ +#define _FC_DOCUMENT_H_ + +#ifndef __FCD_OBJECT_H_ +#include "FCDocument/FCDObject.h" +#endif // __FCD_OBJECT_H_ +#ifndef _FU_PARAMETER_H_ +#include "FUtils/FUParameter.h" +#endif // _FU_PARAMETER_H_ + +#if defined(WIN32) +template class FCOLLADA_EXPORT FCDLibrary; /**< Trick Doxygen. */ +template class FCOLLADA_EXPORT FUUniqueStringMapT; /**< Trick Doxygen. */ +#elif defined(LINUX) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) +template class FCDLibrary; /**< Trick Doxygen. */ +template class FUUniqueStringMapT; /**< Trick Doxygen. */ +#endif // LINUX + +class FCDAnimated; +class FCDAnimation; +class FCDAnimationChannel; +class FCDAnimationClip; +class FCDAsset; +class FCDCamera; +class FCDController; +class FCDEffect; +class FCDEntity; +class FCDEntityReference; +class FCDEmitter; +class FCDExternalReferenceManager; +class FCDExtra; +class FCDForceField; +class FCDGeometry; +class FCDImage; +class FCDLight; +class FCDMaterial; +class FCDObject; +class FCDPhysicsMaterial; +class FCDPhysicsModel; +class FCDPhysicsScene; +class FCDTexture; +class FCDSceneNode; +class FCDVersion; +class FUFileManager; + +/** + A layer declaration. + Contains a name for the layer and the ids of all the entities within the layer. +*/ +class FCOLLADA_EXPORT FCDLayer +{ +public: + fm::string name; /**< The layer name. There is no guarantee of uniqueness. */ + StringList objects; /**< The list of COLLADA entity ids which are contained by this layer. */ +}; + +typedef fm::pvector FCDLayerList; /**< A dynamically-sized array of layer declarations. */ + +typedef FCDLibrary FCDAnimationLibrary; /**< A COLLADA library of animation entities. */ +typedef FCDLibrary FCDAnimationClipLibrary; /**< A COLLADA library of animation clip entities. */ +typedef FCDLibrary FCDCameraLibrary; /**< A COLLADA library of camera entities. */ +typedef FCDLibrary FCDControllerLibrary; /**< A COLLADA library of controller entities. */ +typedef FCDLibrary FCDEffectLibrary; /**< A COLLADA library of effect entities. */ +typedef FCDLibrary FCDEmitterLibrary; /**< A non-standard library of generic emitters. */ +typedef FCDLibrary FCDForceFieldLibrary; /**< A COLLADA library of force fields. */ +typedef FCDLibrary FCDGeometryLibrary; /**< A COLLADA library of geometric entities. */ +typedef FCDLibrary FCDImageLibrary; /**< A COLLADA library of images. */ +typedef FCDLibrary FCDLightLibrary; /**< A COLLADA library of light entities. */ +typedef FCDLibrary FCDMaterialLibrary; /**< A COLLADA library of visual material entities. */ +typedef FCDLibrary FCDVisualSceneNodeLibrary; /**< A COLLADA library of visual scene nodes. */ +typedef FCDLibrary FCDPhysicsModelLibrary; /**< A COLLADA library of physics model entities. */ +typedef FCDLibrary FCDPhysicsMaterialLibrary; /**< A COLLADA library of physics material entities. */ +typedef FCDLibrary FCDPhysicsSceneLibrary; /**< A COLLADA library of physics scene nodes. */ +typedef FUUniqueStringMapT FUSUniqueStringMap; /**< A set of unique strings. */ +typedef fm::map FCDExtraSet; /**< A set of extra trees. */ + +/** @defgroup FCDocument COLLADA Document Object Model. */ + +/** The top class for the COLLADA object model. + + This class holds all the COLLADA libraries, the scene graphs and the + document's asset tag. + + It also holds some global information, such as the animation start and end + time and the layers. This global information is only exported by ColladaMaya + right now. + + @ingroup FCDocument COLLADA Document Object Model +*/ +class FCOLLADA_EXPORT FCDocument : public FCDObject +{ +private: + DeclareObjectType(FCDObject); + + FUFileManager* fileManager; + FUObjectRef externalReferenceManager; + fstring fileUrl; + FCDVersion* version; + FCDExtraSet extraTrees; + + FUSUniqueStringMap* uniqueNameMap; + DeclareParameterRef(FCDEntityReference, visualSceneRoot, FC("Root Visual Scene")); + DeclareParameterContainer(FCDEntityReference, physicsSceneRoots, FC("Root Physics Scenes")); + + // Document parameters + DeclareParameterRef(FCDAsset, asset, FC("Asset Tag")); + DeclareParameterRef(FCDExtra, extra, FC("Extra Tree")); + bool hasStartTime, hasEndTime; + DeclareParameter(float, FUParameterQualifiers::SIMPLE, startTime, FC("Start Time")); + DeclareParameter(float, FUParameterQualifiers::SIMPLE, endTime, FC("End Time")); + FCDLayerList layers; // Maya-only + + // Parsed and merged libraries + DeclareParameterRef(FCDAnimationLibrary, animationLibrary, FC("Animation Library")); + DeclareParameterRef(FCDAnimationClipLibrary, animationClipLibrary, FC("Animation Clip Library")); + DeclareParameterRef(FCDCameraLibrary, cameraLibrary, FC("Camera Library")); + DeclareParameterRef(FCDControllerLibrary, controllerLibrary, FC("Controller Library")); + DeclareParameterRef(FCDEffectLibrary, effectLibrary, FC("Effect Library")); + DeclareParameterRef(FCDForceFieldLibrary, forceFieldLibrary, FC("Force-field Library")); + DeclareParameterRef(FCDGeometryLibrary, geometryLibrary, FC("Geometry Library")); + DeclareParameterRef(FCDImageLibrary, imageLibrary, FC("Image Library")); + DeclareParameterRef(FCDLightLibrary, lightLibrary, FC("Light Library")); + DeclareParameterRef(FCDMaterialLibrary, materialLibrary, FC("Material Library")); + DeclareParameterRef(FCDPhysicsModelLibrary, physicsModelLibrary, FC("Physics Model Library")); + DeclareParameterRef(FCDPhysicsMaterialLibrary, physicsMaterialLibrary, FC("Physics Material Library")); + DeclareParameterRef(FCDPhysicsSceneLibrary, physicsSceneLibrary, FC("Physics Scene Library")); + DeclareParameterRef(FCDVisualSceneNodeLibrary, visualSceneLibrary, FC("Visual Scene Library")); + DeclareParameterRef(FCDEmitterLibrary, emitterLibrary, FC("Emitter Library")); + + // Animated values + typedef fm::map FCDAnimatedSet; + FCDAnimatedSet animatedValues; + +public: + /** Construct a new COLLADA document. */ + FCDocument(); + + /** COLLADA document destructor. This clears out all the memory related to the document. */ + virtual ~FCDocument(); + + /** Retrieves the asset information for this COLLADA document. The asset information should always be present. + @return A pointer to the asset information structure. This pointer should never be NULL. */ + inline FCDAsset* GetAsset() { return asset; } + inline const FCDAsset* GetAsset() const { return asset; } /**< See above. */ + + /** Retrieves the base extra tree for this COLLADA document. An extra tree should always be present, + but is likely to be empty. + @return A pointer to the base extra tree. This pointer should never be NULL. */ + inline FCDExtra* GetExtra() { return extra; } + inline const FCDExtra* GetExtra() const { return extra; } /**< See above. */ + + /** Retrieves the version numbers for this COLLADA document. The version numbers should always be present. + @return The version number structure.*/ + inline FCDVersion& GetVersion() { return *version; } + inline const FCDVersion& GetVersion() const { return *version; } /**< See above. */ + + /** [INTERNAL] Retrieves the local file manager for the COLLADA document. Used to resolve URIs and transform file + paths into their relative or absolute equivalent. May be deprecated in future versions. + @return The file manager for this COLLADA document. This pointer should never be NULL. */ + inline FUFileManager* GetFileManager() { return fileManager; } + inline const FUFileManager* GetFileManager() const { return fileManager; } /**< See above. */ + + /** Retrieves the currently instanced visual scene. + NOTE: GetVisualSceneRoot is deprecated. Please start using GetVisualSceneInstance. + @return The currently instanced visual scene. */ + inline FCDSceneNode* GetVisualSceneInstance() { return const_cast(const_cast(this)->GetVisualSceneInstance()); } + const FCDSceneNode* GetVisualSceneInstance() const; /**< See above. */ + DEPRECATED(3.04A, FCDocument::GetVisualSceneInstance) inline FCDSceneNode* GetVisualSceneRoot() { return GetVisualSceneInstance(); } /**< See above. */ + DEPRECATED(3.04A, FCDocument::GetVisualSceneInstance) inline const FCDSceneNode* GetVisualSceneRoot() const { return GetVisualSceneInstance(); } /**< See above. */ + + /** Retrieves the reference to the currently instanced visual scene. + @return The instanced visual scene reference. */ + inline FCDEntityReference* GetVisualSceneInstanceReference() { return visualSceneRoot; } + inline const FCDEntityReference* GetVisualSceneInstanceReference() const { return visualSceneRoot; } /**< See above. */ + + /** Retrieves the number of instanced physics scenes. + @return The number of instanced physics scenes. */ + inline size_t GetPhysicsSceneInstanceCount() const { return physicsSceneRoots.size(); } + + /** Retrieves one instanced physics scene. + @param index The index of the physics scene to retrieve. + If the index is out-of-bounds, NULL is returned. + @return A currently instanced physics scene. */ + inline FCDPhysicsScene* GetPhysicsSceneInstance(size_t index = 0) { return const_cast(const_cast(this)->GetPhysicsSceneInstance(index)); } + const FCDPhysicsScene* GetPhysicsSceneInstance(size_t index = 0) const; /**< See above. */ + DEPRECATED(3.04A, FCDocument::GetPhysicsSceneInstance) inline FCDPhysicsScene* GetPhysicsSceneRoot(size_t index = 0) { return GetPhysicsSceneInstance(index); } /**< See above. */ + DEPRECATED(3.04A, FCDocument::GetPhysicsSceneInstance) inline const FCDPhysicsScene* GetPhysicsSceneRoot(size_t index = 0) const { return GetPhysicsSceneInstance(index); } /**< See above. */ + + /** Adds one instanced physics scene to the document. + @param scene The newly instanced physics scene. */ + void AddPhysicsSceneInstance(FCDPhysicsScene* scene); + + /** Retrieves a reference to the instanced physics scene. + @param index The index of the physics scene instance reference to + retrieve. If the index is out-of-bounds, NULL is returned. + @return The reference to the index physics scene reference. */ + inline FCDEntityReference* GetPhysicsSceneInstanceReference(size_t index = 0) { if (index == 0 && physicsSceneRoots.empty()) return NULL; FUAssert(index < physicsSceneRoots.size(), return NULL); return physicsSceneRoots[index]; } + inline const FCDEntityReference* GetPhysicsSceneInstanceReference(size_t index = 0) const { if (index == 0 && physicsSceneRoots.empty()) return NULL; FUAssert(index < physicsSceneRoots.size(), return NULL); return physicsSceneRoots[index]; } + + /** Adds an empty reference in the list of instanced physics scenes. + @return The new, empty, reference. */ + FCDEntityReference* AddPhysicsSceneInstanceReference(); + + /** [INTERNAL] Retrieves the map of unique ids for this document. + @return The map of unique ids for this document. */ + inline FUSUniqueStringMap* GetUniqueNameMap() { return uniqueNameMap; } + inline const FUSUniqueStringMap* GetUniqueNameMap() const { return uniqueNameMap; } /**< See above. */ + + /** Retrieves the external reference manager. + @return The external reference manager. */ + inline FCDExternalReferenceManager* GetExternalReferenceManager() { return externalReferenceManager; } + inline const FCDExternalReferenceManager* GetExternalReferenceManager() const { return externalReferenceManager; } /**< See above. */ + + /** Retrieves the file URL for this document. + @return The file URL for the document. */ + const fstring& GetFileUrl() const { return fileUrl; } + + /** Sets the file URL for this document. + Useful when working with external references. + @param filename The filename for the document. */ + void SetFileUrl(const fstring& filename); + + /** Returns whether a start time is being enforced for the document. + @return Whether the document has a start time. */ + inline bool HasStartTime() const { return hasStartTime; } + /** Retrieves the start time set for the document. + @return The document start time. */ + inline float GetStartTime() const { return startTime; } + /** Enforces a certain time as the start time for the document. + @param time The document start time. */ + inline void SetStartTime(float time) { startTime = time; hasStartTime = true; } + + /** Returns whether a end time is being enforced for the document. + @return Whether the document has a end time. */ + inline bool HasEndTime() const { return hasEndTime; } + /** Retrieves the end time set for the document. + @return The document end time. */ + inline float GetEndTime() const { return endTime; } + /** Enforces a certain time as the end time for the document. + @param time The document end time. */ + inline void SetEndTime(float time) { endTime = time; hasEndTime = true; } + + /** Evaluate the animation objects at the given time + @param time The time to evaluate the objects at */ + inline void SetCurrentTime(float time); + + /** Retrieves the list of entity layers. + @return The list of entity layers. */ + inline FCDLayerList& GetLayers() { return layers; } + inline const FCDLayerList& GetLayers() const { return layers; } /**< See above. */ + + /** Retrieves the number of entity layers contained within the document. + @return The number of layers. */ + inline size_t GetLayerCount() const { return layers.size(); } + + /** Retrieves a specific entity layer contained within the document. + @param index The index of the layer. + @return The entity layer. This pointer will be NULL if the index + is out-of-bounds. */ + inline FCDLayer* GetLayer(size_t index) { FUAssert(index < GetLayerCount(), return NULL); return layers.at(index); } + inline const FCDLayer* GetLayer(size_t index) const { FUAssert(index < GetLayerCount(), return NULL); return layers.at(index); } /**< See above. */ + + /** Adds an entity layer to the document. + @return The new layer. */ + FCDLayer* AddLayer(); + + /** Releases an entity layer from the document + @param layer The layer to release. */ + void ReleaseLayer(FCDLayer* layer); + + /** Retrieves the animation library. The animation library contains the animation curves + within a tree structure. To create and find animation curves, do not use the animation + library directly: use the FCDAnimated class, the FindAnimatedValue() function and the + RegisterAnimatedValue() function. + @return The animation library. */ + inline FCDAnimationLibrary* GetAnimationLibrary() { return animationLibrary; } + inline const FCDAnimationLibrary* GetAnimationLibrary() const { return animationLibrary; } /**< See above. */ + + /** Retrieves the animation clip library. The animation clip library contains a list of animation clips. + Each animation clip instantiates nodes from the animation library. Sections of the animation curves + belonging to the instantiated animation nodes are thereby packaged together as animation clips. + @return The animation clip library. */ + inline FCDAnimationClipLibrary* GetAnimationClipLibrary() { return animationClipLibrary; } + inline const FCDAnimationClipLibrary* GetAnimationClipLibrary() const { return animationClipLibrary; } /**< See above. */ + + /** Retrieves the camera library. The camera library contains a list of cameras, which may be + instantiated within the scene graph. COLLADA supports two camera types: perspective and orthographic. + @return The camera library. */ + inline FCDCameraLibrary* GetCameraLibrary() { return cameraLibrary; } + inline const FCDCameraLibrary* GetCameraLibrary() const { return cameraLibrary; } /**< See above. */ + + /** Retrieves the controller library. The controller library contains a list of controllers, which may + be instantiated within the scene graph. COLLADA supports two controller types: skin and morph. + @return The controller library. */ + inline FCDControllerLibrary* GetControllerLibrary() { return controllerLibrary; } + inline const FCDControllerLibrary* GetControllerLibrary() const { return controllerLibrary; } /**< See above. */ + + /** Retrieves the geometry library. The geometry library contains a list of basic geometries, which may + be instantiated within the scene graph and may be used by controllers. + COLLADA supports two geometry types: mesh and spline. + @return The geometry library. */ + inline FCDGeometryLibrary* GetGeometryLibrary() { return geometryLibrary; } + inline const FCDGeometryLibrary* GetGeometryLibrary() const { return geometryLibrary; } /**< See above. */ + + /** Retrieves the physics force field library. + Force fields are emitters of physical force and have no COMMON profile in COLLADA. + @return The force field library. */ + inline FCDForceFieldLibrary* GetForceFieldLibrary() { return forceFieldLibrary; } + inline const FCDForceFieldLibrary* GetForceFieldLibrary() const { return forceFieldLibrary; } /**< See above. */ + + /** Retrieves the image library. The image library contains a list of images. Images are used + by effects for textures. + @return The image library. */ + inline FCDImageLibrary* GetImageLibrary() { return imageLibrary; } + inline const FCDImageLibrary* GetImageLibrary() const { return imageLibrary; } /**< See above. */ + + /** Retrieves the light library. The light library contains a list of light, which may be + instantiated within the scene graph. COLLADA supports four light types: ambient, directional, + point and spot lights. + @return The light library. */ + inline FCDLightLibrary* GetLightLibrary() { return lightLibrary; } + inline const FCDLightLibrary* GetLightLibrary() const { return lightLibrary; } /**< See above. */ + + /** Retrieves the visual material library. The visual material library contains a list of visual materials, + which are bound to mesh polygons within the scene graph. A visual material instantiates an effect and + presets the effect parameters for a given visual result. + @return The visual material library. */ + inline FCDMaterialLibrary* GetMaterialLibrary() { return materialLibrary; } + inline const FCDMaterialLibrary* GetMaterialLibrary() const { return materialLibrary; } /**< See above. */ + + /** Retrieves the effect library. The effect library contains a list of effects, which may be instantiated + by materials. An effect defines an interface for a rendering shader. A ColladaFX effect may contain multiple + passes and techniques for different platforms or level of details. + @return The effect library. */ + inline FCDEffectLibrary* GetEffectLibrary() { return effectLibrary; } + inline const FCDEffectLibrary* GetEffectLibrary() const { return effectLibrary; } /**< See above. */ + + /** Retrieves the visual scene library. The visual scene library contains an acyclic directed graph of + visual scene nodes: a visual scene node contains one or more parent nodes and zero or more child nodes. + A visual scene node also contains 3D transformations: translation, rotation, scale, skew, as well as + the compound transformations: lookAt and matrix. A visual scene node also contains instances of + geometries, controllers, cameras and/or lights. Only one visual scene should be used at one time + by the global scene. + @return The visual scene library. */ + inline FCDVisualSceneNodeLibrary* GetVisualSceneLibrary() { return visualSceneLibrary; } + inline const FCDVisualSceneNodeLibrary* GetVisualSceneLibrary() const { return visualSceneLibrary; } /**< See above. */ + + /** Retrieves the physics model library. + The physics model library contains a list of physics models. + @return The physics model library. */ + inline FCDPhysicsModelLibrary* GetPhysicsModelLibrary() { return physicsModelLibrary; } + inline const FCDPhysicsModelLibrary* GetPhysicsModelLibrary() const { return physicsModelLibrary; } /**< See above. */ + + /** Retrieves the physics material library. + The physics material library contains a list of physics material. + @return The physics material library. */ + inline FCDPhysicsMaterialLibrary* GetPhysicsMaterialLibrary() { return physicsMaterialLibrary; } + inline const FCDPhysicsMaterialLibrary* GetPhysicsMaterialLibrary() const { return physicsMaterialLibrary; } /**< See above. */ + + /** Retrieves the physics scene library. + The physics scene library contains a list of physics scene nodes. + @return The physics scene library. */ + inline FCDPhysicsSceneLibrary* GetPhysicsSceneLibrary() { return physicsSceneLibrary; } + inline const FCDPhysicsSceneLibrary* GetPhysicsSceneLibrary() const { return physicsSceneLibrary; } /**< See above. */ + + /** Retrieves the emitter library. + The emitter library contains a list of emitter definitions. + @return The emitter library. */ + inline FCDEmitterLibrary* GetEmitterLibrary() { return emitterLibrary; } + inline const FCDEmitterLibrary* GetEmitterLibrary() const { return emitterLibrary; } /**< See above. */ + + /** Insert a new visual scene within the visual scene library. + The new visual scene will be used as the root visual scene. + @return The newly created visual scene. */ + FCDSceneNode* AddVisualScene(); + + /** Insert a new physics scene within the physics material library. + The new physics scene will be used as the root physics scene. + @return The newly created physics scene. */ + FCDPhysicsScene* AddPhysicsScene(); + + /** Retrieves the animation tree node that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The animation tree node. This pointer will be NULL if + no matching animation tree node was found. */ + FCDAnimation* FindAnimation(const fm::string& daeId); + + /** Retrieves the animation clip that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The animation clip. This pointer will be NULL if + no matching animation clip was found. */ + FCDAnimationClip* FindAnimationClip(const fm::string& daeId); + + /** Retrieves the camera that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The camera. This pointer will be NULL if no matching camera was found. */ + FCDCamera* FindCamera(const fm::string& daeId); + + /** Retrieves the controller that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The controller. This pointer will be NULL if no matching controller was found. */ + FCDController* FindController(const fm::string& daeId); + + /** Retrieves the effect that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The effect. This pointer will be NULL if no matching effect was found. */ + FCDEffect* FindEffect(const fm::string& daeId); + + /** Retrieves the entity that matches the given COLLADA id. + This function will look through all the libraries for any entity + with the given COLLADA id. + @param daeId A valid COLLADA id. + @return The entity. This pointer will be NULL if no matching entity was found. */ + FCDEntity* FindEntity(const fm::string& daeId); + + /** Retrieves the emitter that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The emitter. This pointer will be NULL if no matching emitter was found. */ + FCDEmitter* FindEmitter(const fm::string& daeId); + + /** Retrieves the force field that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The force field. This pointer will be NULL if no matching force field was found. */ + FCDForceField* FindForceField(const fm::string& daeId); + + /** Retrieves the geometry that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The geometry. This pointer will be NULL if no matching geometry was found. */ + FCDGeometry* FindGeometry(const fm::string& daeId); + + /** Retrieves the image that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The image. This pointer will be NULL if no matching image was found. */ + FCDImage* FindImage(const fm::string& daeId); + + /** Retrieves the layer that matches the given name. + Note that there are no checks for uniqueness in layer names. + @param name A layer name. + @return The layer. This pointer will be NULL if no matching layer was found. */ + FCDLayer* FindLayer(const fm::string& name); + + /** Retrieves the light that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The light. This pointer will be NULL if no matching light was found. */ + FCDLight* FindLight(const fm::string& daeId); + + /** Retrieves the visual material that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The visual material. This pointer will be NULL if no matching visual material was found. */ + FCDMaterial* FindMaterial(const fm::string& daeId); + + /** Retrieves the visual scene that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The visual scene. This pointer will be NULL if no matching visual scene was found. */ + FCDSceneNode* FindVisualScene(const fm::string& daeId); + + /** Retrieves the physics scene that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The physics scene. This pointer will be NULL if no matching physics scene was found. */ + FCDPhysicsScene* FindPhysicsScene(const fm::string& daeId); + + /** Retrieves the physics material that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The physics material. This pointer will be NULL if no matching physics material was found. */ + FCDPhysicsMaterial* FindPhysicsMaterial(const fm::string& daeId); + + /** Retrieves the physics model that matches the given COLLADA id. + @param daeId A valid COLLADA id. + @return The physics model. This pointer will be NULL if no matching physics model was found. */ + FCDPhysicsModel* FindPhysicsModel(const fm::string& daeId); + + /** Retrieves the visual scene node that matches the given COLLADA id. + This method searches through all the visual scenes within the visual scene library and + their child visual scene nodes to find the correct visual scene node. + @param daeId A valid COLLADA id. + @return The visual scene node. This pointer will be NULL if no matching visual scene node was found. */ + const FCDSceneNode* FindSceneNode(const char* daeId) const; + inline FCDSceneNode* FindSceneNode(const char* daeId) { return const_cast(const_cast(this)->FindSceneNode(daeId)); } + + /** [INTERNAL] Registers an animated value with the document. All animated values are + listed within the document. + @param animated The new animated value to list within the document. */ + void RegisterAnimatedValue(FCDAnimated* animated); + + /** [INTERNAL] Unregisters an animated value of the document. All animated values are + listed within the document. This function must be called before deleting an animated value. + @param animated The animated value to un-list from the document. */ + void UnregisterAnimatedValue(FCDAnimated* animated); + + /** [INTERNAL] Registers an extra tree with the document. + All extra trees are listed within the document to support extra-technique plug-ins. + @param tree The new extra tree to list within the document. */ + inline void RegisterExtraTree(FCDExtra* tree) { extraTrees.insert(tree, tree); } + + /** [INTERNAL] Unregisters an extra tree of the document. + All extra trees are listed within the document to support extra-technique plug-ins. + @param tree The extra tree to un-list from the document. */ + inline void UnregisterExtraTree(FCDExtra* tree) { FUAssert(extraTrees.find(tree) != extraTrees.end(), return); extraTrees.erase(tree); } + + /** [INTERNAL] Retrieves the set of extra trees. + This function is meant only to be used for supporting the extra-technique plug-ins. + @return The set of extra trees for this document. */ + inline FCDExtraSet& GetExtraTrees() { return extraTrees; } +}; + +#endif //_FC_DOCUMENT_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocument.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocument.cpp =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocument.cpp (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocument.cpp (revision 24247) @@ -1,385 +1,385 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ -/* - Based on the FS Import classes: - Copyright (C) 2005-2006 Feeling Software Inc - Copyright (C) 2005-2006 Autodesk Media Entertainment - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -#include "StdAfx.h" -#include "FCDocument/FCDocument.h" -#include "FCDocument/FCDAnimated.h" -#include "FCDocument/FCDAnimation.h" -#include "FCDocument/FCDAnimationChannel.h" -#include "FCDocument/FCDAnimationClip.h" -#include "FCDocument/FCDAnimationCurve.h" -#include "FCDocument/FCDAsset.h" -#include "FCDocument/FCDCamera.h" -#include "FCDocument/FCDController.h" -#include "FCDocument/FCDEffect.h" -#include "FCDocument/FCDEmitter.h" -#include "FCDocument/FCDEntityReference.h" -#include "FCDocument/FCDExternalReferenceManager.h" -#include "FCDocument/FCDExtra.h" -#include "FCDocument/FCDForceField.h" -#include "FCDocument/FCDGeometry.h" -#include "FCDocument/FCDImage.h" -#include "FCDocument/FCDLight.h" -#include "FCDocument/FCDLibrary.h" -#include "FCDocument/FCDMaterial.h" -#include "FCDocument/FCDPlaceHolder.h" -#include "FCDocument/FCDPhysicsMaterial.h" -#include "FCDocument/FCDPhysicsModel.h" -#include "FCDocument/FCDPhysicsScene.h" -#include "FCDocument/FCDSceneNode.h" -#include "FCDocument/FCDTexture.h" -#include "FCDocument/FCDVersion.h" -#include "FUtils/FUFileManager.h" -#include "FUtils/FUUniqueStringMap.h" -#include "FUtils/FUDaeSyntax.h" - -// -// FCDocument -// - -ImplementObjectType(FCDocument); - -ImplementParameterObject(FCDocument, FCDEntityReference, visualSceneRoot, new FCDEntityReference(parent->GetDocument(), NULL)); -ImplementParameterObject(FCDocument, FCDEntityReference, physicsSceneRoots, new FCDEntityReference(parent->GetDocument(), NULL)); -ImplementParameterObject(FCDocument, FCDAsset, asset, new FCDAsset(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); -ImplementParameterObject(FCDocument, FCDAnimationLibrary, animationLibrary, new FCDAnimationLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDAnimationClipLibrary, animationClipLibrary, new FCDAnimationClipLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDCameraLibrary, cameraLibrary, new FCDCameraLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDControllerLibrary, controllerLibrary, new FCDControllerLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDEffectLibrary, effectLibrary, new FCDEffectLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDForceFieldLibrary, forceFieldLibrary, new FCDForceFieldLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDGeometryLibrary, geometryLibrary, new FCDGeometryLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDImageLibrary, imageLibrary, new FCDImageLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDLightLibrary, lightLibrary, new FCDLightLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDMaterialLibrary, materialLibrary, new FCDMaterialLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDPhysicsModelLibrary, physicsModelLibrary, new FCDPhysicsModelLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDPhysicsMaterialLibrary, physicsMaterialLibrary, new FCDPhysicsMaterialLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDPhysicsSceneLibrary, physicsSceneLibrary, new FCDPhysicsSceneLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDVisualSceneNodeLibrary, visualSceneLibrary, new FCDVisualSceneNodeLibrary(parent->GetDocument())); -ImplementParameterObject(FCDocument, FCDEmitterLibrary, emitterLibrary, new FCDEmitterLibrary(parent->GetDocument())); - -FCDocument::FCDocument() -: FCDObject(this) -, fileManager(NULL), version(NULL), uniqueNameMap(NULL) -, InitializeParameterNoArg(visualSceneRoot) -, InitializeParameterNoArg(physicsSceneRoots) -, InitializeParameterNoArg(asset) -, InitializeParameterNoArg(extra) -, hasStartTime(false), hasEndTime(false) -, InitializeParameter(startTime, 0.0f) -, InitializeParameter(endTime, 0.0f) -, InitializeParameterNoArg(animationLibrary) -, InitializeParameterNoArg(animationClipLibrary) -, InitializeParameterNoArg(cameraLibrary) -, InitializeParameterNoArg(controllerLibrary) -, InitializeParameterNoArg(effectLibrary) -, InitializeParameterNoArg(forceFieldLibrary) -, InitializeParameterNoArg(geometryLibrary) -, InitializeParameterNoArg(imageLibrary) -, InitializeParameterNoArg(lightLibrary) -, InitializeParameterNoArg(materialLibrary) -, InitializeParameterNoArg(physicsModelLibrary) -, InitializeParameterNoArg(physicsMaterialLibrary) -, InitializeParameterNoArg(physicsSceneLibrary) -, InitializeParameterNoArg(visualSceneLibrary) -, InitializeParameterNoArg(emitterLibrary) -{ - fileManager = new FUFileManager(); - version = new FCDVersion(DAE_SCHEMA_VERSION); - uniqueNameMap = new FUSUniqueStringMap(); - - asset = new FCDAsset(this); - externalReferenceManager = new FCDExternalReferenceManager(this); - extra = new FCDExtra(this, this); - visualSceneRoot = new FCDEntityReference(this, NULL); - - animationLibrary = new FCDAnimationLibrary(this); - animationClipLibrary = new FCDAnimationClipLibrary(this); - cameraLibrary = new FCDCameraLibrary(this); - controllerLibrary = new FCDControllerLibrary(this); - emitterLibrary = new FCDEmitterLibrary(this); - forceFieldLibrary = new FCDForceFieldLibrary(this); - effectLibrary = new FCDEffectLibrary(this); - geometryLibrary = new FCDGeometryLibrary(this); - imageLibrary = new FCDImageLibrary(this); - lightLibrary = new FCDLightLibrary(this); - materialLibrary = new FCDMaterialLibrary(this); - visualSceneLibrary = new FCDVisualSceneNodeLibrary(this); - physicsMaterialLibrary = new FCDPhysicsMaterialLibrary(this); - physicsModelLibrary = new FCDPhysicsModelLibrary(this); - physicsSceneLibrary = new FCDPhysicsSceneLibrary(this); -} - -FCDocument::~FCDocument() -{ - // Release the external references to and from this document - // before all clearing the entities. - FUTrackable::Detach(); - - externalReferenceManager = NULL; - - // Release the libraries and the asset - animationLibrary = NULL; - animationClipLibrary = NULL; - cameraLibrary = NULL; - controllerLibrary = NULL; - effectLibrary = NULL; - emitterLibrary = NULL; - forceFieldLibrary = NULL; - geometryLibrary = NULL; - imageLibrary = NULL; - lightLibrary = NULL; - materialLibrary = NULL; - visualSceneLibrary = NULL; - physicsMaterialLibrary = NULL; - physicsModelLibrary = NULL; - physicsSceneLibrary = NULL; - asset = NULL; - - // Must be released last - CLEAR_POINTER_VECTOR(layers); - while (!animatedValues.empty()) { animatedValues.begin()->first->Release(); } -// animatedValueMap.clear(); - - SAFE_DELETE(fileManager); - SAFE_DELETE(uniqueNameMap); - SAFE_DELETE(version); -} - -const FCDSceneNode* FCDocument::GetVisualSceneInstance() const -{ - if (visualSceneRoot == NULL) return NULL; - const FCDEntity* entity = visualSceneRoot->GetEntity(); - if (entity != NULL && entity->HasType(FCDSceneNode::GetClassType())) return (const FCDSceneNode*) entity; - else return NULL; -} - -const FCDPhysicsScene* FCDocument::GetPhysicsSceneInstance(size_t index) const -{ - if (index == 0 && physicsSceneRoots.empty()) return NULL; - FUAssert(index < physicsSceneRoots.size(), return NULL); - const FCDEntity* entity = physicsSceneRoots[index]->GetEntity(); - if (entity != NULL && entity->HasType(FCDPhysicsScene::GetClassType())) return (const FCDPhysicsScene*) entity; - else return NULL; -} - -FCDEntityReference* FCDocument::AddPhysicsSceneInstanceReference() -{ - physicsSceneRoots.push_back(new FCDEntityReference(this, (FCDObjectWithId*) NULL)); - return physicsSceneRoots.back(); -} - -void FCDocument::AddPhysicsSceneInstance(FCDPhysicsScene* scene) -{ - FCDEntityReference* reference = AddPhysicsSceneInstanceReference(); - reference->SetEntity(scene); -} - -// Adds an entity layer to the document. -FCDLayer* FCDocument::AddLayer() -{ - FCDLayer* layer = new FCDLayer(); - layers.push_back(layer); - return layer; -} - -// Releases an entity layer from the document. -void FCDocument::ReleaseLayer(FCDLayer* layer) -{ - layers.release(layer); -} - -// Search for a specific COLLADA library items with a given COLLADA id. -FCDAnimation* FCDocument::FindAnimation(const fm::string& daeId) { return animationLibrary->FindDaeId(daeId); } -FCDAnimationClip* FCDocument::FindAnimationClip(const fm::string& daeId) { return animationClipLibrary->FindDaeId(daeId); } -FCDCamera* FCDocument::FindCamera(const fm::string& daeId) { return cameraLibrary->FindDaeId(daeId); } -FCDController* FCDocument::FindController(const fm::string& daeId) { return controllerLibrary->FindDaeId(daeId); } -FCDEffect* FCDocument::FindEffect(const fm::string& daeId) { return effectLibrary->FindDaeId(daeId); } -FCDEmitter* FCDocument::FindEmitter(const fm::string& daeId) { return emitterLibrary->FindDaeId(daeId); } -FCDForceField* FCDocument::FindForceField(const fm::string& daeId) { return forceFieldLibrary->FindDaeId(daeId); } -FCDGeometry* FCDocument::FindGeometry(const fm::string& daeId) { return geometryLibrary->FindDaeId(daeId); } -FCDImage* FCDocument::FindImage(const fm::string& daeId) { return imageLibrary->FindDaeId(daeId); } -FCDLayer* FCDocument::FindLayer(const fm::string& name) { for (FCDLayerList::iterator itL = layers.begin(); itL != layers.end(); ++itL) { if ((*itL)->name == name) return *itL; } return NULL; } -FCDLight* FCDocument::FindLight(const fm::string& daeId) { return lightLibrary->FindDaeId(daeId); } -FCDMaterial* FCDocument::FindMaterial(const fm::string& daeId) { return materialLibrary->FindDaeId(daeId); } -FCDSceneNode* FCDocument::FindVisualScene(const fm::string& daeId) { return visualSceneLibrary->FindDaeId(daeId); } -FCDPhysicsScene* FCDocument::FindPhysicsScene(const fm::string& daeId) { return physicsSceneLibrary->FindDaeId(daeId); } -FCDPhysicsMaterial* FCDocument::FindPhysicsMaterial(const fm::string& daeId) { return physicsMaterialLibrary->FindDaeId(daeId); } -FCDPhysicsModel* FCDocument::FindPhysicsModel(const fm::string& daeId) { return physicsModelLibrary->FindDaeId(daeId); } -const FCDSceneNode* FCDocument::FindSceneNode(const char* daeId) const { return visualSceneLibrary->FindDaeId(daeId); } -FCDEntity* FCDocument::FindEntity(const fm::string& daeId) -{ -#define CHECK_LIB(libraryName) { \ - FCDEntity* e = libraryName->FindDaeId(daeId); \ - if (e != NULL) return e; } - - CHECK_LIB(animationLibrary); - CHECK_LIB(animationClipLibrary); - CHECK_LIB(cameraLibrary); - CHECK_LIB(controllerLibrary); - CHECK_LIB(effectLibrary); - CHECK_LIB(emitterLibrary); - CHECK_LIB(forceFieldLibrary); - CHECK_LIB(geometryLibrary); - CHECK_LIB(imageLibrary); - CHECK_LIB(lightLibrary); - CHECK_LIB(materialLibrary); - CHECK_LIB(visualSceneLibrary); - CHECK_LIB(physicsSceneLibrary); - CHECK_LIB(physicsMaterialLibrary); - CHECK_LIB(physicsModelLibrary); -#undef CHECK_LIB - - return NULL; -} - -// Add an animated value to the list -void FCDocument::RegisterAnimatedValue(FCDAnimated* animated) -{ - // Look for a duplicate in order to avoid memory loss - //if (animated->GetValueCount() == 0 || FindAnimatedValue(animated->GetValue(0)) != NULL) - if (animated->GetValueCount() == 0) - { - SAFE_RELEASE(animated); - return; - } - - // List the new animated value - animatedValues.insert(animated, animated); - - //// Also add to the map the individual values for easy retrieval - //size_t count = animated->GetValueCount(); - //for (size_t i = 0; i < count; ++i) - //{ - // const float* value = animated->GetValue(i); - // animatedValueMap.insert(value, animated); - //} -} - -// Unregisters an animated value of the document. -void FCDocument::UnregisterAnimatedValue(FCDAnimated* animated) -{ - if (animated != NULL) - { - // Intentionally search from the end: - // - In the destructor of the document, we delete from the end. - // - In animation exporters, we add to the end and are likely to delete right away. - FCDAnimatedSet::iterator it = animatedValues.find(animated); - if (it != animatedValues.end()) - { - animatedValues.erase(it); - - //// Also remove to the map the individual values contained - //size_t count = animated->GetValueCount(); - //for (size_t i = 0; i < count; ++i) - //{ - // const float* value = animated->GetValue(i); - // FCDAnimatedValueMap::iterator itV = animatedValueMap.find(value); - // if (itV != animatedValueMap.end() && (*itV).second == animated) - // { - // animatedValueMap.erase(itV); - // } - //} - } - } -} -// -//// Retrieve an animated value, given a value pointer -//const FCDAnimated* FCDocument::FindAnimatedValue(const float* ptr) const -//{ -// FCDAnimatedValueMap::const_iterator it = animatedValueMap.find(ptr); -// return (it != animatedValueMap.end()) ? (*it).second : NULL; -//} -// -//// Retrieve an animated float value for a given fully qualified target -//const float* FCDocument::FindAnimatedTarget(const fm::string& fullyQualifiedTarget) -//{ -// if (fullyQualifiedTarget.empty()) return NULL; -// fm::string target = (fullyQualifiedTarget[0] == '#') ? fullyQualifiedTarget.substr(1) : fullyQualifiedTarget; -// fm::string pointer, qualifier; -// FUStringConversion::SplitTarget(target, pointer, qualifier); -// -// // Find the pointer -// FCDAnimated* animatedValue = NULL; -// for (FCDAnimatedSet::iterator itA = animatedValues.begin(); itA != animatedValues.end(); ++itA) -// { -// FCDAnimated* animated = (*itA).first; -// if (animated->GetTargetPointer() == pointer) { animatedValue = animated; break; } -// } -// if (animatedValue == NULL) return NULL; -// -// // Return the qualified value -// size_t index = animatedValue->FindQualifier(qualifier); -// if (index == size_t(-1)) return NULL; -// return animatedValue->GetValue(index); -//} -// -//// Returns whether a given value pointer is animated -//bool FCDocument::IsValueAnimated(const float* ptr) const -//{ -// const FCDAnimated* animated = FindAnimatedValue(ptr); -// return (animated != NULL) ? animated->HasCurve() : false; -//} - -// Insert new library elements -FCDSceneNode* FCDocument::AddVisualScene() -{ - FCDSceneNode* visualScene = visualSceneLibrary->AddEntity(); - if (visualSceneRoot->GetEntity() == NULL) visualSceneRoot->SetEntity(visualScene); - return visualScene; -} -FCDPhysicsScene* FCDocument::AddPhysicsScene() -{ - FCDPhysicsScene* physicsScene = physicsSceneLibrary->AddEntity(); - AddPhysicsSceneInstance(physicsScene); - return physicsScene; -} - -void FCDocument::SetFileUrl(const fstring& filename) -{ - fileManager->PopRootFile(); - fileUrl = GetFileManager()->GetCurrentUri().MakeAbsolute(filename); - fileManager->PushRootFile(fileUrl); -} - -void FCDocument::SetCurrentTime(float time) -{ - for (FCDAnimatedSet::iterator itA = animatedValues.begin(); itA != animatedValues.end(); ++itA) - { - FCDAnimated* animated = (*itA).first; - animated->Evaluate(time); - } - - // We must evaluate all our child documents as well! - for (size_t i = 0; i < externalReferenceManager->GetPlaceHolderCount(); i++) - { - FCDPlaceHolder* placeHolder = externalReferenceManager->GetPlaceHolder(i); - if (placeHolder->IsTargetLoaded()) placeHolder->GetTarget()->SetCurrentTime(time); - } -} - -// More linker-tricking for DLL support. -extern bool CreateLibraryFunctions(FCDocument* doc) -{ - doc->GetForceFieldLibrary()->GetEntityCount(); - doc->GetForceFieldLibrary()->GetEntity(0); - doc->GetImageLibrary()->GetEntityCount(); - doc->GetImageLibrary()->GetEntity(0); - doc->GetPhysicsMaterialLibrary()->GetEntityCount(); - doc->GetPhysicsMaterialLibrary()->GetEntity(0); - doc->GetPhysicsModelLibrary()->GetEntityCount(); - doc->GetPhysicsModelLibrary()->GetEntity(0); - return true; -} +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ +/* + Based on the FS Import classes: + Copyright (C) 2005-2006 Feeling Software Inc + Copyright (C) 2005-2006 Autodesk Media Entertainment + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +#include "StdAfx.h" +#include "FCDocument/FCDocument.h" +#include "FCDocument/FCDAnimated.h" +#include "FCDocument/FCDAnimation.h" +#include "FCDocument/FCDAnimationChannel.h" +#include "FCDocument/FCDAnimationClip.h" +#include "FCDocument/FCDAnimationCurve.h" +#include "FCDocument/FCDAsset.h" +#include "FCDocument/FCDCamera.h" +#include "FCDocument/FCDController.h" +#include "FCDocument/FCDEffect.h" +#include "FCDocument/FCDEmitter.h" +#include "FCDocument/FCDEntityReference.h" +#include "FCDocument/FCDExternalReferenceManager.h" +#include "FCDocument/FCDExtra.h" +#include "FCDocument/FCDForceField.h" +#include "FCDocument/FCDGeometry.h" +#include "FCDocument/FCDImage.h" +#include "FCDocument/FCDLight.h" +#include "FCDocument/FCDLibrary.h" +#include "FCDocument/FCDMaterial.h" +#include "FCDocument/FCDPlaceHolder.h" +#include "FCDocument/FCDPhysicsMaterial.h" +#include "FCDocument/FCDPhysicsModel.h" +#include "FCDocument/FCDPhysicsScene.h" +#include "FCDocument/FCDSceneNode.h" +#include "FCDocument/FCDTexture.h" +#include "FCDocument/FCDVersion.h" +#include "FUtils/FUFileManager.h" +#include "FUtils/FUUniqueStringMap.h" +#include "FUtils/FUDaeSyntax.h" + +// +// FCDocument +// + +ImplementObjectType(FCDocument); + +ImplementParameterObject(FCDocument, FCDEntityReference, visualSceneRoot, new FCDEntityReference(parent->GetDocument(), NULL)); +ImplementParameterObject(FCDocument, FCDEntityReference, physicsSceneRoots, new FCDEntityReference(parent->GetDocument(), NULL)); +ImplementParameterObject(FCDocument, FCDAsset, asset, new FCDAsset(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent)); +ImplementParameterObject(FCDocument, FCDAnimationLibrary, animationLibrary, new FCDAnimationLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDAnimationClipLibrary, animationClipLibrary, new FCDAnimationClipLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDCameraLibrary, cameraLibrary, new FCDCameraLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDControllerLibrary, controllerLibrary, new FCDControllerLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDEffectLibrary, effectLibrary, new FCDEffectLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDForceFieldLibrary, forceFieldLibrary, new FCDForceFieldLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDGeometryLibrary, geometryLibrary, new FCDGeometryLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDImageLibrary, imageLibrary, new FCDImageLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDLightLibrary, lightLibrary, new FCDLightLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDMaterialLibrary, materialLibrary, new FCDMaterialLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDPhysicsModelLibrary, physicsModelLibrary, new FCDPhysicsModelLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDPhysicsMaterialLibrary, physicsMaterialLibrary, new FCDPhysicsMaterialLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDPhysicsSceneLibrary, physicsSceneLibrary, new FCDPhysicsSceneLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDVisualSceneNodeLibrary, visualSceneLibrary, new FCDVisualSceneNodeLibrary(parent->GetDocument())); +ImplementParameterObject(FCDocument, FCDEmitterLibrary, emitterLibrary, new FCDEmitterLibrary(parent->GetDocument())); + +FCDocument::FCDocument() +: FCDObject(this) +, fileManager(NULL), version(NULL), uniqueNameMap(NULL) +, InitializeParameterNoArg(visualSceneRoot) +, InitializeParameterNoArg(physicsSceneRoots) +, InitializeParameterNoArg(asset) +, InitializeParameterNoArg(extra) +, hasStartTime(false), hasEndTime(false) +, InitializeParameter(startTime, 0.0f) +, InitializeParameter(endTime, 0.0f) +, InitializeParameterNoArg(animationLibrary) +, InitializeParameterNoArg(animationClipLibrary) +, InitializeParameterNoArg(cameraLibrary) +, InitializeParameterNoArg(controllerLibrary) +, InitializeParameterNoArg(effectLibrary) +, InitializeParameterNoArg(forceFieldLibrary) +, InitializeParameterNoArg(geometryLibrary) +, InitializeParameterNoArg(imageLibrary) +, InitializeParameterNoArg(lightLibrary) +, InitializeParameterNoArg(materialLibrary) +, InitializeParameterNoArg(physicsModelLibrary) +, InitializeParameterNoArg(physicsMaterialLibrary) +, InitializeParameterNoArg(physicsSceneLibrary) +, InitializeParameterNoArg(visualSceneLibrary) +, InitializeParameterNoArg(emitterLibrary) +{ + fileManager = new FUFileManager(); + version = new FCDVersion(DAE_SCHEMA_VERSION); + uniqueNameMap = new FUSUniqueStringMap(); + + asset = new FCDAsset(this); + externalReferenceManager = new FCDExternalReferenceManager(this); + extra = new FCDExtra(this, this); + visualSceneRoot = new FCDEntityReference(this, NULL); + + animationLibrary = new FCDAnimationLibrary(this); + animationClipLibrary = new FCDAnimationClipLibrary(this); + cameraLibrary = new FCDCameraLibrary(this); + controllerLibrary = new FCDControllerLibrary(this); + emitterLibrary = new FCDEmitterLibrary(this); + forceFieldLibrary = new FCDForceFieldLibrary(this); + effectLibrary = new FCDEffectLibrary(this); + geometryLibrary = new FCDGeometryLibrary(this); + imageLibrary = new FCDImageLibrary(this); + lightLibrary = new FCDLightLibrary(this); + materialLibrary = new FCDMaterialLibrary(this); + visualSceneLibrary = new FCDVisualSceneNodeLibrary(this); + physicsMaterialLibrary = new FCDPhysicsMaterialLibrary(this); + physicsModelLibrary = new FCDPhysicsModelLibrary(this); + physicsSceneLibrary = new FCDPhysicsSceneLibrary(this); +} + +FCDocument::~FCDocument() +{ + // Release the external references to and from this document + // before all clearing the entities. + FUTrackable::Detach(); + + externalReferenceManager = NULL; + + // Release the libraries and the asset + animationLibrary = NULL; + animationClipLibrary = NULL; + cameraLibrary = NULL; + controllerLibrary = NULL; + effectLibrary = NULL; + emitterLibrary = NULL; + forceFieldLibrary = NULL; + geometryLibrary = NULL; + imageLibrary = NULL; + lightLibrary = NULL; + materialLibrary = NULL; + visualSceneLibrary = NULL; + physicsMaterialLibrary = NULL; + physicsModelLibrary = NULL; + physicsSceneLibrary = NULL; + asset = NULL; + + // Must be released last + CLEAR_POINTER_VECTOR(layers); + while (!animatedValues.empty()) { animatedValues.begin()->first->Release(); } +// animatedValueMap.clear(); + + SAFE_DELETE(fileManager); + SAFE_DELETE(uniqueNameMap); + SAFE_DELETE(version); +} + +const FCDSceneNode* FCDocument::GetVisualSceneInstance() const +{ + if (visualSceneRoot == NULL) return NULL; + const FCDEntity* entity = visualSceneRoot->GetEntity(); + if (entity != NULL && entity->HasType(FCDSceneNode::GetClassType())) return (const FCDSceneNode*) entity; + else return NULL; +} + +const FCDPhysicsScene* FCDocument::GetPhysicsSceneInstance(size_t index) const +{ + if (index == 0 && physicsSceneRoots.empty()) return NULL; + FUAssert(index < physicsSceneRoots.size(), return NULL); + const FCDEntity* entity = physicsSceneRoots[index]->GetEntity(); + if (entity != NULL && entity->HasType(FCDPhysicsScene::GetClassType())) return (const FCDPhysicsScene*) entity; + else return NULL; +} + +FCDEntityReference* FCDocument::AddPhysicsSceneInstanceReference() +{ + physicsSceneRoots.push_back(new FCDEntityReference(this, (FCDObjectWithId*) NULL)); + return physicsSceneRoots.back(); +} + +void FCDocument::AddPhysicsSceneInstance(FCDPhysicsScene* scene) +{ + FCDEntityReference* reference = AddPhysicsSceneInstanceReference(); + reference->SetEntity(scene); +} + +// Adds an entity layer to the document. +FCDLayer* FCDocument::AddLayer() +{ + FCDLayer* layer = new FCDLayer(); + layers.push_back(layer); + return layer; +} + +// Releases an entity layer from the document. +void FCDocument::ReleaseLayer(FCDLayer* layer) +{ + layers.release(layer); +} + +// Search for a specific COLLADA library items with a given COLLADA id. +FCDAnimation* FCDocument::FindAnimation(const fm::string& daeId) { return animationLibrary->FindDaeId(daeId); } +FCDAnimationClip* FCDocument::FindAnimationClip(const fm::string& daeId) { return animationClipLibrary->FindDaeId(daeId); } +FCDCamera* FCDocument::FindCamera(const fm::string& daeId) { return cameraLibrary->FindDaeId(daeId); } +FCDController* FCDocument::FindController(const fm::string& daeId) { return controllerLibrary->FindDaeId(daeId); } +FCDEffect* FCDocument::FindEffect(const fm::string& daeId) { return effectLibrary->FindDaeId(daeId); } +FCDEmitter* FCDocument::FindEmitter(const fm::string& daeId) { return emitterLibrary->FindDaeId(daeId); } +FCDForceField* FCDocument::FindForceField(const fm::string& daeId) { return forceFieldLibrary->FindDaeId(daeId); } +FCDGeometry* FCDocument::FindGeometry(const fm::string& daeId) { return geometryLibrary->FindDaeId(daeId); } +FCDImage* FCDocument::FindImage(const fm::string& daeId) { return imageLibrary->FindDaeId(daeId); } +FCDLayer* FCDocument::FindLayer(const fm::string& name) { for (FCDLayerList::iterator itL = layers.begin(); itL != layers.end(); ++itL) { if ((*itL)->name == name) return *itL; } return NULL; } +FCDLight* FCDocument::FindLight(const fm::string& daeId) { return lightLibrary->FindDaeId(daeId); } +FCDMaterial* FCDocument::FindMaterial(const fm::string& daeId) { return materialLibrary->FindDaeId(daeId); } +FCDSceneNode* FCDocument::FindVisualScene(const fm::string& daeId) { return visualSceneLibrary->FindDaeId(daeId); } +FCDPhysicsScene* FCDocument::FindPhysicsScene(const fm::string& daeId) { return physicsSceneLibrary->FindDaeId(daeId); } +FCDPhysicsMaterial* FCDocument::FindPhysicsMaterial(const fm::string& daeId) { return physicsMaterialLibrary->FindDaeId(daeId); } +FCDPhysicsModel* FCDocument::FindPhysicsModel(const fm::string& daeId) { return physicsModelLibrary->FindDaeId(daeId); } +const FCDSceneNode* FCDocument::FindSceneNode(const char* daeId) const { return visualSceneLibrary->FindDaeId(daeId); } +FCDEntity* FCDocument::FindEntity(const fm::string& daeId) +{ +#define CHECK_LIB(libraryName) { \ + FCDEntity* e = libraryName->FindDaeId(daeId); \ + if (e != NULL) return e; } + + CHECK_LIB(animationLibrary); + CHECK_LIB(animationClipLibrary); + CHECK_LIB(cameraLibrary); + CHECK_LIB(controllerLibrary); + CHECK_LIB(effectLibrary); + CHECK_LIB(emitterLibrary); + CHECK_LIB(forceFieldLibrary); + CHECK_LIB(geometryLibrary); + CHECK_LIB(imageLibrary); + CHECK_LIB(lightLibrary); + CHECK_LIB(materialLibrary); + CHECK_LIB(visualSceneLibrary); + CHECK_LIB(physicsSceneLibrary); + CHECK_LIB(physicsMaterialLibrary); + CHECK_LIB(physicsModelLibrary); +#undef CHECK_LIB + + return NULL; +} + +// Add an animated value to the list +void FCDocument::RegisterAnimatedValue(FCDAnimated* animated) +{ + // Look for a duplicate in order to avoid memory loss + //if (animated->GetValueCount() == 0 || FindAnimatedValue(animated->GetValue(0)) != NULL) + if (animated->GetValueCount() == 0) + { + SAFE_RELEASE(animated); + return; + } + + // List the new animated value + animatedValues.insert(animated, animated); + + //// Also add to the map the individual values for easy retrieval + //size_t count = animated->GetValueCount(); + //for (size_t i = 0; i < count; ++i) + //{ + // const float* value = animated->GetValue(i); + // animatedValueMap.insert(value, animated); + //} +} + +// Unregisters an animated value of the document. +void FCDocument::UnregisterAnimatedValue(FCDAnimated* animated) +{ + if (animated != NULL) + { + // Intentionally search from the end: + // - In the destructor of the document, we delete from the end. + // - In animation exporters, we add to the end and are likely to delete right away. + FCDAnimatedSet::iterator it = animatedValues.find(animated); + if (it != animatedValues.end()) + { + animatedValues.erase(it); + + //// Also remove to the map the individual values contained + //size_t count = animated->GetValueCount(); + //for (size_t i = 0; i < count; ++i) + //{ + // const float* value = animated->GetValue(i); + // FCDAnimatedValueMap::iterator itV = animatedValueMap.find(value); + // if (itV != animatedValueMap.end() && (*itV).second == animated) + // { + // animatedValueMap.erase(itV); + // } + //} + } + } +} +// +//// Retrieve an animated value, given a value pointer +//const FCDAnimated* FCDocument::FindAnimatedValue(const float* ptr) const +//{ +// FCDAnimatedValueMap::const_iterator it = animatedValueMap.find(ptr); +// return (it != animatedValueMap.end()) ? (*it).second : NULL; +//} +// +//// Retrieve an animated float value for a given fully qualified target +//const float* FCDocument::FindAnimatedTarget(const fm::string& fullyQualifiedTarget) +//{ +// if (fullyQualifiedTarget.empty()) return NULL; +// fm::string target = (fullyQualifiedTarget[0] == '#') ? fullyQualifiedTarget.substr(1) : fullyQualifiedTarget; +// fm::string pointer, qualifier; +// FUStringConversion::SplitTarget(target, pointer, qualifier); +// +// // Find the pointer +// FCDAnimated* animatedValue = NULL; +// for (FCDAnimatedSet::iterator itA = animatedValues.begin(); itA != animatedValues.end(); ++itA) +// { +// FCDAnimated* animated = (*itA).first; +// if (animated->GetTargetPointer() == pointer) { animatedValue = animated; break; } +// } +// if (animatedValue == NULL) return NULL; +// +// // Return the qualified value +// size_t index = animatedValue->FindQualifier(qualifier); +// if (index == size_t(-1)) return NULL; +// return animatedValue->GetValue(index); +//} +// +//// Returns whether a given value pointer is animated +//bool FCDocument::IsValueAnimated(const float* ptr) const +//{ +// const FCDAnimated* animated = FindAnimatedValue(ptr); +// return (animated != NULL) ? animated->HasCurve() : false; +//} + +// Insert new library elements +FCDSceneNode* FCDocument::AddVisualScene() +{ + FCDSceneNode* visualScene = visualSceneLibrary->AddEntity(); + if (visualSceneRoot->GetEntity() == NULL) visualSceneRoot->SetEntity(visualScene); + return visualScene; +} +FCDPhysicsScene* FCDocument::AddPhysicsScene() +{ + FCDPhysicsScene* physicsScene = physicsSceneLibrary->AddEntity(); + AddPhysicsSceneInstance(physicsScene); + return physicsScene; +} + +void FCDocument::SetFileUrl(const fstring& filename) +{ + fileManager->PopRootFile(); + fileUrl = GetFileManager()->GetCurrentUri().MakeAbsolute(filename); + fileManager->PushRootFile(fileUrl); +} + +void FCDocument::SetCurrentTime(float time) +{ + for (FCDAnimatedSet::iterator itA = animatedValues.begin(); itA != animatedValues.end(); ++itA) + { + FCDAnimated* animated = (*itA).first; + animated->Evaluate(time); + } + + // We must evaluate all our child documents as well! + for (size_t i = 0; i < externalReferenceManager->GetPlaceHolderCount(); i++) + { + FCDPlaceHolder* placeHolder = externalReferenceManager->GetPlaceHolder(i); + if (placeHolder->IsTargetLoaded()) placeHolder->GetTarget()->SetCurrentTime(time); + } +} + +// More linker-tricking for DLL support. +extern bool CreateLibraryFunctions(FCDocument* doc) +{ + doc->GetForceFieldLibrary()->GetEntityCount(); + doc->GetForceFieldLibrary()->GetEntity(0); + doc->GetImageLibrary()->GetEntityCount(); + doc->GetImageLibrary()->GetEntity(0); + doc->GetPhysicsMaterialLibrary()->GetEntityCount(); + doc->GetPhysicsMaterialLibrary()->GetEntity(0); + doc->GetPhysicsModelLibrary()->GetEntityCount(); + doc->GetPhysicsModelLibrary()->GetEntity(0); + return true; +} Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocument.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocumentTools.h =================================================================== --- ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocumentTools.h (revision 24246) +++ ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocumentTools.h (revision 24247) @@ -1,41 +1,41 @@ -/* - Copyright (C) 2005-2007 Feeling Software Inc. - Portions of the code are: - Copyright (C) 2005-2007 Sony Computer Entertainment America - - MIT License: http://www.opensource.org/licenses/mit-license.php -*/ - -/** - @file FCDocumentTools.h - This file contains the FCDocumentTools namespace. -*/ - -#ifndef _FC_DOCUMENT_TOOLS_H_ -#define _FC_DOCUMENT_TOOLS_H_ - -/** - Contains pre-processing tools or post-processing tools used to - modify whole COLLADA documents. - @ingroup FCDocument -*/ -namespace FCDocumentTools -{ - /** Standardizes the up-axis and the length units accross the whole document. - Regardless of whether your application can handle different up-axis values or - different length units, you should call this function at least once - to ensure that the whole document has only one up-axis and one length unit. - @param document The COLLADA document to process. - @param upAxis The wanted up-axis for the whole document. If the - zero-vector is given, the up-axis of the document-level asset information - structure is used. - @param unitInMeters The wanted length unit. If this value is zero, the length - unit of the document-level asset information structure is used. - @param handleTargets This flag is very specific to ColladaMax which handles the - specificities of targeted cameras and lights: the pivots cannot be modified - simply, since the re-targeting will happen before the pivot transform is done. */ - void FCOLLADA_EXPORT StandardizeUpAxisAndLength(FCDocument* document, const FMVector3& upAxis = FMVector3::Origin, float unitInMeters = 0.0f, bool handleTargets=false); - -}; - -#endif // _FC_DOCUMENT_TOOLS_H_ +/* + Copyright (C) 2005-2007 Feeling Software Inc. + Portions of the code are: + Copyright (C) 2005-2007 Sony Computer Entertainment America + + MIT License: http://www.opensource.org/licenses/mit-license.php +*/ + +/** + @file FCDocumentTools.h + This file contains the FCDocumentTools namespace. +*/ + +#ifndef _FC_DOCUMENT_TOOLS_H_ +#define _FC_DOCUMENT_TOOLS_H_ + +/** + Contains pre-processing tools or post-processing tools used to + modify whole COLLADA documents. + @ingroup FCDocument +*/ +namespace FCDocumentTools +{ + /** Standardizes the up-axis and the length units accross the whole document. + Regardless of whether your application can handle different up-axis values or + different length units, you should call this function at least once + to ensure that the whole document has only one up-axis and one length unit. + @param document The COLLADA document to process. + @param upAxis The wanted up-axis for the whole document. If the + zero-vector is given, the up-axis of the document-level asset information + structure is used. + @param unitInMeters The wanted length unit. If this value is zero, the length + unit of the document-level asset information structure is used. + @param handleTargets This flag is very specific to ColladaMax which handles the + specificities of targeted cameras and lights: the pivots cannot be modified + simply, since the re-targeting will happen before the pivot transform is done. */ + void FCOLLADA_EXPORT StandardizeUpAxisAndLength(FCDocument* document, const FMVector3& upAxis = FMVector3::Origin, float unitInMeters = 0.0f, bool handleTargets=false); + +}; + +#endif // _FC_DOCUMENT_TOOLS_H_ Property changes on: ps/trunk/libraries/source/fcollada/src/FCollada/FCDocument/FCDocumentTools.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property