question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image texture in a cube

See original GitHub issue

I create a cube and I’m trying to apply some texture on it using this code:

function createCube(sx, sy, sz, p, ry, image){

    var texture = THREE.ImageUtils.loadTexture(image);

    var material = new THREE.MeshLambertMaterial( { map: texture } );
    var cube = new THREE.Mesh( new THREE.CubeGeometry( sx, sy, sz ), material );
    cube.position = p;
    cube.rotation.y = ry;
    scene.add(cube);

}

I need to repeat the image only in one cube face like a wallpaper. I have tried to use RepeatWrapping, but it didn’t work and I’m not finding this object in the three.js source code to understand how it works.

Any help?

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nathaliaspatriciocommented, Mar 9, 2012

Ok, I have looked and change my source code to:

function createCube(sx, sy, sz, p, ry, image){

    var texture = THREE.ImageUtils.loadTexture(image);
    texture.repeat.set( 4, 2 );
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping;

    var material = new THREE.MeshLambertMaterial( { map: texture } );
    var cube = new THREE.Mesh( new THREE.CubeGeometry( sx, sy, sz ), material );
    cube.position = p;
    cube.rotation.y = ry;
    scene.add(cube);

}

But everything is strange here. It is not repeating the image along the face. I want to know what’s the meaning of these numbers… I saw in the three.js source code that is a Vector2, but I don’t know what they really do.

Another question is about the image size. Does it matter?

0reactions
karmakumarcommented, Aug 16, 2016

Try this project . Full code available below. https://github.com/karmakumar/threejs_create_plane/tree/dev/three

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Texture a Cube in Blender : 4 Steps - Instructables
Now click on the little button that has the dot in the middle of it towards the right of the Color line in...
Read more >
Tutorial 5 : A Textured Cube
When texturing a mesh, you need a way to tell to OpenGL which part of the image has to be used for each...
Read more >
CubeTexture – three.js docs
CubeTexture. Creates a cube texture made up of six images. ... CubeTexture is almost equivalent in functionality and usage to Texture.
Read more >
100+ Free Texture Cube & Texture Images - Pixabay
Find images of Texture Cube. ✓ Free for commercial use ✓ No attribution required ✓ High quality images.
Read more >
Texturing a cube with different images using OpenGL
so you simply add the x,y to your texture coordinate for each vertex of each face where i is the selected texture and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found