1

I'm trying to display shapes in three.js. Unfortunately nothing is displayed and I can't really figure out what I am missing. The set up is basically as in the following code snippet

let canvas = document.getElementById(this.canvasId);
this.scene = new Scene();
this.renderer = new WebGLRenderer({canvas: canvas});

//create the camera and set the viewport
let width = canvas.clientWidth;
let height = canvas.clientHeight;

canvas.width = width;
canvas.height = height;
this.renderer.setViewport(0, 0, width, height);

this.camera = new OrthographicCamera(width / -2, width/2, height/-2, height/2, -500, 1000);

//create a square as shape
let shape = new Shape();
shape.moveTo(100, 100);
shape.lineTo(200, 100);
shape.lineTo(200, 200);
shape.lineTo(100,200);
shape.lineTo(100,100);

let shapeGeom = new ShapeGeometry(shape);
let shapeMaterial = new MeshBasicMaterial({color: 0x00ff00});
let shapeMesh = new Mesh(shapeGeom, shapeMaterial);
shapeMesh.position.set(200, 200, 0);
this.scene.add(shapeMesh)

//render
this.renderer.render(this.scene, this.camera);

Thanks for any help!

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • For one thing, see https://stackoverflow.com/questions/17558085/three-js-orthographic-camera/17567292#17567292. – WestLangley May 30 '17 at 15:43
  • Thanks @WestLangley that helped. I changed the values for top & bottom boundaries. Could you maybe explain why it is not possible to have a negative value for the top and a positive one for the bottom. What if my world coordinates are 'upside down'? – Janekdererste May 30 '17 at 16:15
  • three.js uses a right-handed-coordinate system, so your world coordinates should be, too. – WestLangley May 30 '17 at 16:32
  • Okay, Thanks for your help! – Janekdererste May 30 '17 at 17:10

0 Answers0