void addBones(const HACD::SimpleSkinnedVertex &v,uint32_t *bones,uint32_t &bcount, const HACD::SimpleBone *sbones)
		{
			if ( v.mWeight[0] >= sbones[v.mBone[0]].mBoneMinimalWeight) addBone(v.mBone[0],bones,bcount);
			if ( v.mWeight[1] >= sbones[v.mBone[1]].mBoneMinimalWeight) addBone(v.mBone[1],bones,bcount);
			if ( v.mWeight[2] >= sbones[v.mBone[2]].mBoneMinimalWeight) addBone(v.mBone[2],bones,bcount);
			if ( v.mWeight[3] >= sbones[v.mBone[3]].mBoneMinimalWeight) addBone(v.mBone[3],bones,bcount);
		}
示例#2
0
Item_bone::Item_bone( Item *parent, const QString& name, Item_armature* _armature, int _id) : Item( parent, name){
	armature = _armature;
	qDebug() << _id;
	if (id == -1){
		armature->max_bone_id++;
		id = armature->max_bone_id;
		} // would be better to scan for a free ID....
	else{
		id = _id;
		if (id > armature->max_bone_id)
			armature->max_bone_id = id;
		}

	setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable | Qt::ItemIsEditable| Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
	setIcon( 0, QIcon(":/images/xpm/bone.xpm") );

	menu->addAction( QIcon(":/images/xpm/bone.xpm"), QString("Add Bone"), this, SLOT( addBone()) );
	menu->addAction( QIcon(":/images/xpm/del.xpm"), QString("Delete"), this, SLOT(deleteLater()) );

	SCRIPT2MENU(menu);

	quat[0] = 0.0;
	quat[1] = 0.0;
	quat[2] = 0.0;
	quat[3] = 1.0;
	}
