Difference between revisions of "Project3F18"

From Immersive Visualization Lab Wiki
Jump to: navigation, search
Line 7: Line 7:
 
The total score for this project is 100 points. Additionally, you can obtain up to 10 points of extra credit.
 
The total score for this project is 100 points. Additionally, you can obtain up to 10 points of extra credit.
  
==1. Applying a Texture (25 Points)==
+
==1. Textured Robot Torso ( Points)==
  
The first step of the project is to texture a robot component so that you can later use it as part of your robot.
+
The first step of the project is to create a textured robot torso, which you will later use as part of your robot.
  
 
Start with code that uses your trackball code, and modify it so that trackball rotations control the camera instead. (If you didn't get that to work, keyboard controls to rotate the camera will suffice.)
 
Start with code that uses your trackball code, and modify it so that trackball rotations control the camera instead. (If you didn't get that to work, keyboard controls to rotate the camera will suffice.)
  
Thanks to our tutors Weichen and former tutor Yining, you have the following robot parts to choose from: head, body, limb, eye, antenna. You will find the OBJ files in [[Media:Robot-parts-2018.zip |this ZIP file]]. Each vertex has not only a 3D coordinate and a normal associated with it, but also a texture coordinate. This allows you to map textures to the surfaces of the robot. Note that unlike the previous obj files in the course, each face has different indices for v/vt/vn. So you are going to need to update your parser accordingly, when you add texture support. One of ways to deal with the different indices is to re-order (and duplicate) the v/vt/vn data when parsing so that their indices align. The following code fragment from "OpenGLInsights" might be useful:
+
Thanks to our tutors Weichen and former tutor Yining, you have the following robot parts to choose from: head, body (torso), limb, eye, antenna. You will find the OBJ files in [[Media:Robot-parts-2018.zip |this ZIP file]]. Each vertex has not only a 3D coordinate and a normal associated with it, but also a texture coordinate. This allows you to map textures to the surfaces of the robot. Note that unlike the previous obj files in the course, each face has different indices for v/vt/vn. So you are going to need to update your parser accordingly, when you add texture support. One of ways to deal with the different indices is to re-order (and duplicate) the v/vt/vn data when parsing so that their indices align. The following code fragment from "OpenGLInsights" might be useful:
  
 
<pre>
 
<pre>
Line 38: Line 38:
 
</pre>
 
</pre>
  
Choose '''one''' of the robot parts to apply a texture to. Best candidates are the body and the head.
+
Load in the robot body with its texture coordinates. Then apply a texture to it. You can use any (non-offensive) image you find on the internet, or use a picture from your own collection. Best is to trim and resize the image to a size of 512x512 pixels.
 
+
Choose a texture image for the robot part. You can use any non-offensive image you find on the internet through image search, for example, or use a picture from your own collection. Best is to trim and resize it to a size of roughly 512x512 pixels.
+
  
 
Load the image into your C++ code. We provide [[Media:project3s16-texture.cpp | sample code]] which loads a PPM image file and uses it as a texture for a quad. If you decide to use an image in a format other than PPM (eg, JPEG), you need to convert it to PPM first. The above mentioned image processing tool [http://www.irfanview.com IrfanView] for Windows will do this for you. Alternatively, you can use a third party library such as [http://lonesock.net/soil.html SOIL] to natively load JPEG images, or other image formats.
 
Load the image into your C++ code. We provide [[Media:project3s16-texture.cpp | sample code]] which loads a PPM image file and uses it as a texture for a quad. If you decide to use an image in a format other than PPM (eg, JPEG), you need to convert it to PPM first. The above mentioned image processing tool [http://www.irfanview.com IrfanView] for Windows will do this for you. Alternatively, you can use a third party library such as [http://lonesock.net/soil.html SOIL] to natively load JPEG images, or other image formats.
Line 58: Line 56:
  
  
<!--
+
==2. Scene Graph Engine ( Points)==
 
+
==2. Scene Graph Engine (20 Points)==
+
  
To connect the parts of the robot (head, torso, limbs, eyes, antennae), we need to first implement a simple scene graph structure for our rendering engine. This scene graph should consist of at least three nodes: <tt>Node</tt>, <tt>Transform</tt> and <tt>Geometry</tt>. You are free to add more scene graph node types as you see fit.
+
To create a robot with multiple moving body parts (head, torso, limbs, eyes, antennae), we need to first implement a simple scene graph structure for our rendering engine. This scene graph should consist of at least three nodes: <tt>Node</tt>, <tt>Transform</tt> and <tt>Geometry</tt>. You are free to add more scene graph node types as you see fit.
  
 
* Class <tt>Node</tt> should be abstract and serve as the common base class. It should implement the following class methods:
 
* Class <tt>Node</tt> should be abstract and serve as the common base class. It should implement the following class methods:
Line 78: Line 74:
 
** have a class method which draws the 3D model associated with this node.  
 
** have a class method which draws the 3D model associated with this node.  
  
==3. Walking Android Robot (25 Points)==
+
==3. Walking Android Robot ( Points)==
  
Now that we have the scene graph classes, it is time to put them to work, and build a robot with them.  
+
Now that we have the scene graph classes, it is time to put them to work. Build your own robot using the <tt>addChild</tt> methods. Use at least 3 different types of parts for your robot (e.g., body, head and limb). In total, your robot needs to consist of at least 4 parts, 3 of which need to be moving independently from one another and they need to be connected to the 4th part. One of the robot parts needs to be the textured torso which you created in part 1 of the project.
  
 
+
Here is an example of a robot with two antennas, two eyeballs, one head, one torso and 4 limbs (2 legs and 2 arms), before applying a texture:
Build your own robot using the <tt>addChild</tt> methods. Use at least 3 different types of parts for your robot (e.g., body, head and limb). In total, your robot needs to consist of at least 4 parts, 3 of which need to be moving independently from one another and they need to be connected to the 4th part. At least one of the parts needs to have a texture on it. The texture can be any image you can find on the internet. If you need to resize your image, we recommend the free [https://www.irfanview.com IrfanView] if you are using Windows. (15 points)
+
 
+
This is an example of a valid robot with two antennas, two eyeballs, one head, one torso and 4 limbs (2 legs and 2 arms), before application of a texture:
+
  
 
[[Image:robot.png]]
 
[[Image:robot.png]]
  
Use your creativity to build the most creative robot in class! The 5 most creative robots in class, after a vote on Piazza, are going to get extra credit.
+
Use your creativity to build the most creative robot in class! The 5 most creative robots in class are going to get extra credit, after a vote on Piazza.
  
 
Once you've created your scene graph, you need to get your rendering engine ready to recursively traverse the scene graph for rendering by creating a root node of type Group and calling its draw() function with the identity matrix as its parameter.
 
Once you've created your scene graph, you need to get your rendering engine ready to recursively traverse the scene graph for rendering by creating a root node of type Group and calling its draw() function with the identity matrix as its parameter.
  
Animate the robot to make it look like it is walking, by changing the matrices in the Transform nodes. (10 points)
+
Animate the robot to make it look like it is walking, by changing the matrices in the Transform nodes.
  
==4. Robot Army (15 Points)==
+
==4. Robot Army ( Points)==
  
Test your implementation by constructing a scene which consists of a large amount of robots, at least 100. The robots can all be identical clones.
+
Construct a scene which consists of a large amount of robots, at least 100. The robots can all be identical clones.
  
* Distribute the robots on a 2D grid (i.e., place them on a plane with uniform spacing). For 100 robots, use a 10x10 grid. (10 points)
+
* Distribute the robots on a 2D grid (i.e., place them on a plane with uniform spacing). For 100 robots, use a 10x10 grid.
 
+
* Enable the animation for all the robots so that they look like they are walking.
* Enable the animation for all the robots so that they look like they are walking. (3 points)
+
* Enable your rotation and scale routines (keyboard or mouse) to allow rotating the grid of 3D objects and zoom in or out.
 
+
* Enable your rotation and scale routines (keyboard or mouse) to allow rotating the grid of 3D objects and zoom in or out. (2 points)
+
  
 
This image illustrates the grid layout of the robots:
 
This image illustrates the grid layout of the robots:
Line 109: Line 100:
 
[[Image:robot-army.png]]
 
[[Image:robot-army.png]]
  
 
+
<!--
 
==5. Culling (15 Points)==
 
==5. Culling (15 Points)==
  
Line 121: Line 112:
  
 
Increase the amount of robots by orders of magnitude, by creating a larger array of them. A good portion of the array should be off screen for the culling to be effective. Display the rendering time per frame in your text window, and show that by turning culling on your rendering time decreases. (2 points)
 
Increase the amount of robots by orders of magnitude, by creating a larger array of them. A good portion of the array should be off screen for the culling to be effective. Display the rendering time per frame in your text window, and show that by turning culling on your rendering time decreases. (2 points)
 +
  
 
==6. Extra Credit (Max. 10 Points)==
 
==6. Extra Credit (Max. 10 Points)==
Line 129: Line 121:
  
 
c) This can be done in conjunction with b) using tight bounding boxes, or with the original bounding spheres: create a hierarchical culling algorithm by storing bounding box/sphere information at every level of the scene graph, so that you can cull an entire branch of the scene graph at once. Structure your scene graph so that you have multiple levels (for instance, by subdividing your army into four quarters, and create a node above each quarter army. Also use the increased FOV like in part b) to demonstrate what gets culled when. (5 points)  
 
c) This can be done in conjunction with b) using tight bounding boxes, or with the original bounding spheres: create a hierarchical culling algorithm by storing bounding box/sphere information at every level of the scene graph, so that you can cull an entire branch of the scene graph at once. Structure your scene graph so that you have multiple levels (for instance, by subdividing your army into four quarters, and create a node above each quarter army. Also use the increased FOV like in part b) to demonstrate what gets culled when. (5 points)  
 +
 +
-->
  
 
==7. Creativity Contest (Up to 5 Points)==
 
==7. Creativity Contest (Up to 5 Points)==
Line 135: Line 129:
  
 
The winner of the contest will get 5 points of extra credit. The second will get 4 points, third gets 3, fourth 2, fifth 1 point. This extra credit is on top of the regular extra credit so one can theoretically get 115 points for this homework project.
 
The winner of the contest will get 5 points of extra credit. The second will get 4 points, third gets 3, fourth 2, fifth 1 point. This extra credit is on top of the regular extra credit so one can theoretically get 115 points for this homework project.
 
-->
 
  
 
<!--
 
<!--

Revision as of 14:29, 20 October 2018

Contents

Project 3: Textures, Scene Graphs and Culling

This page is currently under construction. It will be completed on Oct 20. Feel free to start working on it at any time.

In this project you will need to implement a scene graph to render an army of animated robots with textures on them.

The total score for this project is 100 points. Additionally, you can obtain up to 10 points of extra credit.

1. Textured Robot Torso ( Points)

The first step of the project is to create a textured robot torso, which you will later use as part of your robot.

Start with code that uses your trackball code, and modify it so that trackball rotations control the camera instead. (If you didn't get that to work, keyboard controls to rotate the camera will suffice.)

Thanks to our tutors Weichen and former tutor Yining, you have the following robot parts to choose from: head, body (torso), limb, eye, antenna. You will find the OBJ files in this ZIP file. Each vertex has not only a 3D coordinate and a normal associated with it, but also a texture coordinate. This allows you to map textures to the surfaces of the robot. Note that unlike the previous obj files in the course, each face has different indices for v/vt/vn. So you are going to need to update your parser accordingly, when you add texture support. One of ways to deal with the different indices is to re-order (and duplicate) the v/vt/vn data when parsing so that their indices align. The following code fragment from "OpenGLInsights" might be useful:

// For each triangle
for( unsigned int v=0; v<vertexIndices.size(); v+=3 )
{
    // For each vertex of the triangle
    for ( unsigned int i=0; i<3; i+=1 )
    {
        unsigned int vertexIndex = vertexIndices[v+i];
        glm::vec3 vertex = temp_vertices[ vertexIndex-1 ];
        
        unsigned int uvIndex = uvIndices[v+i];
        glm::vec2 uv = temp_uvs[ uvIndex-1 ];

        unsigned int normalIndex = normalIndices[v+i];
        glm::vec3 normal = temp_normals[ normalIndex-1 ];

        out_vertices.push_back(vertex);
        out_uvs.push_back(uv);
        out_normals.push_back(normal);
    }
}

Load in the robot body with its texture coordinates. Then apply a texture to it. You can use any (non-offensive) image you find on the internet, or use a picture from your own collection. Best is to trim and resize the image to a size of 512x512 pixels.

Load the image into your C++ code. We provide sample code which loads a PPM image file and uses it as a texture for a quad. If you decide to use an image in a format other than PPM (eg, JPEG), you need to convert it to PPM first. The above mentioned image processing tool IrfanView for Windows will do this for you. Alternatively, you can use a third party library such as SOIL to natively load JPEG images, or other image formats.

Use the following settings for your texture after your first glBindTexture(GL_TEXTURE_CUBE_MAP, id) for correct lighting and filtering settings:

  // Use bilinear interpolation for higher image quality:
  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  // Use clamp to edge to hide avoid repeating the texture:
  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


2. Scene Graph Engine ( Points)

To create a robot with multiple moving body parts (head, torso, limbs, eyes, antennae), we need to first implement a simple scene graph structure for our rendering engine. This scene graph should consist of at least three nodes: Node, Transform and Geometry. You are free to add more scene graph node types as you see fit.

  • Class Node should be abstract and serve as the common base class. It should implement the following class methods:
    • an abstract draw method: virtual void draw(Matrix4 C)=0
    • an abstract virtual void update()=0 method to separate bounding sphere updates from rendering (4 points)
  • Transform should be derived from Node and have the following features: (8 points)
    • store a 4x4 transformation matrix M
    • store a list of pointers to child nodes (std::list<Node*>)
    • provide class methods to add and remove child nodes (addChild(), removeChild()) from the list
    • its draw method needs to traverse the list of children and call each child node's draw function
    • when draw(C) is called, multiply matrix M with matrix C.
  • Geometry should be derived from Node and have the following features: (8 points)
    • set the modelview matrix to the current C matrix
    • an initialization method to load a 3D model (OBJ file) whose filename is passed to it (init(string filename). Your OBJ loader from project 2 should work.
    • have a class method which draws the 3D model associated with this node.

3. Walking Android Robot ( Points)

Now that we have the scene graph classes, it is time to put them to work. Build your own robot using the addChild methods. Use at least 3 different types of parts for your robot (e.g., body, head and limb). In total, your robot needs to consist of at least 4 parts, 3 of which need to be moving independently from one another and they need to be connected to the 4th part. One of the robot parts needs to be the textured torso which you created in part 1 of the project.

Here is an example of a robot with two antennas, two eyeballs, one head, one torso and 4 limbs (2 legs and 2 arms), before applying a texture:

Robot.png

Use your creativity to build the most creative robot in class! The 5 most creative robots in class are going to get extra credit, after a vote on Piazza.

Once you've created your scene graph, you need to get your rendering engine ready to recursively traverse the scene graph for rendering by creating a root node of type Group and calling its draw() function with the identity matrix as its parameter.

Animate the robot to make it look like it is walking, by changing the matrices in the Transform nodes.

4. Robot Army ( Points)

Construct a scene which consists of a large amount of robots, at least 100. The robots can all be identical clones.

  • Distribute the robots on a 2D grid (i.e., place them on a plane with uniform spacing). For 100 robots, use a 10x10 grid.
  • Enable the animation for all the robots so that they look like they are walking.
  • Enable your rotation and scale routines (keyboard or mouse) to allow rotating the grid of 3D objects and zoom in or out.

This image illustrates the grid layout of the robots:

Robot-army.png


7. Creativity Contest (Up to 5 Points)

We're going to have a contest for the top 5 most creative robot creations. Submit a JPEG image or GIF animation of your robot to Piazza by the deadline. Instructions will be posted on Piazza. To create a GIF animation you can use this converter. To convert any image file format to a GIF image, we recommend IrfanView. The top five most voted for robots are going to get extra credit.

The winner of the contest will get 5 points of extra credit. The second will get 4 points, third gets 3, fourth 2, fifth 1 point. This extra credit is on top of the regular extra credit so one can theoretically get 115 points for this homework project.