您的位置:86VR > VR教学频道 > 技术教程 > Shockwave3D > Shockwave3D Lingo 制作实例教程(英文)
发表您的文章
站点最新
虚拟现实技术漫谈
Pixar大学知名教授Pamela Blotner…
NextLimit 发布 Maxwell Render Be…
感受精彩、演绎精华――郁刚谈广告…
2005暑期高校数码媒体教学研讨会将…
Shockwave3D制作虚拟手机实例教程…
Shockwave3D Lingo 制作实例教程(…
Land of the Dead
地形建模工具Creator Terrain Stud…
Octaga免费播放器1.8版本发布
热门文章
virtools dev中文手冊简体教程共享…
虚拟美国古村庄
免费角色动画模型下载
搬运机器人(Cult3D)
《三维游戏设计师宝典-学OpenGL编3…
EON Studio详细基础教程[下载]
《魔兽世界》亡灵术士PK
向量几何在游戏编程中的使用
MAYA 脚本语言 MEL 系列教程
3ds max烘焙:Render To Texture对…
Shockwave3D Lingo 制作实例教程(英文)
类型:整理 | 来自:86VR | 作者:Marty Plumbo | 时间:2005-6-23 |  点击:

  在该教程中,作者制作了一个基础的3D坦克游戏的“shell”,使用了3D Lingo 和一些位图材质。在此基础上,检查3D Lingo 的各种元素,制作,浏览,在3D场景中操作物体操作物体。教程包括:3D Lingo的介绍,3D程序序言,开始制作,创建灯光,制作背景,创建环境,实现交互,总结,下载源文件,观看原作品。

Introducing 3D Lingo

Whatever you decide to create with the new interactive 3D features in Macromedia Director MX, you’re almost certainly going to have to create some 3D content before you can make it happen. While the primary means of creating complex Director 3D content is to export it from 3D software packages such as 3ds Max and Maya, Director also provides the ability to create simple 3D content entirely with Lingo.

3D Programming from the Ground Up

In this tutorial, we’ll create the “shell” of a basic 3D tank game, using nothing but 3D Lingo and a few imported bitmap textures. Along the way, we’ll examine each of the various elements of 3D Lingo employed to create, view, and manipulate objects in any 3D scene. While most of the topics that we’ll cover could each easily be the subject of several articles themselves, we’ll keep the coverage broad and focused on foundational concepts. This is important, as no matter what you decide to do with 3D in Director, a firm understanding of the basics of 3D Lingo is crucial to making it happen.

Note that this tutorial assumes that the reader is familiar with the basics of Director 3D and is familiar with basic Lingo programming concepts.

Getting Started

First, you will need to download the sample files for the project. Before beginning the exercise, examine and run the finished.dir file, a completed (and heavily commented) version of the exercise.

To begin the exercise, load the start.dir file. Note that it consists of a single, empty 3D cast member, instanced to a single frame of the movie. Begin by creating a new sprite behavior and instancing it to the 3D sprite.

The heart of all 3D in Director is the 3D cast member. Each 3D cast member is a complete 3D world, containing any number of various “node” objects, such as models, lights and cameras.  Before we can use Lingo to create or manipulate nodes in our 3D cast member, we’ll need to create a beginSprite handler to initialize a few key properties, by entering the following in the behavior: 

property pSprite, pScene, pCamera

 on beginSprite me

    pSprite=sprite(me.spriteNum)

    pScene=pSprite.member

    pScene.resetWorld()

    pCamera=pSprite.camera

 end

The properties pSprite and pScene should be familiar as pointers to the memory objects of the sprite and its cast member. Note the line in which we have the cast member call its resetWorld function, which returns the 3D world to its native state. All 3D cast members have numerous such 3D-related functions built into them. Become acquainted with the format of this line of code, as we will use it repeatedly, both to call 3D functions inside our cast member, as well as to manipulate the properties of the nodes within it.

Note also the property pCamera, which is unique to Director 3D. This is a reference to the default camera of our empty 3D world.  Like all nodes, the default camera has various properties that we can test and set once we have a reference to it.

Creating a Light

 

Before we can do anything interesting with the camera, we’ll need something to look at in the scene. So, we next illuminate the scene by creating and positioning a light node in it by adding the following lines to the beginSprite handler:

 x=pScene.newLight("pointLight01",#point)

 x.transform.position=vector(0,3000,0)

Director 3D supports various kinds of lights, each with different properties and characteristics. To get our scene illuminated quickly, we create a “point” light, which has the useful quality of illuminating the scene in all directions from its location.  We create the point light by calling the newLight function in the 3D cast member. This function has two parameters, which assign a node name to, and specify the style of the light.

 

After the function call, a new point light rests at world coordinate position (0,0,0), the default for all newly created nodes. So that it can more fully illuminate our scene, we then transform the position of the light to a location 3000 units above (0,0,0). We do this by setting the light’s position transform property, using a vector data type. Vector variables hold three values, which makes them quite useful for setting 3D properties that require discrete X, Y, and Z values, such as the position transform.

 

There’s one last bit of technique worth pointing out here. Since each node in a 3D world must have a unique name, we do not need to maintain a property reference to the light and thus can use a simple local variable when initially creating and positioning it. If we need to reference it later, say to reposition it, we can just use the node name (“pointLight01”) that we have assigned it. This too will become a familiar practice.

Creating a Backdrop

 

Next, we will create a static backdrop by adding the following lines to the handler:

x=pScene.newTexture("skyTexture",é

    #fromCastMember,member("sky_map"))

 pCamera.addBackdrop (x,point(0,0),0)

Note that backdrops are a camera property. In essence, they allow you to place a single texture behind all of the nodes in the scene. Textures are elements used to give “material” quality to the surface of a node, typically in the form of an image. The texture applied to our backdrop is defined by a bitmap cast member, drawn to look like a blue, gradated sky.

 

Run the movie to confirm that your scene looks similar to Figure A.

Figure A

 

Every visible geometric object in a 3D world is a “model”, instanced from an invisible “model resource”. The relationship between the model and model resource is essentially the same as that between Director’s traditional 2D sprites and cast members. Thus, multiple models can be instanced from the same model resource, any changes to a model resource will be reflected by all models instanced from it, changes to instances do not effect other instances, and so on.

We will create our futuristic, spheroid “tank” by first creating a model resource and then instancing it.  Since we will need to refer back to this model often, we will define a property reference to it. So, we will first modify the behavior’s property declaration line to read as follows:

property pSprite, pScene, pCamera, pTank

Next, add the following lines to the beginSprite behavior to create the sphere resource and instance:

x=pScene.newModelResource("tank",#sphere)

 x.radius=10

 pTank=pScene.newModel("tank",x)

Note how after creating the sphere model resource, we then define the radius property and created a model instance based on the model resource and specified property. This too will become familiar practice.

 

Run the movie to confirm that your scene looks similar to Figure B.

 

Figure B

Next, add the following lines to create a shader resource and instance it to the surface of the tank sphere. Shaders are used to define more complex surface quality for objects than is possible with textures alone, allowing for such additional properties as reflectance, transparency and tiling. Note that one of the properties of the shader is a texture:

x=pScene.newShader("shaderResource01",é   

    #standard)

 x.texture=pScene.newTextureé

 ("textureResource01",é

 #fromCastMember,member("tank_map"))

 pTank.shader=x

  The final step to creating the first-person elements of our tank game is to hierarchically link the camera to the sphere. Since the tank will eventually have the ability to move around the scene, this will ensure that we are always along for the ride. The following lines make the camera a “child” of the tank sphere and then adjusts its position relative to it:

pTank.addChild(pCamera)  

 pCamera.transform=pTank.transform

 pCamera.transform.position=vector(0,18,30)

 pCamera.transform.rotation=vector(-5,0,0)

Creating the Environment

Now, using variations on the same techniques that we used to create the tank sphere, we will create and position a grass-covered plane:

x=pScene.newModelResourceé

    ("groundResource",#plane,#front)

 x.length=5000

 x.width=5000

 y=pScene.newModel("groundplane",x)

 y.transform.rotation=vector(90,0,0)

 s=pScene.newShaderé

    ("checkShaderResource",#standard)

 s.texture=pScene.newTextureé

    ("checkTextureResource",é

    #fromCastMember,member("ground_map"))

 y.shader=s

 y.shader.textureTransform.scale=é

    vector(.01,.01,.01)

While a few more resource and instance properties are being manipulated now, the approach is the same as before. Note the last line though, which calls the shader’s textureTransform.scale property to tile its texture.

Run the movie to confirm that your scene looks similar to Figure C.

Figure C

Now, using still another variation on the techniques used to create the tank sphere, we will create and randomly position and orient forty monolithic cubes across the grass-covered plane:

x=pScene.newModelResource("boxResource",é

    #box)

 x.width=100

 x.length=200

 x.height=100

 s=pScene.newShaderé

    ("cementShaderResource",#standard)

 s.texture=pScene.newTextureé

    ("cementTextureResource",é

    #fromCastMember,member("cement_map"))

 repeat with y=1 to 40

    m=pScene.newModel("boxModel" && y,x)

    m.shaderList=s

    m.transform.position=vector(2000-é

       random(4000),30,2000-random(4000))

    m.transform.rotation=vector(randomé

       (360),random(360),random(360))

 end repeat

Note here the use of string concatenation to create unique node names for each monolith instance on the fly. And, note our first use of the transform rotation property to randomly orient the monoliths on the X, Y, and Z axes.

Run the movie to confirm that your scene looks similar to Figure D.

 

Figure D

 

And finally, to add a dash of variety to the scene, we create and randomly position a particle system fountain in the scene. Particle systems are among the more amply parameterized elements available in Director 3D. While we only define ten parameters for our particle system, we could use many more:

r=pScene.newModelResourceé

    ("particleResource",#particle)

 r.lifetime=2000

 r.colorRange.start=rgb(255,0,0)

 r.colorRange.end=rgb(255,0,255)

 r.sizeRange.start=2

 r.sizeRange.end=1

 r.gravity=vector(0,-10,0)

 r.emitter.numParticles=3000

 r.emitter.direction=vector(0,180,0)

 r.emitter.angle=25

 r.emitter.maxSpeed=300

 m=pScene.newModel("particleInstance",r)

 m.transform.position=vectoré

    (2000-random(4000),5,2000-random(4000)) 

Creating Interaction

The last step in creating our simple game shell is to make it interactive. One of the best things about interactive 3D is that everything that we’ve created in 3D Lingo up until now isn’t just a static image, but a complete and dimensional world, waiting to be explored.

We’ll navigate the our 3D world by transforming the position of the tank sphere in the scene. And, not coincidentally, since we linked the scene camera to the tank, it will automatically follow it as we do so!

To do this, we will need to modify the behavior’s property declaration line to read as follows:

property pSprite, pScene, pCamera,é

   pTank, pSpeed

 Then, add the exitFrame handler below to the behavior to process the transformation of the tank’s postion, based on the keypresses to the keyboard arrow keys:

on exitFrame me

   if keyPressed(123) thené

      pTank.rotate(0,2,0)

   if keyPressed(124) thené

      pTank.rotate(0,-2,0)

   if keyPressed(125) thené

      pSpeed=min(10,pSpeed+.5)

   if keyPressed(126) thené

      pSpeed=max(-10,pSpeed-.5)

   pTank.translate(0,0,pSpeed) 

   go the frame

 end

Note that the exitFrame handler also loops the movie in the current frame, so as to ensure regular updating of the tank position.

Run the movie and roam the scene to see if you can locate the fountain, as shown in Figure E.

Figure E

Conclusion

So thee you have it.  Our simple tank game is complete, as is our overview of the basic concepts and techniques of 3D Lingo. Try to create variations of the game by studying the properties and functions used in it in Director’s online help and manuals. In no time at all, you’ll be well on your way to creating interactive 3D content of your own!

附件下载

观看最后的作品效果(使用方向键)

(完)
可打印版本 | 文章评论 | 我来纠错
 
上篇文章: 浅谈virtools和shockwave 3D 返回:Shockwave3D 下篇文章:Shockwave3D制作虚拟手机实例教…
相关文章
 
网友评论
笔名:
内容:
 
友情
链接
86VR | 虚拟无忌