Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

骨骼glb模型导入后,无法正常显示(面会出现扭曲和错乱) #642

Open
jsmask opened this issue Jul 25, 2024 · 0 comments
Labels

Comments

@jsmask
Copy link

jsmask commented Jul 25, 2024

maptalks-three

把带有骨骼的模型导入进去,面会出现扭曲和错乱,而把一个没有骨骼的模型导入就显示正常,应该部分模型才会这样,因为官方机器人的骨骼却是正常的,暂时不明白什么原因。
代码如下:

function addGltf() {
    clock = new THREE.Clock();
    const dracoLoader = new DRACOLoader();
    dracoLoader.setDecoderPath("/draco/");
    let loader = new GLTFLoader();
    loader.setDRACOLoader(dracoLoader);
    loader.load('/models/pikachu.glb',(gltf) => {
        animations = gltf.animations;
        model = gltf.scene;
        model.rotation.x = Math.PI / 2;
        model.rotation.y = -Math.PI / 3;
        model.scale.setScalar(.1);
        scene.add(model)
        addAnimations()

        activeAction = actions["Idle"];
        activeAction.play()
        model.position.copy(threeLayer.coordinateToVector3(map.getCenter()));
        animate();
    });
}

function addAnimations() {
    mixer = new THREE.AnimationMixer(model);
    actions = {};

    for (let i = 0; i < animations.length; i++) {
        let clip = animations[i];
        let action = mixer.clipAction(clip);
        actions[clip.name] = action;
        action.clampWhenFinished = true;
        action.loop = THREE.Loop;
    }
}

function animate() {
    let dt = clock.getDelta();
    if (mixer) mixer.update(dt);
    requestAnimationFrame(animate);
    if (threeLayer._needsUpdate) {
        threeLayer.redraw();
    }
}

模型资源地址:
https://sketchfab.com/3d-models/pikachu-37c740f674cd4719a1d1d2970bbe8c30

@deyihu deyihu added the bug label Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants