Professional Web Applications Themes

Attatching sounds to 3D objects - Macromedia Director 3D

Im sure there was an old topic about this but i cant find it anywhere. There is a way of attatching a sound to a 3d object within the .w3d file, so that if the camera gets closer the sound volume increases. If anybody knows what im talking about and can help it would be much appriciated! Thanks, Rich...

  1. #1

    Default Attatching sounds to 3D objects

    Im sure there was an old topic about this but i cant find it anywhere. There is
    a way of attatching a sound to a 3d object within the .w3d file, so that if the
    camera gets closer the sound volume increases. If anybody knows what im talking
    about and can help it would be much appriciated!

    Thanks, Rich

    r1chard..w3lch Guest

  2. #2

    Default Re: Attatching sounds to 3D objects

    theres is a behaviour in the chromelib pack that does this,
    http://www.chromelib.com

    I find these so handy, does anyone know when there may be an update of these
    coming out, or even what new goodies are on the way.

    hope this helps

    milochong Guest

  3. #3

    Default Re: Attatching sounds to 3D objects

    Thanks for the quick reply. would i have to purchase this pack? also what is the behaviour called? Thanks
    Rich
    r1chard..w3lch Guest

  4. #4

    Default Re: Attatching sounds to 3D objects

    Or you could just measure the distance between the camera and the object, and
    use that as a factor for setting your volume, like this:

    objDist = (obj.transform.position - cam.transform.position).length
    soundVolume = min(255,integer((10.0/objDist)*255))

    The above will give you a maximum volume when the object is within 10 units
    (hence the 10.0), and will tail off as the object gets further away, becoming
    almost inaudible at a distance of 1000 units.

    The equation makes sure the value is an integer (suitable for using as a sound
    channel volume), and it caps the value at 255.

    You might want to adjust it so the sound remains louder at further distances
    by increasing the value from 10.0 to 100.0 or something, depending on the
    intended loudness of your object, and the relative scale of your scene.

    hope this helps!

    - Ben


    duckets Guest

  5. #5

    Default Re: Attatching sounds to 3D objects

    Hi ben, thanks for the reply. Your solution sounds pretty much what I'm trying
    to work out, the only problem is im a bit confused at where I would quote the
    model within my .w3d world and where I would quote the sound in my cast list?
    My .w3d world is fairly basic but there are a few different models that make
    it up, e.g: landscape, cube1, cube2, sphere1.

    Thanks Rich

    r1chard..w3lch Guest

  6. #6

    Default Re: Attatching sounds to 3D objects

    if your 3d cast member is called "myscene" then add these lines before the code
    I posted originally.

    scene = member("myscene")
    cam = scene.camera[1]
    obj = scene.model("cube1")

    or whatever object you want to pick out as the sound emitter...

    - ben

    duckets Guest

  7. #7

    Default Re: Attatching sounds to 3D objects

    Hi, thanks for the response Ben,
    I understand the script but im not sure how i'd tell director which sound it
    needs to emit from the 3d object as there is currently no mention of sound in
    the script.

    Thanks
    Rich

    r1chard..w3lch Guest

  8. #8

    Default Re: Attatching sounds to 3D objects

    Ok, so the full set of code would be something like the attached lines below.

    When and where you actually use the lines which play the sound are up to you
    (you obviously don't want to be re-triggering a sound every single frame).
    Probably you'll want to either play a looped sound in a channel, then just
    adjust the volume - or you'll want to re-trigger a sound at certain moments.
    Either way, the code below should be a good starting point to work from.

    hope this helps!

    - Ben


    scene = member("myscene")
    cam = scene.camera[1]
    obj = scene.model("cube1")

    -------------

    objDist = (obj.transform.position - cam.transform.position).length
    soundVolume = min(255,integer((10.0/objDist)*255))

    sound(1).volume = soundVolume
    sound(1).play(member("footstep sound"))

    duckets Guest

  9. #9

    Default Re: Attatching sounds to 3D objects

    Hi Ben, I've tried the code but its not working as yet. I've tried a few
    variations, like writing the code in amongst my main movement behavior,
    creating a movie script and trying it as a new behavior onto the 3d world.

    Here?s what I've attempted to use with no success yet (but also no errors)
    Do you have any ideas of what I?m doing wrong?




    on beginsprite me

    scene = member("level RN")
    cam = scene.newcamera("2egocam")
    obj = scene.model("hke_move_soundcube")

    -------------

    objDist = (obj.transform.position - cam.transform.position).length
    soundVolume = min(255,integer((100.0/objDist)*2055)) -- max volume when cam
    is 100 units away

    sound(4).volume = soundVolume
    sound(4).play(member("CRLOOP2"))

    end

    r1chard..w3lch Guest

  10. #10

    Default Re: Attatching sounds to 3D objects

    Yep, because you have the volume equations in your 'beginsprite' handler,
    you're not re-calculating the volume each frame.

    If "CRLOOP2" is a looped sound, you won't need to re-trigger it, so the code
    that you'll need to perform each frame (or each time your 3d object moves) is
    this:

    objDist = (obj.transform.position - cam.transform.position).length
    soundVolume = min(255,integer((100.0/objDist)*255))
    sound(4).volume = soundVolume

    You've also somehow accidentally got 2055 in there, instead of 255.

    - Ben


    duckets Guest

  11. #11

    Default Re: Attatching sounds to 3D objects

    Hi, thanks for your reply,
    It says 'object expected'. The camera is called "2egocam"
    The camera is created in the 'movement' script so im unsure if direcor does
    not realise this or i need to put something else in the lingo...



    on beginsprite me


    scene = member("level RN")
    cam = scene.camera("2egocam")

    obj = scene.model("hke_move_soundcube")

    ----------------------

    objDist = (obj.transform.position - cam.transform.position).length
    soundVolume = min(255,integer((100.0/objDist)*255))
    sound(4).volume = soundVolume
    sound(4).play(member("CRLOOP2"))

    end

    r1chard..w3lch Guest

  12. #12

    Default Re: Attatching sounds to 3D objects

    Well without seeing how your movie is set up in general, it's difficult to
    advise.
    Is this sound code a behaviour on your 3d scene?
    Is the 'movement' script also a behaviour on your 3d scene?

    If so, make sure the 'movement' behaviour is higher up in the behaviour list
    than the volume script, because they are executed in that order. If the
    movement script creates the cam, then of course this will have to happen
    before you try to use references to the cam.

    Which line generates the 'object expected' error?

    Also - from the code you posted - it looks like you still haven't moved the
    actual sound volume calculations out of the beginsprite handler -
    because the volume will need to be recalculated each frame (or each time the
    object moves), so they should be in an enterFrame handler or someplace similar.

    - Ben




    duckets Guest

  13. #13

    Default Re: Attatching sounds to 3D objects

    Hi
    I can now hear sound but it makes no difference how far / near the camara is
    from the sound emmiting cube.
    My character is a 3d shape which is right next to the camara. Would it work if
    i could use the characters 3d model as the 'ears' that hear the sound from the
    emmiting cube?

    In other words would I be able to replace where it says 'cam' with
    something relevent to my characters 3d model?


    scene = member("level RN")
    cam = scene.model("character")

    obj = scene.model("hke_move_soundcube")

    ----------------------

    objDist = (obj.transform.position - cam.transform.position).length
    soundVolume = min(255,integer((100.0/objDist)*255))
    sound(4).volume = soundVolume
    sound(4).play(member("CRLOOP2"))





    Rich

    r1chard..w3lch Guest

  14. #14

    Default Re: Attatching sounds to 3D objects

    [q]Originally posted by: duckets
    Also - from the code you posted - it looks like you still haven't moved the
    actual sound volume calculations out of the beginsprite handler -
    because the volume will need to be recalculated each frame (or each time the
    object moves), so they should be in an enterFrame handler or someplace similar.
    [/q]

    Have you done the above yet?


    [q]Originally posted by: r1chard..w3lch
    Would it work if i could use the characters 3d model as the 'ears' that hear
    the sound from the emmiting cube? <snip> would I be able to replace where it
    says 'cam' with something relevent to my characters 3d model?[/q]

    It should work, but it should also work with your camera too. But feel free to
    try it out for yourself - you don't have to ask first! :-)

    If you have moved the calculations into an enterframe/exitframe handler
    as advised above, then perhaps you have more than one camera in your scene, and
    you're referring to the wrong one.

    All you're trying to do is ascertain the distance between two objects in your
    scene. It shouldn't matter what kind of objects these are (cameras, models,
    lights, group nodes etc).

    Remember you can drag your 3d cast member into the object inspector, to
    inspect what exactly is contained within your 3d scene.

    - Ben


    duckets Guest

  15. #15

    Default Re: Attatching sounds to 3D objects

    Hello milochong,

    I wait for news about Director 11 before updating the Chrome Lib.

    r1chard..w3lch, the 3D Sound behavior controls the sound volume based on the
    distance between the emitter model and the current camera. It is in the free
    version. You don't have to purchase the pay version.

    Best regards,
    Karl Sigiscar.

    http://www.chromelib.com/



    Newt99 Guest

Similar Threads

  1. Newbie Question? Aligning Objects to other Objects?
    By grant.smith@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 6
    Last Post: April 27th, 09:10 PM
  2. Help with sounds
    By Fu Man in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: February 20th, 01:54 PM
  3. Help with sounds
    By CesareRocchi in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 20th, 01:53 PM
  4. Storing Objects/Arrays in Stored Objects
    By teflon000 webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: January 24th, 07:11 PM
  5. Attatching content to emails using PHP
    By frank in forum PHP Development
    Replies: 2
    Last Post: June 30th, 09:23 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139