Building a Forest with Functions
Weâll need a lot of trees for our forest. We could build them one at a time, but weâre not going to do that. Instead, letâs add the following JavaScript after all of the avatar body parts:
â | âfunctionâ makeTreeAt(x, z) { |
â | âvarâ trunk = ânewâ THREE.Mesh( |
â | ânewâ THREE.CylinderGeometry(50, 50, 200), |
â | ânewâ THREE.MeshBasicMaterial({color: â'sienna'â}) |
â | ); |
â | |
â | âvarâ top = ânewâ THREE.Mesh( |
â | ânewâ THREE.SphereGeometry(150), |
â | ânewâ THREE.MeshBasicMaterial({color: â'forestgreen'â}) |
â | ); |
â | top.position.y = 175; |
â | trunk.add(top); |
â | |
â | trunk.position.âsetâ(x, -75, z); |
â | scene.add(trunk); |
â | } |
â | |
â | makeTreeAt( 500, ... |
Get 3D Game Programming for Kids, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.