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


C++ MeshRenderer::setMesh方法代码示例

本文整理汇总了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);
}
开发者ID:mortennobel,项目名称:PolyPlane,代码行数:10,代码来源:Exhaustion.cpp

示例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));
}
开发者ID:mortennobel,项目名称:PolyPlane,代码行数:16,代码来源:Terrain.cpp

示例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));
}
开发者ID:mortennobel,项目名称:PolyPlane,代码行数:18,代码来源:Terrain.cpp

示例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);
    }
}
开发者ID:mortennobel,项目名称:PolyPlane,代码行数:40,代码来源:Terrain.cpp


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