2008年8月28日

在我做的其中一个关于Lines3D实验时候碰到需要动态改变line的始末座标的问题。看了一下lines3D类,渲染方式也是采用仿射变换实现。在实例化lines3D时,提供了几个参数,其中包括有始末顶点座标v0和v1(Vertex3D类)。猜想如果能改变这两个座标,是否能实现线条的跳动效果?但答案竟然是否定。我使用如下代码:

 

for each(var line:Line3D in lines.lines)
{
    line.v0 
= new Vertex3D(nx0, ny0, nz0);
    line.v1 
= new Vertex3D(nx1, ny1, nz1);
}

 

发现line消失了,这正是我不解之处。查看了几个相关的父类的project方法,没发现原因。根据每帧的重新渲染,假如改变始末座标,应该能正常达到目的。暂时还是放下这个问题,尝试用另外一种方法去实现。我尝试每帧把所有line remove掉,再重新绘制。我使用如下代码:

 

lines.lines.length = 0;

 

            var x0:Number = 0;
            var y0:Number 
= 0;
            var z0:Number 
= 0
            
            var pv:Vertex3D 
= new Vertex3D(x0,y0,z0);
            var nv:Vertex3D;
            
for(var n:Number = 0; n <= 10; n ++)
            {
                nv 
= new Vertex3D(x0 + 50*n, Math.random() * 300 - 150 + 50*n, Math.random() * 300 - 150 + 50*n);
                lines.addNewLine(
1, pv.x, pv.y, pv.z, nv.x, nv.y, nv.z);
                pv 
= nv;
            }

 

OK,目的似乎达到。但发现内存使用疯狂上升,增量达到1m/s。大概1分钟后,直接卡死了。猜想是否在仿射变换后,绘制到canvas的线条没有被清除?追究了一番后,发现问题不是出在这里。Back to basic,从addNewLine方法继续网上追踪,发现在Lines3D类的addLine方法:

 

            lines.push(line);
            line.instance 
= this;
            
if(geometry.vertices.indexOf(line.v0) == -1)
            {
                geometry.vertices.push(line.v0);
            }
            
            
if(geometry.vertices.indexOf(line.v1) == -1)
            {
                geometry.vertices.push(line.v1);
            }
            
            
if(line.cV){
                
if(geometry.vertices.indexOf(line.cV) == -1)
                {
                    geometry.vertices.push(line.cV);
                }
                
            }

 

geometry.vertices喺不断push,难怪内存使用上升得十分快。看来问题找到了。解决方法也很简单:

 

            lines.lines.length = 0;
            lines.geometry.vertices.length 
= 0;

            var x0:Number 
= 0;
            var y0:Number 
= 0;
            var z0:Number 
= 0
            
            var pv:Vertex3D 
= new Vertex3D(x0,y0,z0);
            var nv:Vertex3D;
            
for(var n:Number = 0; n <= 10; n ++)
            {
                nv 
= new Vertex3D(x0 + 50*n, Math.random() * 300 - 150 + 50*n, Math.random() * 300 - 150 + 50*n);
                lines.addNewLine(
1, pv.x, pv.y, pv.z, nv.x, nv.y, nv.z);
                pv 
= nv;
            }

 

内存使用基本稳定下来了。接下来尝试做一些基于lines3D的特效,下回分解。

posted @ 2008-08-28 12:32 牛牛猪 阅读(10) | 评论 (0)编辑
  2008年8月25日
     摘要:


Preview:http://niuniuzhu.cn/p/PixelsRank

由于粒子拥有初速度vx0,vy0,vz0,其中vx0,vz0我们不用改变,它们是粒子能够分散到四周的重要条件。看看vy0,初速度我为0,假设粒子和地板之间的距离为d,有这样一个公式vy -= dy * p.weight * .004,当距离越远,加速度就越大,这个不难理解。当粒子和地板发生碰撞,也就是d=0的时候,vy改变方向:vy *= -1。并且vx,vy,vz都会损失速度vx *= _damp,vy *= _damp;,vz *= _damp;。直到vx=vy=vz=0,粒子停止运动。当所有粒子停止运  阅读全文
posted @ 2008-08-25 10:56 牛牛猪 阅读(74) | 评论 (0)编辑
  2008年8月21日
     摘要:
Preview:http://niuniuzhu.cn/p/PixelSprings/

做这个demo花了比较长时间,第一,曾经让我思考了很久的三维球体碰撞反弹算法。十分幸运,我在搜索相关资料的时候,找到一个二维球体碰撞反弹的例子。该例子图文并茂,很好的分析了各种碰撞的情况,并介绍了算法。

如何发散到三维空间里应用呢?突然想起能量守恒定律,似乎粒子在一个理想空间(没有外力作用,没有能量损失)下运动,那么他具有初速度vx0,vy0,vz0,合速度为v0 = vx0^2 + vy0^2 + vz0^2 。

  阅读全文
