Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw a custom 3d surface using three.js?

Tags:

math

three.js

3d

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.

like image 358
user3699912 Avatar asked Jun 18 '14 20:06

user3699912


People also ask

What can you build with three js?

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.

What is rendering in three js?

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.


2 Answers

Following examples are linked from three.js website:

  • http://stemkoski.github.io/Three.js/Graphulus-Function.html
  • http://stemkoski.github.io/Three.js/Graphulus-Surface.html

both of these examples are using THREE.ParametricGeometry

like image 156
makc Avatar answered Oct 30 '22 20:10

makc


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/

like image 32
pailhead Avatar answered Oct 30 '22 20:10

pailhead