【问题标题】:ThreeJS Animation geometry doesn't update but position does?ThreeJS 动画几何不更新但位置更新?
【发布时间】:2015-12-16 09:07:06
【问题描述】:

我先说我是 Blender / 3DS MAX / ThreeJS 和图形编程的新手。

我从星际争霸编辑器中将异龙(来自星际争霸)拍打翅膀的动画导出为 .m3 文件,然后将其导入 Blender。导出后,我可以将生成的 .json 导入到我的 ES6 应用程序中,但由于某种原因,使用 THREE.Animation,当导入的 Mutalisk 的位置正确更改时,它会左右摆动,但 Mutalisk 对象的实际摆动不会'不会发生。

我的渲染器如下所示:

import THREE from 'three';

export default class Renderer {
  constructor(game, canvas) {
    this.game = game;
    this.canvas = canvas;

    this.scene = new THREE.Scene();

    this.camera = new THREE.PerspectiveCamera(75, this.canvas.width / this.canvas.height, 1, 10000);
    this.camera.position.z = 2;
    this.camera.position.y = 1;

    this.clock = new THREE.Clock;

    this.renderer = new THREE.WebGLRenderer({ canvas: this.canvas });
    this.renderer.setSize( this.canvas.width, this.canvas.height );
  }

  // called by my Game class, which waits for the mesh to load before attempting to add it to the scene
  addMeshToScene(mesh) {
    this.mesh = mesh;

    this.scene.add(this.mesh);

    this.animation = new THREE.Animation(
      this.mesh,
      this.mesh.geometry.animations[ 2 ]
    );

    this.animation.play();
  }

  renderFrame() {
    THREE.AnimationHandler.update(this.clock.getDelta());

    this.renderer.render(this.scene, this.camera);
  }
}

这是渲染。正如我所说,我浏览器中的异龙在 Y 轴上弹跳,但没有摆动。

谁能解释一下为什么会发生运动,而不是拍打?

编辑:这是我的 Blender 导出设置。

【问题讨论】:

  • 有趣的是,我刚刚注意到我所有的动画[] 每个都有 44 个步骤。我猜这可能是我的 Blender 导出的问题。
  • 你能报告你在导出器中选择了哪些动画参数吗?
  • 如何实例化Renderer?你在哪里打电话addMeshToScene,在哪里打电话renderFrame
  • 在我的 Game 类中,有一个 setup 方法只调用了this.setRenderer(new Renderer(this, this.canvas))。我不认为那部分代码不是问题。在 Blender 中:几何:顶点、面、法线、UV、骨骼、蒙皮。应用修改器(选中)几何 UInt16Array。骨骼动画,休息。嵌入动画。设置,复制纹理。
  • 我用我当前的代码创建了一个仓库。我所说的一切都在client/js/renderer.js

标签: javascript 3d three.js ecmascript-6 blender


【解决方案1】:

解决了。问题是材料必须处于蒙皮模式才能正确包裹骨架。当我从 JSON 创建网格时,我必须设置 material.skinning = true

import THREE from 'three';

export default class Mesh {
  constructor(name) {
    this.name = name;
    this.loaded = false;
    this.filepath = `./meshes/${this.name}.json`
    this.load();
  }

  load() {
    var loader = new THREE.JSONLoader();
    loader.load(this.filepath, (geometry) => {
      this.geometry = geometry;
      var material = new THREE.MeshBasicMaterial( { color: 0x00ffff, wireframe: true } );
      material.skinning = true; // this is where the magic happens
      this.mesh = new THREE.SkinnedMesh(geometry, material);
      this.loaded = true;
    });
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-29
    • 2014-06-21
    • 2015-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多