Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

How can I apply Texture on Cube using Three.js

    // Make a cube with Lambert material
    // ---------------------------------
    // Lower fragments can increase performance
    var cubeWidth = cubeSize,
        cubeHeight = cubeSize,
        cubeDepth = 10,
        cubeQuality = 1;
    // create the cube's material
    

var cubeMaterial = new THREE.MeshLambertMaterial(
            {
                color: 0xb22222
            }
            );
    
// create a cube with sphere geometry and the meterial

    cube = new THREE.Mesh(
        new THREE.BoxGeometry(
            cubeWidth, 
            cubeHeight, 
            cubeDepth,
            cubeQuality,
            cubeQuality,
            cubeQuality
            ),
        cubeMaterial);
        

        

lift the cube to half of the playing space height

cube.position.z = fieldDepth/2;

set the cube x position in the left of the play field

cube.position.x = -fieldWidth/3;

----------add the cube to the scene-------------------------

scene.add(cube);

I have tried ;

var texture = new THREE.TextureLoader();
    var texture1 = texture.load('scripts/kan.png');
    
    cube = new THREE.Mesh(
        new THREE.BoxGeometry(
            cubeWidth, 
            cubeHeight, 
            cubeDepth,
            cubeQuality,
            cubeQuality,
            cubeQuality
            ));
    
    
    var cubeMaterial = new THREE.MeshBasicMaterial(
        {
             map: texture1
            //color: 0xb22222
        }
        );
    // create a cube with sphere geometry and the meterial
    
    mesh = new THREE.Mesh( cube, cubeMaterial );

And this, but it didn't work

const texture = new THREE.TextureLoader().load( 'kan.png' );
    
    var cubeMaterial = new THREE.MeshLambertMaterial(
        {
            //color: 0xb22222
            map: texture
        }
        );

I am also getting the following error : THREE.Material: 'map' parameter is undefined

question from:https://stackoverflow.com/questions/65860123/how-can-i-apply-texture-on-cube-using-three-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...