How to connect Threejs to React?

Here is an example of how to set this up (see demo): import React, { Component } from ‘react’ import * as THREE from ‘three’ class Scene extends Component { constructor(props) { super(props) this.start = this.start.bind(this) this.stop = this.stop.bind(this) this.animate = this.animate.bind(this) } componentDidMount() { const width = this.mount.clientWidth const height = this.mount.clientHeight const scene … Read more

catch the click event on a specific mesh in the renderer

You can generate a callback like this. First define your callback function for each object: mesh.callback = function() { console.log( this.name ); } Then follow the standard picking pattern: var raycaster = new THREE.Raycaster(); var mouse = new THREE.Vector2(); function onDocumentMouseDown( event ) { event.preventDefault(); mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 – … Read more

Three.js – Can I ‘apply’ position, rotation, and scale to the geometry?

You can apply an object’s transform to the object’s geometry directly, and then reset the position, rotation, and scale like so: object.updateMatrix(); object.geometry.applyMatrix4( object.matrix ); object.position.set( 0, 0, 0 ); object.rotation.set( 0, 0, 0 ); object.scale.set( 1, 1, 1 ); object.updateMatrix(); three.js r.150

How to change face color in Three.js

Update library to r53. Add vertexColors: THREE.FaceColors in material. And finally use face.color.setRGB( Math.random(), Math.random(), Math.random()). Now no need to traverse loop for 4 sides (a,b,c,d) for THREE.Face4 or 3 sides (a,b,c) for THREE.Face3. This works in both WebGL and Canvas rendering. Example three.js r53

Three.js and loading a cross-domain image

Update In newer versions of THREE.js cross origin images are handled by default. THREE.ImageUtils.loadTexture is deprecated. It’s common to use TextureLoader const loader = new THREE.TextureLoader(); const mapOverlay = loader.load(‘http://i.imgur.com/3tU4Vig.jpg’); Original Answer This works THREE.ImageUtils.crossOrigin = ”; var mapOverlay = THREE.ImageUtils.loadTexture(‘http://i.imgur.com/3tU4Vig.jpg’); Here’s a sample var canvas = document.getElementById(“c”); var renderer = new THREE.WebGLRenderer({canvas: canvas}); var … Read more

Three.js/WebGL: Large spheres appear broken at intersection

The short answer, set your z near plane further away Change camera = new THREE.PerspectiveCamera( 100, window.innerWidth / window.innerHeight, 0.1, 3500000); to var zNear = 1000; var zFar = 3500000; camera = new THREE.PerspectiveCamera( 100, window.innerWidth / window.innerHeight, zNear, zFar); Note: I don’t know if 1000 will work, if it doesn’t try 10000. A zBuffer, … Read more

three.js transparent object occlusion

Yes, in three.js you can create an object that is invisible, but still occludes other objects as if it were visible. To do that, you need to use two features available in three.js: Object3D.renderOrder and Material.colorWrite. You need to make sure the invisible object is rendered prior to the object(s) it must occlude. You control … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)