Ejemplo n.º 1
0
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));
}
Ejemplo n.º 2
0
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);
  
  
}
Ejemplo n.º 3
0
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));
}
Ejemplo n.º 4
0
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);
    }
}