Skip to content

Week 09: 3D

Bryan Ma edited this page Apr 16, 2019 · 18 revisions

Topics:

  • homework review
  • P3D renderer - size(600, 600, P3D)
  • 2d drawing functions in 3D (i.e. rect(), ellipse())
  • 2d drawing functions that take a z parameter (i.e. line(), point())
  • drawing lines and polygons with beginShape(), vertex(), endShape()
  • 3D primitives box(), sphere() with sphereDetail()
  • very quick look at textures, lighting, cameras in 3D
  • perlin noise - 1D, 2D, 3D
  • getting ready for finals

Drawing in 3D in Processing:

Basically everything we've been doing in two dimensions in Processing can be applied to three dimensions. A point can have a z position, so can a line.

point(100, 100);          // 2d point
point(100, 100, 100);     // 3d point
line(0, 0, 50, 50);       // 2d line
line(0, 0, 0, 50, 50, 0); // 3d line

Rect and Ellipse don't take z position values as arguments, however. Neither do 3d primitives like box and sphere. We can use translation to place them where we like:

translate(100, 50, -200); // translate in 3 dimensions
box(100);                 // draw a box 100 units wide

More sophisticated models could be read into memory by Processing, for example OBJs, or created manually or programmatically using beginShape(), vertex(), and endShape(). There are a number of inherent complexities with how some of this works, so please go through the reference and its associated elements: https://processing.org/reference/beginShape_.html

The Processing P3D tutorial covers everything we went over in class, please go over it in detail: https://processing.org/tutorials/p3d/

Finally there is a topic not covered in class in w09_01_vertexShapes, which is the use of vertex color. Notice that certain shapes have colors that blend between the different vertices of the polygon. Have a go with creating some of your own polygons with interpolated vertex colors like this to experiment.

w09_03_3dBall and w09_04_3dPhysics are 3d versions of behavior we've written into code earlier in the semester. Please use them for reference as well.

Perlin Noise:

Excellent Daniel Shiffman series on the topic, please go through all of it: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6bgPNQAdxQZpJuJCjeOr7VD (notice that he's using p5.js instead of processing but it should work in exactly the same way in Processing)

Another, older Daniel Shiffman video that he uses Processing in: https://www.youtube.com/watch?v=8ZEMLCnn8v0&list=PLRqwX-V7Uu6YVljJvFRCyRM6mmF5wMPeE&index=6

Please see sketches w09_05_1dNoise, w09_06_2dNoise, and w09_07_3dNoise for examples. I also include Daniel Shiffman's more complex w09_08_flowField for reference on a more sophisticated usage of noise - to generate flow fields applying forces to mover objects.

Take a look at https://hendhyhutomoere.wordpress.com/2013/11/14/perlin-noise-and-its-application/ for some other background on noise and what you can use it for.

Extra:

Included an example w09_00_arraylistRemove as a reminder of how to remove elements from an arraylist as we did at the beginning of class looking at homework assignments. (probably what the issue was with that was that the position wasn't being compared properly)

Homework:

The homework for this week is to develop a new original sketch using your skills so far, and integrating elements from this week. This could mean a data visualization in 3d, a 3d physics simulation, something using noise, etc. Every one of these points is worth a single point to implement, up to five points.

  • Incorporates some kind of 3D drawing
  • Incorporates an object that creates a custom mesh with beginShape vertex endShape, etc.
  • Uses physical simulation (forces, acceleration, mass, etc) in conjunction with 3D elements
  • Uses noise some way in your sketch to influence behavior or visuals
  • Combines a topic from class with the use of external data in some way in your sketch to separate data from logic
  • Combines a topic from class with the use of external data sourced from a live API and visualizes it in your sketch
  • Combines a topic from class with the use of multiple states managed with at least one switch statement
  • Simulates a living or natural system in some way (e.g. flocking, but doesn't need to be that complex)
  • Uses classes with inheritance and polymorphism to derive and organize different physical behavior
  • Is original and interesting to me in some way (yes this is subjective sorry)

Finals Research

The final for this class will be an original code project that demonstrates the skills you've developed over the year of taking Code 1 and 2. Next week we will have short one on one meetings to discuss what you're considering for your final project. Please be ready with some idea of the following:

  • A description of the core idea you are interested in. Explain why you're interested in it.
  • A description of the form you are interested in. Show reference from existing projects.
  • What you think you might want your user to do with your project.
  • Pick one existing project for a precedent. Use https://processing.org/exhibition/ as a starting point. Beyond that, look around for games or data visualizations - both of those topics are very appropriate kinds of approaches and very relevant to the material we've covered this year.

Clone this wiki locally