3 Replies Latest reply on Dec 22, 2006 1:44 PM by praesul

    cloneModelFromCastMember help


      I'm trying to take a model from one Shockwave 3D object and put it in another. Using cloneModelFromCastMember I've got it to the point where in debug mode, I can verify that my destination cast member has all the same modelResource and model properties, all the same shaders and textures as the source, yet nothing displays in the 3d window. I also attempted to copy light settings and camera settings, and I have a fairly high confidence level that the values are what they should be (again, I can see them when debugging). The only oddity, which I think is fine, is that there are multiple copies of shaders resulting from cloneModelFromCastMember. A duplicate shader is created for each model piece that uses that shader. I'm hoping that I'm just missing something fundamental like a "set this camera as your primary camera" function, or "now that you've built a light, actually activate it" function. Here are all the important parts of the code:
      --In a movie script that calls on startMovie
      gSource = member("AJ_pedalTest")
      gScene = member("Scene")

      gSource .resetWorld()


      repeat with i = 1 to gSource.model.count
      modelName = gSource.model .name
      if gScene.model(modelName) = void then
      gScene.cloneModelFromCastMember(modelName, modelName, gSource)
      end if
      end repeat

      And then in a on beginSprite behavior:
      gPointer = sprite("ourObject")

      --Set up camera
      mainCam = gScene.newCamera("mainCamera")
      mainCam.transform = gSource.camera[2].transform

      --Set up light sources
      copiedLight = gScene.newLight("copiedLight",#point)
      copiedLight = gSource.light[2]

      It all compiles and runs, and all the fields of my source cast member and destination cast member match, but nothing displays in the sprite window on the stage. Any ideas?

      Thanks very much for your time!
        • 1. cloneModelFromCastMember help
          PpHammer Level 1
          Sorry, wasn't the reply you were looking for.
          • 2. Re: cloneModelFromCastMember help
            duckets Level 1
            You're creating a new camera in 'gScene', but you don't appear to be making the viewport sprite actually use that cam (so its probably still using the default camera).

            Perhaps you need this after you create 'mainCam':

            gPointer.camera = mainCam

            hope this helps!

            - Ben
            • 3. Re: cloneModelFromCastMember help
              praesul Level 1
              For anyone who's interested, I ended up using loadFile()
              One word of caution- because of the time required to load things, you should load things in the "enterframe" handler, and before and after each loadFile call make sure you have a loop that runs until your shockwave 3d object state ( member("myObject").state is 0 or 4 indicating that Director is ready to go and finished loading previous items.
              Here's my code as an example:

              on enterframe me \
              if pIsFirstEntry = 0 then
              pIsFirstEntry = 1
              pScene.loadFile( "AJ_bonesTest.w3d", false, true )

              repeat while ((pScene.state <> 4) and (pScene.state <> 0))
              end repeat

              pScene.loadFile( "floor.w3d", false, true )

              repeat while ((pScene.state <> 4) and (pScene.state <> 0))
              end repeat