void VRMLBodyLoaderImpl::readJointSubNodes(LinkInfo& iLink, MFNode& childNodes, const ProtoIdSet& acceptableProtoIds, const Affine3& T) { for(size_t i = 0; i < childNodes.size(); ++i){ bool doTraverse = false; VRMLNode* childNode = childNodes[i].get(); if(!childNode->isCategoryOf(PROTO_INSTANCE_NODE)){ doTraverse = true; } else { VRMLProtoInstance* protoInstance = static_cast<VRMLProtoInstance*>(childNode); int id = PROTO_UNDEFINED; const string& protoName = protoInstance->proto->protoName; ProtoInfoMap::iterator p = protoInfoMap.find(protoName); if(p == protoInfoMap.end()){ doTraverse = true; childNode = protoInstance->actualNode.get(); } else { id = p->second.id; if(!acceptableProtoIds.test(id)){ throw invalid_argument(str(format(_("%1% node is not in a correct place.")) % protoName)); } if(isVerbose){ messageIndent += 2; } switch(id){ case PROTO_JOINT: if(!T.matrix().isApprox(Affine3::MatrixType::Identity())){ throw invalid_argument( str(format(_("Joint node \"%1%\" is not in a correct place.")) % protoInstance->defName)); } iLink.link->appendChild(readJointNode(protoInstance, iLink.link->Rs())); break; case PROTO_SEGMENT: readSegmentNode(iLink, protoInstance, T); linkOriginalMap[iLink.link] = childNodes[i]; break; case PROTO_SURFACE: readSurfaceNode(iLink, protoInstance, T); break; case PROTO_DEVICE: readDeviceNode(iLink, protoInstance, T); break; default: doTraverse = true; break; } if(isVerbose){ messageIndent -= 2; } } } if(doTraverse && childNode->isCategoryOf(GROUPING_NODE)){ VRMLGroup* group = static_cast<VRMLGroup*>(childNode); if(VRMLTransform* transform = dynamic_cast<VRMLTransform*>(group)){ readJointSubNodes(iLink, group->getChildren(), acceptableProtoIds, T * transform->toAffine3d()); } else { readJointSubNodes(iLink, group->getChildren(), acceptableProtoIds, T); } } } }
void PhongShadowProgram::setTransformMatrices(const Affine3& viewMatrix, const Affine3& modelMatrix, const Matrix4& PV) { const Affine3f VM = (viewMatrix * modelMatrix).cast<float>(); const Matrix3f N = VM.linear(); const Matrix4f PVM = (PV * modelMatrix.matrix()).cast<float>(); if(useUniformBlockToPassTransformationMatrices){ transformBlockBuffer.write(modelViewMatrixIndex, VM); transformBlockBuffer.write(normalMatrixIndex, N); transformBlockBuffer.write(MVPIndex, PVM); transformBlockBuffer.flush(); } else { glUniformMatrix4fv(modelViewMatrixLocation, 1, GL_FALSE, VM.data()); glUniformMatrix3fv(normalMatrixLocation, 1, GL_FALSE, N.data()); glUniformMatrix4fv(MVPLocation, 1, GL_FALSE, PVM.data()); for(int i=0; i < numShadows_; ++i){ ShadowInfo& shadow = shadowInfos[i]; const Matrix4f BPVM = (shadow.BPV * modelMatrix.matrix()).cast<float>(); glUniformMatrix4fv(shadow.shadowMatrixLocation, 1, GL_FALSE, BPVM.data()); } } }