small medium large xlarge

Generic-user-small
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: http://gamingjs.com/ice/#B/jVZtT9swEP7eX3HiU5hCkpp1SLxJqOuAaZSJVtq+IS9xsac0rmzTAL9+fgnO8taSJmp799zdc4/Pdc//8Oz18jy2b6NzmQq2USBFenFAldqcxvETXrPi6fsiSvk6XlJBSPRXHugQh/1A0JQKvibf2AuR/aGXI4A4hiVlEvRdUiIISPW8WgErgD8L0PkIlCzPgeLNhhSnOmKLBciUFAQuoCAlLG8eZrNoYSzB4dmonRNrhoRIULTK/Z4Dyw1J1aPAinGdqmRFxsuIFQURv1imKMQN2w1hT1SdVcGpJiZwg8FPImxGtiVT6w1OJmGjSghjfSf6OjR5XI5owyXTziJ60+kmSWJctr8IZ1ngQM2+rCCZwKVrz3RW8bGd8kJx126qV81rJkiRaYFFg/QUF1ssHypXYHm9AyNJ1IK9kaAjTdijjA3NePq8JoWKzFxFdsmyKWV5FvikGV/PcmJAvqlP1QWL5dXDEqb3X2/n13A/1xxnMJ/9XsKP2/nMw0Z2Afi21codkXTOxRrnd1gRwXBu2jFYQ6bZ9WvODJ1rogdUiddgnITwRT/jz0kVg7dY4W6BwOQKXfUGEu2DOli92lrc4Gg8SUL98m7U9NfueiAcsMeEjJ6GEMVF1twbG7OzfLPHJyHoyZxU/Fecq53wSQNOCd6Z3cpoH8MnjoUZDsdpxQVcWa42k/U8dtha7Yy11q5GtvVLdCWkn1pCq0gdsIMEarHoWcIhGmg/D9QighyTnKz61TCOD4nhga1ZGZDCw4frA2oy2CtEjdzLAfWRcMthB693JjojaTkYa3sxjK21FmYAj8ZoMjAUJmIHC0AtHj1iDBFpT0UfE9Si8v9Y9AlilfuIHh7YJDGohsc7AnZbt2p3trobBW2ty5pvzYpm7x9359AAe0tVihtr3+B1qqF95ZCvh/wRM+dlCJLywSOzdWD648p9COyPbQj+NPb/Zf4B. Can you please find the problem? Thank you!

Chris_strom_headshot_200_pragsmall
09 Nov 2017, 02:10
Chris Strom (265 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);
avatar.add(h1);

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

.

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 :)

-Chris

Generic-user-small
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