原著:Gary Rosenzweig
翻译:jerrowolf
上周我为大家演示了如何利用Director8.5中shockwave 3D成员类型来创建一个旋转的球体。球体是原型之一,可以用lingo创建而不是用昂贵的3D软件。原型中还有很多其他的类型,这周,我们创建一个立方体,一个圆柱体,和一个平面。
现在我们要写一个behavior用于3D精灵,首先创建一个3D成员,然后把它放在score中,这一步和上周我教你的一样。这个behavior开始的时候要重置3D成员,然后通过调用自定义的句柄来创建每一个原型。
property pScene, pSphere, pBox, pCylinder, pPlane
on beginSprite me
pScene = sprite (me.spriteNum).member
-- reset the world when done
pScene.resetWorld ()
-- create box, cylinder and plane
createBox (me)
createCylinder (me)
createPlane (me)
end
句柄createbox创造一个立方体的模型,和我们上周创建球体的过程相同。立方体没有球体的radius(半径)属性,但它有width、height,还有length属性。我们创建的这个立方体各个边长都是20像素。
on createBox me
-- create a box resource
boxResource = pScene.newModelResource ("BoxResource", #box)
boxResource.width = 20
boxResource.height = 20
boxResource.length = 20
现在,原型创建好了,我们要利用这个原型创建一个模型。我们用属性变量pBox来储存这个模型。
-- create new model
pBox = pScene.newModel ("Box", boxResource)
为这个模型来上材质有些麻烦,因为立方体有6个面。我们通过成员“textture-blue”来创建一个材质,然后为这个材质创建一个名字为“box shader”的shader。
然后我们我们用一个循环来使立方体shaderlist中的所有项都等于这个shader。这样就会创建一个不错的蓝色立方体。
-- assign a texture to all 6 faces
pScene.newtexture ("box texture", #fromCastMember, member ("texture-blue"))
pScene.newshader ("box shader", #standard)