Adobe Director Online
 
Sridevi Aishwariya

Viswanath S
Director Developer

Simple w3d editor using 3D Save feature

 
Download the source file here.
 

With Director 11, a new feature is introduced where we could save the properties of a w3d member during authoring or projector. Let’s try to use this capability and create a simple w3d editor. This might look like a simple application of this feature but I’m sure my developer friends out there would use this feature extensively to create cool applications :)

The editor what we are going to discuss will have the following features.

  1. User will create a shape (We will take it as a Sphere), apply a Shader and Texture
  2. Save it as a w3d file which can be used further by any director session.

Let’s start one by one…

Part 1: Create a shape, appy a Shader and Texture

  1. Launch Director and create a shockwave 3D member (Insert>Media Element>Shockwave 3D) Name it as ‘3dScene’
  2. Place the 3D Member on the stage. (Stage Size: 500x240)
  3. Let’s do our first script to keep the playhead in the frame. Double click the first frame in the frame script channel and type the following script.


    on
    exitFrame me

      go the frame

    end


  4. Now, let’s go to the next step and create the shape, in this case a cube. Create a classic button on the stage as ‘Create Sphere’.
  5. Right-Click on the button and choose ‘Script…’. Script window opens. Name the script as ‘scr:createSphere’ and type the following.

    on mouseUp

      -- Assign the variable myBoxResource to the modelResource

      mySphereResource = member("3dScene").modelResource("sphereResource1")

     

      -- Check whether the modelResource is available. If not, create the

      -- model Resource and the model.

      if mySphereResource = void then

        mySphereResource = member("3dScene").newModelResource("sphereResource1", #sphere)

        mySphereResource.radius = 50

       

        -- create a new model named mySphere1

        myBox = member("3dScene").newModel("mySphere1", mySphereResource)

       

        -- Create a new shader

        myShader = member("3dScene").newShader("myShader1", #standard)

       

        -- Assign the shader to the model

        member("3dScene").model(1).shader = myShader

       

        -- Create a new texture from the cast member 'picture'

        myTexture = member("3dScene").newTexture("myTexture1", #fromCastmember, member("picture"))

       

        -- Assign the texture to the shader

        myShader.Texture = myTexture

      end if

    end


  6. Play the movie and click the button ‘Create Sphere’. You should be able to see the cube in 3D Scene.

Part 2: Save it as a w3d file

Let’s try to save this w3d file. There are two things here. If you use saveWorld() command and save the file, you will be able to see the changes when you open the file again. There is one more magical command savew3d(). This will help you to save the 3D Scene as an external w3d file. Isn’t it cool?! Let’s see how to save it as an external w3d file.

  1. Create a button on stage as ‘Save as w3d’
  2. Right-click the button and choose ‘Script…’. Name the script as ‘scr:savew3d’. Type the following code.

    on mouseUp me

      -- savew3d() command saves the scene as w3d member.

      member("3dScene").savew3d(the moviePath & "newFile.w3d")

    end


  3. Play the movie and click the ‘Save as w3d’ member. Now, you can check in the explorer next to the movie file a w3d has been created.

If we want to create the sphere again, then you need to reset the scene because the script we have written checks whether the modelResource is available and only then it proceeds. So if you want to reset the scene, create a button ‘Reset World’ and write the following script for that.

on mouseUp me

  -- resetWorld() resets the 3D Scene to it's initial state.

  member("3dScene").resetWorld()

end

Now, you can create projector out of this movie and use it. You can enhance this more to do a good editor using the powerful savew3d() feature. As you already know, this feature works only for Authoring and Projector...not in Shockwave and you know why :)

w3d Texture Editor using 3D Save:

Along the same lines, I've created a Texture Editor in which you can load any w3d file, modify the texture and save it as w3d file with any name. In this sample, most of the texture properties are editable. Download the source here

Feedback:
If you have any questions or comments concerning this article, please send a message to viswa1999@yahoo.com

 
spacer image
This is not an official site from Adobe. If you need any clarifications, please mail me at info@adobedirectoronline.com