posted @ 2008-08-21 01:47 牛牛猪 阅读(174) | 评论 (0)编辑
  2008年8月18日

一个外国学生写的教程。

 

 

帖子原文:

 

One of my students (Alex Green) put together this example on mapping textures in 3DS Max using Photoshop. We are working on a site for Duke Energy and have been building washers and dryers all week.

The big joke around here is that we teach them to build jet planes (for fun) and next washers and dryers - that's reality!

Alex is a graphics design student and Flex Guru, and he is graduating in December!

Enjoy the video

posted @ 2008-08-18 23:52 牛牛猪 阅读(105) | 评论 (2)编辑
  2008年8月14日
     摘要: 一个基于PV3D的粒子效果。该实验展示了大量粒子在引力场作用下的“奇观”。 同时还展示了PV3D的pixel3d类和BitmapLayerEffect类的强大功能。该实验使用了3200个pixel和5个引力场和两个EffectLayer,稍微显得有些力不从心。

稍后还做一些Sound方面的试验,期待有更加惊人的效果。

Preview:http://niuniuzhu.cn/p/MotionPixel



  阅读全文
posted @ 2008-08-14 02:13 牛牛猪 阅读(206) | 评论 (0)编辑
  2008年8月12日
     摘要: 看到一个表演沙子的视频受到启发,并参考了国外一个网站的demo,,心血来潮做了一个模仿。但发现该demo一个严重的弊端—CPU占用非常高,那是由于每次遍历粒子是否在鼠标范围内的结果。于是我做了一下优化,在没有鼠标动作的时候,放弃这些多余的计算。但仍然存在弊端,对于在鼠标有动作的时候,运算依然没有得到有效优化。打算在遍历粒子上做些小动作,例如把整个容器划分为几个区域,根据鼠标点击范围选择该从哪些范围内获取粒子。这样在运算上会得到有效的优化。

碍于CPU的高占用率,画布无法调整得更大,待解决了上述问题后,或许能得到更多的扩展应用。

Preview:http://niuniuzhu.cn/p/SandBox
  阅读全文
posted @ 2008-08-12 12:34 牛牛猪 阅读(230) | 评论 (0)编辑
  2008年8月11日
     摘要: 偶然发现一个外国人写的基于PV3D的投射阴影类——Papervision Shadow Casting。除了效率比较低(这是PV3D的通病了,和这个类没任何关系 - -!),还算是比较强了。
先不多说,我们先看看如何使用。
首先,我们需要光源
然后创建一个DisplayObject3D,例子里用了DAE
Preview:http://niuniuzhu.cn/p/3DRenderDemo/index.html?p=4  阅读全文
posted @ 2008-08-11 11:23 牛牛猪 阅读(230) | 评论 (0)编辑
  2008年8月10日

While Gumbo is still in active development, Flex 3.1 should be out this month and Flex 3.2 is planned for fall 2008. Gumbo will introduce new language features and different set of components that will make some existing Flex 3 components absolute. FXG is new document format and compiler will treat this format as external asset. New tags in FXG and MXML 2009 will be < Private >, < Library >, < Declarations >, < Definition >, < DesignLayer > and < Reparent >.

Instead of current http://www.adobe.com/2006/mxml namespace, Gumbo will introduce new language namespace http://ns.adobe.com/mxml/2009, but Gumbo will also recognize old namespace too. Some older tags like Binding, Script, Style and others will loose mx: prefix. But, built-in types like Array, Number etc will also loose it’s prefix.

Full details on MXML 2009 and FXG, but also if you wish to see it, here is example : Skinning a button in Flex 4 using FXG.

posted @ 2008-08-10 11:50 牛牛猪 阅读(129) | 评论 (0)编辑
  2008年8月8日
     摘要: Preview:http://niuniuzhu.cn/p/ActiveWord/Main.html
在用户输入文本并提交后,在容器里还存在上一次的MC,该如何处理?我们必须让他们按照原来的路径返回到起点,然后removeChild。回来上面提到的addList列表,当用户点击按钮后,我们先把addList里面的东西,复制到removeList列表,然后清空addList列表(说一个题外话,清空Array用array.length = 0是最高效率的 - -!)。然后再调用一次Character类的startRender方法。看到上面startRender的if(pathList),由于上一次移动后,路径并没有被清空,所以当这个列表不为null,表明这个M  阅读全文
posted @ 2008-08-08 00:57 牛牛猪 阅读(169) | 评论 (0)编辑
  2008年8月2日
     摘要: 在Mr.doob's blog看到一个惊人的demo。文章中指出,该模型并非由DAE或者Collda导入,而是一个叫Voxel data的数据生成。Voxel意思是volumetric + pixel,也就是体积+象素,他存放着大量的节点,这些节点描述三维空间里一个固定格子的值,类似象素的定义(把象素放大为一个格子)。这里有更多关于Voxel data的描述。  阅读全文
posted @ 2008-08-02 09:28 牛牛猪 阅读(164) | 评论 (0)编辑