1

I have a simple Three.js code that works properly in Three.js v68 but it displays 2 cubes instead of a cube and a sphere in Three.js v71. If I draw the sphere first it will draw two spheres.

        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
        camera.position.z = 5;

        var renderer = new THREE.WebGLRenderer();
        renderer.setSize( window.innerWidth, window.innerHeight );
        document.body.appendChild( renderer.domElement );

        var CubeGeometry = new THREE.BoxGeometry( 1, 1, 1 );
        var CubeMaterial = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
        var cube = new THREE.Mesh( CubeGeometry, CubeMaterial );
        scene.add( cube );

        var spheregeometry = new THREE.SphereGeometry(1, 16, 16);
        var spherematerial = new THREE.MeshBasicMaterial({ color: 0x00ff00});
        var sphere = new THREE.Mesh(spheregeometry, spherematerial);
        sphere.position.set(-2.0, 0, 0);
        scene.add(sphere);

        renderer.render(scene, camera);
ruff
  • 61
  • 1
  • 1
  • 3
  • can you create a jsfiddle because I dont see how can this code produce two cubes when only one is added to the scene. – gaitat Apr 16 '15 at 21:17
  • Ok, I think I solved my problem. I was in the process of making the jsFiddle and I removed all the other libraries that I was using. It turns out Box2DWeb.min.js was causing the problem. It works fine in v68 but not in v71. Anyway thanks :) – ruff Apr 16 '15 at 23:55
  • yeah i found this problem too i have created a series of fiddles to demonstarte it too attached in this post, seems the two libraries dont play together very nicely anymore, did you find a way to resolve it with later versions of threejs? here is my post.... https://stackoverflow.com/questions/49784101/javascript-games-threejs-and-box2d-conflicts – Rhys Lloyd Thomas Apr 12 '18 at 11:11

0 Answers0