void Z3DTexture::uploadTexture() { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); bind(); if (is1DTexture()) glTexImage1D(m_textureTarget, 0, m_internalFormat, m_dimensions.x, 0, m_dataFormat, m_dataType, m_data); else if (is2DTexture()) glTexImage2D(m_textureTarget, 0, m_internalFormat, m_dimensions.x, m_dimensions.y, 0, m_dataFormat, m_dataType, m_data); else if (is3DTexture()) glTexImage3D(m_textureTarget, 0, m_internalFormat, m_dimensions.x, m_dimensions.y, m_dimensions.z, 0, m_dataFormat, m_dataType, m_data); if (useMipmap()) glGenerateMipmap(m_textureTarget); CHECK_GL_ERROR; }
void Helper4::addVariableBSDF( const std::string& param_name_as, const std::string& param_type_as, const std::string& param_name_maya ) { std::string param_value; const std::string plugName(param_name_maya); MString fullPlugName((m_nodename+"."+plugName).c_str()); int connected = liquidmaya::ShaderMgr::getSingletonPtr()->convertibleConnection(fullPlugName.asChar()); if( connected == 0 ) { if( isType("color", param_type_as) ) { MDoubleArray val; val.setLength(3); IfMErrorWarn(MGlobal::executeCommand("getAttr (\""+fullPlugName+"\")", val)); param_value = m_nodename+"_"+plugName; createColor3(m_assembly->colors(), param_value.c_str(), val[0], val[1], val[2]); } else if( isType("scalar", param_type_as) ) { MDoubleArray val; val.setLength(3); IfMErrorWarn(MGlobal::executeCommand("getAttr (\""+fullPlugName+"\")", val)); //val contains (r,b,g) value, but I only use val[0] for 'scalar' MString strVal0; strVal0.set(val[0]); param_value = strVal0.asChar(); } else { liquidMessage2(messageWarning,"only [color],[scalar] are handled for an unconnected plug in BSDF. " "the plug of %s is unhandled.", fullPlugName.asChar()); param_value = "unhandled"; } } else if(connected == 1)//the color plug is linked in. { if( isType("texture_instance", param_type_as) ) { MStringArray srcPlug; IfMErrorWarn(MGlobal::executeCommand("listConnections -source true -plugs true \""+fullPlugName+"\"", srcPlug)); assert(srcPlug.length()==1); MStringArray src; srcPlug[0].split('.',src); MString srcNode(src[0]); if( is2DTexture(srcNode) || is3DTexture(srcNode) ) { //visitFile(srcNode.asChar()); param_value = getTextureInstanceName(srcNode.asChar()); }else{ liquidMessage2(messageWarning,"type of [%s] is unhandled.(not 2Dtexture and 3Dtexture). [%s]", srcNode.asChar(), fullPlugName.asChar()); param_value = "unhandled"; } } else if( isType("bsdf", param_type_as) ) { //bsdf0 value MString srcBSDFModel; IfMErrorWarn(MGlobal::executeCommand("getAttr (\""+fullPlugName+"\")", srcBSDFModel)); MStringArray srcPlug; IfMErrorWarn(MGlobal::executeCommand("listConnections -source true -plugs true \""+fullPlugName+"\"", srcPlug)); assert(srcPlug.length()==1); MStringArray src; srcPlug[0].split('.',src); MString srcNode(src[0]); param_value = srcNode.asChar(); } else{ liquidMessage2(messageWarning,"only [texture_instance],[bsdf] are handled for a connected-in plug in BSDF." "the plug of %s is unhandled.", fullPlugName.asChar()); param_value = "unhandled"; } }else{// $(fullPlugName) is connected out // if $(fullPlugName) plug is connected out to "bsdf0"/"bsdf1" of a "bsdf_mix" node, // we also need to create this plug for appleseed // get destination node(s) MStringArray desNodePlug; IfMErrorWarn(MGlobal::executeCommand("listConnections -destination true -plugs true \""+fullPlugName+"\"", desNodePlug)); // check whether $(fullPlugName) is connected to a BSDF node bool isConnectedToA_BSDFMixNode = false; MString desPlug; for(std::size_t i = 0; i< desNodePlug.length(); ++i) { MStringArray des; desNodePlug[i].split('.',des); MString desNode(des[0]); //destination node BSDF type MString desNodeBSDFType; IfMErrorWarn(MGlobal::executeCommand( "getAttr \""+desNode+".rmanShaderType\"", desNodeBSDFType)); if(desNodeBSDFType == "bsdf_mix") { isConnectedToA_BSDFMixNode = true; desPlug = des[1]; } } // if $(fullPlugName) is connected out to "bsdf0"/"bsdf1" of a "bsdf_mix" node // we also need to create this plug for appleseed if( isConnectedToA_BSDFMixNode && (desPlug=="bsdf0" ||desPlug=="bsdf1") ) { if( isType("color", param_type_as) ) { MDoubleArray val; val.setLength(3); IfMErrorWarn(MGlobal::executeCommand("getAttr (\""+fullPlugName+"\")", val)); param_value = m_nodename+"_"+plugName; createColor3(m_assembly->colors(), param_value.c_str(), val[0], val[1], val[2]); } else if( isType("scalar", param_type_as) ) { MDoubleArray val; val.setLength(3); IfMErrorWarn(MGlobal::executeCommand("getAttr (\""+fullPlugName+"\")", val)); //val contains (r,b,g) value, but I only use val[0] for 'scalar' MString strVal0; strVal0.set(val[0]); param_value = strVal0.asChar(); } else if( isType("texture_instance", param_type_as) ) { MStringArray srcPlug; IfMErrorWarn(MGlobal::executeCommand("listConnections -source true -plugs true \""+fullPlugName+"\"", srcPlug)); assert(srcPlug.length()==1); MStringArray src; srcPlug[0].split('.',src); MString srcNode(src[0]); if( is2DTexture(srcNode) || is3DTexture(srcNode) ) { //visitFile(srcNode.asChar()); param_value = getTextureInstanceName(srcNode.asChar()); }else{ liquidMessage2(messageWarning,"type of [%s] is unhandled.(not 2Dtexture and 3Dtexture). [%s]", srcNode.asChar(), fullPlugName.asChar()); param_value = "unhandled"; } } else { liquidMessage2(messageWarning,"only [color],[scalar],[texture_instance] are handled for an connected-out plug in BSDF. " "the plug of %s is unhandled.", fullPlugName.asChar()); param_value = "unhandled"; } }//if( nodetype=="bsdf_mix" && (desPlug=="bsdf0" ||desPlug=="bsdf1") ) else { liquidMessage2(messageWarning,"[%s] is connected out. But not connected to brdf node, or not brdf0/brdf1 of a brdf node." " So I don't create the value for this plug.", fullPlugName.asChar()); } } // addVariableBSDF(param_name_as, param_value); }
void Helper4::addVariableSS(const std::string& param_name_as, const std::string& param_type_as, const std::string& param_name_maya ) { //std::string ss_name(getSurfaceShaderName(m_nodename,m_ss_model)); asr::ParamArray ss_params; { std::string param_value; const std::string plugName(param_name_maya); MString fullPlugName((m_nodename+"."+plugName).c_str()); int connected = liquidmaya::ShaderMgr::getSingletonPtr()->convertibleConnection(fullPlugName.asChar()); if(connected ==0) { if( isType("color", param_type_as) ) { MDoubleArray val; val.setLength(3); IfMErrorWarn(MGlobal::executeCommand("getAttr (\""+fullPlugName+"\")", val)); param_value = m_nodename+"_"+plugName; createColor3(m_assembly->colors(), param_value.c_str(), val[0], val[1], val[2]); } else if( isType("scalar", param_type_as) ) { MDoubleArray val; val.setLength(3); IfMErrorWarn(MGlobal::executeCommand("getAttr (\""+fullPlugName+"\")", val)); //val contains (r,b,g) value, but I only use val[0] for 'scalar' MString strVal0; strVal0.set(val[0]); param_value = strVal0.asChar(); } else if( isType("string", param_type_as)) { MString val; IfMErrorWarn(MGlobal::executeCommand("getAttr (\""+fullPlugName+"\")", val)); param_value = val.asChar(); } else { liquidMessage2(messageWarning,"only [color],[scalar],[string] are handled for an unconnected plug in Surface Shader. " "the plug of %s is unhandled.", fullPlugName.asChar()); param_value = "unhandled"; } } else if(connected == 1)//the plug is linked in. { if( isType("texture_instance", param_type_as) ) { MStringArray srcPlug; IfMErrorWarn(MGlobal::executeCommand("listConnections -source true -plugs true \""+fullPlugName+"\"", srcPlug)); assert(srcPlug.length()==1); MStringArray src; srcPlug[0].split('.',src); MString srcNode(src[0]); if( is2DTexture(srcNode) || is3DTexture(srcNode) ) { //visitFile(srcNode.asChar()); param_value = getTextureInstanceName(srcNode.asChar()); }else{ liquidMessage2(messageWarning,"only [texture2D],[texture3D] are handled for a texture_instance connected-in plug in Surface Shader." "the plug of %s is unhandled.", fullPlugName.asChar()); param_value = "unhandled"; } } else{ liquidMessage2(messageWarning,"only [texture_instance] is handled for a connected-in plug in Surface Shader." "the plug of %s is unhandled.", fullPlugName.asChar()); param_value = "unhandled"; } }else{ liquidMessage2(messageWarning,"[%s] is connected out.", fullPlugName.asChar()); } // addVariableSS(param_name_as, param_value); } }