使用 Three.js 组织 html5 webgl canvas 动画中的对象
我想画一只 3D 猫(带动画),它只不过是一堆 3D 对象 - 椭球体、金字塔、球体等。 我有两个问题:
1)有什么方法可以定义自己的复杂几何 3D 对象,而不是标准的 Three.js 对象,例如球体、立方体...
2)当为整只猫制作动画时,我应该为每个猫定义一个动画函数目的?有什么办法可以将一些对象组合在一起吗?
I want to draw a 3D cat(with animation) which is no more than a bunch of 3D objects - ellipsoids, pyramids, spheres, etc.
And I have 2 questions:
1) Are there any ways to define your own complex geometrical 3D objects rather than standard Three.js objects such as Sphere, Cube...
2) When animation the whole cat should I define an animation function for each object? Is there any way to combine some objects together?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于问题一,我建议阅读参数驱动建模 ,这将使您能够制作一致的复杂对象,而无需每次创建对象时都重新发明轮子。至于创建自定义对象,就像多段线实际上是具有标准线方法(以及特定于对象的方法)的迭代实现的线的集合一样,您将创建一个 javascript 对象,其中包含以下集合:创建自定义形状所需的对象。 这里有一个很好的 webgl 备忘单,可以为您提供一些帮助。
问题二有点类似于我们上面描述复杂对象的方式,因为当您编写 Cat 对象渲染/动画函数时,您将在每个对象的基础上处理动画(完整对象静态运动除外,想象一下一只猫在自动扶梯上)。约束或参数驱动设计将再次成为您的救星,因为两个或多个对象部分叠加的事实并不意味着这些对象是显式链接的。
作为尾注,我建议您查看 clojurescript。对于此类工作来说可能没有必要,但 lisp 在 CAD 脚本世界中非常流行,从长远来看,至少熟悉编码约定肯定会给自己带来好处 - 很多问题在从事这个项目时,您将得到各种编程语言的答案,但您可能会发现,许多答案是由在栅栏两侧工作的人员(CAD/编程)编写的用 lisp 编写。这是最后一个通用 CAD 论坛,它是所有 CAD 相关内容的重要资源。
For question one I'd recommend reading up on parameter driven modelling, this will allow you to make consistent complex objects without reinventing the wheel every time you create one. As for creating the custom objects, much like in the way polylines are are effectively a collection of lines with iterative implementations of the standard line methods (as well as object-specific methods) you'd create a javascript object which contains a collection of the objects necessary to create your custom shape. Here's a good webgl cheat sheet to help you out a bit.
Question two is somewhat similar to the way we've described complex objects above in that while you'll write a Cat object render / animate function, you'll handle the animation on a per object basis (with the exception full object static movement, imagine a cat on an escalator). Once again constraint, or parameter driven design will be your saviour here since the fact that two or more objects are partially superposed in no way means that the objects are explicitly linked.
As an end note I'd recommend looking into clojurescript. It might not be necessary for this type of work but lisp is very popular in the CAD scripting world and you'd definitely be doin' yourself a favour in the long run by at least familiarising yourself with the coding conventions - a lot of the questions you're goin' to have whilst working on this project will be answered in a variety of programming languages but you'll likely find that many of the answers that were written by folk working on both sides of the fence (cad/programming) will be written in lisp. Here's a final general CAD forum that's a great resource for all things CAD.