简体   繁体   English

使用three.js在html5 webgl画布动画中组织对象

[英]Organizing objects in html5 webgl canvas animation with three.js

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: 我想绘制一个3D猫(带有动画),它只不过是一堆3D对象-椭圆体,金字塔,球体等。我有2个问题:

1) Are there any ways to define your own complex geometrical 3D objects rather than standard Three.js objects such as Sphere, Cube... 1)有什么方法可以定义自己的复杂几何3D对象,而不是标准的Three.js对象,例如Sphere,Cube ...

2) When animation the whole cat should I define an animation function for each object? 2)当动画整个猫时,我应该为每个对象定义一个动画功能吗? Is there any way to combine some objects together? 有什么方法可以将某些对象组合在一起?

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. 至于创建自定义对象,就像折线实际上是具有标准线方法(以及特定于对象的方法)的迭代实现的线的集合一样,您将创建一个javascript对象,其中包含创建自定义形状所需的对象。 Here's a good webgl cheat sheet to help you out a bit. 这是一个很好的webgl备忘单,可以帮助您一点。

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). 第二个问题与我们上面描述复杂对象的方式有些相似,尽管您将编写Cat对象的render / animate函数,但将以每个对象为基础处理动画(除了全对象静态运动,想象一下自动扶梯上的猫)。 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 . 最后,我建议您研究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. 这类工作可能不是必需的,但是lisp在CAD脚本世界中非常流行,并且从长远来看,您肯定会成为一个帮手,至少要熟悉一下编码约定,这是很多问题您将在从事此项目的过程中会用多种编程语言回答,但您可能会发现,由围墙两边的工作人员(cad /编程)编写的许多答案会用Lisp写成。 Here's a final general CAD forum that's a great resource for all things CAD. 这是最终的通用CAD论坛 ,它是所有CAD的绝佳资源。

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

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