Exemplo n.º 1
0
// we first define an assembly which contains the world assembly. This "uberMaster" contains the global transformation.
void defineMasterAssembly(renderer::Project* project)
{
    MMatrix conversionMatrix;
    conversionMatrix.setToIdentity();
    World* world = getWorldPtr();
    if (world != 0)
    {
        RenderGlobals* rg = world->mRenderGlobals.get();
        if (rg != 0)
            conversionMatrix = rg->globalConversionMatrix;
    }
    if (getSceneFromProject(project)->assemblies().get_by_name("world") == 0)
    {
        foundation::auto_release_ptr<renderer::Assembly> assembly(renderer::AssemblyFactory().create("world", renderer::ParamArray()));
        getSceneFromProject(project)->assemblies().insert(assembly);
        foundation::Matrix4d appMatrix;
        MMatrix transformMatrix;
        transformMatrix.setToIdentity();
        transformMatrix *= conversionMatrix;
        foundation::auto_release_ptr<renderer::AssemblyInstance> assemblyInstance = renderer::AssemblyInstanceFactory::create("world_Inst", renderer::ParamArray(), "world");
        MMatrixToAMatrix(transformMatrix, appMatrix);
        assemblyInstance->transform_sequence().set_transform(0.0, foundation::Transformd::from_local_to_parent(appMatrix));
        getSceneFromProject(project)->assembly_instances().insert(assemblyInstance);
    }
}
Exemplo n.º 2
0
void fillMatrices(const MayaObject* obj, renderer::TransformSequence& transformSequence)
{
    MMatrix conversionMatrix = getWorldPtr()->mRenderGlobals->globalConversionMatrix;
    float scaleFactor = getWorldPtr()->mRenderGlobals->scaleFactor;
    transformSequence.clear();
    std::vector<MMatrix> transformMatrices;

    // In IPR mode we have to update the matrix from the dagPath
    if (getWorldPtr()->getRenderType() == World::IPRRENDER && !obj->isInstancerObject)
    {
        transformMatrices.push_back(obj->dagPath.inclusiveMatrix());
    }
    else
    {
        transformMatrices = obj->transformMatrices;
    }
    size_t numSteps = transformMatrices.size();
    size_t divSteps = numSteps;
    if (divSteps > 1)
        divSteps -= 1;
    float stepSize = 1.0f / (float)divSteps;
    float start = 0.0f;

    // cameras pos has to be scaled because it is not placed into the world assembly but directly in the scene.
    // We only scale the transform because a scaled camera will result in different renderings (e.g. dof)
    foundation::Matrix4d appMatrix;
    MMatrix transformMatrix;
    for (size_t matrixId = 0; matrixId < numSteps; matrixId++)
    {
        MMatrix colMatrix = transformMatrices[matrixId];
        if (obj->mobject.hasFn(MFn::kCamera))
        {
            colMatrix.matrix[3][0] *= scaleFactor;
            colMatrix.matrix[3][1] *= scaleFactor;
            colMatrix.matrix[3][2] *= scaleFactor;
        }
        MMatrixToAMatrix(colMatrix, appMatrix);
        transformSequence.set_transform(
            start + stepSize * matrixId,
            foundation::Transformd::from_local_to_parent(appMatrix));
    }
}
Exemplo n.º 3
0
void fillTransformMatrices(const MayaObject* obj, renderer::Light* light)
{
    std::vector<MMatrix> transformMatrices;
    // in ipr mode we have to update the matrix manually
    if (getWorldPtr()->getRenderType() == World::IPRRENDER)
    {
        transformMatrices.push_back(obj->dagPath.inclusiveMatrix());
    } 
    else
    {
        transformMatrices = obj->transformMatrices;
    }
    foundation::Matrix4d appMatrix;
    MMatrix colMatrix = transformMatrices[0];
    MMatrixToAMatrix(colMatrix, appMatrix);
    light->set_transform(foundation::Transformd::from_local_to_parent(appMatrix));
}
Exemplo n.º 4
0
MString defineTexture(MFnDependencyNode& shader, MString& attributeName)
{
    boost::shared_ptr<AppleseedRenderer> appleRenderer = boost::static_pointer_cast<AppleseedRenderer>(getWorldPtr()->mRenderer);
    assert(appleRenderer != 0);
    renderer::Scene* scene = getSceneFromProject(appleRenderer->getProjectPtr());
    foundation::SearchPaths &searchPaths = appleRenderer->getProjectPtr()->search_paths();

    MStatus stat;
    MString textureDefinition("");
    MPlug plug = shader.findPlug(attributeName, &stat);
    if (stat != MStatus::kSuccess)
        return textureDefinition;
    if (!plug.isConnected())
        return textureDefinition;
    MObject connectedNode = getConnectedInNode(plug);

    if (!connectedNode.hasFn(MFn::kFileTexture))
        return textureDefinition;

    MFnDependencyNode fileTextureNode(connectedNode, &stat);
    MString textureName = fileTextureNode.name() + "_texture";
    MString fileTextureName = "";
    getString(MString("fileTextureName"), fileTextureNode, fileTextureName);
    if (!pystring::endswith(fileTextureName.asChar(), ".exr") || (fileTextureName.length() == 0))
    {
        if (fileTextureName.length() == 0)
            Logging::warning(MString("FileTextureName has no content."));
        else
            Logging::warning(MString("FileTextureName does not have an .exr extension. Other filetypes are not yet supported, sorry."));
        return textureDefinition;
    }

    removeTextureEntityIfItExists(textureName);

    MString colorProfile = "srgb";

    renderer::ParamArray params;
    Logging::debug(MString("Now inserting file name: ") + fileTextureName);
    params.insert("filename", fileTextureName.asChar());      // OpenEXR only for now. The param is called filename but it can be a path
    params.insert("color_space", colorProfile.asChar());

    foundation::auto_release_ptr<renderer::Texture> textureElement(
        renderer::DiskTexture2dFactory().create(
        textureName.asChar(),
            params,
            searchPaths));    // the project holds a set of search paths to find textures and other assets
    scene->textures().insert(textureElement);

    bool alphaIsLuminance = false;
    getBool(MString("alphaIsLuminance"), fileTextureNode, alphaIsLuminance);
    renderer::ParamArray tInstParams;
    tInstParams.insert("addressing_mode", "clamp");
    tInstParams.insert("filtering_mode", "bilinear");
    if (alphaIsLuminance)
        tInstParams.insert("alpha_mode", "luminance");

    MString textureInstanceName = textureName + "_texInst";
    foundation::auto_release_ptr<renderer::TextureInstance> tinst = renderer::TextureInstanceFactory().create(
       textureInstanceName.asChar(),
       tInstParams,
       textureName.asChar());

    scene->texture_instances().insert(tinst);

    return textureInstanceName;
}
Exemplo n.º 5
0
void removeTextureEntityIfItExists(MString& textureName)
{
    boost::shared_ptr<AppleseedRenderer> appleRenderer = boost::static_pointer_cast<AppleseedRenderer>(getWorldPtr()->mRenderer);
    assert(appleRenderer != 0);
    renderer::Scene* scene = getSceneFromProject(appleRenderer->getProjectPtr());

    const MString textureInstanceName = textureName + "_texInst";
    renderer::Texture* texture = scene->textures().get_by_name(textureName.asChar());
    if (texture != 0)
        scene->textures().remove(texture);

    renderer::TextureInstance* textureInstance = scene->texture_instances().get_by_name(textureInstanceName.asChar());
    if (textureInstance != 0)
        scene->texture_instances().remove(textureInstance);
}
Exemplo n.º 6
0
renderer::AssemblyInstance* getAssemblyInstance(const MayaObject* obj)
{
    boost::shared_ptr<AppleseedRenderer> appleRenderer = boost::static_pointer_cast<AppleseedRenderer>(getWorldPtr()->mRenderer);
    MayaObject* assemblyObject = getAssemblyMayaObject(obj);

    MString assemblyName = getAssemblyName(assemblyObject);
    MString assemblyInstanceName = getAssemblyInstanceName(assemblyObject);
    renderer::Assembly* masterAssembly = getMasterAssemblyFromProject(appleRenderer->getProjectPtr());
    renderer::AssemblyInstance* masterAssemblyInstance = appleRenderer->getProjectPtr()->get_scene()->assembly_instances().get_by_name("world_Inst");
    if (assemblyName == "world" || assemblyObject == 0 || (obj->mobject.hasFn(MFn::kLight) && !obj->mobject.hasFn(MFn::kAreaLight)))
        return masterAssemblyInstance;
    return masterAssembly->assembly_instances().get_by_name(assemblyInstanceName.asChar());
}
Exemplo n.º 7
0
renderer::AssemblyInstance* createAssemblyInstance(const MayaObject* obj)
{
    MayaObject* assemblyObject = getAssemblyMayaObject(obj);
    boost::shared_ptr<AppleseedRenderer> appleRenderer = boost::static_pointer_cast<AppleseedRenderer>(getWorldPtr()->mRenderer);
    renderer::Assembly* ass = getAssembly(obj);
    renderer::Assembly* master = getMasterAssemblyFromProject(appleRenderer->getProjectPtr());
    MString assemblyInstanceName = getAssemblyInstanceName(assemblyObject);
    foundation::auto_release_ptr<renderer::AssemblyInstance> assemblyInstance = renderer::AssemblyInstanceFactory::create(assemblyInstanceName.asChar(), renderer::ParamArray(), ass->get_name());
    fillMatrices(obj, assemblyInstance->transform_sequence());
    renderer::AssemblyInstance* assInst = assemblyInstance.get();
    master->assembly_instances().insert(assemblyInstance);
    return assInst;
}
Exemplo n.º 8
0
renderer::Assembly* createAssembly(const MayaObject* obj)
{
    MayaObject* assemblyObject = getAssemblyMayaObject(obj);

    boost::shared_ptr<AppleseedRenderer> appleRenderer = boost::static_pointer_cast<AppleseedRenderer>(getWorldPtr()->mRenderer);
    renderer::Assembly* master = getMasterAssemblyFromProject(appleRenderer->getProjectPtr());
    if (obj->mobject.hasFn(MFn::kLight) && !obj->mobject.hasFn(MFn::kAreaLight))
        return master;

    if (assemblyObject == 0)
        return master;

    MString assemblyName = getAssemblyName(assemblyObject);

    if (assemblyName == "world")
        return master;

    foundation::auto_release_ptr<renderer::Assembly> assembly(
        renderer::AssemblyFactory().create(assemblyName.asChar(), renderer::ParamArray()));
    renderer::Assembly* ass = assembly.get();
    master->assemblies().insert(assembly);

    return ass;
}
Exemplo n.º 9
0
	void MayaRendererFactory::deleteRenderer()
	{
		getWorldPtr()->worldRendererPtr.reset();
	}
