in threejs i want to change the skybox textures dynamically, am added 2 scenes here so i attached one scene to my skybox, so i decided to remove the skybox before switch from on texture to another, and the skybox textures are reflecting Environmentmap on the object, if i change the textures by select from the given list, am checking textures with the switch case and adding the texture , the reflection on the object is working, but if i switch skyBoxMaterial to selected texture Enviromentmap changed successfully but the reflection on the object is not changed to current Enviromentmap
Following is my code:
function envmap(envmap)
{
switch(envmap)
{
case 'canary':
var urls = [
'textures/cube/canary/pos-x.png',
'textures/cube/canary/neg-x.png',
'textures/cube/canary/pos-y.png',
'textures/cube/canary/neg-y.png',
'textures/cube/canary/pos-z.png',
'textures/cube/canary/neg-z.png'
];
//var cubemap = THREE.ImageUtils.loadTextureCube(urls); // load textures
break;
case 'Park2':
var urls = [
'textures/cube/Park2/posx.jpg',
'textures/cube/Park2/negx.jpg',
'textures/cube/Park2/posy.jpg',
'textures/cube/Park2/negy.jpg',
'textures/cube/Park2/posz.jpg',
'textures/cube/Park2/negz.jpg'
];
//var cubemap = THREE.ImageUtils.loadTextureCube(urls); // load textures
break;
case 'Park3Med':
var urls = [
'textures/cube/Park3Med/px.jpg',
'textures/cube/Park3Med/nx.jpg',
'textures/cube/Park3Med/py.jpg',
'textures/cube/Park3Med/ny.jpg',
'textures/cube/Park3Med/pz.jpg',
'textures/cube/Park3Med/nz.jpg'
];
//var cubemap = THREE.ImageUtils.loadTextureCube(urls); // load textures
break;
case 'Bridge2':
var urls = [
'textures/cube/Bridge2/posx.jpg',
'textures/cube/Bridge2/negx.jpg',
'textures/cube/Bridge2/posy.jpg',
'textures/cube/Bridge2/negy.jpg',
'textures/cube/Bridge2/posz.jpg',
'textures/cube/Bridge2/negz.jpg'
];
//var cubemap = THREE.ImageUtils.loadTextureCube(urls); // load textures
break;
case 'pisa':
var urls = [
'textures/cube/pisa/px.png',
'textures/cube/pisa/nx.png',
'textures/cube/pisa/py.png',
'textures/cube/pisa/ny.png',
'textures/cube/pisa/pz.png',
'textures/cube/pisa/nz.png'
];
//var cubemap = THREE.ImageUtils.loadTextureCube(urls); // load textures
break;
default:
var urls = [
'textures/cube/canary/pos-x.png',
'textures/cube/canary/neg-x.png',
'textures/cube/canary/pos-y.png',
'textures/cube/canary/neg-y.png',
'textures/cube/canary/pos-z.png',
'textures/cube/canary/neg-z.png'
];
break;
}
var cubemap = THREE.ImageUtils.loadTextureCube(urls,undefined, render); // load textures
cubemap.needsUpdate = true;
cubemap.format = THREE.RGBFormat;
var shader = THREE.ShaderLib['cube']; // init cube shader from built-in lib
shader.uniforms['tCube'].value = cubemap; // apply textures to shader
// create shader material
var skyBoxMaterial = new THREE.ShaderMaterial( {
fragmentShader: shader.fragmentShader,
vertexShader: shader.vertexShader,
uniforms: shader.uniforms,
depthWrite: false,
side: THREE.BackSide
});
alert(skybox);
if (skybox)
{
sceneCube.remove(skybox);
}
skybox = new THREE.Mesh( new THREE.BoxGeometry( 1000, 1000, 1000 ), skyBoxMaterial );
sceneCube.add( skybox );
var reflectionMaterial = new THREE.MeshBasicMaterial({
color: 0xcccccc,
envMap: cubemap
});
var object = scene.getObjectByName ("myname", true);
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh )
{
//child.geometry.computeFaceNormals();
var geometry = child.geometry;
//console.log(geometry);
material = child.material;
material.transparent = true;
child.material.needsUpdate = true;
child.material.map = reflectionMaterial;
mesh = new THREE.Mesh(geometry, reflectionMaterial);
scene.add(mesh);
}
});
}
three.js
, notthree.min.js
for that purpose. Ask questions about three.js, not help-me-debug-my-code-questions. 2. Remove theneedsUpdate
flags, and add them only when needed. 3. What ischild.material.map = reflectionMaterial
??? – WestLangleychild.material.map = reflectionMaterial
is the traverse of the object with the wherereflectionMaterial
isvar reflectionMaterial = new THREE.MeshBasicMaterial({ color: 0xcccccc, envMap: cubemap });
– Jothi KannanTypeError: offset is undefined
in three.js online25341
i will try to fix it – Jothi Kannanchild.material.map
is aTHREE.Texture
.reflectionMaterial
is aTHREE.MeshBasicMaterial
. – WestLangleyreflectionMaterial
tochild.material.map
?? actually i want a Environment for an object, and that the Environment reflection will apply to my model as like in the attached image imgur.com/5ZGmwpv, it is working fine, but while switch from one Environment to others i can't override the reflection on object it still on the old environment reflection – Jothi Kannan