void SkeletonBlendedGeometry::calculatePositions(void)
{
    if(getBaseGeometry() == NULL)
    {
        //Error
        SWARNING << "Base Geometry is NULL." << std::endl;
        return;
    }
    if(getPositions() == NULL)
    {
        //Error
        SWARNING << "Positions is NULL." << std::endl;
        return;
    }
    if(getBaseGeometry()->getPositions() == NULL)
    {
        //Error
        SWARNING << "Base Geometry Postions is NULL." << std::endl;
        return;
    }

    Pnt3f CalculatedPoint;
    Pnt3f BasePoint;
    //Vec3f CalculatedNormal;

    //Zero the Position Property
    zeroGeoProperty(getPositions());

    //Update the Positions and Normals
    UInt32 WeightIndex, JointIndex, VertexIndex;
    UInt32 NumWeightIndexTuples(getWeightIndexes()->size()/3);
    for(UInt32 i(0) ; i < NumWeightIndexTuples ; ++i)
    {
        VertexIndex = getWeightIndexes()->getValue<UInt32>( 3 * i     );
        JointIndex  = getWeightIndexes()->getValue<UInt32>((3 * i) + 1);
        WeightIndex = getWeightIndexes()->getValue<UInt32>((3 * i) + 2);

        //v*BSM*IBM*JM*JW
        getBaseGeometry()->getPositions()->getValue<Pnt3f>(BasePoint, VertexIndex);

        _JointPoseTransforms[JointIndex].mult(BasePoint, BasePoint);

        //Add the displacement to the value at this position
        getPositions()->getValue<Pnt3f>(CalculatedPoint, VertexIndex);
        CalculatedPoint += Vec3f(BasePoint) * getWeights()->getValue<Pnt1f>(WeightIndex)[0];
        getPositions()->setValue<Pnt3f>(CalculatedPoint, VertexIndex);
    }

    for(UInt32 i = 0; i < _mfParents.size(); i++)
    {
        _mfParents[i]->invalidateVolume();
    }

    _volumeCache.setValid();
    _volumeCache.setEmpty();

    _NeedRecalc = false;
}
void SkeletonBlendedGeometry::skeletonUpdated(void)
{
	produceChangedEvent();
    if(getBaseGeometry())
    {
        calculatePositions();
    }
}
void SkeletonBlendedGeometry::drawPrimitives(DrawEnv *pEnv)
{
    if(getBaseGeometry())
    {
        calculateJointTransform();
        if(_NeedRecalc)
        {
            calculatePositions();
        }
    }

    Inherited::drawPrimitives(pEnv);
}
void SkeletonBlendedGeometry::changed(ConstFieldMaskArg whichField, 
                                      UInt32            origin,
                                      BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    if((whichField & BaseGeometryFieldMask) &&
            getBaseGeometry() != NULL)
    {
        if(getBaseGeometry()->getTypes() != NULL)
        {
            setTypes(getBaseGeometry()->getTypes());
        }
        if(getBaseGeometry()->getLengths() != NULL)
        {
            setLengths(getBaseGeometry()->getLengths());
        }
        if(getBaseGeometry()->getPositions() != NULL)
        {
            GeoPropertyUnrecPtr Pos(getBaseGeometry()->getPositions()->clone());
            setPositions(dynamic_pointer_cast<GeoVectorProperty>(Pos));
        }
        if(getBaseGeometry()->getNormals() != NULL)
        {
            GeoPropertyUnrecPtr Norm(getBaseGeometry()->getNormals()->clone());
            setNormals(dynamic_pointer_cast<GeoVectorProperty>(Norm));
        }
        if(getBaseGeometry()->getColors() != NULL)
        {
            setColors(getBaseGeometry()->getColors());
        }
        if(getBaseGeometry()->getSecondaryColors() != NULL)
        {
            setSecondaryColors(getBaseGeometry()->getSecondaryColors());
        }
        if(getBaseGeometry()->getTexCoords() != NULL)
        {
            setTexCoords(getBaseGeometry()->getTexCoords());
        }
        if(getBaseGeometry()->getTexCoords1() != NULL)
        {
            setTexCoords1(getBaseGeometry()->getTexCoords1());
        }
        if(getBaseGeometry()->getTexCoords2() != NULL)
        {
            setTexCoords2(getBaseGeometry()->getTexCoords2());
        }
        if(getBaseGeometry()->getTexCoords3() != NULL)
        {
            setTexCoords3(getBaseGeometry()->getTexCoords3());
        }
        if(getBaseGeometry()->getTexCoords4() != NULL)
        {
            setTexCoords4(getBaseGeometry()->getTexCoords4());
        }
        if(getBaseGeometry()->getTexCoords5() != NULL)
        {
            setTexCoords5(getBaseGeometry()->getTexCoords5());
        }
        if(getBaseGeometry()->getTexCoords6() != NULL)
        {
            setTexCoords6(getBaseGeometry()->getTexCoords6());
        }
        if(getBaseGeometry()->getTexCoords7() != NULL)
        {
            setTexCoords7(getBaseGeometry()->getTexCoords7());
        }
        if(getBaseGeometry()->getIndices() != NULL)
        {
            setIndices(getBaseGeometry()->getIndices());
        }
        setMaterial(getBaseGeometry()->getMaterial());
    }

    if( (whichField & InternalJointsFieldMask) ||
        (whichField & InternalWeightIndexesFieldMask) ||
        (whichField & InternalWeightsFieldMask))
    {
        calculatePositions();
    }
}
void SkeletonBlendedGeometry::calculatePositions(void)
{
	if(getBaseGeometry() == NULL)
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Base Geometry is NULL." << std::endl;
        return;
    }
	if(getPositions() == NULL)
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Positions is NULL." << std::endl;
        return;
	}
	if(getBaseGeometry()->getPositions() == NULL)
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Base Geometry Postions is NULL." << std::endl;
        return;
	}

    Pnt3f CalculatedPoint;
    Pnt3f BasePointInfluenced;
    Pnt3f BasePoint;
    Vec3f CalculatedNormal;


    //Reset all points
    GeoVectorPropertyUnrecPtr ResetPositions(dynamic_pointer_cast<GeoVectorProperty>(getBaseGeometry()->getPositions()->clone()));
    setPositions(ResetPositions);

    UInt32 WeightIndex, JointIndex, VertexIndex;
    //Update the Positions and Normals
    for(UInt32 i(0) ; i < getWeights()->size() ; ++i)
    {
        VertexIndex = getWeightIndexes()->getValue<UInt32>( 3 * i     );
        JointIndex  = getWeightIndexes()->getValue<UInt32>((3 * i) + 1);
        WeightIndex = getWeightIndexes()->getValue<UInt32>((3 * i) + 2);

        //Get the position of this index from the base geometry
        getBaseGeometry()->getPositions()->getValue<Pnt3f>(BasePoint, VertexIndex);

        //Get the Influence matrix of this joint
        //Apply the influence of this joint to the position
        getBindTransformationDiff(JointIndex).mult(BasePoint, BasePointInfluenced);

        //Add the displacement to the value at this position
        getPositions()->getValue<Pnt3f>(CalculatedPoint, VertexIndex);
        //Scale the influence by the blend amount
        CalculatedPoint += getWeights()->getValue<Pnt1f>(WeightIndex)[0] * (BasePointInfluenced - BasePoint);
        getPositions()->setValue<Pnt3f>(CalculatedPoint, VertexIndex);
    }

    for(UInt32 i = 0; i < _mfParents.size(); i++)
    {
        _mfParents[i]->invalidateVolume();
    }

    _volumeCache.setValid();
    _volumeCache.setEmpty();
}
Exemplo n.º 6
0
void MorphGeometry::changed(ConstFieldMaskArg whichField, 
                            UInt32            origin,
                            BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    //Do not respond to changes that have a Sync origin
    if(origin & ChangedOrigin::Sync)
    {
        return;
    }

    if(whichField & BaseGeometryFieldMask)
    {
        if(getBaseGeometry() != NULL)
        {
            if(getBaseGeometry()->getTypes() != NULL)
            {
                GeoIntegralPropertyUnrecPtr Prop = dynamic_pointer_cast<GeoIntegralProperty>(getBaseGeometry()->getTypes()->clone());
                setTypes(Prop);
            }
            if(getBaseGeometry()->getLengths() != NULL)
            {
                GeoIntegralPropertyUnrecPtr Prop = dynamic_pointer_cast<GeoIntegralProperty>(getBaseGeometry()->getLengths()->clone());
                setLengths(Prop);
            }
            if(getBaseGeometry()->getIndices() != NULL)
            {
                GeoIntegralPropertyUnrecPtr Prop = dynamic_pointer_cast<GeoIntegralProperty>(getBaseGeometry()->getIndices()->clone());
                setIndices(Prop);
            }
            for(UInt16 i(0) ; i<Geometry::LastIndex ; ++i)
            {
                if(getBaseGeometry()->getProperty(i) != NULL)
                {
                    GeoVectorPropertyUnrecPtr Prop = dynamic_pointer_cast<GeoVectorProperty>(getBaseGeometry()->getProperty(i)->clone());
                    setProperty(Prop, i);
                }
                else
                {
                    setProperty(NULL, i);
                }
            }
            setMaterial(getBaseGeometry()->getMaterial());
        }
        else
        {
            setTypes(NULL);
            setLengths(NULL);
            for(UInt16 i(0) ; i<Geometry::LastIndex ; ++i)
            {
                setProperty(NULL, i);
            }
            setIndices(NULL);
            setMaterial(NULL);
        }
    }

    if((whichField & InternalWeightsFieldMask)  ||
        (whichField & InternalTargetGeometriesFieldMask)  ||
        (whichField & BaseGeometryFieldMask)  ||
        (whichField & MorphPropertiesFieldMask))
    {
        updateMorph();
    }
}
Exemplo n.º 7
0
void MorphGeometry::updateMorph(void)
{
    if(!getBaseGeometry())
    {
        SWARNING << "No Base Geometry" << std::endl;
        return;
    }

    for(UInt32 i(0) ; i<getMFMorphProperties()->size() ; ++i)
    {
        GeoVectorProperty* BaseProp(getBaseGeometry()->getProperty(getMorphProperties(i)));

        GeoVectorPropertyUnrecPtr Prop(getProperty(getMorphProperties(i)));
        switch(getBlendingMethod())
        {
            case Relative:
                {
                    //Reset the Base mesh
                    UInt32 NumBytesToCopy(Prop->getFormatSize() * BaseProp->size() * BaseProp->getDimension());
                    memcpy(Prop->editData(), BaseProp->getData(), NumBytesToCopy);
                }
                break;
            default:
                SWARNING << "Invalid blending method: " << getBlendingMethod()
                         << ". Using Normalized method." << std::endl;
            case Normalized:
                {
                    Real32 Weight(1.0f);
                    for(UInt32 j(0) ; j < getNumMorphTargets() ; ++j)
                    {
                        Weight -= osgAbs(getMorphTargetWeight(j));
                    }
                    //Zero out the property
                    zeroGeoProperty(Prop);

                    //Call the morph property with the given property format
                    morphGeoProperty(BaseProp, Prop, Weight);
                }
                break;
        }
        setProperty(Prop, getMorphProperties(i));

        //Loop through all morph targets
        Geometry* Target;
        GeoVectorProperty* TargetProp;
        Real32 Weight;
        for(UInt32 j(0) ; j < getNumMorphTargets() ; ++j)
        {
            //If the Weight is really small then don't apply it
            Weight = osgAbs(getMorphTargetWeight(j));
            if(Weight < 0.000001f)
            {
                continue;
            }

            Target = getMorphTarget(j);
            TargetProp = Target->getProperty(getMorphProperties(i));

            //Call the morph property with the given property format
            morphGeoProperty(TargetProp, Prop, Weight);
        }
    }
}
void SkeletonBlendedGeometry::changed(ConstFieldMaskArg whichField, 
                                      UInt32            origin,
                                      BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    //Do not respond to changes that have a Sync origin
    if(origin & ChangedOrigin::Sync)
    {
        return;
    }

    if((whichField & BaseGeometryFieldMask) &&
            getBaseGeometry() != NULL)
    {
        if(getBaseGeometry()->getTypes() != NULL)
        {
            setTypes(getBaseGeometry()->getTypes());
        }
        if(getBaseGeometry()->getLengths() != NULL)
        {
            setLengths(getBaseGeometry()->getLengths());
        }
        if(getBaseGeometry()->getPositions() != NULL)
        {
            GeoPropertyUnrecPtr Pos(getBaseGeometry()->getPositions()->clone());
            setPositions(dynamic_pointer_cast<GeoVectorProperty>(Pos));
        }
        if(getBaseGeometry()->getNormals() != NULL)
        {
            GeoPropertyUnrecPtr Norm(getBaseGeometry()->getNormals()->clone());
            setNormals(dynamic_pointer_cast<GeoVectorProperty>(Norm));
        }
        if(getBaseGeometry()->getColors() != NULL)
        {
            setColors(getBaseGeometry()->getColors());
        }
        if(getBaseGeometry()->getSecondaryColors() != NULL)
        {
            setSecondaryColors(getBaseGeometry()->getSecondaryColors());
        }
        if(getBaseGeometry()->getTexCoords() != NULL)
        {
            setTexCoords(getBaseGeometry()->getTexCoords());
        }
        if(getBaseGeometry()->getTexCoords1() != NULL)
        {
            setTexCoords1(getBaseGeometry()->getTexCoords1());
        }
        if(getBaseGeometry()->getTexCoords2() != NULL)
        {
            setTexCoords2(getBaseGeometry()->getTexCoords2());
        }
        if(getBaseGeometry()->getTexCoords3() != NULL)
        {
            setTexCoords3(getBaseGeometry()->getTexCoords3());
        }
        if(getBaseGeometry()->getTexCoords4() != NULL)
        {
            setTexCoords4(getBaseGeometry()->getTexCoords4());
        }
        if(getBaseGeometry()->getTexCoords5() != NULL)
        {
            setTexCoords5(getBaseGeometry()->getTexCoords5());
        }
        if(getBaseGeometry()->getTexCoords6() != NULL)
        {
            setTexCoords6(getBaseGeometry()->getTexCoords6());
        }
        if(getBaseGeometry()->getTexCoords7() != NULL)
        {
            setTexCoords7(getBaseGeometry()->getTexCoords7());
        }
        if(getBaseGeometry()->getIndices() != NULL)
        {
            setIndices(getBaseGeometry()->getIndices());
        }
        setMaterial(getBaseGeometry()->getMaterial());
    }

    if(whichField & InternalJointsFieldMask)
    {
        _JointPoseTransforms.resize(getNumJoints());
    }

    if( (whichField & BaseGeometryFieldMask) ||
        (whichField & InternalJointsFieldMask) ||
        (whichField & InternalWeightIndexesFieldMask) ||
        (whichField & InternalWeightsFieldMask) ||
        (whichField & BindTransformationFieldMask))
    {
        if(getNumJoints() > 0)
        {
            _JointPoseTransforms.resize(getNumJoints());
            calculatePositions();
        }
    }
}
void SkeletonBlendedGeometry::changed(ConstFieldMaskArg whichField, 
                                      UInt32            origin,
                                      BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    if((whichField & BaseGeometryFieldMask) &&
            getBaseGeometry() != NULL)
    {
        if(getBaseGeometry()->getTypes() != NULL)
        {
            setTypes(getBaseGeometry()->getTypes());
        }
        if(getBaseGeometry()->getLengths() != NULL)
        {
            setLengths(getBaseGeometry()->getLengths());
        }
        if(getBaseGeometry()->getPositions() != NULL)
        {
            GeoPropertyUnrecPtr Pos(getBaseGeometry()->getPositions()->clone());
            setPositions(dynamic_pointer_cast<GeoVectorProperty>(Pos));
        }
        if(getBaseGeometry()->getNormals() != NULL)
        {
            GeoPropertyUnrecPtr Norm(getBaseGeometry()->getNormals()->clone());
            setNormals(dynamic_pointer_cast<GeoVectorProperty>(Norm));
        }
        if(getBaseGeometry()->getColors() != NULL)
        {
            setColors(getBaseGeometry()->getColors());
        }
        if(getBaseGeometry()->getSecondaryColors() != NULL)
        {
            setSecondaryColors(getBaseGeometry()->getSecondaryColors());
        }
        if(getBaseGeometry()->getTexCoords() != NULL)
        {
            setTexCoords(getBaseGeometry()->getTexCoords());
        }
        if(getBaseGeometry()->getTexCoords1() != NULL)
        {
            setTexCoords1(getBaseGeometry()->getTexCoords1());
        }
        if(getBaseGeometry()->getTexCoords2() != NULL)
        {
            setTexCoords2(getBaseGeometry()->getTexCoords2());
        }
        if(getBaseGeometry()->getTexCoords3() != NULL)
        {
            setTexCoords3(getBaseGeometry()->getTexCoords3());
        }
        if(getBaseGeometry()->getTexCoords4() != NULL)
        {
            setTexCoords4(getBaseGeometry()->getTexCoords4());
        }
        if(getBaseGeometry()->getTexCoords5() != NULL)
        {
            setTexCoords5(getBaseGeometry()->getTexCoords5());
        }
        if(getBaseGeometry()->getTexCoords6() != NULL)
        {
            setTexCoords6(getBaseGeometry()->getTexCoords6());
        }
        if(getBaseGeometry()->getTexCoords7() != NULL)
        {
            setTexCoords7(getBaseGeometry()->getTexCoords7());
        }
        if(getBaseGeometry()->getIndices() != NULL)
        {
            setIndices(getBaseGeometry()->getIndices());
        }
        setMaterial(getBaseGeometry()->getMaterial());
    }

    if((whichField & JointsFieldMask) ||
        (whichField & PositionIndexesFieldMask) ||
        (whichField & BlendAmountsFieldMask))
    {
        calculatePositions();
    }

    if(whichField & SkeletonsFieldMask)
    {
        for(std::vector<EventConnection>::iterator Itor(_SkeletonListenerConnections.begin()) ; Itor != _SkeletonListenerConnections.end() ; ++Itor)
        {
            Itor->disconnect();
        }

        _SkeletonListenerConnections.clear();

        for(UInt32 i(0) ; i<getMFSkeletons()->size() ; ++i)
        {
            _SkeletonListenerConnections.push_back(getSkeletons(i)->addSkeletonListener(this));
        }
    }
}
void SkeletonBlendedGeometry::calculatePositions(void)
{
	if(getBaseGeometry() == NULL)
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Base Geometry is NULL." << std::endl;
        return;
	if(getPositions() == NULL)
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Positions is NULL." << std::endl;
        return;
	}
	if(getBaseGeometry()->getPositions() == NULL)
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Base Geometry Postions is NULL." << std::endl;
        return;
	}
	if(getMFPositionIndexes()->size() != getMFJoints()->size())
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Positions Indexes size is not the same as the affecting Joints size." << std::endl;
        return;
	}
	}
	if(getMFPositionIndexes()->size() != getMFBlendAmounts()->size())
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Positions Indexes size is not the same as the affecting blend amount size." << std::endl;
        return;
	}

    Pnt3f CalculatedPoint;
    Pnt3f PointTemp;
    Vec3f CalculatedNormal;


    //Set the values of all points to 0
    for (int i(0); i < getPositions()->size(); ++i)
    {
        getPositions()->setValue(Pnt3f(0, 0, 0), i);
    }

    //Update the Positions and Normals
    for(UInt32 i(0) ; i < getMFPositionIndexes()->size() ; ++i)
    {

        Matrix temp = getJoints(i)->getAbsoluteDifferenceTransformation();
        temp.scale(getBlendAmounts(i));
        getBaseGeometry()->getPositions()->getValue<Pnt3f>(PointTemp, getPositionIndexes(i));
        temp.mult(PointTemp, CalculatedPoint);
        //temp.mult(getBaseGeometry()->getNormals()->getValue(getPositionIndexes(i)), CalculatedNormal);
        

        //Add
        CalculatedPoint += PointTemp.subZero();
        getPositions()->setValue<Pnt3f>(CalculatedPoint, getPositionIndexes(i));
    }

    for(UInt32 i = 0; i < _mfParents.size(); i++)
    {
        _mfParents[i]->invalidateVolume();
    }

    _volumeCache.setValid();
    _volumeCache.setEmpty();
}