本文整理汇总了C++中MeshRenderer::setMesh方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshRenderer::setMesh方法的具体用法?C++ MeshRenderer::setMesh怎么用?C++ MeshRenderer::setMesh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshRenderer
的用法示例。
在下文中一共展示了MeshRenderer::setMesh方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Component
Exhaustion::Exhaustion(kick::GameObject *gameObject) : Component(gameObject) {
MeshRenderer* mr = gameObject->addComponent<MeshRenderer>();
Material *material = new Material();
material->setShader(Project::loadShader("poly-assets/shaders/unlit_vertex_colored.shader"));
mr->setMaterial(material);
Mesh *mesh = new Mesh();
mesh->setMeshData(loadPlyData("poly-assets/models","cloud.ply"));
mr->setMesh(mesh);
}
示例2: addPlant
void Terrain::addPlant(Transform *parent, vec3 pos){
static int plantCounter = 0;
plantCounter++;
Mesh* plantMesh = plants[plantCounter % plants.size()];
auto gameObject = Engine::activeScene()->createGameObject("Terrain");
MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
meshRenderer->setMesh(plantMesh);
Material *material = new Material();
material->setShader(Project::loadShader("poly-assets/shaders/diffuse_vertex_colored.shader"));
meshRenderer->setMaterial(material);
vec3 finalPos = (vec3)(parent->globalMatrix()*vec4(pos,1.0f));
gameObject->transform()->setLocalPosition(finalPos);
gameObject->transform()->setLocalScale(vec3(1)*linearRand(0.5f,1.5f));
gameObject->transform()->setLocalRotationEuler(vec3(0,(float)linearRand(-M_PI,M_PI),0));
}
示例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);
}
}