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:
@@ -1070,6 +1070,8 @@ bool LLDAELoader::OpenFile(const std::string& filename)
|
||||
mTransform = rotation;
|
||||
|
||||
mTransform.condition();
|
||||
|
||||
mBindTransform.setIdentity();
|
||||
|
||||
U32 submodel_limit = count > 0 ? mGeneratedModelLimit/count : 0;
|
||||
for (daeInt idx = 0; idx < count; ++idx)
|
||||
@@ -1126,33 +1128,7 @@ bool LLDAELoader::OpenFile(const std::string& filename)
|
||||
}
|
||||
|
||||
count = db->getElementCount(NULL, COLLADA_TYPE_SKIN);
|
||||
for (daeInt idx = 0; idx < count; ++idx)
|
||||
{ //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;
|
||||
LL_INFOS()<< "Collada skins to be processed: " << count <<LL_ENDL;
|
||||
|
||||
daeElement* scene = root->getDescendant("visual_scene");
|
||||
|
||||
@@ -1167,7 +1143,7 @@ bool LLDAELoader::OpenFile(const std::string& filename)
|
||||
|
||||
bool badElement = false;
|
||||
|
||||
processElement( scene, badElement, &dae );
|
||||
processElement( scene, badElement, &dae, root);
|
||||
|
||||
if ( badElement )
|
||||
{
|
||||
@@ -1255,6 +1231,8 @@ void LLDAELoader::processDomModel(LLModel* model, DAE* dae, daeElement* root, do
|
||||
|
||||
LLMatrix4 trans = normalized_transformation;
|
||||
trans *= skin_info.mBindShapeMatrix;
|
||||
trans *= mBindTransform;
|
||||
|
||||
skin_info.mBindShapeMatrix = trans;
|
||||
}
|
||||
|
||||
@@ -2012,9 +1990,9 @@ daeElement* LLDAELoader::getChildFromElement( daeElement* pElement, std::string
|
||||
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;
|
||||
|
||||
domNode* node = daeSafeCast<domNode>(element);
|
||||
@@ -2022,6 +2000,7 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
||||
{
|
||||
pushed_mat = true;
|
||||
saved_transform = mTransform;
|
||||
saved_bind_transform = mBindTransform;
|
||||
}
|
||||
|
||||
domTranslate* translate = daeSafeCast<domTranslate>(element);
|
||||
@@ -2029,12 +2008,17 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
||||
{
|
||||
domFloat3 dom_value = translate->getValue();
|
||||
|
||||
LLMatrix4 translation;
|
||||
LLMatrix4 translation, translation2;
|
||||
translation.setTranslation(LLVector3(dom_value[0], dom_value[1], dom_value[2]));
|
||||
translation2 = translation;
|
||||
|
||||
translation *= mTransform;
|
||||
mTransform = translation;
|
||||
mTransform.condition();
|
||||
|
||||
translation2 *= mBindTransform;
|
||||
mBindTransform = translation2;
|
||||
mBindTransform.condition();
|
||||
}
|
||||
|
||||
domRotate* rotate = daeSafeCast<domRotate>(element);
|
||||
@@ -2042,12 +2026,17 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
||||
{
|
||||
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));
|
||||
rotation2 = rotation;
|
||||
|
||||
rotation *= mTransform;
|
||||
mTransform = rotation;
|
||||
mTransform.condition();
|
||||
|
||||
rotation2 *= mBindTransform;
|
||||
mBindTransform = rotation2;
|
||||
mBindTransform.condition();
|
||||
}
|
||||
|
||||
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]);
|
||||
scale_vector.abs(); // Set all values positive, since we don't currently support mirrored meshes
|
||||
LLMatrix4 scaling;
|
||||
LLMatrix4 scaling, scaling2;
|
||||
scaling.initScale(scale_vector);
|
||||
scaling2 = scaling;
|
||||
|
||||
scaling *= mTransform;
|
||||
mTransform = scaling;
|
||||
mTransform.condition();
|
||||
|
||||
scaling2 *= mBindTransform;
|
||||
mBindTransform = scaling2;
|
||||
mBindTransform.condition();
|
||||
}
|
||||
|
||||
domMatrix* matrix = daeSafeCast<domMatrix>(element);
|
||||
@@ -2071,7 +2065,7 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
|
||||
{
|
||||
domFloat4x4 dom_value = matrix->getValue();
|
||||
|
||||
LLMatrix4 matrix_transform;
|
||||
LLMatrix4 matrix_transform, matrix_transform2;
|
||||
|
||||
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;
|
||||
mTransform = matrix_transform;
|
||||
mTransform.condition();
|
||||
|
||||
matrix_transform2 *= mBindTransform;
|
||||
mBindTransform = matrix_transform2;
|
||||
mBindTransform.condition();
|
||||
}
|
||||
|
||||
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();
|
||||
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();
|
||||
for (S32 i = 0; i < childCount; i++)
|
||||
{
|
||||
processElement(children[i],badElement, dae);
|
||||
processElement(children[i],badElement, dae, domRoot);
|
||||
}
|
||||
|
||||
if (pushed_mat)
|
||||
{ //this element was a node, restore transform before processiing siblings
|
||||
mTransform = saved_transform;
|
||||
mBindTransform = saved_bind_transform;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
|
||||
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);
|
||||
|
||||
material_map getMaterials(LLModel* model, domInstance_geometry* instance_geo, DAE* dae);
|
||||
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
|
||||
S32 mLod;
|
||||
|
||||
LLMatrix4 mTransform;
|
||||
LLMatrix4 mTransform, mBindTransform;
|
||||
BOOL mFirstTransform;
|
||||
LLVector3 mExtents[2];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user