//Variables for setup
import * as THREE from 'three';
import {FBXLoader} from 'three/addons/loaders/FBXLoader.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
let container;
let camara;
let renderer;
let scene;
function init(){
container= document.querySelector('.scene');
console.log(GLTFLoader);
//Create scene
scene = new THREE.Scene();
const fov=35;
const aspect= container.clientWidth/container.clientHeight;
const near= 0.1;
const far = 1000;
//camara setup
camara = new THREE.PerspectiveCamera(fov,aspect,near, far);
camara.position.set(0,2,10);
const ambient = new THREE.AmbientLight(0x404040, 2);
scene.add(ambient);
const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(10, 25, 20);
scene.add(light);
//renderer setup
renderer = new THREE.WebGLRenderer({antialias:true, alpha:true});
renderer.setSize(container.clientWidth,container.clientHeight);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.outputEncoding = THREE.sRGBEncoding;
container.appendChild(renderer.domElement);
const controls = new OrbitControls(camara, renderer.domElement)
controls.enableDamping = true
controls.target.set(0, 1, 0)
// Setup Textures and the FBX Files URLs
let modelUrl1 = "static/lib/admin-3.2.0/3d_1/FBX/source/Cow.FBX";
let modelUrl2 = "static/lib/admin-3.2.0/3d_1/textures/Cow.tga.png";
let modelUrl3 = "static/lib/admin-3.2.0/3d_1/textures/Eye_Brown.tga.png";
let modelUrl4 = "static/lib/admin-3.2.0/3d_1/textures/Cow_Normals.tga.png";
let modelUrl5 = "static/lib/admin-3.2.0/3d_1/textures/Eye_Shine.tga.png";
// Setup Animations and the FBX Files URLs
let Animate_Sleep = "static/lib/admin 3.2.0/3d_1/FBX/source/animations/Sleep.FBX";
const fbxLoader = new FBXLoader()
fbxLoader.load(modelUrl1, function(fbx) {
//Initialize each png Textures
let textureLoader = new THREE.TextureLoader();
const texture1 = textureLoader.load( modelUrl2 );
texture1.flipY = true;
const texture2 = textureLoader.load( modelUrl3 );
texture2.flipY = true;
const normalTexture = textureLoader.load( modelUrl4 );
normalTexture.flipY = true;
const Eye_Shine = textureLoader.load( modelUrl5 );
normalTexture.flipY = false;
fbx.traverse((child) => {
if ( child.isMesh && child.geometry ) {
// note: for a multi-material mesh, `o.material` may be an array,
// in which case you'd need to set `.map` on each value.s
if (child.name == "Cow_Mesh") {
child.material = new THREE.MeshPhongMaterial({
map:texture1,
normalMap: normalTexture
})}
else if (child.name == "Eye_Left") {
child.material = new THREE.MeshPhongMaterial({
map:texture2,
normalMap: Eye_Shine})
};
if (child.name == "Eye_Right") {
child.material = new THREE.MeshPhongMaterial({
map:texture2,
normalMap: Eye_Shine})
};
child.receiveShadow = true;
child.castShadow = true;
}
});
fbx.scale.setScalar(0.02);
fbx.rotation.x = -1.5;
scene.add(fbx);
// Carga las animaciones
const loaderAnimations = new FBXLoader();
loaderAnimations.load(Animate_Sleep, function (animations) {
// Crea un AnimationMixer
let mixer = new THREE.AnimationMixer(fbx);
mixer.clipAction(animations[0]).play();
});
animate();
});
function animate() {
requestAnimationFrame(animate);
controls.update(scene);
var delta = this.clock.getDelta();
if (this.mixer) this.mixer.update(delta)
renderer.render(scene,camara);
}
}
init()
function onWindowResize() {
camara.aspect = container.clientWidth/container.clientHeight;
camara.updateProjectionMatrix();
renderer.setSize(container.clientWidth, container.clientHeight);
}
window.addEventListener('resize', onWindowResize);
This is the code the animation is not rendering and the console is not reporting any error