Exemplo n.º 10
0
	void RenderGlobalsFactory::deleteRenderGlobals()
	{
		getWorldPtr()->worldRenderGlobalsPtr.reset();
	}
Exemplo n.º 11
0
	std::shared_ptr<RenderGlobals> RenderGlobalsFactory::getRenderGlobals()
	{
		return getWorldPtr()->worldRenderGlobalsPtr;
	}
Exemplo n.º 12
0
mtco_MayaScene::~mtco_MayaScene()
{
	logger.debug("mtco maya scene destructor.");
	getWorldPtr()->worldRenderGlobals = NULL;
}
Exemplo n.º 13
0
void mtco_MayaScene::getRenderGlobals()
{
	this->renderGlobals = new mtco_RenderGlobals();
	MayaScene::renderGlobals = renderGlobals;
	getWorldPtr()->worldRenderGlobals = this->renderGlobals;
}
Exemplo n.º 14
0
	void MayaToWorld::callAfterNewCallback(void *)
	{
		getWorldPtr()->afterNewScene();
	}
Exemplo n.º 15
0
	void MayaToWorld::callAfterOpenCallback(void *)
	{
		getWorldPtr()->afterOpenScene();
	}
Exemplo n.º 16
0
	void MayaRendererFactory::createRenderer()
	{
		getWorldPtr()->worldRendererPtr = std::shared_ptr<Renderer>(new MtRender::MtRenderer());
	}
Exemplo n.º 17
0
	void RenderGlobalsFactory::createRenderGlobals()
	{
		getWorldPtr()->worldRenderGlobalsPtr = std::shared_ptr<RenderGlobals> (new RenderGlobals());
	}
Exemplo n.º 18
0
	std::shared_ptr<Renderer> MayaRendererFactory::getRenderer()
	{
		return getWorldPtr()->worldRendererPtr;
	}