user1252381
user1252381

Reputation: 11

three.js - Cannot call method 'loadTexture' of undefined

Sorry for my English. I've got a problem while working with Three.js. In every example of loading a texture I see this code:

var map = THREE.ImageUtils.loadTexture( "obj/textures/textures38.jpg" );
    map.wrapS   = map.wrapT = THREE.RepeatWrapping;
    map.repeat.set( 3, 3 );

Could you tell me, why can i get messages like

Uncaught TypeError: Cannot call method 'loadTexture' of undefined 

This works well:

var material=new THREE.MeshPhongMaterial({color:16777215,map:ImageUtils.loadTexture("obj/textures/textures38.jpg")});

P.S. Three.js version that I currently use is not last

Thank you.

Upvotes: 1

Views: 1231

Answers (2)

nale
nale

Reputation: 1

I used

import { BasisTextureLoader } from './jsm/loaders.basisTexureLoader.js'; 
const loadersvariable = BasisTextureLoader.load("img.jpg");

You need to change permissions on the folder and file or you will get a 403 forbidden error. Point the import path to the dependency to the three.js loader folder but it all has to be together cause all the file link together then you have to call the variable from the file for it to be live without calling the variable from the file you get uncaught referenceError: BasisTextureLoader is not defined

or you can do

<script type="module"> import { TextureLoader } from './src/loaders/TextureLoader.js';
const imagevariablename = new Textureloader.load("image.jpg");
also the displacementmap of examples folder in three.js has a working texture.loader already to copy

Upvotes: 0

mrdoob
mrdoob

Reputation: 19592

P.S. Three.js version that I currently use is not last

You just answered your own question. Probably that version didn't have ImageUtils namespaced yet. Always recommended using the latest version.

Upvotes: 1

Related Questions