GameObject * GameObject::createFromFile(const std::string & path)
{
    GameObject *ret = new GameObject("Primitive");
    ret->AddComponent<MeshRenderer>();
    ret->AddComponent<MeshFilter>();

    Mesh * mesh = Resources::LoadMesh(path);

    if (!mesh)
    {
        return NULL;
    }

    Graphics::uploadMesh(mesh);

    MeshFilter *mf = ret->GetComponent<MeshFilter>();
    if (mf) {
     mf->setMesh(mesh);
    }

    MeshRenderer *renderer = ret->GetComponent<MeshRenderer>();
    if (renderer)
    {

    }

    return ret;
}
Exemple #2
0
GameObject* GameObject::createPrimitive(int primitiveType)
{
  GameObject* gameObject = new GameObject();

  MeshFilter* meshFilter = gameObject->addComponent<MeshFilter>();
  meshFilter->setMesh(Resources::load<Mesh>("primitives/cube"));

  MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
  //meshRenderer->setMaterial(material);

  return gameObject;
}
Exemple #3
0
void SkyBox::onAwake()
{
  Debug::log("SkyBox awoken");

  std::vector<Vector3> vertices;
  vertices.push_back(Vector3(-100, -100, 50));
  vertices.push_back(Vector3(-100, 100, 50));
  vertices.push_back(Vector3(100, 100, 50));
  vertices.push_back(Vector3(100, 100, 50));
  vertices.push_back(Vector3(100, -100, 50));
  vertices.push_back(Vector3(-100, -100, 50));

  std::vector<Vector2> uv;
  uv.push_back(Vector2(0, 1));
  uv.push_back(Vector2(0, 0));
  uv.push_back(Vector2(1, 0));
  uv.push_back(Vector2(1, 0));
  uv.push_back(Vector2(1, 1));
  uv.push_back(Vector2(0, 1));

  std::vector<int> triangles;
  triangles.push_back(0);
  triangles.push_back(1);
  triangles.push_back(2);
  triangles.push_back(3);
  triangles.push_back(4);
  triangles.push_back(5);

  Mesh* mesh = new Mesh();
  mesh->setVertices(vertices);
  mesh->setUv(uv);
  mesh->setTriangles(triangles, 0);

  MeshFilter* meshFilter = getGameObject()->addComponent<MeshFilter>();
  meshFilter->setMesh(mesh);

  Texture2d* texture = Resources::load<Texture2d>("textures/clouds");

  //Texture2d* texture = new Texture2d(1, 1);
  //texture->setPixel(0, 0, Color(1, 0, 0));
  //texture->apply();

  Material* material = new Material(Resources::load<Material>("shaders/Internal-SkyboxTexture"));
  material->setMainTexture(texture);

  MeshRenderer* meshRenderer = getGameObject()->addComponent<MeshRenderer>();
  meshRenderer->setMaterial(material);

  //getGameObject()->getTransform()->translate(Vector3(0, 0, 10));
  //getGameObject()->getTransform()->rotate(Vector3(0, 180, 0));
}
Exemple #4
0
void BloomScreen::onAwake()
{
  BloomCamera::create();
  playerGo = new GameObject("Player");
  playerGo->getTransform()->setPosition(Vector3(-10, 0, -10));

  MeshRenderer* playerMr = playerGo->addComponent<MeshRenderer>();
  playerMr->setMaterial(Resources::load<Material>("shaders/Internal-MeshRendererTexture"));
  playerMr->getMaterial()->setMainTexture(Resources::load<Texture2d>("models/curuthers/Whiskers_diffuse").cast<Texture>());

  arc<Mesh> mesh = Resources::load<Mesh>("models/curuthers/curuthers");
  MeshFilter* playerMf = playerGo->addComponent<MeshFilter>();
  playerMf->setMesh(mesh);
}
Exemple #5
0
void WaterScreen::onAwake()
{
  accel = 0.0f;
  WaterCamera::create();
  effectUp = true;
  effectOffset = 0.0f;
  texOffset = 0.0f;

  waterGo = new GameObject("Water");
  waterGo->getTransform()->rotate(Vector3(0, 180, 0));
  waterGo->getTransform()->translate(Vector3(0, -1, 0));
  waterMr = waterGo->addComponent<MeshRenderer>();
  MeshFilter* waterMf = waterGo->addComponent<MeshFilter>();
  waterMf->setMesh(Resources::load<Mesh>("models/water/water"));
  waterMaterial = Resources::load<Material>("shaders/water");
  waterMr->setMaterial(waterMaterial);
  arc<Texture2d> waterTexture = Resources::load<Texture2d>("models/water/water");
  waterMaterial->setMainTexture(waterTexture.cast<Texture>());

  playerGo = new GameObject("Player");
  playerGo->getTransform()->setPosition(Vector3(0, 0, 0));

  playerMr = playerGo->addComponent<AnimatedMeshRenderer>();

  arc<AnimatedMesh> mesh = Resources::load<AnimatedMesh>("models/captain/captain");
  playerMr->setAnimatedMesh(mesh);

  for(int i = 0; i < playerMr->getRoot()->getTransform()->getChildCount(); i++)
  {
    if(playerMr->getRoot()->getTransform()->getChild(i)->getGameObject()->getName() == "Lightsaber")
    {
      arc<Material> fullRed = Resources::load<Material>("shaders/accum/full_red");
      fullRed->setMainTexture(Resources::load<Texture2d>("models/captain/captain").cast<Texture>());
      playerMr->getRoot()->getTransform()->getChild(i)->getGameObject()->getComponent<MeshRenderer>()
        ->setMaterial(fullRed);
    }
  }

  runAnimation = Resources::load<Animation>("models/captain/run.anm");
  idleAnimation = Resources::load<Animation>("models/captain/idle.anm");
  jumpAnimation = Resources::load<Animation>("models/captain/jump.anm");
  playerMr->setAnimation(idleAnimation);
  playerMr->setFps(1);
  playerMr->play();

  //Mesh* mesh = Resources::load<Mesh>("models/captain/captain");
  //MeshFilter* playerMf = playerGo->addComponent<MeshFilter>();
  //playerMf->setMesh(mesh);
}
Exemple #6
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));
}
Exemple #7
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);
  
  
}
void SelectAnimationScreen::onAwake()
{
  modelGo = new GameObject("Model");
  modelGo->addComponent<MeshRenderer>();
  MeshFilter* mf = modelGo->addComponent<MeshFilter>();
  mf->setMesh(Resources::load<Mesh>(SelectModelScreen::choice.substr(0, SelectModelScreen::choice.length() - 4)));

  std::string modelDir = Util::pathOnly(SelectModelScreen::choice);

  Debug::log(modelDir);

  Util::scanDir(modelDir, &files);

  for(int i = 0; i < files.size(); i++)
  {
    std::string curr = files.at(i);

    if(curr.length() <= 4 || curr.substr(curr.length() - 4) != ".anm")
    {
      files.erase(files.begin() + i);
      i--;
    }
  }
}
GameObject* GameObject::createPrimitive(PrimitiveType type)
{
   GameObject *ret = new GameObject("Primitive");
   ret->AddComponent<MeshRenderer>();
   ret->AddComponent<MeshFilter>();

   Mesh* mesh = new Mesh();

   const float shapeSize = 5.5f;

   if (type == GAMEOBJECT_QUAD) {
       mesh->vertices.push_back(glm::vec3(-shapeSize,0,-shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize,0,shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize,0,-shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize,0,shapeSize));

       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,1));
       mesh->uvs.push_back(glm::vec2(1,0));
       mesh->uvs.push_back(glm::vec2(1,1));

       mesh->colors.push_back(Color::Red());
       mesh->colors.push_back(Color::Green());
       mesh->colors.push_back(Color::Blue());
       mesh->colors.push_back(Color::Pink());

       mesh->triangles.push_back(0);
       mesh->triangles.push_back(2);
       mesh->triangles.push_back(1);
       mesh->triangles.push_back(0);
       mesh->triangles.push_back(3);
       mesh->triangles.push_back(1);
   }

   if (type == GAMEOBJECT_CUBE) {
       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize, shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize, -shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize,-shapeSize, shapeSize));

       mesh->vertices.push_back(glm::vec3(-shapeSize,  shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize,  shapeSize,  shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize,  shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize,  shapeSize,  shapeSize));

       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize,-shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize,shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize, shapeSize,-shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize, shapeSize,shapeSize));

       mesh->vertices.push_back(glm::vec3(shapeSize, -shapeSize,-shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize, -shapeSize,shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize, shapeSize,-shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize, shapeSize,shapeSize));

       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize, shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize,  shapeSize, shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize, -shapeSize, shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize,  shapeSize, shapeSize));

       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize,  shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize, -shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize,  shapeSize, -shapeSize));

       mesh->normals.push_back(glm::vec3(0,-1,0));
       mesh->normals.push_back(glm::vec3(0,-1,0));
       mesh->normals.push_back(glm::vec3(0,-1,0));
       mesh->normals.push_back(glm::vec3(0,-1,0));

       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));

       mesh->normals.push_back(glm::vec3(-1,0,0));
       mesh->normals.push_back(glm::vec3(-1,0,0));
       mesh->normals.push_back(glm::vec3(-1,0,0));
       mesh->normals.push_back(glm::vec3(-1,0,0));

       mesh->normals.push_back(glm::vec3(1,0,0));
       mesh->normals.push_back(glm::vec3(1,0,0));
       mesh->normals.push_back(glm::vec3(1,0,0));
       mesh->normals.push_back(glm::vec3(1,0,0));

       mesh->normals.push_back(glm::vec3(0,0,1));
       mesh->normals.push_back(glm::vec3(0,0,1));
       mesh->normals.push_back(glm::vec3(0,0,1));
       mesh->normals.push_back(glm::vec3(0,0,1));

       mesh->normals.push_back(glm::vec3(0,0,-1));
       mesh->normals.push_back(glm::vec3(0,0,-1));
       mesh->normals.push_back(glm::vec3(0,0,-1));
       mesh->normals.push_back(glm::vec3(0,0,-1));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,USHRT_MAX));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,0));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,USHRT_MAX));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,USHRT_MAX));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,0));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,USHRT_MAX));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,USHRT_MAX));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,0));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,USHRT_MAX));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,1.0f));
       mesh->uvs.push_back(glm::vec2(1.0f,0));
       mesh->uvs.push_back(glm::vec2(1.0f,1.0f));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,1.0f));
       mesh->uvs.push_back(glm::vec2(1.0f,0));
       mesh->uvs.push_back(glm::vec2(1.0f,1.0f));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,1.0f));
       mesh->uvs.push_back(glm::vec2(1.0f,0));
       mesh->uvs.push_back(glm::vec2(1.0f,1.0f));

       mesh->colors.push_back(Color::Red());
       mesh->colors.push_back(Color::Red());
       mesh->colors.push_back(Color::Red());
       mesh->colors.push_back(Color::Red());


       mesh->colors.push_back(Color::Green());
       mesh->colors.push_back(Color::Green());
       mesh->colors.push_back(Color::Green());
       mesh->colors.push_back(Color::Green());


       mesh->colors.push_back(Color::Blue());
       mesh->colors.push_back(Color::Blue());
       mesh->colors.push_back(Color::Blue());
       mesh->colors.push_back(Color::Blue());


       mesh->colors.push_back(Color::Pink());
       mesh->colors.push_back(Color::Pink());
       mesh->colors.push_back(Color::Pink());
       mesh->colors.push_back(Color::Pink());


       mesh->triangles.push_back(0);
       mesh->triangles.push_back(1);
       mesh->triangles.push_back(2);
       mesh->triangles.push_back(1);
       mesh->triangles.push_back(3);
       mesh->triangles.push_back(2);

       mesh->triangles.push_back(4);
       mesh->triangles.push_back(5);
       mesh->triangles.push_back(6);
       mesh->triangles.push_back(5);
       mesh->triangles.push_back(7);
       mesh->triangles.push_back(6);

       mesh->triangles.push_back(8);
       mesh->triangles.push_back(9);
       mesh->triangles.push_back(10);
       mesh->triangles.push_back(9);
       mesh->triangles.push_back(11);
       mesh->triangles.push_back(10);

       mesh->triangles.push_back(12);
       mesh->triangles.push_back(13);
       mesh->triangles.push_back(14);
       mesh->triangles.push_back(13);
       mesh->triangles.push_back(15);
       mesh->triangles.push_back(14);
   }


   Graphics::uploadMesh(mesh);

   //MeshFilter* mf = dynamic_cast<MeshFilter*>(ret->getComponent("MeshFilter"));
   MeshFilter *mf = ret->GetComponent<MeshFilter>();
   if (mf) {
    mf->setMesh(mesh);
   }

   MeshRenderer *renderer = ret->GetComponent<MeshRenderer>();
   if (renderer)
   {
       //Material * newMaterial = new Material();
       //Shader * phongShader = Shader::Find("phong");
       //newMaterial->setShader(phongShader);

       //renderer->setMaterial(newMaterial);
   }

   return ret;
}