简体   繁体   English

如何将多个Blender JSON模型合并到Three.js Object3D对象中?

[英]How do I merge multiple Blender JSON models into a Three.js Object3D object?

How do I merge multiple Blender JSON models into a Three.js Object3D object? 如何将多个Blender JSON模型合并到Three.js Object3D对象中? Google is of no hope as far as I can tell. 据我所知,谷歌没有希望。

What if you merged them Blender-side and then exported as a whole object? 如果将它们合并到Blender端,然后作为一个整体导出,该怎么办?

In Three.js you can merge geometries and if they're identical, also materials, but if you don't have identical geometries and have multple materials, you're out of luck... 在Three.js中,您可以合并几何形状,如果它们相同,也可以合并材料,但是如果您没有相同的几何形状并且具有多种材料,那么您就不走运了...

I am struggling with the same exact question and so far I didn't find any solutions in Three.js itself, so trying to do it Blender-side. 我在同一个确切的问题上苦苦挣扎,到目前为止,我在Three.js本身中没有找到任何解决方案,因此尝试在Blender端进行操作。 On the other hand, hardcoding this engine-side might be easier than using Blender. 另一方面,对该引擎端进行硬编码可能比使用Blender容易。 This is one tough piece of software to understand ^^ 这是一件难以理解的软件^^

Is there a reason you need the exported JSON objects to end up in exactly one Three.js Object3D? 您是否有理由需要导出的JSON对象恰好在一个Three.js Object3D中结束? Is it enough to control both objects with one parent object? 用一个父对象控制两个对象就足够了吗?

You can add the objects as children to an empty parent object and then control that. 您可以将这些对象作为子对象添加到一个空的父对象中,然后对其进行控制。 This gist demos the process. 本要点演示了该过程。

var parent = new THREE.Object3D();
parent.add(blenderObj1);
parent.add(blenderObj2);
parent.scale.set(1,2,0.5);

Edit 编辑

Here's a scene that demos in what you mention in the comments. 这是演示您在评论中提到的场景的场景。 Try changing the number of boxes per side (you'll get side^2 boxes) and toggling the parent. 尝试更改每边的盒子数量(您会得到side ^ 2个盒子)并切换父对象。

Quick side note: As of 4/25/16, there's a bug in Chrome that can cause a texture race condition. 快速附注:从16/4/25开始, Chrome中存在一个错误,错误可能导致纹理竞争状况。 Reloading the page can help if the boxes look funny. 如果框看起来很有趣,则重新加载页面可能会有所帮助。

To address your points: 要解决您的观点:

The parent object must allow users to add and remove objects from the parent, 父对象必须允许用户添加和删除父对象,

Object3D has .add() and .remove() that do just that. Object3D具有.add()和.remove()来执行此操作。

.add ( object, ... )

.remove ( object, ... )

, and the parent must be able to be rotated as a whole. ,并且父级必须能够整体旋转。

This is exactly how parenting works. 这正是养育子女的方式。 Just do something like: 只需执行以下操作:

parent.rotation.x = Math.PI / 2;

And all the children rotate with the parent. 所有的孩子都与父母一起旋转。 Note, they rotate as if the world rotated (since for them, it did). 请注意,它们的旋转就像世界在旋转一样(因为它们旋转了)。 Their individual transforms are untouched. 他们的个人变形未受影响。

Not merging the children into a single parent would create jagged animation. 不将孩子合并到单亲中会产生锯齿状的动画。

Not inherently. 不是天生的。 Assuming you aren't out to reduce draw calls (more on this below), use of a parenting object does not significantly influence the frame rate. 假设您不打算减少绘制调用(请参见下文中的更多内容),则使用育儿对象不会显着影响帧速率。 My quick tests on an old Macbook Air renders 10k objects without any crashes, even if it starts to run hot. 我在旧Macbook Air上进行的快速测试可以渲染1万个对象,即使它开始运行时也不会崩溃。 Performance is going to suffer with 10k objects no matter what you do. 无论您做什么,性能都会受到1万个对象的影响。

Having all your geometry all together will reduce your draw calls and speed things up. 将所有几何图形放在一起将减少绘制调用并加快处理速度。 Keep in mind that all of the geometry will be completely static relative to each other object. 请记住,所有几何图形相对于其他对象都是完全静态的。 So, assuming you can't take the obvious, elegant, and far simpler solution suggested by Scharnvirk (make your merged object in Blender and take that as a single object), you could save a small bit of bandwidth by cloning the geometry on the fly. 因此,假设您无法采用Scharnvirk建议的明显,优雅且简单得多的解决方案(在Blender中创建合并的对象,并将其作为单个对象),则可以通过在桌面上克隆几何来节省少量带宽。飞。 In which case, three.js Geometry has a merge() function 在这种情况下, three.js Geometry具有merge()函数

.merge ( geometry, matrix, materialIndexOffset )

Merge two geometries or geometry and geometry from object (using object's transform)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM