如何在 Flash 中沿着 3D 立方体的边旋转渐变 - ActionScript 3.0

发布于 2024-08-02 20:23:11 字数 847 浏览 8 评论 0原文

你好,我要实现的目标是,用鼠标操纵 3D 立方体,每面墙上都有渐变填充。

我发现了一些与渐变和 3D 旋转立方体相对应的源代码,但问题是:

当我将这两个东西放在一起时,效果看起来像是立方体是一个线框,对隐藏在第一个平面纯黑色背景后面的某些渐变背景具有透明度。渐变始终保持静止。

旋转/显示立方体的方法在输入三个参数 rotx .roty, rotz 时得到,我想利用它并将其应用于每侧显示的渐变。渐变有自己的矩阵,但我不知道如何以及何时操纵此渐变以获得所需的效果 - 我的意思是变换/旋转渐变,使其看起来像绘制在立方体的一侧并沿其 3D 位置变换。我猜想每一侧都应该有单独的梯度矩阵,但是如何转换这个矩阵以适应 rotx,roty,i rotz。有人可以帮助我吗?

这是渐变的来源 http://snipplr.com/view.php?codeview&id=7050

以及可以获得 cube fla 文件的网站 http://www.flashandmath.com/flashcs4/cs4simple3d/index.html

这是上面链接中的 .fla 文件代码,经过我的修改

http://pastebin.com/fdc431a4

Hello I got goal to achieve, 3d cube manipulated with mouse with gradient filling on each wall.

I found some source codes coresponding to gradients and 3d rotating cube but here is the problem:

When i put these two things together the effect looks like the cube was a wireframe with transparency to some gradient background hidden behind the first plane solid black background. Gradient always stays still.

Method which rotates/displays cube got at input three parameters rotx .roty, rotz i'd like to make use of it and apply it to gradients displayed on each side. gradient got own matrix but i don't have a clue how and when manipulate this gradient to get desired effect - i mean transform/rotate gradient in way ro look like it is painted on side of cube and tranform along to it 3d position. I guess that each side should have separate gradient matrix dor each side but what to do to transform this matrix to fit along with rotx,roty, i rotz. Can anyone help me?

here is source for gradient
http://snipplr.com/view.php?codeview&id=7050

and site where you can get cube fla file
http://www.flashandmath.com/flashcs4/cs4simple3d/index.html

and here is code of .fla file from link above with my modifications

http://pastebin.com/fdc431a4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仙女山的月亮 2024-08-09 20:23:11

这实际上是不可能的......透视变形不是仿射变换,这就是为什么有不是一个合适的参数来创建具有正确透视变形的渐变的矩阵...

我认为 Flash 10 最简单的方法实际上是采取不同的方式...所有 DisplayObjects 都可以在空间中转换,所以您只需用 DisplayObject 表示任何面,对其执行所有转换,然后剩下要做的就是 z 排序...


编辑:您正在寻找的近似值是完全不可能的..想象一个立方体,面对着你,有一个从黑到白、从上到下的线性渐变……当你开始向右旋转时,渐变线不再保持平行,而是开始形成圆锥形渐变。 ,所有都汇聚在一点...

第二段中的方法正是您正在寻找的...创建一个 DisplayObject (Shape 应该做到这一点,您不需要 MovieClips),为其绘制渐变,然后使用 xyzrotationXrotationY 在 3D 空间中进行变换code> 和 rotationZ ...一旦您使用多个对象,您将需要手动对它们进行 z 排序...如果您想要 3d 渐变,您将不得不放弃它编写代码并使用这种方法,这是迄今为止最简单的...

您的 AS3 问题实际上与该语言没有任何关系...您应该重新考虑您的方法...从一种新语言和未知语言开始API,在不了解背后理论的情况下尝试增强 3D 引擎,并不是最好的做法...

您应该首先开始习惯该语言...一旦您对它感到满意,我认为对你来说最好的方法是使用一个好的 AS3 3d 引擎,例如 sandy、papervision、away3d、alternativa 或其他......例如,使用 sandy,你创建一个天空盒(一个 3d 立方体)并分配你想要的任何材质它的面孔,你就完成了......而且,这些引擎与 3D 建模软件互操作,所以你可以导入复杂的模型并做一些非常酷的事情,而不是仅仅手工创建一些多面体并摆弄它们......但要按照逻辑顺序并有足够的理论知识做事...

那么祝你好运...;)


greetz

back2dos

this is not really possible ... perspective distortion is not an affine transformation, which is why there is not matrix that'd be a suitable parameter to create a gradient with the correct perspective distortion ...

i think the most simple way for flash 10 is to actually go a different way ... all DisplayObjects can be transformed in space, so you simply represent any face by a DisplayObject, perform all transformations on it, and then all that is left to do is z-sorting ...


edit: the approximation you are looking for is quite impossible ... imagine a cube, facing you, having a linear gradient from black to white, from the top to the bottom ... as you start turning it right, the lines of the gradient no longer stay parallel, instead they start forming a conical gradient, all converging in one point ...

the approach in the 2nd paragraph is exactly what you are looking for ... create a DisplayObject (Shape should do it, you don't need MovieClips for that), draw a gradient to it, and then transform it in 3d space using x, y, z, rotationX, rotationY and rotationZ ... and as soon as you use more than one object, you will need to manually z-sort them ... if you want 3d-gradients, you will have to drop that code and use this approach, which is by far the most simple ...

your problems with AS3 really doesn't have anything to do with the language ... you should reconsider your approach ... starting with a new language and an unknown API, trying to enhance a 3d-engine without having knowledge of the theory behind, is not really the best thing to do ...

you should start getting used to the language first ... once you feel comfortable with it, i think the best way to go for you is using a good AS3 3d engine, such as sandy, papervision, away3d, alternativa or whatever ... for example with sandy, you create a sky box (a 3d cube) and assign any materials you want to it's faces and you're done ... and also, these engines interoperate with 3d modeling software, so instead of just creating some polyhedrons by hand and playing around with them, you can import complex model and do some pretty cool stuff ... but do things in logical order and with sufficient theoretical knowledge ...

good luck then ... ;)


greetz

back2dos

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文