spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » THREE JS » Page 1
Three.js Efficiently Mapping Uvs to Plane
You want to be able to modify the UVs of a PlaneGeometry so a repeated texture always renders the same size, regardless of the dimensions of the plane. This is an alternative to setting texture.repeat values. Here is the pattern to follow: // geometry var width = 20; // width of plane in world units var height = 10; // height of plane in world units var size = 5; // texture block size in wor

Categories : Three Js

Object always in front of camera
if i understand you right, the object needs to reposition in front of the camera, and look at the camera. try this: function render() { camera.updateProjectionMatrix(); var zCamVec = new THREE.Vector3(0,0,1); var position = camera.localToWorld(zCamVec); obj.position.set(position.x, position.y, position.z); obj.lookAt(camera.position); renderer.render(scene, camera); }

Categories : Three Js

Turning an SVG strip into a 3d flat ring
You should be able to achieve that with the Mod3 library (it's Bend modifier in particular) and the three.js plugin it comes with. Be sure to check our the three.js example the library comes with. Off the top of my head, you can try this after importing the Mod3 library: var mstack = new MOD3.ModifierStack( MOD3.LibraryThree, YOUR_MESH_HERE ).worker( true ); var bend = new MOD3.Bend( ); bend.of

Categories : Three Js

How to change colour of CubeGeometry with Three.js?
I would use a MeshFaceMaterial. Check this fiddle function setColours() { for (var i = 0; i < 6; i++) { box.material.materials[i].color.setHex(changeColours[i]); } } var startMaterials = []; for(var i = 0; i < 6; i++){ startMaterials.push(new THREE.MeshLambertMaterial({color: startColours[i]})); } var material = new THREE.MeshFaceMaterial(startMaterials); var geometry = new THR

Categories : Three Js

three.js shadow map shows on back side issue. Is there a work around?
Easy fix: light.shadowBias = 0.001; instead of light.shadowBias = -0.001; I've seen examples on the web using negative bias. I'm not sure if that is correct behaviour. Good luck! UPDATE You will see some shadow acne on the light terminal on the sphere. This appears to be an issue with three.js shadow mapping methods and is due for an update AFAIK.

Categories : Three Js

Threejs normal values in shader are set to 0
In your vertex shader the vec3 normal should be an attribute (since each vertex has a normal) not a uniform: attribute vec3 normal; Here is the working version of your code.

Categories : Three Js

Why do I need to define a precision value in webgl shaders?
There is no default precision in WebGL fragment shaders. (High precision is default for vertex shaders.) The easiest solution is to add precision highp float; to all of your fragment shaders, which will eliminate the need to define the precision for all floating point vector variables, but generally, precision mediump float; will be preferable, for performance. I do not advise lowp; the goo

Categories : Three Js

three.js maintaining creases when smooth shading custom geometry
WestLangley is correct in the comment above. To get the sharp edges I wanted, I simply duplicated vertices that were on "creases" while constructing my geometry. Then I used the standard computeVertexNormals() function included in the THREE.Geometry() prototype. I was constructing my geometry with a home-made 'loft' function: basically iterating through an array of shapes (using i) and creating

Categories : Three Js

threejs selecting different parts of a mesh
You may create additional attribute for each triangle, that would be color of the bodypart that it belongs to. So, all triangles of the left leg would be red, all triangles of right leg would be blue etc. Render your model normally, and add second pass where you would render triangles colored in the way described above, so no shading at all. Then, you could get your mouse position where the user

Categories : Three Js

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.applyMatrix( 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.69

Categories : Three Js

shadowCamera does not follow SpotLigth rotation
One solution is to add light.target as a child of the scene. scene.add( light.target ); If, instead, you had an object in your scene as the target, you could use this pattern: scene.add( myObject ); spotLight.target = myObject; For further information, see the three.js github post https://github.com/mrdoob/three.js/issues/5555. updated fiddle: http://jsfiddle.net/95t964o0/8 three.js r.69

Categories : Three Js

three.js strange behaviour on transparent materials
What I have done in my THREE.js application is disable transparency completely on all your materials. Then I enable "alphaTest" parameter on my materials. What this will do is disable smooth alpha, and use a cut-off value for either transparent, or not transparent. Here are my settings for materials: specular: new THREE.Color( 0x101010 ), shininess: 40, alphaTest: 0.15, color: new THREE.Color( 0

Categories : Three Js

Stereo effect and event listener in threejs
There are game extensions available for Three.js grouped in a library called THREEx. You should take a look at threex.domevents which adds typical Dom events to elements in the canvas.

Categories : Three Js

3 and 4 degree curves in three.js
I suggest to implement your own calculation algorithm, it is fairly easy, the learning process is short and worth the time invested. Check this page: http://pomax.github.io/bezierinfo/ It describes a method (language agnostic) that you can calculate Beziér curves with any number of control points, although the a calculation that is specific to a certain number of control points (like cubic or qu

Categories : Three Js


Recently Add
Lock multiple Three.js meshes in relation to one another
Three.js Efficiently Mapping Uvs to Plane
Object always in front of camera
Turning an SVG strip into a 3d flat ring
How to change colour of CubeGeometry with Three.js?
three.js shadow map shows on back side issue. Is there a work around?
Threejs normal values in shader are set to 0
Why do I need to define a precision value in webgl shaders?
three.js maintaining creases when smooth shading custom geometry
threejs selecting different parts of a mesh
Three.js - Can I 'apply' position, rotation, and scale to the geometry?
shadowCamera does not follow SpotLigth rotation
three.js strange behaviour on transparent materials
Stereo effect and event listener in threejs
3 and 4 degree curves in three.js
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.