small medium large xlarge

08 Nov 2017, 21:10
Brendon S. (2 posts)

Hi! I have started reading your book a view days ago and came up with some code. I am trying to code two avatars, and they won’t appear. Here is the code: Can you please find the problem? Thank you!

09 Nov 2017, 02:10
Chris Strom (278 posts)

The trouble is with the value of head. It is being used for too many things – too many different things.

This gets a little complicated, but maybe I can explain a bit. Line 31 assigns head to a shape - a SphereGeometry. Then line 69 assigns head to a mesh that is the combination of the head from line 31 plus a cover. Then line 74 tries to create another head mesh, head2. Meshes are the combination of a shape and cover, but on line 74, the code creates a mesh with head and a cover. By now head is no longer a shape – since line 69 it is a mesh. So on line 74, the code is trying to create a mesh from a mesh and a cover – not a shape and cover.

Hopefully that explanation helps. No worries if not. Like I said, it’s a little complicated.

The fix is easier. The quickest thing to do is to use something other than head on line 69 and 74. Something like this should work:


//head for Avatar
var h1 = new THREE.Mesh(head, cover);
h1.position.set(0, 130, 0);

//head for Avatar 2
var h2 = new THREE.Mesh(head, cover);
h2.position.set(0, 130, 0);


One last thing: be sure to read chapter 2 if you haven’t already. It covers how JavaScript errors are reported in the JavaScript console. It probably wouldn’t have helped too much in this case because you get a weird error creating a mesh from a mesh. Still, it reports the line number that has a problem. so it’s a least a start.

Lastly, kudos on the two avatars. They’re looking good :)


09 Nov 2017, 21:09
Brendon S. (2 posts)

Thank you! I see what you’re saying. I just treated the head variable like I treated the other two shape variables, hand and foot. In the future I’ll be more careful. Thank you again!

You must be logged in to comment