Model-space transformations applied to skinned model and bind shape matrix
Skin data is retrieved in processElement() by instance_controller elements, and calling processDomModel(), replacing the daeDatabase method
This commit is contained in:
@@ -1071,6 +1071,8 @@ bool LLDAELoader::OpenFile(const std::string& filename)
|
|||||||
|
|
||||||
mTransform.condition();
|
mTransform.condition();
|
||||||
|
|
||||||
|
mBindTransform.setIdentity();
|
||||||
|
|
||||||
U32 submodel_limit = count > 0 ? mGeneratedModelLimit/count : 0;
|
U32 submodel_limit = count > 0 ? mGeneratedModelLimit/count : 0;
|
||||||
for (daeInt idx = 0; idx < count; ++idx)
|
for (daeInt idx = 0; idx < count; ++idx)
|
||||||
{ //build map of domEntities to LLModel
|
{ //build map of domEntities to LLModel
|
||||||
@@ -1126,33 +1128,7 @@ bool LLDAELoader::OpenFile(const std::string& filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
count = db->getElementCount(NULL, COLLADA_TYPE_SKIN);
|
count = db->getElementCount(NULL, COLLADA_TYPE_SKIN);
|
||||||
for (daeInt idx = 0; idx < count; ++idx)
|
LL_INFOS()<< "Collada skins to be processed: " << count <<LL_ENDL;
|
||||||
{ //add skinned meshes as instances
|
|
||||||
domSkin* skin = NULL;
|
|
||||||
db->getElement((daeElement**) &skin, idx, NULL, COLLADA_TYPE_SKIN);
|
|
||||||
|
|
||||||
if (skin)
|
|
||||||
{
|
|
||||||
domGeometry* geom = daeSafeCast<domGeometry>(skin->getSource().getElement());
|
|
||||||
|
|
||||||
if (geom)
|
|
||||||
{
|
|
||||||
domMesh* mesh = geom->getMesh();
|
|
||||||
if (mesh)
|
|
||||||
{
|
|
||||||
std::vector< LLPointer< LLModel > >::iterator i = mModelsMap[mesh].begin();
|
|
||||||
while (i != mModelsMap[mesh].end())
|
|
||||||
{
|
|
||||||
LLPointer<LLModel> mdl = *i;
|
|
||||||
LLDAELoader::processDomModel(mdl, &dae, root, mesh, skin);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LL_INFOS()<< "Collada skins processed: " << count <<LL_ENDL;
|
|
||||||
|
|
||||||
daeElement* scene = root->getDescendant("visual_scene");
|
daeElement* scene = root->getDescendant("visual_scene");
|
||||||
|
|
||||||
@@ -1167,7 +1143,7 @@ bool LLDAELoader::OpenFile(const std::string& filename)
|
|||||||
|
|
||||||
bool badElement = false;
|
bool badElement = false;
|
||||||
|
|
||||||
processElement( scene, badElement, &dae );
|
processElement( scene, badElement, &dae, root);
|
||||||
|
|
||||||
if ( badElement )
|
if ( badElement )
|
||||||
{
|
{
|
||||||
@@ -1255,6 +1231,8 @@ void LLDAELoader::processDomModel(LLModel* model, DAE* dae, daeElement* root, do
|
|||||||
|
|
||||||
LLMatrix4 trans = normalized_transformation;
|
LLMatrix4 trans = normalized_transformation;
|
||||||
trans *= skin_info.mBindShapeMatrix;
|
trans *= skin_info.mBindShapeMatrix;
|
||||||
|
trans *= mBindTransform;
|
||||||
|
|
||||||
skin_info.mBindShapeMatrix = trans;
|
skin_info.mBindShapeMatrix = trans;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2012,9 +1990,9 @@ daeElement* LLDAELoader::getChildFromElement( daeElement* pElement, std::string
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* dae )
|
void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* dae, daeElement* domRoot)
|
||||||
{
|
{
|
||||||
LLMatrix4 saved_transform;
|
LLMatrix4 saved_transform, saved_bind_transform;
|
||||||
bool pushed_mat = false;
|
bool pushed_mat = false;
|
||||||
|
|
||||||
domNode* node = daeSafeCast<domNode>(element);
|
domNode* node = daeSafeCast<domNode>(element);
|
||||||
@@ -2022,6 +2000,7 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
|||||||
{
|
{
|
||||||
pushed_mat = true;
|
pushed_mat = true;
|
||||||
saved_transform = mTransform;
|
saved_transform = mTransform;
|
||||||
|
saved_bind_transform = mBindTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
domTranslate* translate = daeSafeCast<domTranslate>(element);
|
domTranslate* translate = daeSafeCast<domTranslate>(element);
|
||||||
@@ -2029,12 +2008,17 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
|||||||
{
|
{
|
||||||
domFloat3 dom_value = translate->getValue();
|
domFloat3 dom_value = translate->getValue();
|
||||||
|
|
||||||
LLMatrix4 translation;
|
LLMatrix4 translation, translation2;
|
||||||
translation.setTranslation(LLVector3(dom_value[0], dom_value[1], dom_value[2]));
|
translation.setTranslation(LLVector3(dom_value[0], dom_value[1], dom_value[2]));
|
||||||
|
translation2 = translation;
|
||||||
|
|
||||||
translation *= mTransform;
|
translation *= mTransform;
|
||||||
mTransform = translation;
|
mTransform = translation;
|
||||||
mTransform.condition();
|
mTransform.condition();
|
||||||
|
|
||||||
|
translation2 *= mBindTransform;
|
||||||
|
mBindTransform = translation2;
|
||||||
|
mBindTransform.condition();
|
||||||
}
|
}
|
||||||
|
|
||||||
domRotate* rotate = daeSafeCast<domRotate>(element);
|
domRotate* rotate = daeSafeCast<domRotate>(element);
|
||||||
@@ -2042,12 +2026,17 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
|||||||
{
|
{
|
||||||
domFloat4 dom_value = rotate->getValue();
|
domFloat4 dom_value = rotate->getValue();
|
||||||
|
|
||||||
LLMatrix4 rotation;
|
LLMatrix4 rotation, rotation2;
|
||||||
rotation.initRotTrans(dom_value[3] * DEG_TO_RAD, LLVector3(dom_value[0], dom_value[1], dom_value[2]), LLVector3(0, 0, 0));
|
rotation.initRotTrans(dom_value[3] * DEG_TO_RAD, LLVector3(dom_value[0], dom_value[1], dom_value[2]), LLVector3(0, 0, 0));
|
||||||
|
rotation2 = rotation;
|
||||||
|
|
||||||
rotation *= mTransform;
|
rotation *= mTransform;
|
||||||
mTransform = rotation;
|
mTransform = rotation;
|
||||||
mTransform.condition();
|
mTransform.condition();
|
||||||
|
|
||||||
|
rotation2 *= mBindTransform;
|
||||||
|
mBindTransform = rotation2;
|
||||||
|
mBindTransform.condition();
|
||||||
}
|
}
|
||||||
|
|
||||||
domScale* scale = daeSafeCast<domScale>(element);
|
domScale* scale = daeSafeCast<domScale>(element);
|
||||||
@@ -2058,12 +2047,17 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
|||||||
|
|
||||||
LLVector3 scale_vector = LLVector3(dom_value[0], dom_value[1], dom_value[2]);
|
LLVector3 scale_vector = LLVector3(dom_value[0], dom_value[1], dom_value[2]);
|
||||||
scale_vector.abs(); // Set all values positive, since we don't currently support mirrored meshes
|
scale_vector.abs(); // Set all values positive, since we don't currently support mirrored meshes
|
||||||
LLMatrix4 scaling;
|
LLMatrix4 scaling, scaling2;
|
||||||
scaling.initScale(scale_vector);
|
scaling.initScale(scale_vector);
|
||||||
|
scaling2 = scaling;
|
||||||
|
|
||||||
scaling *= mTransform;
|
scaling *= mTransform;
|
||||||
mTransform = scaling;
|
mTransform = scaling;
|
||||||
mTransform.condition();
|
mTransform.condition();
|
||||||
|
|
||||||
|
scaling2 *= mBindTransform;
|
||||||
|
mBindTransform = scaling2;
|
||||||
|
mBindTransform.condition();
|
||||||
}
|
}
|
||||||
|
|
||||||
domMatrix* matrix = daeSafeCast<domMatrix>(element);
|
domMatrix* matrix = daeSafeCast<domMatrix>(element);
|
||||||
@@ -2071,7 +2065,7 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
|||||||
{
|
{
|
||||||
domFloat4x4 dom_value = matrix->getValue();
|
domFloat4x4 dom_value = matrix->getValue();
|
||||||
|
|
||||||
LLMatrix4 matrix_transform;
|
LLMatrix4 matrix_transform, matrix_transform2;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
@@ -2081,9 +2075,15 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matrix_transform2 = matrix_transform;
|
||||||
|
|
||||||
matrix_transform *= mTransform;
|
matrix_transform *= mTransform;
|
||||||
mTransform = matrix_transform;
|
mTransform = matrix_transform;
|
||||||
mTransform.condition();
|
mTransform.condition();
|
||||||
|
|
||||||
|
matrix_transform2 *= mBindTransform;
|
||||||
|
mBindTransform = matrix_transform2;
|
||||||
|
mBindTransform.condition();
|
||||||
}
|
}
|
||||||
|
|
||||||
domInstance_geometry* instance_geo = daeSafeCast<domInstance_geometry>(element);
|
domInstance_geometry* instance_geo = daeSafeCast<domInstance_geometry>(element);
|
||||||
@@ -2180,7 +2180,36 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
|||||||
daeElement* instance = instance_node->getUrl().getElement();
|
daeElement* instance = instance_node->getUrl().getElement();
|
||||||
if (instance)
|
if (instance)
|
||||||
{
|
{
|
||||||
processElement(instance,badElement, dae);
|
processElement(instance,badElement, dae, domRoot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
domInstance_controller* instance_ctl = daeSafeCast<domInstance_controller>(element);
|
||||||
|
if (instance_ctl)
|
||||||
|
{
|
||||||
|
domController* ctl = daeSafeCast<domController>(instance_ctl->getUrl().getElement());
|
||||||
|
if (ctl)
|
||||||
|
{
|
||||||
|
domSkin* skin = ctl->getSkin();
|
||||||
|
if (skin)
|
||||||
|
{
|
||||||
|
domGeometry* geom = daeSafeCast<domGeometry>(skin->getSource().getElement());
|
||||||
|
|
||||||
|
if (geom)
|
||||||
|
{
|
||||||
|
domMesh* mesh = geom->getMesh();
|
||||||
|
if (mesh)
|
||||||
|
{
|
||||||
|
std::vector< LLPointer< LLModel > >::iterator i = mModelsMap[mesh].begin();
|
||||||
|
while (i != mModelsMap[mesh].end())
|
||||||
|
{
|
||||||
|
LLPointer<LLModel> mdl = *i;
|
||||||
|
LLDAELoader::processDomModel(mdl, dae, domRoot, mesh, skin);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2189,12 +2218,13 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
|||||||
int childCount = children.getCount();
|
int childCount = children.getCount();
|
||||||
for (S32 i = 0; i < childCount; i++)
|
for (S32 i = 0; i < childCount; i++)
|
||||||
{
|
{
|
||||||
processElement(children[i],badElement, dae);
|
processElement(children[i],badElement, dae, domRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pushed_mat)
|
if (pushed_mat)
|
||||||
{ //this element was a node, restore transform before processiing siblings
|
{ //this element was a node, restore transform before processiing siblings
|
||||||
mTransform = saved_transform;
|
mTransform = saved_transform;
|
||||||
|
mBindTransform = saved_bind_transform;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void processElement(daeElement* element, bool& badElement, DAE* dae);
|
void processElement(daeElement* element, bool& badElement, DAE* dae, daeElement* domRoot);
|
||||||
void processDomModel(LLModel* model, DAE* dae, daeElement* pRoot, domMesh* mesh, domSkin* skin);
|
void processDomModel(LLModel* model, DAE* dae, daeElement* pRoot, domMesh* mesh, domSkin* skin);
|
||||||
|
|
||||||
material_map getMaterials(LLModel* model, domInstance_geometry* instance_geo, DAE* dae);
|
material_map getMaterials(LLModel* model, domInstance_geometry* instance_geo, DAE* dae);
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public:
|
|||||||
|
|
||||||
S32 mLod;
|
S32 mLod;
|
||||||
|
|
||||||
LLMatrix4 mTransform;
|
LLMatrix4 mTransform, mBindTransform;
|
||||||
BOOL mFirstTransform;
|
BOOL mFirstTransform;
|
||||||
LLVector3 mExtents[2];
|
LLVector3 mExtents[2];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user