Threejs. How to make the animation of multi-gltf model?

I am working on a DOTA2 website and try to add heros’ 3D model in the web. I extracted a hero’s model, but it includes many gltf files and textures. One of files is the hero’s body and the rest are asscesories, such as hat, weapon, clouth.

I try to play the animation of the model, but only the body part gltf file includes animations, the rest part doesn’t have any animation. Thus, when I play the animation, only the hero’s body is acting, the rest part is fixed.

Here is my code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import * as THREE from 'three'
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { useRef, useEffect } from 'react'
import './App.css'
import { AmbientLight } from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
const modelList = [
'warlock.gltf',
'warlock_bag.gltf',
'warlock_bracers.gltf',
'warlock_cape.gltf',
'warlock_lantern.gltf',
'warlock_robe.gltf',
'warlock_shoulder.gltf',
'warlock_staff.gltf'];
function App() {
const mount = useRef(null);
const mixer = useRef(null);
useEffect(() => {
const loader = new GLTFLoader();
const scene = new THREE.Scene();
const clock = new THREE.Clock();
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
1000
);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
mount.current.appendChild(renderer.domElement);
const ambientLight = new AmbientLight(0xffffff, 1);
scene.add(ambientLight);
const grayColor = new THREE.Color(0.5, 0.5, 0.5);
scene.background = grayColor;
camera.position.z = 5;
camera.position.y = 5;
camera.position.x = 5;
camera.lookAt(0, 0, 0);
const axesHelper = new THREE.AxesHelper(5);
scene.add(axesHelper);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
var character = null;
loader.load(`model/warlock.gltf`, (gltf) => {
character = gltf.scene;
scene.add(character);
mixer.current = new THREE.AnimationMixer(gltf.scene);
const animation = gltf.animations[1];
if (animation) {
const action = mixer.current.clipAction(animation);
action.play();
}
LoadOtherPart();
console.log(gltf);
animate();
});
function LoadOtherPart() {
modelList.forEach((model) => {
loader.load(`model/${model}`, (gltf) => {
if(model !== 'warlock.gltf'){
character.add(gltf.scene);
}
});
})
}
function animate() {
requestAnimationFrame(animate);
if(mixer.current){
const delta = clock.getDelta();
mixer.current.update(delta);
}
renderer.render(scene, camera);
controls.update();
}
return () => {
mount.current.removeChild(renderer.domElement);
};
}, []);
return (
<div ref={mount}>
</div>
)
}
export default App;
</code>
<code>import * as THREE from 'three' import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; import { useRef, useEffect } from 'react' import './App.css' import { AmbientLight } from 'three'; import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'; const modelList = [ 'warlock.gltf', 'warlock_bag.gltf', 'warlock_bracers.gltf', 'warlock_cape.gltf', 'warlock_lantern.gltf', 'warlock_robe.gltf', 'warlock_shoulder.gltf', 'warlock_staff.gltf']; function App() { const mount = useRef(null); const mixer = useRef(null); useEffect(() => { const loader = new GLTFLoader(); const scene = new THREE.Scene(); const clock = new THREE.Clock(); const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 ); const renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); mount.current.appendChild(renderer.domElement); const ambientLight = new AmbientLight(0xffffff, 1); scene.add(ambientLight); const grayColor = new THREE.Color(0.5, 0.5, 0.5); scene.background = grayColor; camera.position.z = 5; camera.position.y = 5; camera.position.x = 5; camera.lookAt(0, 0, 0); const axesHelper = new THREE.AxesHelper(5); scene.add(axesHelper); const controls = new OrbitControls(camera, renderer.domElement); controls.enableDamping = true; controls.dampingFactor = 0.05; var character = null; loader.load(`model/warlock.gltf`, (gltf) => { character = gltf.scene; scene.add(character); mixer.current = new THREE.AnimationMixer(gltf.scene); const animation = gltf.animations[1]; if (animation) { const action = mixer.current.clipAction(animation); action.play(); } LoadOtherPart(); console.log(gltf); animate(); }); function LoadOtherPart() { modelList.forEach((model) => { loader.load(`model/${model}`, (gltf) => { if(model !== 'warlock.gltf'){ character.add(gltf.scene); } }); }) } function animate() { requestAnimationFrame(animate); if(mixer.current){ const delta = clock.getDelta(); mixer.current.update(delta); } renderer.render(scene, camera); controls.update(); } return () => { mount.current.removeChild(renderer.domElement); }; }, []); return ( <div ref={mount}> </div> ) } export default App; </code>
import * as THREE from 'three'
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { useRef, useEffect } from 'react'
import './App.css'
import { AmbientLight } from 'three'; 
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';

const modelList = [
  'warlock.gltf',
  'warlock_bag.gltf',
  'warlock_bracers.gltf',
  'warlock_cape.gltf',
  'warlock_lantern.gltf',
  'warlock_robe.gltf',
  'warlock_shoulder.gltf',
  'warlock_staff.gltf'];

function App() {
  const mount = useRef(null);
  
  const mixer = useRef(null);


  useEffect(() => {
    const loader = new GLTFLoader();
    const scene = new THREE.Scene();
    const clock = new THREE.Clock();
    const camera = new THREE.PerspectiveCamera(
      45,
      window.innerWidth / window.innerHeight,
      0.1,
      1000
    );  

    const renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    mount.current.appendChild(renderer.domElement);

    const ambientLight = new AmbientLight(0xffffff, 1);
    scene.add(ambientLight);
    
    const grayColor = new THREE.Color(0.5, 0.5, 0.5);
    scene.background = grayColor; 

    camera.position.z = 5;
    camera.position.y = 5;
    camera.position.x = 5;
    camera.lookAt(0, 0, 0);

    const axesHelper = new THREE.AxesHelper(5);
    scene.add(axesHelper);

    const controls = new OrbitControls(camera, renderer.domElement); 
    controls.enableDamping = true; 
    controls.dampingFactor = 0.05;

    var character = null;

    loader.load(`model/warlock.gltf`, (gltf) => { 
        character = gltf.scene;
        scene.add(character);
        mixer.current = new THREE.AnimationMixer(gltf.scene);  

        const animation = gltf.animations[1];  
        if (animation) {  
          const action = mixer.current.clipAction(animation); 
          action.play();
        } 

        LoadOtherPart();

        console.log(gltf);
        animate();
    });

    function LoadOtherPart() {
      modelList.forEach((model) => {
        loader.load(`model/${model}`, (gltf) => {
          if(model !== 'warlock.gltf'){
            character.add(gltf.scene);
          }
        });
      })
    }
  
    function animate() {  
      requestAnimationFrame(animate); 

      if(mixer.current){
        const delta = clock.getDelta();
        mixer.current.update(delta);  
      }
      
      renderer.render(scene, camera);  
      controls.update(); 
    }

    return () => {  
      mount.current.removeChild(renderer.domElement);  
    };
  }, []);

  return (
    <div ref={mount}>
    </div>
  )
}

export default App;

I thought the rest part should be the children of th body part, and the gltf file may include the relative position data. I try it, but it still not work. Is it possible only use the threejs to achieve that accessories animate with the body properly? How can I solve the problem?

Thank you so much!

New contributor

Malakanata Sublahamatina is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật