Accessibility
 
Home > Products > Director > Support > Basics of Director 3D
Macromedia Director Support Center - Basics of Director 3D
3DText2

When you open and play the 3DText2 sample movie, you can extrude text to the 3D world by clicking the top left button on the Stage. You can then use the other two buttons to apply a shader to every other letter or to every letter. All three buttons include behaviors that call the following handlers, which you'll find in the movie script.

The following code is an error trap that causes the handler to exit if a model called 3dText is already in the world. If the model exists and you try to create another model of the same name, an error message appears.

on extrudeTextToWorld
    if not(member("scene").model("3dText").voidP) then exit 

The prepareShaders handler calls the handler that creates all the shaders used in the movie. The prepareLightAndCamera handler calls the handler that sets up the lighting and camera position for the movie. By preparing the lights and camera position, you ensure that your text is visible in the movie.

The following code defines the extruded text as a model resource and assigns it to a variable for convenience:

textModelResource = member("textSample").extrude3d(member("scene")) 

The following code creates a new model, which uses the new textModelResource variable:

nm = member("scene").newModel("3dText", textModelResource)

The new model is extruded from the text "I'm shocked!" Because the text has 11 characters (including punctuation), it has 11 shaders—one for each character.

The following repeat loop assigns the same shader to each character.

    repeat with x = 1 to member("scene").model("3dText").shaderList.count

        member("scene").model("3dText").shaderList[x] = member("scene").shader("shMetal")

    end repeat
end
This code creates a shader and texture for the model:
on prepareShaders
    member("scene").newTexture("texMetal", #fromCastMember, member("metallic"))

    member("scene").shader("shMetal").texture = member("scene").texture("texMetal")
This code creates another shader and texture for the model. It uses the newTexture function to add the texture to the texture list and assigns the texture to the shLines shader:
    member("scene").newTexture("texLines", #fromCastMember, member("lines")) member("scene").newShader("shLines", #standard)

    member("scene").shader("shLines").texture = member("scene").texture("texLines")

end
The following handler sets the directionalPreset , directionalColor , and ambientColor properties of the cast member. This modifies the lighting of the scene.
on prepareLightAndCamera
    member("scene").directionalPreset = #bottomLeft
    member("scene").directionalColor = rgb(255, 255, 255)
    member("scene").ambientColor = rgb(255, 255, 255)
This code points the camera toward the new model's position:
    member("scene").camera[1].transform.position = vector(266, 0, 300)
    member("scene").camera[1].transform.rotation = vector(0, 0, 0)

end
The following handler applies the shLines shader to half of the letters. Notice that the shLines shader is applied only to odd-numbered items on the shader list; the shLines shader will appear on every other letter. This is done with the mod function, which divides a number by 2 and returns a remainder of either 0 or 1.
on addLinesToHalf
    if member("scene").model("3dText").voidP then exit
    repeat with x = 1 to member("scene").model("3dText").shaderList.count
        if x mod 2 = 1 then -- if x is an odd number
            member("scene").model("3dText").shaderList[x] =
            member("scene").shader("shLines")
        else
            member("scene").model("3dText").shaderList[x] = 
            member("scene").shader("shMetal")
        end if 

    end repeat
end
The following handler applies the shLines shader to all of the letters.
on addLinesToAll
    if member("scene").model("3dText").voidP then exit
    repeat with x = 1 to member("scene").model("3dText").shaderList.count

        member("scene").model("3dText").shaderList[x] = member("scene").shader("shLines")

    end repeat

end
To Table of Contents Back to Previous document