Professional Web Applications Themes

Swap image maps with JavaScript - Macromedia Director 3D

I am trying to swap image maps on a model using JavaScript but can't get the syntax right. My file is located here: (UVMapChange_JavaScript_010208.dir). In Lingo I was able to swap maps, but the UV coordinates weren't consistent. Could someone give me a hand with swapping the images using JavaScript, and help me ensure that the UV coordinates are consistent? Thanks for any assistance....

  1. #1

    Default Swap image maps with JavaScript

    I am trying to swap image maps on a model using JavaScript but can't get the
    syntax right. My file is located here: (UVMapChange_JavaScript_010208.dir). In
    Lingo I was able to swap maps, but the UV coordinates weren't consistent.

    Could someone give me a hand with swapping the images using JavaScript, and
    help me ensure that the UV coordinates are consistent?

    Thanks for any assistance.

    adam@blueapplestudio Guest

  2. #2

    Default Re: Swap image maps with JavaScript

    have you tried using render to texture on the object before you export. you wouldnt have to be conserned about how it will line up. once its reapplied
    tyree_2 Guest

  3. #3

    Default Re: Swap image maps with JavaScript


    Thanks for the response. I am using LightWave's Shockwave exporter and do not
    see any sort of "render to texture" option in the dialogue boxes. Perhaps I am
    missing something, or maybe you are using a different 3D application and/or

    Any thoughts on the JavaScript syntax for actually changing the images? I can
    do it in Lingo, as it is fairly well-doented, but I need to build this
    application with JavaScript.

    adam@blueapplestudio Guest

  4. #4

    Default Re: Swap image maps with JavaScript

    no, I havent flipped images in javascript in years. render to texture isnt associated with the exporter. it should be a feature of lightwave its somewhat common in 3d packages
    tyree_2 Guest

  5. #5

    Default Re: Swap image maps with JavaScript

    By "render to texture" it sounds like you may be referring to texture baking,
    right? Even if I bake all of my lights, bump, etc. to a new image I still need
    to worry about how it lines up in Director.

    Just so I am clear, when the object is initially brought in to Director it
    looks fine. The map is lined up on the geometry perfectly. The problem occurs
    when I try to replace the existing image mapped to the object with a new cast
    member image. The new image from the cast gets mapped to the object in an odd,
    inverted-looking way. It may be that the map is getting flipped across an
    axis, or all of the UV coords are getting multiplied by -1 or something. I am
    guessing that there is a conflict between the way that LightWave writes UVs and
    how Director reads them.

    adam@blueapplestudio Guest

  6. #6

    Default Re: Swap image maps with JavaScript

    it may be a problem with lightwave. I export from max and flip textures that
    have been baked without a problem from within director. have you tried baking
    one texture. exporting that one and making adjustments to that same texture in
    photoshop or whatever editor it may be. the placement and dimensions would be
    the same only the way it looks would be different

    tyree_2 Guest

  7. #7

    Default Re: Swap image maps with JavaScript

    i'm not sure if it makes any difference but you may want to ensure your original texture and the replacement texture the same size, or at least the same proportion (of course powers of two).
    Ex Guest

  8. #8

    Default Re: Swap image maps with JavaScript

    The way that LightWave writes the UVs in the .w3d is likely the problem. Why
    it works on the initial import and then fails later is baffling to me. Someone
    in the LightWave forums said that flipping the image (prior to importing to the
    cast, or within Director through scripting) solves the problem.

    This problem doesn't require baking to be seen, though; baking really has
    nothing to do with it. I can reapply the same image that is already on it in
    the 3d application and the problem occurs- his face gets mapped to his rear end.

    adam@blueapplestudio Guest

  9. #9

    Default Re: Swap image maps with JavaScript

    I looked at your file you posted and while I cant help with the javascript I
    noticed a couple of things: first of

    all you cant switch the textures if you never instantiate the red texture.
    redTexture=member(1).newTexture("redMap",#fromcast member,member("redMap")

    then you can switch the texture with
    member(1).model("blueMan").shader.texture=redTextu re

    now the problem with your texture coordinates. Well the simple fix might be

    member(1).model("blueMan").shader.texturetransform list[1].rotation=vector(0,0,-9

    But you will notice that the belly button is in the wrong place because the
    problem is that your UV coordinates reflect the image and so rotating the face
    into position doesnt really fix it. Furthermore if you reapply the original
    texture it is now off by 90 degrees since it the texture was exported correctly
    (for the UV coords you specified), why because your UV coordinates are flipped
    vertically! SO it is a matter of reflecting the image not rotating it. So what
    you really need to do is either flip the V coordinates in your modelling
    aplication and reexport or use imaging lingo on the image of the source
    texturemember before creating its texture something like this:

    on flipImage tImage, tBitDepth, tFlipDirection
    tNewImage = image(tImage.width, tImage.height, tBitDepth)
    tPt1 = point(0,0)
    tPt2 = point(tImage.width, 0)
    tPt3 = point(tImage.width, tImage.height)
    tPt4 = point(0, tImage.height)
    case tFlipDirection of
    #horizontal: tQuad = [tPt2, tPt1, tPt4, tPt3]
    #vertical: tQuad = [tPt4, tPt3, tPt2, tPt1]
    end case
    tNewImage.copypixels(tImage, tQuad, tImage.rect)
    return tNewImage

    _eyesonly Guest

  10. #10

    Default Re: Swap image maps with JavaScript

    Thanks for the response, _eyesonly. I will try and apply your advice first thing at work tomorrow.

    Take care.
    adam@blueapplestudio Guest

  11. #11

    Default Re: Swap image maps with JavaScript

    Instead of flipping the images inside of Director, I have just flipped them in
    Photoshop before importing them. Worked great.

    Also, I don't know if you need to create the redTexture variable that you are
    talking about, but it certainly may be useful for clarity. I was able to
    accomplish all of my map swapping using the attached code in 2 scripts, a
    Behovior and a Movie Script.

    global nCounter

    on prepareMovie me

    --Resets the 3D cast members

    --Applies the meshDeform modifier to the cast member.
    member("BlueMan").model("BlueMan").addModifier(#me shDeform)

    --Creates a variable that will be used as a counter.
    --This counter will allow the image maps to swap back and forth.
    nCounter = 0


    global nCounter

    on exitFrame me

    --Changes the image applied to the object.
    if ((nCounter mod 2) = 0) then
    member("BlueMan").texture("BlueMap").image=member( "BlueMap").image
    member("BlueMan").texture("BlueMap").image=member( "RedMap").image
    end if

    --Increments the counter.
    nCounter = nCounter + 1


    adam@blueapplestudio Guest

  12. #12

    Default Re: Swap image maps with JavaScript

    you can certainly change the image of the texture the way you are doing but it
    is creating a memory leak (recursive pointer) and you wouldn't be able to get
    away with more than one of these going in a scene and if you leave your movie
    going long enough it will crash eventually. If anything you should use:
    member("BlueMan").texture("BlueMap").image=member( "RedMap").image.duplicate()
    which does not create a recursive pointer. But you really dont need to mess
    with the image of member in yoour case since you arent compositing or blending
    images, you could simply change the member of the texture and get the same
    member("BlueMan").texture("BlueMap").member=member ("RedMap")

    Also I wouldnt gratuitously apply a meshdeform modifier if you dont need it.
    In fact even if you use a meshdeform modify to actually retrieve data from the
    mesh or to change it you still want to remove the modifier afterwards since
    each modifier in the scene adds a significant drain on resources.

    _eyesonly Guest

  13. #13

    Default Re: Swap image maps with JavaScript

    Thank you very much for pointing out the memory leak issue. I am fairly new to
    scripting and usually don't discover those problems unless someone like you
    points them out, or I spend hours debugging.

    I think I need to use the meshDeform modifier to access animations, right?
    Your point is well taken though regarding the modifier's removal when not

    Thank you very much for your excellent advice, _eyesonly, and to everyone else
    that has lent a hand in this.

    Take care.

    adam@blueapplestudio Guest

Similar Threads

  1. Swap image also swap link
    By Timothy Robertson in forum Dreamweaver AppDev
    Replies: 2
    Last Post: May 26th, 05:29 PM
  2. Image Rollovers and Image Maps
    By meeesta in forum Macromedia Dynamic HTML
    Replies: 3
    Last Post: October 26th, 01:27 PM
  3. Javascript swap image problem
    By Spike in forum Macromedia Flash
    Replies: 0
    Last Post: February 10th, 10:49 AM
  4. How can I combine image maps & rollovers using image ready?
    By jamalserroukh in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 2
    Last Post: September 1st, 12:01 AM
  5. GDI+ and Image Maps
    By Kevin Vaughn in forum ASP.NET General
    Replies: 0
    Last Post: July 11th, 06:56 PM


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