Uncaught TypeError: Cannot set property ‘material’ of undefined
I’ll post the full code:
var container, controls;
var camera, scene, renderergl;
var model, blood, newMaterial;
init();
animate();
function init() {
container = document.createElement('div');
container.className = "experience-div";
$('body').prepend(container);
$('.experience-div').addClass('transformv-active');
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);
scene = new THREE.Scene();
new RGBELoader().setDataType(THREE.UnsignedByteType).load('https://ui-unicorn.co.uk/hostinger-exp/royal_esplanade_1k.hdr', function(texture) {
var envMap = pmremGenerator.fromEquirectangular(texture).texture;
scene.environment = envMap;
texture.dispose();
pmremGenerator.dispose();
var roughnessMipmapper = new RoughnessMipmapper(renderergl);
var loader = new GLTFLoader();
loader.load('sam.gltf', function(gltf) {
model = gltf.scene;
gltf.scene.traverse(function(child) {
if (child.isMesh) {
roughnessMipmapper.generateMipmaps(child.material);
}
});
gltf.scene.scale.set(.0065, .0065, .0065);
gltf.scene.position.set(0, -0.8, 0);
gltf.scene.rotation.set(0, 1.5, 0);
scene.add(model);
roughnessMipmapper.dispose();
});
});
renderergl = new THREE.WebGLRenderer({
antialias: true,
alpha: true
});
renderergl.setPixelRatio(window.devicePixelRatio);
renderergl.setSize(window.innerWidth, window.innerHeight);
renderergl.toneMapping = THREE.ACESFilmicToneMapping;
renderergl.toneMappingExposure = 0.8;
renderergl.outputEncoding = THREE.sRGBEncoding;
renderergl.setClearColor( 0x000000, 0 );
container.appendChild(renderergl.domElement);
$('.experience-div canvas').attr('id', 'canvas');
var pmremGenerator = new THREE.PMREMGenerator(renderergl);
pmremGenerator.compileEquirectangularShader();
}
function FullPage() {
if( $('#showcase-slider').length > 0 ){
$('#showcase-slider').fullpage({
navigation: true,
navigationPosition: 'left',
afterLoad: function(anchorLink, index, direction){
if(index === 1){
$('#about-slide-tx1').css('opacity','0.00');
if ($('body').hasClass('opaci')){
$('.experience-div').fadeTo('slow', 1.00);
$('.home-slide-title').fadeTo('1000', 1.00);
TWEEN.removeAll();
var tweenScale = new TWEEN.Tween(model.scale)
.to({x:.0065, y:.0065, z:.0065}, 2500).easing(TWEEN.Easing.Quadratic.InOut).start();
var tweenRotation = new TWEEN.Tween(model.rotation)
.to({x:0, y:1.5, z:0}, 2500).easing(TWEEN.Easing.Quadratic.InOut).start();
}
$("#fp-nav, .chat-on-page").removeClass('move-right');
$("#fp-nav, .chat-on-page").css({opacity: '1'});
}
if(index === 2){
$('body').addClass('opaci');
if ($('body').hasClass('opaci')){
$('#about-slide-tx1').delay(850).fadeTo(1000, 1.00);
$('.experience-div').fadeTo(500, 0.55);
$('.home-slide-title').fadeTo('1000', 0.00);
TWEEN.removeAll();
var tweenScale3 = new TWEEN.Tween(model.scale)
.to({x:.01, y:.01, z:.01}, 2500).easing(TWEEN.Easing.Quadratic.InOut).start();
var tweenRotation3 = new TWEEN.Tween(model.rotation)
.to({x:0, y:3, z:0}, 2500).easing(TWEEN.Easing.Quadratic.InOut).start();
}
//CHANGE MATERIAL COLOR OF THE BLOOD MESH
//CHANGE MATERIAL COLOR OF THE BLOOD MESH
//CHANGE MATERIAL COLOR OF THE BLOOD MESH
newMaterial = new THREE.MeshStandardMaterial({color: 0xff0000});
model.getObjectById('LowpolyBlood_Bake_Blood_0.001').material = newMaterial;
$("#fp-nav, .chat-on-page").removeClass('move-right');
$("#fp-nav, .chat-on-page").css({opacity: '1'});
}
}
});
}
}
I can’t see any obvious errors…