예제 #1
0
Actor* Parser::parseMesh(xml_node_iterator sceneElement)
{
	// setting the mesh
	const char* filename = sceneElement->attribute("file").value();

	TriangleMesh* mesh = MeshReader().execute(filename);

	Primitive* primitive = new TriangleMeshShape(mesh);

	xml_node op;
	if ((op = sceneElement->child("transform")) != NULL) {
		vec3 position(0, 0, 0);
		quat q(vec3(0, 0, 0));
		vec3 scale(1, 1, 1);
		float x, y, z;

		xml_object_range<xml_node_iterator> transformations = op.children();

		for (xml_node_iterator transformation = transformations.begin(); transformation != transformations.end(); ++transformation)
		{
			if (strcmp(transformation->name(), "position") == 0)
			{
				const char * stringTranslation = transformation->text().as_string();

				sscanf(stringTranslation, "%f %f %f", &x, &y, &z);
				vec3 translationVec(x, y, z);
				position = translationVec;
			}
			else if (strcmp(transformation->name(), "scale") == 0)
			{
				float s_ = transformation->text().as_float();
				vec3 newS(s_, s_, s_);
				scale = newS;
			}
			else if (strcmp(transformation->name(), "rotation") == 0)
			{
				float angle = transformation->child("angle").text().as_float();

				const char * _Axis = transformation->child("axis").text().as_string();
				sscanf(_Axis, "%f %f %f", &x, &y, &z);
				vec3 axis(x, y, z);
				q = quat(axis, angle);
			}

			mesh->transform(mat4::TRS(position, q, scale));
		}
	}
	if ((op = sceneElement->child("material")) != NULL) {
		Material * material = parseMaterial(op);
		primitive->setMaterial(material);
	}
	else
	{
		Material * material = MaterialFactory::New();
		primitive->setMaterial(material->getDefault());
	}

	Actor* act = new Actor(*primitive);
	act->setName(filename);

	return act;
}
예제 #2
0
void ContentReader(FbxNode* pNode,FbxAMatrix parentMatrix)
{
    FbxNodeAttribute::EType lAttributeType;
    int i;
    if(pNode->GetNodeAttribute() == NULL)
    {
        FBXSDK_printf("NULL Node Attribute\n");
    }
    else
    {
        lAttributeType = (pNode->GetNodeAttribute()->GetAttributeType());
        switch (lAttributeType)
        {
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eUnknown:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eNull:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eMarker:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eSkeleton:
            SkeletonReader(pNode,parentMatrix);
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eMesh:
            MeshReader(pNode);
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eNurbs:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::ePatch:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eCamera:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eCameraStereo:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eCameraSwitcher:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eLight:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eOpticalReference:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eOpticalMarker:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eNurbsCurve:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eTrimNurbsSurface:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eBoundary:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eNurbsSurface:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eShape:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eLODGroup:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eSubDiv:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eCachedEffect:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eLine:
            break;
        default:
            break;
        }
    }
    for(i = 0; i<pNode->GetChildCount(); i++)
    {
        ContentReader(pNode->GetChild(i),parentMatrix);
    }

}