如何用AS来3D建模

      Flash 2004-7-28 16:19
1.3d模型:
A:投影:3d的模型是由x,y,z三个坐标来确定一个点的。那如何在屏幕上用x,y来确定这个点呢?这对于他本身来说是没什么用处的,但是我可以 组合一些点来构成一个对象 就像这样:
mass.shapes[whichShape][whichPoint]
意思是: mass=MovieClip shapes=一个包含有3d的不同的面或者形状的数组;
shapes的第一个属性(whichShape)是对象的一个面的id,在一个立方体中,我们可以让shapes[0]是顶面shapes[1]是左边的面等等。
一个面是由点构成的,三角形有三个点 四边形有四个。第二个属性就是 在这个面上的一个点的ID,如果我们想得到这个面上的第一个点的ID我可以 这样写:mass.shapes[0][0]; 那第三个面上的第二个点就是mass.shapes[2][1]
而这篇文章的目的就是要写出:
extrude(mass, whichShape, 100); // where 100 would be the thickness of our desired logo.
B.点阵:
多个面共享一个点--一个立方体的顶点链接着三个面。如果想让立方体旋转,真正旋转的是那些点。在一个立方体中,如果有四个点来确定一个面的话,那么每秒就有24个点旋转。(但是,我们可以另加一个点的列表,每个面公用其中的一些点)。那么每秒就只有8各点旋转。所以我们需要一个外部的点列表:mass.pts[whichPoint] 每个点需要增加一些属性:
mass.pts[0] = new Object(); // only objects can have properties
p = mass.pts[0]; // donot want to write mass.pts[0] a lot
p.x = 5; p.y = 10; p.z = 32; // p now has 3 properties, x, y, z

1.我们需要一个类快,将所有的原料填充进去:
createEmptyMovieClip("mass", _root.depth++);
2.我们需要三角形的三个点:
mass.pts = new Array();
// only do this once, makes pts an array

mass.pts[0] = new Object;
//makes a point where we can add properties
mass.pts[0].x = 0; mass.pts[0].y = 0; mass.pts[0].z = 0;

mass.pts[1] = new Object;
//makes another point
mass.pts[1].x = 40; mass.pts[0].y =40; mass.pts[0].z = 0;

mass.pts[2] = new Object;
//makes another point
mass.pts[2].x = 0; mass.pts[0].y =40; mass.pts[0].z = 0;

他们仍然只是空间上的点:我们可以给他固定一个形状,我们需要在mass上增加一些东西来构成不同的形状。
mass.shapes = new Array ();
// only write this once in the script
我们最终通过这些点勾画了一个形状
mass.shapes[0][0] = 2;
// first point in shape will be the point with ID = 0
mass.shapes[0][1] = 0;
// 2nd point in shape will be the point with ID = 1
mass.shapes[0][2] = 1;
// first point in shape will be the point with ID = 2

2。顶点检查:

//一个非常有用的优化函数;检查一个点是否存在,如果存在就返回其ID

function checkPts(mc, x, y, z)
{
f = -1;
for (b = 0; b < mc.pts.length; b++)
{
if (mc.pts[b].x == x)
if (mc.pts[b].y == y & mc.pts[b].z == z)
f = b;
if (f > -1) break;
}
return f;
}

B. Actual extrude:

function extrude (mc, from, amount) // which mass, shape, and desired depth
{
// this will go through each point in our shape
for (i = 0; i < mc.shapes[from].length; i++)
{
// let?s check if our point with a change depth (z) already exists
k = checkPts(mc, mc.pts[mc.shapes[from][i]].x, mc.pts[mc.shapes[from][i]].y, mc.pts[mc.shapes[from][i]].z + amount);

if ( k == -1)
{
// if it doesn?t, lets make a new one with the extruded z
k = mc.pts.length;
mc.pts[k] = new Object;
mc.pts[k].x = mc.pts[mc.shapes[from][i]].x;
mc.pts[k].y = mc.pts[mc.shapes[from][i]].y;
mc.pts[k].z = mc.pts[mc.shapes[from][i]].z + amount;
// the only change from the original coordinate is z, depth
}

// lets make a face out of this coordinate, the previous, and their extruded copy
// that means it?ll be on of the sides of the new shape (not top or bottom)
// need to make sure we start on the second coordinate though:
if (i > 0)
{

// make a new face
mc.shapes[mc.shapes.length] = new Array();
mc.shapes[mc.shapes.length-1][0] = checkPts(mc, mc.pts[mc.shapes[from][i]].x, mc.pts[mc.shapes[from][i]].y, mc.pts[mc.shapes[from][i]].z + amount);
mc.shapes[mc.shapes.length-1][1] = checkPts(mc, mc.pts[mc.shapes[from][i - 1]].x, mc.pts[mc.shapes[from][i - 1]].y, mc.pts[mc.shapes[from][i - 1]].z + amount);
mc.shapes[mc.shapes.length-1][2] = mc.shapes[from][i - 1];
mc.shapes[mc.shapes.length-1][3] = mc.shapes[from][i];
}
}
// we still need to make the last face, connecting from the first coordinate, last, and their extruded copies

mc.shapes[mc.shapes.length] = new Array();
mc.shapes[mc.shapes.length-1][0] = checkPts(mc, mc.pts[mc.shapes[from].length-1].x, mc.pts[mc.shapes[from].length-1].y, mc.pts[mc.shapes[from].length-1].z + amount );
mc.shapes[mc.shapes.length-1][1] = mc.shapes[from][mc.shapes[from].length - 1];
mc.shapes[mc.shapes.length-1][2] = mc.shapes[from][0];
mc.shapes[mc.shapes.length-1][3] = checkPts(mc, mc.pts[ mc.shapes[from][0] ].x, mc.pts[ mc.shapes[from][0]].y, mc.pts[ mc.shapes[from][0]].z + amount);

// and lets make the top of the shape
mc.shapes[mc.shapes.length] = new Array();
for (i = 0; i < mc.shapes[from].length; i++)
mc.shapes[mc.shapes.length - 1][i] = checkPts(mc, mc.pts[mc.shapes[from][i]].x, mc.pts[mc.shapes[from][i]].y, mc.pts[mc.shapes[from][i]].z + amount);
}
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}