Professional Web Applications Themes

setting shaders - why doesn't this code work ? - Macromedia Director 3D

myCake.layers.model.shader = _global.altShader; trace("switched to alternate shader"); trace("myCake.layers.model.shaderList.count = " + myCake.layers.model.shaderList.count); var j = 0; sl = myCake.layers.model.shaderList for (j = 1; j<= sl.count; j++) { trace("i = " + i + ", j = " + j); sl[j] = _global.altShader; } trace("SPLAT"); 1) myCake is an instantiation of a javascript class "Cake" 2) layers is an instance variable of the class "Cake", layers ia a javascript array 3) references to models are stored in the layers array, at this point the models use the #cylinder and #box model resource primitives 4) _global.altShader is a shader created with newShader ...

  1. #1

    Default setting shaders - why doesn't this code work ?

    myCake.layers.model.shader = _global.altShader;
    trace("switched to alternate shader");

    trace("myCake.layers.model.shaderList.count = " +
    myCake.layers.model.shaderList.count);

    var j = 0;
    sl = myCake.layers.model.shaderList
    for (j = 1; j<= sl.count; j++) {
    trace("i = " + i + ", j = " + j);
    sl[j] = _global.altShader;
    }
    trace("SPLAT");

    1) myCake is an instantiation of a javascript class "Cake"
    2) layers is an instance variable of the class "Cake", layers ia a javascript
    array
    3) references to models are stored in the layers array, at this point the
    models use the #cylinder and #box model resource primitives
    4) _global.altShader is a shader created with newShader function, the shader
    has a texture associated with it created from a bitmap member.

    I want to be able to select one of the models in the layers array, and change
    all of the shaders in the shadeList to the _global.altShader shader.

    In the debugger, I can see the shader being added to the 3d "world" member
    In the debugger, I can see the model.shader value being set to the
    _global.altShader

    ...what ever I do in the "for loop" I never see shaderList[2] through
    shaderList[6] getting set, the shaders remain the "defaultShader". The trace
    function within the loop correctly shows the index value "j" running through
    the values 1, 2, 3, 4, 5, 6.....the obscure Director doention states thet
    the shaderList is a linear list, and I've tried both the bracketed "[]" syntax,
    shown above, and the dot syntax using .setAt(2, _global.altShader)

    I see the model.shader value and the model.shaderList[1] values getting set to
    _global.altShader, this is good, and I understand that model.shader is actually
    just a reference to the first shader in the shaderList, but I can not set the
    other shaders in the shaderList to my _global.altShader, this is bad......

    am I the only person trying to do this in JavaScript ? Am I referencing
    thingys wrong ?

    Any help would keep me from pulling out the (few) hairs that remain.....
    Thanks

    bruchs Guest

  2. #2

    Default Re: setting shaders - why doesn't this code work ?

    You might want to try setting the shaderList through it's model:
    m = myCake.layers.model;
    then...
    m.shaderList[j] = _global.altShader;

    The reason being, under Lingo,
    sl = myCake.layers.model.shaderList
    will create a copy of the model's shaderList list, rather than a pointer to
    the model's shaderList. Just a guess, I have some doubt that this will help,
    especially since you mention your example works on the first element in the
    shaderList.


    nick kang Guest

Similar Threads

  1. Find and Replace Doesn't Work in Code
    By ProPhotoSupply in forum Macromedia Dynamic HTML
    Replies: 7
    Last Post: April 11th, 05:01 PM
  2. How the non-photorealistic shaders work?
    By Sebastian in forum Macromedia Director 3D
    Replies: 0
    Last Post: February 13th, 03:01 PM
  3. Replies: 2
    Last Post: December 30th, 05:27 PM
  4. Setting up MTRR's doesn't work
    By Paolo Amoroso in forum Linux Setup, Configuration & Administration
    Replies: 0
    Last Post: September 13th, 06:28 PM
  5. Code view doesn't work - DW4 Mac
    By Mac-Test in forum Macromedia Dreamweaver
    Replies: 3
    Last Post: July 12th, 09:33 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