Exemple #1
0
void SkeletonModel::setJointStates(QVector<JointState> states) {
    Model::setJointStates(states);

    // Determine the default eye position for avatar scale = 1.0
    int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
    if (0 <= headJointIndex && headJointIndex < _jointStates.size()) {

        glm::vec3 leftEyePosition, rightEyePosition;
        getEyeModelPositions(leftEyePosition, rightEyePosition);
        glm::vec3 midEyePosition = (leftEyePosition + rightEyePosition) / 2.0f;

        int rootJointIndex = _geometry->getFBXGeometry().rootJointIndex;
        glm::vec3 rootModelPosition;
        getJointPosition(rootJointIndex, rootModelPosition);

        _defaultEyeModelPosition = midEyePosition - rootModelPosition;
        _defaultEyeModelPosition.z = -_defaultEyeModelPosition.z;

        // Skeleton may have already been scaled so unscale it
        _defaultEyeModelPosition = _defaultEyeModelPosition / _scale;
    }

    // the SkeletonModel override of updateJointState() will clear the translation part
    // of its root joint and we need that done before we try to build shapes hence we
    // recompute all joint transforms at this time.
    for (int i = 0; i < _jointStates.size(); i++) {
        updateJointState(i);
    }

    clearShapes();
    if (_enableShapes) {
        buildShapes();
    }
}
Exemple #2
0
void PhysicsEntity::setEnableShapes(bool enable) {
    if (enable != _enableShapes) {
        clearShapes();
        _enableShapes = enable;
        if (_enableShapes) {
            buildShapes();
        }
    }
}   
Exemple #3
0
void SkeletonModel::initJointStates(QVector<JointState> states) {
    const FBXGeometry& geometry = _geometry->getFBXGeometry();
    glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;

    int rootJointIndex = geometry.rootJointIndex;
    int leftHandJointIndex = geometry.leftHandJointIndex;
    int leftElbowJointIndex = leftHandJointIndex >= 0 ? geometry.joints.at(leftHandJointIndex).parentIndex : -1;
    int leftShoulderJointIndex = leftElbowJointIndex >= 0 ? geometry.joints.at(leftElbowJointIndex).parentIndex : -1;
    int rightHandJointIndex = geometry.rightHandJointIndex;
    int rightElbowJointIndex = rightHandJointIndex >= 0 ? geometry.joints.at(rightHandJointIndex).parentIndex : -1;
    int rightShoulderJointIndex = rightElbowJointIndex >= 0 ? geometry.joints.at(rightElbowJointIndex).parentIndex : -1;

    _boundingRadius = _rig->initJointStates(states, parentTransform,
                                            rootJointIndex,
                                            leftHandJointIndex,
                                            leftElbowJointIndex,
                                            leftShoulderJointIndex,
                                            rightHandJointIndex,
                                            rightElbowJointIndex,
                                            rightShoulderJointIndex);

    // Determine the default eye position for avatar scale = 1.0
    int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
    if (0 <= headJointIndex && headJointIndex < _rig->getJointStateCount()) {

        glm::vec3 leftEyePosition, rightEyePosition;
        getEyeModelPositions(leftEyePosition, rightEyePosition);
        glm::vec3 midEyePosition = (leftEyePosition + rightEyePosition) / 2.0f;

        int rootJointIndex = _geometry->getFBXGeometry().rootJointIndex;
        glm::vec3 rootModelPosition;
        getJointPosition(rootJointIndex, rootModelPosition);

        _defaultEyeModelPosition = midEyePosition - rootModelPosition;
        _defaultEyeModelPosition.z = -_defaultEyeModelPosition.z;

        // Skeleton may have already been scaled so unscale it
        _defaultEyeModelPosition = _defaultEyeModelPosition / _scale;
    }

    // the SkeletonModel override of updateJointState() will clear the translation part
    // of its root joint and we need that done before we try to build shapes hence we
    // recompute all joint transforms at this time.
    for (int i = 0; i < _rig->getJointStateCount(); i++) {
        _rig->updateJointState(i, parentTransform);
    }

    buildShapes();

    Extents meshExtents = getMeshExtents();
    _headClipDistance = -(meshExtents.minimum.z / _scale.z - _defaultEyeModelPosition.z);
    _headClipDistance = std::max(_headClipDistance, DEFAULT_NEAR_CLIP);

    _owningAvatar->rebuildSkeletonBody();
    emit skeletonLoaded();
}
Exemple #4
0
SkeletonRagdoll* SkeletonModel::buildRagdoll() {
    if (!_ragdoll) {
        _ragdoll = new SkeletonRagdoll(this);
        if (_enableShapes) {
            clearShapes();
            buildShapes();
        }
    }
    return _ragdoll;
}
void VoxelShapeManager::updateVoxels(const quint64& now, CubeList& cubes) {
    const quint64 VOXEL_UPDATE_PERIOD = 100000; // usec
    _updateExpiry = now + VOXEL_UPDATE_PERIOD;
    PhysicsSimulation* simulation = getSimulation();
    if (!simulation) {
        return;
    }

    int numChanges = 0;
    VoxelPool::iterator voxelItr = _voxels.begin();
    while (voxelItr != _voxels.end()) {
        // look for this voxel in cubes
        CubeList::iterator cubeItr = cubes.find(voxelItr.key());
        if (cubeItr == cubes.end()) {
            // did not find it --> remove the voxel
            simulation->removeShape(voxelItr.value()._shape);
            voxelItr = _voxels.erase(voxelItr);
            ++numChanges;
        } else {
            // found it --> remove the cube
            cubes.erase(cubeItr);
            voxelItr++;
        }
    }

    // add remaining cubes to _voxels
    glm::vec3 simulationOrigin = simulation->getTranslation();
    CubeList::const_iterator cubeItr = cubes.constBegin();
    while (cubeItr != cubes.constEnd()) {
        AACube cube = cubeItr.value();
        AACubeShape* shape = new AACubeShape(cube.getScale(), cube.calcCenter() - simulationOrigin);
        shape->setEntity(this);
        VoxelInfo voxel = {cube, shape };
        _voxels.insert(cubeItr.key(), voxel);
        ++numChanges;
        ++cubeItr;
    }

    if (numChanges > 0) {
        buildShapes();
    }
}
Exemple #6
0
void SkeletonModel::initJointStates(QVector<JointState> states) {
    Model::initJointStates(states);

    // Determine the default eye position for avatar scale = 1.0
    int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
    if (0 <= headJointIndex && headJointIndex < _jointStates.size()) {

        glm::vec3 leftEyePosition, rightEyePosition;
        getEyeModelPositions(leftEyePosition, rightEyePosition);
        glm::vec3 midEyePosition = (leftEyePosition + rightEyePosition) / 2.0f;

        int rootJointIndex = _geometry->getFBXGeometry().rootJointIndex;
        glm::vec3 rootModelPosition;
        getJointPosition(rootJointIndex, rootModelPosition);

        _defaultEyeModelPosition = midEyePosition - rootModelPosition;
        _defaultEyeModelPosition.z = -_defaultEyeModelPosition.z;

        // Skeleton may have already been scaled so unscale it
        _defaultEyeModelPosition = _defaultEyeModelPosition / _scale;
    }

    // the SkeletonModel override of updateJointState() will clear the translation part
    // of its root joint and we need that done before we try to build shapes hence we
    // recompute all joint transforms at this time.
    for (int i = 0; i < _jointStates.size(); i++) {
        updateJointState(i);
    }

    clearShapes();
    if (_enableShapes) {
        buildShapes();
    }

    Extents meshExtents = getMeshExtents();
    _headClipDistance = -(meshExtents.minimum.z / _scale.z - _defaultEyeModelPosition.z);
    _headClipDistance = std::max(_headClipDistance, DEFAULT_NEAR_CLIP);

    _owningAvatar->rebuildSkeletonBody();
    emit skeletonLoaded();
}
 void buildObjects(CScene*& pScene, const pugi::xml_node& _objects)
 {
   // TODO: based on the file type load manager
   // ogl::CBuilderManager* pManager = ogl::CBuilderManager::getInstance();
   
   ogl::CMd5ObjectBuilder*   pMd5Builder   = new ogl::CMd5ObjectBuilder;
   ogl::CPlaneObjectBuilder* pPlaneBuilder = new ogl::CPlaneObjectBuilder;
   ogl::CBoxObjectBuilder*   pBoxBuilder   = new ogl::CBoxObjectBuilder;
 
   for(pugi::xml_node _object = _objects.first_child(); _object; _object = _object.next_sibling())
   {
     pugi::xml_attribute _type = _object.attribute("type");
     if(!_type)
       throw EXCEPTION << "<object type=\"?\" > attribute is mandatory!";
     pugi::xml_attribute _id    = _object.attribute("id");
     if(!_id)
       throw EXCEPTION << "<object id=\"?\"> attribute is mandatory!";
     //pugi::xml_attribute _ref = _object.attribute("ref");
     
     ogl::CObject* pObject = nullptr;
     sys::CDescriptor oDescriptor(app::tags::OBJECT);
     
     if(strncmp(_type.value(), "md5mesh", 7) == 0) 
     {
       pugi::xml_attribute _src = _object.attribute("src");
       if(!_src)
         throw EXCEPTION << "<object src=\"?\"> attribute is mandatory!";
         
       pMd5Builder->setFile(_src.value());
       pMd5Builder->addOption(ogl::CObjectBuilder::NORMALIZED);
       pMd5Builder->addOption(ogl::CObjectBuilder::FLIPYZ); // this might not work with animation
       pObject = pMd5Builder->build();
       
       oDescriptor += ogl::tags::MESH + ogl::tags::MD5MESH;
     }
     else if(strncmp(_type.value(), "plane", 5) == 0) 
     {
       float width = 1.0f;
       pugi::xml_attribute _width = _object.attribute("width");
       if(_width)
         sscanf(_width.value(), "%f", &width);
       pPlaneBuilder->setWidth(width);
       
       float height = 1.0f;
       pugi::xml_attribute _height = _object.attribute("height");
       if(_height)
         sscanf(_height.value(), "%f", &height);
       pPlaneBuilder->setHeight(height);
       
       int subdivisions = 1;
       pugi::xml_attribute _subdivisions = _object.attribute("subdivisions");
       if(_subdivisions)
         sscanf(_subdivisions.value(), "%d", &subdivisions);
       pPlaneBuilder->setSubdivisions(subdivisions);
       
       pPlaneBuilder->setTextureScale(0.5f);
       pPlaneBuilder->addOption(ogl::CPlaneObjectBuilder::REPEAT_UV);
       pPlaneBuilder->addOption(ogl::CObjectBuilder::TANGENTS);
       pObject = pPlaneBuilder->build();
       
       oDescriptor += ogl::tags::PLANE;
     }
     else if(strncmp(_type.value(), "box", 3) == 0) 
     {
       float width = 1.0f;
       pugi::xml_attribute _width = _object.attribute("width");
       if(_width)
         sscanf(_width.value(), "%f", &width);
       pBoxBuilder->setWidth(width);
       
       float height = 1.0f;
       pugi::xml_attribute _height = _object.attribute("height");
       if(_height)
         sscanf(_height.value(), "%f", &height);
       pBoxBuilder->setHeight(height);
       
       float depth = 1.0f;
       pugi::xml_attribute _depth = _object.attribute("depth");
       if(_depth)
         sscanf(_depth.value(), "%f", &depth);
       pBoxBuilder->setDepth(depth);
       
       pugi::xml_attribute _invert = _object.attribute("invert");
       if(_invert)
         pBoxBuilder->addOption(ogl::CObjectBuilder::INVERTED);
     
       pObject = pBoxBuilder->build();
       
       oDescriptor += ogl::tags::BOX;
     }
     else
     {
       throw EXCEPTION << "<object type=\"" << _type.value() << "\"> Not implemented!";
     }
     
     glExitIfError();
     
     pugi::xml_node _shapes = _object.child("shapes");
     if(_shapes)
       buildShapes(pObject, _shapes);
     pugi::xml_attribute _position = _object.attribute("position");
     if(_position)
     {
       float position[3] = { 0.0f, 0.0f, 0.0f };
       if(sscanf(_position.value(), "%f %f %f", &position[0], &position[1], &position[2]) != 0)
         pObject->translate(math::vec3(position[0], position[1], position[2]));
     }
     pugi::xml_attribute _scale = _object.attribute("scale");
     if(_scale)
     {
       float scale = 1.0f;
       if(sscanf(_scale.value(), "%f", &scale) != 0)
         pObject->scale(scale);
     }
     
     // save to CTransformHistory
     
     pScene->addObject(new app::CSceneObject(pObject, oDescriptor));
   }
   
   _DELETE(pMd5Builder);
   _DELETE(pPlaneBuilder);
   _DELETE(pBoxBuilder);
 }