opengl-esthree.jsmappingtextures

Non-radial texture mapping over a ring geometry in WebGL using Three.js


I am trying to simulate image deformation effects using textures over 2D geomtries using the ThreeJS library. I want to apply a texture image over a hollow circle (basically, a ring built by the THREE.RingGeometry function) and obtain the results shown at this image:

Texture image and desired results

Following I show the results I am obtaining in my scene both for the solid ring and its wireframed version:

Texture applied over the ring and its corresponding wireframed version

The problem is that, as you see, the texture is been applied in a radial way, from the center of the ring to the outside. However, what I really need is to apply the texture image on a concentric circle way, as shown in the first image of this question.

The idea is to produce a deformed version of the original texture over a ring shape. I would like to know how this effect can be programmatically achieved through Three.js in such a way that the destination shape can be any arbitrary 2D geometry .

Following, there is the relevant code I am using to draw my scene:

var texture = THREE.ImageUtils.loadTexture('./images/texture.png');

var wireRing = new THREE.Mesh(new THREE.RingGeometry(10, 20, 50, 5, 0, Math.PI * 2), new THREE.MeshBasicMaterial({map: texture, wireframe: true}));
wireRing.position.set(-25, 50, 0);
scene.add(wireRing);

var ring = new THREE.Mesh(new THREE.RingGeometry(10, 20, 50, 5, 0, Math.PI * 2), new THREE.MeshBasicMaterial({map: texture}));
ring.position.set(25, 50, 0);
scene.add(ring);

Solution

  • You just need to change the UV mapping in RingGeometry like so:

    uvs.push( new THREE.Vector2( o / thetaSegments, i / phiSegments ) );
    

    Also, if you want to rotate the texture around the ring, you instantiate the RingGeometry by varying the thetaStart parameter:

    var geometry = new THREE.RingGeometry( 10, 20, 50, 5, thetaStart, Math.PI * 2 );
    

    three.js r.67