BoneNodePtr Skeleton::createBone(const core::string& name,BoneNode*parent){
	BoneNodePtr bone=new BoneNode(name,0,this,parent);
	if(parent)
		parent->addBone(bone);
	/*
	else
		m_bones.push_back(bone);*/

	addBone(bone);
	return bone;
}
示例#4
0
DBBone* DBArmature::createBone(BoneData* boneData)
{
    std::string boneName = boneData->name;
    DBBone *existedBone = getBone(boneName);
    if(existedBone != nullptr)
        return existedBone;
    
    std::string parentName = boneData->parent;
    
    DBBone *bone = nullptr;
    
    if( !parentName.empty() && !this->getBone(parentName))
    {
        BoneData* parentBoneData = this->_pArmatureData->getBoneData(parentName);
        createBone(parentBoneData);
    }
    
    bone = DBBone::create(boneData);
    addBone(bone, parentName.c_str());
    
    return bone;
}
示例#5
0
//!
MakeHSkeleton::MakeHSkeleton()
{
	mJoints.clear();
	mBones.clear();
	vec3 zero(0,0,0);
	addJoint(zero); //0: head
	addJoint(zero); //1: neck
	addJoint(zero); //2: left shoulder
	addJoint(zero); //3: right shoulder
	addJoint(zero); //4: torso
	addJoint(zero); //5: left elbow
	addJoint(zero); //6: right elbow
	addJoint(zero); //7: left hand
	addJoint(zero); //8: right hand
	addJoint(zero); //9: left hip
	addJoint(zero); //10: right hip
	addJoint(zero); //11: left knee
	addJoint(zero); //12: right knee
	addJoint(zero); //13: left foot
	addJoint(zero); //14: right foot
	addJoint(zero); //15: left finger
	addJoint(zero); //16: right finger
	addJoint(zero); //17: left toe
	addJoint(zero); //18: right toe

	addBone(0,1,-1); //0: head
	addBone(1,2,0); //1: left shoulder
	addBone(1,3,0); //2: right shoulder
	addBone(1,4,0); //3: breast
	addBone(4,9,3); //4: left abdomen
	addBone(4,10,3); //5: right abdomen
	addBone(2,5,1); //6: left upper arm
	addBone(3,6,2); //7: right upper arm
	addBone(9,11,4); //8: left upper leg
	addBone(10,12,5); //9: right upper leg
	addBone(5,7,6); //10: left lower arm
	addBone(6,8,7); //11: right lower arm
	addBone(11,13,8); //12: left lower leg
	addBone(12,14,9); //13: right lower leg
	addBone(7,15,10); //14: left hand
	addBone(8,16,11); //15: right hand
	addBone(13,17,12); //16: left foot
	addBone(14,18,13); //17: right foot
}
示例#6
0
void Actor::initializeBones()
{
    // 초기화
    const float baseSize = 10.f;
    destroy();

    /// 본 추가
    addBone(Bone::None, Vector3(0.f,0.f,0.f), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Hip_Center", Bone::Hip_Center);
    addBone(Bone::Hip_Center, Vector3(0.f, 20.f, 0.f), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Spine", Bone::Spine);
    addBone(Bone::Spine, Vector3(0.f, 50.f, 0.f), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Shoulder_Center", Bone::Shoulder_Center);

    addBone(Bone::Shoulder_Center, Vector3(0, 25, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Head", Bone::Head);

    addBone(Bone::Shoulder_Center, Vector3(-30, -10, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Shoulder_Right", Bone::Shoulder_Right);
    addBone(Bone::Shoulder_Right, Vector3(-50, 0, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Elbow_Right", Bone::Elbow_Right);
    addBone(Bone::Elbow_Right, Vector3(-40, 0, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Wrist_Right", Bone::Wrist_Right);
    addBone(Bone::Wrist_Right, Vector3(-20, 0, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Hand_Right", Bone::Hand_Right);

    addBone(Bone::Shoulder_Center, Vector3(30, -10, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Shoulder_Left", Bone::Shoulder_Left);
    addBone(Bone::Shoulder_Left, Vector3(50, 0, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Elbow_Left", Bone::Elbow_Left);
    addBone(Bone::Elbow_Left, Vector3(40 , 0, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Wrist_Left", Bone::Wrist_Left);
    addBone(Bone::Wrist_Left, Vector3(20, 0, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Hand_Left", Bone::Hand_Left);

    addBone(Bone::Hip_Center, Vector3(-20, -10, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Hip_Right", Bone::Hip_Right);
    addBone(Bone::Hip_Right, Vector3(0, -90, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Knee_Right", Bone::Knee_Right);
    addBone(Bone::Knee_Right, Vector3(0, -70, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Ankle_Right", Bone::Ankle_Right);
    addBone(Bone::Ankle_Right, Vector3(0, -10, -20), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Foot_Right", Bone::Foot_Right);

    addBone(Bone::Hip_Center, Vector3(20, -10, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Hip_Left", Bone::Hip_Left);
    addBone(Bone::Hip_Left, Vector3(0, -90, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Knee_Left", Bone::Knee_Left);
    addBone(Bone::Knee_Left, Vector3(0, -70, 0), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Ankle_Left", Bone::Ankle_Left);
    addBone(Bone::Ankle_Left, Vector3(0, -10, -20), Quaternion(), Vector3(1.f, 1.f, 1.f),
        "Foot_Left", Bone::Foot_Left);

}
示例#7
0
ArmatureData * JSONDataParser::_parseArmature(const rapidjson::Value & rawData)
{
    const auto armature = BaseObject::borrowObject<ArmatureData>();
    armature->name = _getString(rawData, NAME, "");
    armature->frameRate = _getNumber(rawData, FRAME_RATE, this->_data->frameRate);

    if (rawData.HasMember(TYPE) && rawData[TYPE].IsString())
    {
        armature->type = _getArmatureType(rawData[TYPE].GetString());
    }
    else
    {
        armature->type = (ArmatureType)_getNumber(rawData, TYPE, (int)ArmatureType::Armature);
    }

    this->_armature = armature;
    this->_rawBones.clear();

    if (rawData.HasMember(BONE))
    {
        for (const auto& boneObject : rawData[BONE].GetArray())
        {
            const auto bone = _parseBone(boneObject);
            armature->addBone(bone, _getString(boneObject, PARENT, ""));
            this->_rawBones.push_back(bone);
        }
    }

    if (rawData.HasMember(IK))
    {
        for (const auto& ikObject : rawData[IK].GetArray())
        {
            _parseIK(ikObject);
        }
    }

    if (rawData.HasMember(SLOT))
    {
        for (const auto& slotObject : rawData[SLOT].GetArray())
        {
            armature->addSlot(_parseSlot(slotObject));
        }
    }

    if (rawData.HasMember(SKIN))
    {
        for (const auto& skinObject : rawData[SKIN].GetArray())
        {
            armature->addSkin(_parseSkin(skinObject));
        }
    }

    if (rawData.HasMember(ANIMATION))
    {
        for (const auto& animationObject : rawData[ANIMATION].GetArray())
        {
            armature->addAnimation(_parseAnimation(animationObject));
        }
    }

    this->_armature = nullptr;
    this->_rawBones.clear();


    if (this->_isParentCooriinate && _getBoolean(rawData, IS_GLOBAL, true)) 
    {
        this->_globalToLocal(armature);
    }

    return armature;
}
示例#8
0
void AnimDebugDraw::update() {

    render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene();
    if (!scene) {
        return;
    }
    if (!render::Item::isValidID(_itemID)) {
        return;
    }
    render::Transaction transaction;
    transaction.updateItem<AnimDebugDrawData>(_itemID, [&](AnimDebugDrawData& data) {

        const size_t VERTICES_PER_BONE = (6 + (NUM_CIRCLE_SLICES * 2) * 3);
        const size_t VERTICES_PER_LINK = 8 * 2;
        const size_t VERTICES_PER_RAY = 2;

        const float BONE_RADIUS = 0.01f; // 1 cm
        const float POSE_RADIUS = 0.1f; // 10 cm

        // figure out how many verts we will need.
        int numVerts = 0;

        for (auto& iter : _absolutePoses) {
            AnimSkeleton::ConstPointer& skeleton = std::get<0>(iter.second);
            numVerts += skeleton->getNumJoints() * VERTICES_PER_BONE;
            for (auto i = 0; i < skeleton->getNumJoints(); i++) {
                auto parentIndex = skeleton->getParentIndex(i);
                if (parentIndex >= 0) {
                    numVerts += VERTICES_PER_LINK;
                }
            }
        }

        // count marker verts from shared DebugDraw singleton
        auto markerMap = DebugDraw::getInstance().getMarkerMap();
        numVerts += (int)markerMap.size() * VERTICES_PER_BONE;
        auto myAvatarMarkerMap = DebugDraw::getInstance().getMyAvatarMarkerMap();
        numVerts += (int)myAvatarMarkerMap.size() * VERTICES_PER_BONE;
        auto rays = DebugDraw::getInstance().getRays();
        DebugDraw::getInstance().clearRays();
        numVerts += (int)rays.size() * VERTICES_PER_RAY;

        // allocate verts!
        std::vector<AnimDebugDrawData::Vertex> vertices;
        vertices.resize(numVerts);
        //Vertex* verts = (Vertex*)data._vertexBuffer->editData();
        AnimDebugDrawData::Vertex* v = nullptr;
        if (numVerts) {
            v = &vertices[0];
        }

        // draw absolute poses
        for (auto& iter : _absolutePoses) {
            AnimSkeleton::ConstPointer& skeleton = std::get<0>(iter.second);
            AnimPoseVec& absPoses = std::get<1>(iter.second);
            AnimPose rootPose = std::get<2>(iter.second);
            glm::vec4 color = std::get<3>(iter.second);

            for (int i = 0; i < skeleton->getNumJoints(); i++) {
                const float radius = BONE_RADIUS / (absPoses[i].scale().x * rootPose.scale().x);

                // draw bone
                addBone(rootPose, absPoses[i], radius, color, v);

                // draw link to parent
                auto parentIndex = skeleton->getParentIndex(i);
                if (parentIndex >= 0) {
                    assert(parentIndex < skeleton->getNumJoints());
                    addLink(rootPose, absPoses[i], absPoses[parentIndex], radius, color, v);
                }
            }
        }

        // draw markers from shared DebugDraw singleton
        for (auto& iter : markerMap) {
            glm::quat rot = std::get<0>(iter.second);
            glm::vec3 pos = std::get<1>(iter.second);
            glm::vec4 color = std::get<2>(iter.second);
            const float radius = POSE_RADIUS;
            addBone(AnimPose::identity, AnimPose(glm::vec3(1), rot, pos), radius, color, v);
        }

        AnimPose myAvatarPose(glm::vec3(1), DebugDraw::getInstance().getMyAvatarRot(), DebugDraw::getInstance().getMyAvatarPos());
        for (auto& iter : myAvatarMarkerMap) {
            glm::quat rot = std::get<0>(iter.second);
            glm::vec3 pos = std::get<1>(iter.second);
            glm::vec4 color = std::get<2>(iter.second);
            const float radius = POSE_RADIUS;
            addBone(myAvatarPose, AnimPose(glm::vec3(1), rot, pos), radius, color, v);
        }

        // draw rays from shared DebugDraw singleton
        for (auto& iter : rays) {
            addLine(std::get<0>(iter), std::get<1>(iter), std::get<2>(iter), v);
        }

        data._vertexBuffer->resize(sizeof(AnimDebugDrawData::Vertex) * numVerts);
        data._vertexBuffer->setSubData<AnimDebugDrawData::Vertex>(0, vertices);

        assert((!numVerts && !v) || (numVerts == (v - &vertices[0])));

        render::Item::Bound theBound;
        for (int i = 0; i < numVerts; i++) {
            theBound += vertices[i].pos;
        }
        data._bound = theBound;

        data._isVisible = (numVerts > 0);

        data._indexBuffer->resize(sizeof(uint16_t) * numVerts);
        for (int i = 0; i < numVerts; i++) {
            data._indexBuffer->setSubData<uint16_t>(i, (uint16_t)i);;
        }
    });
    scene->enqueueTransaction(transaction);
}
//The default constructor.
Armature::Armature(std::string name, std::string rootBoneName)
{
    m_Name = name;
    m_Root = new Bone(rootBoneName, NULL);
    addBone(m_Root);
}
示例#10
0
void AnimDebugDraw::update() {

    render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene();
    if (!scene) {
        return;
    }

    render::PendingChanges pendingChanges;
    pendingChanges.updateItem<AnimDebugDrawData>(_itemID, [&](AnimDebugDrawData& data) {

        const size_t VERTICES_PER_BONE = (6 + (NUM_CIRCLE_SLICES * 2) * 3);
        const size_t VERTICES_PER_LINK = 8 * 2;

        const float BONE_RADIUS = 0.01f; // 1 cm
        const float POSE_RADIUS = 0.1f; // 10 cm

        // figure out how many verts we will need.
        int numVerts = 0;

        for (auto& iter : _absolutePoses) {
            AnimSkeleton::ConstPointer& skeleton = std::get<0>(iter.second);
            numVerts += skeleton->getNumJoints() * VERTICES_PER_BONE;
            for (auto i = 0; i < skeleton->getNumJoints(); i++) {
                auto parentIndex = skeleton->getParentIndex(i);
                if (parentIndex >= 0) {
                    numVerts += VERTICES_PER_LINK;
                }
            }
        }

        // count marker verts from shared DebugDraw singleton
        auto markerMap = DebugDraw::getInstance().getMarkerMap();
        numVerts += (int)markerMap.size() * VERTICES_PER_BONE;
        auto myAvatarMarkerMap = DebugDraw::getInstance().getMyAvatarMarkerMap();
        numVerts += (int)myAvatarMarkerMap.size() * VERTICES_PER_BONE;

        // allocate verts!
        data._vertexBuffer->resize(sizeof(Vertex) * numVerts);
        Vertex* verts = (Vertex*)data._vertexBuffer->editData();
        Vertex* v = verts;

        // draw absolute poses
        for (auto& iter : _absolutePoses) {
            AnimSkeleton::ConstPointer& skeleton = std::get<0>(iter.second);
            AnimPoseVec& absPoses = std::get<1>(iter.second);
            AnimPose rootPose = std::get<2>(iter.second);
            glm::vec4 color = std::get<3>(iter.second);

            for (int i = 0; i < skeleton->getNumJoints(); i++) {
                const float radius = BONE_RADIUS / (absPoses[i].scale.x * rootPose.scale.x);

                // draw bone
                addBone(rootPose, absPoses[i], radius, v);

                // draw link to parent
                auto parentIndex = skeleton->getParentIndex(i);
                if (parentIndex >= 0) {
                    assert(parentIndex < skeleton->getNumJoints());
                    addLink(rootPose, absPoses[i], absPoses[parentIndex], radius, color, v);
                }
            }
        }

        // draw markers from shared DebugDraw singleton
        for (auto& iter : markerMap) {
            glm::quat rot = std::get<0>(iter.second);
            glm::vec3 pos = std::get<1>(iter.second);
            glm::vec4 color = std::get<2>(iter.second);  // TODO: currently ignored.
            Q_UNUSED(color);
            const float radius = POSE_RADIUS;
            addBone(AnimPose::identity, AnimPose(glm::vec3(1), rot, pos), radius, v);
        }

        AnimPose myAvatarPose(glm::vec3(1), DebugDraw::getInstance().getMyAvatarRot(), DebugDraw::getInstance().getMyAvatarPos());
        for (auto& iter : myAvatarMarkerMap) {
            glm::quat rot = std::get<0>(iter.second);
            glm::vec3 pos = std::get<1>(iter.second);
            glm::vec4 color = std::get<2>(iter.second);  // TODO: currently ignored.
            Q_UNUSED(color);
            const float radius = POSE_RADIUS;
            addBone(myAvatarPose, AnimPose(glm::vec3(1), rot, pos), radius, v);
        }

        assert(numVerts == (v - verts));

        data._indexBuffer->resize(sizeof(uint16_t) * numVerts);
        uint16_t* indices = (uint16_t*)data._indexBuffer->editData();
        for (int i = 0; i < numVerts; i++) {
            indices[i] = i;
        }
    });
    scene->enqueuePendingChanges(pendingChanges);
}