本文整理汇总了C++中MeshRenderer::setMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshRenderer::setMaterial方法的具体用法?C++ MeshRenderer::setMaterial怎么用?C++ MeshRenderer::setMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshRenderer
的用法示例。
在下文中一共展示了MeshRenderer::setMaterial方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onAwake
void Terrain::onAwake()
{
MeshRenderer* mr = getGameObject()->addComponent<MeshRenderer>();
MeshFilter* mf = getGameObject()->addComponent<MeshFilter>();
arc<Mesh> mesh = Resources::load<Mesh>("models/terrain/terrain");
arc<Texture2d> tex = Resources::load<Texture2d>("models/terrain/terrain");
arc<Material> material(new Material(Resources::load<Material>("shaders/Internal-MeshRendererTexture")));
material->setMainTexture(tex.cast<Texture>());
mr->setMaterial(material);
mf->setMesh(mesh);
MeshCollider* meshCollider = getGameObject()->addComponent<MeshCollider>();
getGameObject()->getTransform()->setPosition(Vector3(0, -1, 25));
}
示例2: onAwake
void LayerScreen::onAwake()
{
cameraGo = LayerCamera::create();
playerGo = new GameObject("Player");
//playerGo->setLayer(1 << 1);
playerGo->getTransform()->setPosition(Vector3(0, 0, 0));
MeshRenderer* playerMr = playerGo->addComponent<MeshRenderer>();
playerMr->setMaterial(Resources::load<Material>("shaders/textured"));
playerMr->getMaterial()->setMainTexture(Resources::load<Texture2d>("models/curuthers/Whiskers_diffuse"));
Mesh* mesh = Resources::load<Mesh>("models/curuthers/curuthers");
MeshFilter* playerMf = playerGo->addComponent<MeshFilter>();
playerMf->setMesh(mesh);
}
示例3: addCloud
void Terrain::addCloud(vec3 pos, vec3 min, vec3 max){
static MeshData* cloudMesh = loadPlyData("poly-assets/models","cloud.ply");
static Mesh *mesh = new Mesh();
mesh->setMeshData(cloudMesh);
auto gameObject = Engine::activeScene()->createGameObject("Cloud");
gameObject->addComponent<Cloud>(min, max);
MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
meshRenderer->setMesh(mesh);
Material *material = new Material();
material->setShader(Project::loadShader("poly-assets/shaders/unlit_vertex_colored.shader"));
meshRenderer->setMaterial(material);
gameObject->transform()->setLocalPosition(pos);
gameObject->transform()->setLocalScale(vec3(1)*linearRand(0.5f,5.0f));
gameObject->transform()->setLocalRotationEuler(vec3(0,(float)linearRand(-M_PI,M_PI),0));
}
示例4: buildTerrain
void Terrain::buildTerrain(vec2 offset, Mesh *mesh, MeshData* meshData, vec3 min, vec3 max){
auto gameObject = Engine::activeScene()->createGameObject("Terrain");
MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
meshRenderer->setMesh(mesh);
Material *material = new Material();
material->setShader(Project::loadShader("poly-assets/shaders/unlit_vertex_colored.shader"));
meshRenderer->setMaterial(material);
gameObject->transform()->setPosition(vec3{offset.x*200*worldScale, 0, offset.y*200*worldScale});
gameObject->transform()->setLocalScale(vec3{worldScale, 1, worldScale});
gameObject->transform()->setLocalRotationEuler(vec3{0,M_PI*(offset.x+offset.y),0});
auto& indices = meshData->submeshIndices(0);
auto& pos = meshData->position();
for (int i=0;i<190;i++){
// find random triangle
int index = (int)linearRand(0.0f, indices.size()/3-1.0f)*3;
vec3 p1 = pos[index];
vec3 p2 = pos[index+1];
vec3 p3 = pos[index+2];
if (p1.y <-0.1){
continue;
}
bool horizontal =glm::abs(p1.y- p2.y)+glm::abs(p2.y-p3.y)<0.1f;
if (horizontal){
vec3 midpoint = (p1+p2+p3)*(1/3.0f);
addPlant (gameObject->transform(), midpoint);
}
}
for (int i=0;i<20;i++){
float x= linearRand((-100.0f),(100.0f));
float z= linearRand((-100.0f),(100.0f));
vec3 cloudPos = vec3(x,0,z) * worldScale + gameObject->transform()->position();
cloudPos.y = linearRand(20.0f,50.0f);
addCloud(cloudPos, min, max);
}
}