Beispiel #1
0
void GDExporter::GetUniqueRenderContexts( MFnTransform& transform, std::list<GDRenderContext>& uniqueContexts )
{
	for(unsigned int i = 0; i < transform.childCount(); ++i)
	{
		if( transform.child(i).apiType() == MFn::kMesh )
		{
			MFnMesh childMesh( transform.child(i) );

			if( childMesh.isIntermediateObject() )
				continue;

			MDagPath meshPath;
			childMesh.getPath(meshPath);
			MFnDependencyNode depNode(meshPath.node());
			MStatus fpResult;
			MPlug gdRenderContextPlug = childMesh.findPlug("GDRenderContext", &fpResult);

			if( fpResult != MS::kSuccess )
				continue;

			GDRenderContext newContext(gdRenderContextPlug);

			bool bFound = false;
			std::list<GDRenderContext>::iterator uniqueIter = uniqueContexts.begin();
			for(; uniqueIter != uniqueContexts.end(); ++uniqueIter )
			{
				if( (*uniqueIter) == newContext )
				{
					bFound = true;
					break;
				}
			}

			if( bFound == false )
				uniqueContexts.push_back( newContext );
			else
				gdRenderContextPlug.child(0).setValue( (*uniqueIter).name.c_str() );
		}
		else if( transform.child(i).apiType() == MFn::kTransform )
		{
			MFnTransform childTransform( transform.child(i) );
			GetUniqueRenderContexts( childTransform, uniqueContexts );
		}
	}
}
Beispiel #2
0
bool GDExporter::GetSelectedMeshTransformPath(MDagPath &transformPath)
{
	MSelectionList currSelection;
	MGlobal::getActiveSelectionList(currSelection);

	unsigned int selectionCount = currSelection.length();
	
	MFnMesh* exportingMesh = 0;

	for(unsigned int selectionIndex = 0; selectionIndex < selectionCount; ++selectionIndex )
	{
		MDagPath currPath;
		currSelection.getDagPath(selectionIndex, currPath);

		if( currPath.apiType() != MFn::kTransform )
			continue;

		MFnTransform currTransform(currPath);
		unsigned int childCount = currTransform.childCount();
		for(unsigned int childIndex = 0; childIndex < childCount; ++childIndex)
		{
			MObject childObject = currTransform.child(childIndex);
			if( childObject.apiType() == MFn::kMesh )
			{
				MFnMesh childMesh(childObject);
				if( childMesh.isIntermediateObject() )
					continue;

				currTransform.getPath(transformPath);
				return true;
			}
		}
	}

	return false;
}
Beispiel #3
0
void BulletNifLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags, const osg::Matrixf &transform,
                                       bool isAnimated, bool avoid)
{
    assert(shape != nullptr);

    // If the object was marked "NCO" earlier, it shouldn't collide with
    // anything. So don't do anything.
    if ((flags & 0x800))
    {
        return;
    }

    if (!shape->skin.empty())
        isAnimated = false;

    if (shape->data.empty())
        return;
    if (shape->data->triangles.empty())
        return;

    if (isAnimated)
    {
        if (!mCompoundShape)
            mCompoundShape.reset(new btCompoundShape);

        std::unique_ptr<btTriangleMesh> childMesh(new btTriangleMesh);

        fillTriangleMesh(*childMesh, shape->data.get());

        std::unique_ptr<Resource::TriangleMeshShape> childShape(new Resource::TriangleMeshShape(childMesh.get(), true));
        childMesh.release();

        float scale = shape->trafo.scale;
        const Nif::Node* parent = shape;
        while (parent->parent)
        {
            parent = parent->parent;
            scale *= parent->trafo.scale;
        }
        osg::Quat q = transform.getRotate();
        osg::Vec3f v = transform.getTrans();
        childShape->setLocalScaling(btVector3(scale, scale, scale));

        btTransform trans(btQuaternion(q.x(), q.y(), q.z(), q.w()), btVector3(v.x(), v.y(), v.z()));

        mShape->mAnimatedShapes.insert(std::make_pair(shape->recIndex, mCompoundShape->getNumChildShapes()));

        mCompoundShape->addChildShape(trans, childShape.get());
        childShape.release();
    }
    else if (avoid)
    {
        if (!mAvoidStaticMesh)
            mAvoidStaticMesh.reset(new btTriangleMesh(false));

        fillTriangleMeshWithTransform(*mAvoidStaticMesh, shape->data.get(), transform);
    }
    else
    {
        if (!mStaticMesh)
            mStaticMesh.reset(new btTriangleMesh(false));

        // Static shape, just transform all vertices into position
        fillTriangleMeshWithTransform(*mStaticMesh, shape->data.get(), transform);
    }
}