Is there any example of how to set a texture of 3DModel through Javascript?
I tried following but I always get "Resource is not defined" error:
// Create a new Resource with the file's URI as the argument
modelResource = new Resource( "pdf://sphere.u3d" );
// use Scene method "addModel" with Resource as an argument,
// returns top level node from loaded 3D file
model = scene.addModel( modelResource );
// Create a new Resource with the file's URI as the argument
imageResource = new Resource( "pdf://grid.jpg" );
// use the Image constructor with the Resource as an argument,
image = new Image( imageResource );
// set the loaded 3D model's diffuse texture to the image
model.material.diffuseTexture.setImage( image );
// loading of resources can be inlined if they are only used once
bump = new Image( new Resource( "pdf://knurl.jpg" ) );
// set the loaded 3D model's bump texture to the image
model.material.bumpTexture.setImage( bump );
I have the same problem, i cant change the material texture of my 3D object.
I see in the documentation JS 3D that this function setImage is deprecated
here is my code above, I want to change the texture of the mesh material which is called "ground"
txResource = new Resource("pdf://toto.jpg");
txImage = new Image(txResource);
mshMatl = scene.meshes.getByName("ground").material;
mshMatl.diffuseTexture.setImage(txImage);
anynody know how to change the material texture by a file ressource ?
thanks
regards
Hi
thanks for your response
Unfortunately this does not work
i have integrated the picture toto.jpg in the pdf resource file
and I have integrated this code into a file. js :
var _mat = scene.meshes.getByName( "ground" ).material;
var _tex = new Image( new Resource( "pdf://toto.jpg" ) );
_mat.diffuseTexture.image = _tex;
in the console debug appear on line 3 (_mat.diffuseTexture.image = _tex;) :
"Code: 45(0x2d): Object is invalid"
I specify that this 3D mesh ground contains an textural material already existing in the U3D file
an idea about this problem please ?
thanks for your help
North America
Europe, Middle East and Africa
Asia Pacific