What functions/math do I use to draw a 3d surface? For example, how do I generate z = sin(x+y)? How are the points calculated and drawn? I couldn't find any examples.
Three. js is a powerful library for creating three-dimensional models and games. With just a few lines of JavaScript, you can create anything from simple 3D patterns to photorealistic, real-time scenes. You can build simple and complex 3D geometrics, animate and move objects through a lifelike scene, and more.
If you have ever wanted to build a game with JavaScript, you might have come across Three. js. Three. js is a library that we can use to render 3D graphics in the browser. The whole thing is in JavaScript, so with some logic you can add animation, interaction, or even turn it into a game.
Following examples are linked from three.js website:
both of these examples are using THREE.ParametricGeometry
https://threejs.org/docs/#api/en/geometries/PlaneGeometry
Something like this contains vertices. If a vertex consists of [x,y,z] you can apply your function there by looping through all the vertices.
http://aerotwist.com/tutorials/an-introduction-to-shaders-part-1/
this tutorial is an example how you can use shaders to do the same thing MUCH faster
I believe that this tutorial is a great starting point for all things realtime 3d: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With