当前位置: 首页>>代码示例>>C++>>正文


C++ SubMesh::setMaterial方法代码示例

本文整理汇总了C++中SubMesh::setMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ SubMesh::setMaterial方法的具体用法?C++ SubMesh::setMaterial怎么用?C++ SubMesh::setMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SubMesh的用法示例。


在下文中一共展示了SubMesh::setMaterial方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: extractPolygons


//.........这里部分代码省略.........
								}
							}
						}

						submesh.addVertex(vertex1);
						submesh.addVertex(vertex2);
						submesh.addVertex(vertex3);
					}
				}
			}

			{
				Material material;

				{
					MObjectArray shaders;
					MIntArray indices;
					fnMesh.getConnectedShaders(0, shaders, indices);
					unsigned int shaderCount = shaders.length();

					MPlugArray connections;
					MFnDependencyNode shaderGroup(shaders[compi]);
					MPlug shaderPlug = shaderGroup.findPlug("surfaceShader");
					shaderPlug.connectedTo(connections, true, false);

					for(unsigned int u = 0; u < connections.length(); u++) {
						if(connections[u].node().hasFn(MFn::kLambert)) {

							MFnLambertShader lambertShader(connections[u].node());
							MPlugArray plugs;
							lambertShader.findPlug("color").connectedTo(plugs, true, false);

							for (unsigned int p = 0; p < plugs.length(); p++) {
								MPlug object = plugs[p];
								if (!object.isNull()) {
									MObject node = object.node();
									if (node.hasFn(MFn::kFileTexture)) {
										MFnDependencyNode* diffuseMapNode = new MFnDependencyNode(node);

										MPlug filenamePlug = diffuseMapNode->findPlug ("fileTextureName");
										MString mayaFileName;
										filenamePlug.getValue (mayaFileName);
										std::string diffuseMapFileName = mayaFileName.asChar();
										std::string diffuseMapAssetPath = extractAssetPath(diffuseMapFileName);
										material.addTexture("ColorMap", diffuseMapAssetPath);
									}
								} 
							}

							MColor color = lambertShader.color();
							MString materialNameRaw = lambertShader.name();
							std::string materialName = materialNameRaw.asChar();
							material.setName(materialName);

							Vector4MaterialParameter* diffuseColorParameter = new Vector4MaterialParameter("DiffuseColor");
							diffuseColorParameter->value.x = color.r;
							diffuseColorParameter->value.y = color.g;
							diffuseColorParameter->value.z = color.b;
							diffuseColorParameter->value.w = color.a;

							material.addParameter(diffuseColorParameter);
						}
					}
				}

				{
					if (material.hasTextures()) {
						material.setEffect("shaders/deferred_render_colormap_normal_depth.cg");
					}
					else {
						material.setEffect("shaders/deferred_render_color_normal_depth.cg");
					}
				}


				{
					FloatMaterialParameter* specularPowerParameter = new FloatMaterialParameter("SpecularPower");
					specularPowerParameter->value = 1.0;
					material.addParameter(specularPowerParameter);
				}

				{
					FloatMaterialParameter* specularIntensityParameter = new FloatMaterialParameter("SpecularIntensity");
					specularIntensityParameter->value = 1.0f;
					material.addParameter(specularIntensityParameter);
				}

				{
					FloatMaterialParameter* diffusePowerParameter = new FloatMaterialParameter("DiffusePower");
					diffusePowerParameter->value = 1.0f;
					material.addParameter(diffusePowerParameter);
				}

				submesh.setMaterial(material);
			}

			model->addSubMesh(submesh);
		}
	}
}
开发者ID:nkostelnik,项目名称:importer,代码行数:101,代码来源:MayaReader.cpp


注:本文中的SubMesh::setMaterial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。