Professional Web Applications Themes

How to stick texture to a mesh object? - Macromedia Director 3D

I write an instance by my comprehension. But it seems not right at all. It didn't work. My instance is in [url]http://www.gzvr.com/test/MeshProblem/testMesh.htm[/url] The code of the button is: on mouseUp me --below is code in subject "newMesh" in Director Help nm = member("scene").newMesh("pyramid",6 , 5, 0, 3) nm.vertexList = [ vector(0,0,0), vector(40,0,0), vector(40,0,40), vector(0,0,40), vector(20,50,20) ] nm.colorList = [ rgb(255,0,0), rgb(0,255,0), rgb(0,0,255) ] nm.face[1].vertices = [ 4,1,2 ] nm.face[2].vertices = [ 4,2,3 ] nm.face[3].vertices = [ 5,2,1 ] nm.face[4].vertices = [ 5,3,2 ] nm.face[5].vertices = [ 5,4,3 ] nm.face[6].vertices = [ 5,1,4 ] nm.face[1].colors = [3,2,3] nm.face[2].colors = [3,3,2] nm.face[3].colors ...

  1. #1

    Default How to stick texture to a mesh object?

    I write an instance by my comprehension. But it seems not right at all. It
    didn't work. My instance is in
    [url]http://www.gzvr.com/test/MeshProblem/testMesh.htm[/url]
    The code of the button is:

    on mouseUp me
    --below is code in subject "newMesh" in Director Help
    nm = member("scene").newMesh("pyramid",6 , 5, 0, 3)
    nm.vertexList = [ vector(0,0,0), vector(40,0,0), vector(40,0,40),
    vector(0,0,40), vector(20,50,20) ]
    nm.colorList = [ rgb(255,0,0), rgb(0,255,0), rgb(0,0,255) ]
    nm.face[1].vertices = [ 4,1,2 ]
    nm.face[2].vertices = [ 4,2,3 ]
    nm.face[3].vertices = [ 5,2,1 ]
    nm.face[4].vertices = [ 5,3,2 ]
    nm.face[5].vertices = [ 5,4,3 ]
    nm.face[6].vertices = [ 5,1,4 ]
    nm.face[1].colors = [3,2,3]
    nm.face[2].colors = [3,3,2]
    nm.face[3].colors = [1,3,2]
    nm.face[4].colors = [1,2,3]
    nm.face[5].colors = [1,3,2]
    nm.face[6].colors = [1,2,3]
    nm.generateNormals(#flat)
    nm.build()
    nm = member("scene").newModel("Pyramid1", nm)

    --below is my code. I write it by my comprehension. It didn't work.
    member("scene").newtexture("map",#fromcastmember,m ember("myTexture"))
    member("scene").newshader("myShader", #standard)
    member("scene").shader("myShader").texture = member("scene").texture("map")
    repeat with i = 1 to nm.shaderList.count
    nm.shaderList[i] = member("scene").shader("myShader")
    end repeat
    end

    Note that there is no picture having been sticked on the mesh model. It seems
    there is colorful pattern on it because different vertex has been set different
    color. My texture picture is
    [url]http://www.gzvr.com/test/MeshProblem/StraightArrowTest.png[/url]



    WrongAgain Guest

  2. #2

    Default Re: How to stick texture to a mesh object?

    hello wrongagain

    vertex colors override any shader settings including the texture of a shader.
    it's an "either or" type of thing, you can't use both at the same time.

    omit the colorlist, when creating the mesh and use 0 for the number of colors
    and you'll see the shader.

    but still you won't see the texture on your model, as all texture coords are
    set to point(0,0).
    either define proper texture coordinates for each vertex or use a
    #texturemodelist[<indexOfYourTexture>] <> #none (e.g. #wrapplanar), which will
    automatically generate texture coordinates according to the texturemodelist
    setting.

    on a sidenote:
    there's a little quirk in the repeat loop to set the shaderlist:

    repeat with i = 1 to nm.shaderList.count
    nm.shaderList = member("scene").shader("myShader")
    end repeat


    first of all a code design hint:
    you should never "repeat to" an expression (-> the last value of your repeat
    with i = first to last), as it gets evaluated on each iteration. so on each
    iteration the count of the shaderlist of model nm is evaluated. not a biggie,
    but still costs cycles.
    two options here:

    cnt = nm.shaderList.count
    repeat with i = 1 to cnt
    ...

    or, if the ordering doesn't matter (most of the cases):

    repeat with i = nm.shaderList.count down to 1
    ...

    the second case looks very similar to the "wrong case", BUT the start
    parameter of a loop must only be evaluated once, when the loop starts, for
    obvious reasons.

    so option 2 is the best, as you even save the creation of the variable cnt :-)

    but there is another error in your repeat loop:

    setting the shaderlist property of a model IS already a shortcut to set ALL
    shaders of the model at once.

    so:
    nm.shaderList = member("scene").shader("myShader")

    would have been enough in your case.
    doing it in a repeat loop would have looked like:

    repeat with i = nm.shaderList.count down to 1
    nm.shaderList[i] = member("scene").shader("myShader")
    end repeat


    still you would waste cycles, as you dereference the member AND the shader of
    the member in each iteration. (referencing a member by name can slow down the
    performance noticeably especially, if you have lots of members)
    so you should store results, which you reuse more than once in local variables:

    mem = member("scene")
    mem.newtexture("map",#fromcastmember,member("myTex ture"))
    mem.newshader("myShader", #standard)
    mem.shader("myShader").texture = mem.texture("map")

    shd = mem.shader("myShader")
    repeat with i = nm.shaderList.count down to 1
    nm.shaderList[i] = shd
    end repeat



    which saved you a bunch of member("scene")'s


    HTH


    a?ex Guest

  3. #3

    Default Re: How to stick texture to a mesh object?

    but still you won't see the texture on your model, as all texture coords are
    set to point(0,0).
    either define proper texture coordinates for each vertex or use a
    #texturemodelist[<indexOfYourTexture>] <> #none (e.g. #wrapplanar), which will
    automatically generate texture coordinates according to the texturemodelist
    setting.
    ----------------------------------------------------------------
    In fact, what I want to know is how to set the texture coordinates. In my
    comprehension, it should be:

    nm.textureCoordinateList = [[0,0],[1,0],[1,1],[1,0],[0.5,0.5]]

    I want the bottom of the pyramid is exactly my texture picture. I think
    there is five vertexes so there should be five items in list. I don't know if
    it is right. But it didn't work yet.


    Add the sentence above to my code. And according your advice, I modified the
    code, as follow:

    on mouseUp me
    --below is code in subject "newMesh" in Director Help
    nm = member("scene").newMesh("pyramid",6 , 5, 0, 0, 5)
    nm.vertexList = [ vector(0,0,0), vector(40,0,0), vector(40,0,40),
    vector(0,0,40), vector(20,50,20) ]
    nm.face[1].vertices = [ 4,1,2 ]
    nm.face[2].vertices = [ 4,2,3 ]
    nm.face[3].vertices = [ 5,2,1 ]
    nm.face[4].vertices = [ 5,3,2 ]
    nm.face[5].vertices = [ 5,4,3 ]
    nm.face[6].vertices = [ 5,1,4 ]
    nm.generateNormals(#flat)
    nm.textureCoordinateList = [[0,0],[1,0],[1,1],[1,0],[0.5,0.5]] <------Add
    this
    nm.build()
    nm = member("scene").newModel("Pyramid1", nm)

    --below is my code. I write it by my comprehension. It didn't work.
    p_scene = member("scene")
    p_scene.newtexture("map",#fromcastmember,member("m yTexture"))
    p_scene.newshader("myShader", #standard)
    p_scene.shader("myShader").texture = p_scene.texture("map")
    nm.shaderList = member("scene").shader("myShader")
    end


    But the texture didn't display correctly yet. Where is wrong in my code?





    WrongAgain Guest

  4. #4

    Default Re: How to stick texture to a mesh object?

    you need to assign the texture coordinates to the faces also.
    not only the vertices, something like:



    nm = member("scene").newMesh("pyramid",6 , 5, 0, 0, 5)
    nm.vertexList = [ vector(0,0,0), vector(40,0,0), vector(40,0,40),
    vector(0,0,40), vector(20,50,20) ]
    nm.textureCoordinateList = [[0,0],[1,0],[1,1],[0,1],[0.5,1]]

    nm.face[1].vertices = [ 4,1,2 ]
    nm.face[1].texcoords = [ 1,2,3 ]

    nm.face[2].vertices = [ 4,2,3 ]
    nm.face[2].texcoords = [ 1,3,4 ]


    nm.face[3].vertices = [ 5,2,1 ]
    nm.face[3].texcoords = [ 5,1,2 ]

    nm.face[4].vertices = [ 5,3,2 ]
    nm.face[4].texcoords = [ 5,1,2 ]

    nm.face[5].vertices = [ 5,4,3 ]
    nm.face[5].texcoords = [ 5,1,2 ]

    nm.face[6].vertices = [ 5,1,4 ]
    nm.face[6].texcoords = [ 5,1,2 ]

    nm.generateNormals(#flat)

    nm.build()
    nm = member("scene").newModel("Pyramid1", nm)

    --below is my code. I write it by my comprehension. It didn't work.
    p_scene = member("scene")
    p_scene.newtexture("map",#fromcastmember,member("m yTexture"))
    p_scene.newshader("myShader", #standard)
    p_scene.shader("myShader").texture = p_scene.texture("map")
    nm.shaderList = member("scene").shader("myShader")



    I don't know how you want to map the texture on the triangle faces.
    something like the above should work.

    a?ex Guest

  5. #5

    Default Re: How to stick texture to a mesh object?

    Yes your code do work, thanks. And:


    I don't know how you want to map the texture on the triangle faces.
    something like the above should work.
    --------------------------------------------------------------
    It's my first time to use lingo to stick texture. I have no experience about
    it. I read the Help and write code by my imagination.
    What I want to do is only to create an object and stick texture on it.
    Textures on object should not be distorted. Is there any method more simply or
    more usual?


    WrongAgain Guest

  6. #6

    Default Re: How to stick texture to a mesh object?

    no, you are prett ymuch on your own, as soon as the objects you want to create
    can't be created with the few built-in primitives, you must "make your hands
    dirty".
    the whole shockwave3d is more intended to be a "playback" engine to deal with
    3-D data created in a 3-D package, which offer an user interface to the "low
    level" stiff you can do by code with sw3d.
    Nonetheless the fact that we CAN do the low level stuff like this "by hand"
    sets sw3d apart and I really appreciate that, as it allows for very small
    filesizes with truely dynamic apps, which generate the content at runtime on
    demand.

    If on the other hand, I would an easier way to create a pyramid and map a
    texture onto the faces with full control over the mapping mode, I can always
    use one of many 3-D packages, that export to w3d format and create the content
    faster than programming it from scratch.

    It depends on the needs, the project, the timeline, the payment etc.
    I always tend to the "programming route", if possible (at least for such easy
    objects as your pyramid is),

    as for the texture mapping: in some cases you don't need to mess around with
    texture coordinates and can simply use one of the the #texturelistmode setting,
    like #wrapplanar.



    a?ex Guest

  7. #7

    Default Re: How to stick texture to a mesh object?

    My project is a dynamic app, so the first response in my mind was to create
    the objects dynamically. But now I think about it, find the objects also can be
    built in 3-D packages previously. It will be OK as long as making appropriate
    transformations on them before use. :-)


    As for #wrapplanar, I had ever tried it, but it can not give me what I want.
    When using #wrapplanar, the texture became strange bars. Look:
    [url]http://www.gzvr.com/test/MeshProblem/testMesh1.htm[/url]
    It seems the texture projective direction is not right. I don?t know how to
    control the projective direction.
    The code of above (using #wrapplanar) is as follow:

    on mouseUp me
    nm = member("scene").newMesh("pyramid",6 , 5, 0, 0, 0)
    nm.vertexList = [ vector(0,0,0), vector(40,0,0), vector(40,0,40),
    vector(0,0,40), vector(20,50,20) ]
    nm.face[1].vertices = [ 4,1,2 ]
    nm.face[2].vertices = [ 4,2,3 ]
    nm.face[3].vertices = [ 5,2,1 ]
    nm.face[4].vertices = [ 5,3,2 ]
    nm.face[5].vertices = [ 5,4,3 ]
    nm.face[6].vertices = [ 5,1,4 ]
    nm.generateNormals(#flat)
    nm.build()
    nm = member("scene").newModel("Pyramid1", nm)

    p_scene = member("scene")
    p_scene.newtexture("map",#fromcastmember,member("m yTexture"))
    myShader = p_scene.newshader("myShader", #standard)
    myShader.texture = p_scene.texture("map")
    myShader.textureMode = #wrapPlanar -- ?----------here, use #wrapPlanar
    nm.shaderList = member("scene").shader("myShader")
    end


    WrongAgain Guest

  8. #8

    Default Re: How to stick texture to a mesh object?

    the wraptransformlist of the shader controls how the wrapplanar is mapped onto
    the model.
    get yourself the 3DPI ([url]http://www.3DPI-director.com[/url]) in order to INSPECT and
    explore all these PROPERTIES.
    :-)
    indispensable tool, when it comes to 3-D in director.

    a?ex Guest

  9. #9

    Default Re: How to stick texture to a mesh object?

    I got it.
    Thanks for your patience! I leant much from here. :-)

    WrongAgain Guest

Similar Threads

  1. How to stick transparent texture?
    By WrongAgain in forum Macromedia Director 3D
    Replies: 5
    Last Post: June 21st, 09:53 AM
  2. Synchron object positions by mesh scaling !
    By Orry71 in forum Macromedia Director 3D
    Replies: 1
    Last Post: June 1st, 09:05 PM
  3. Texture a mesh
    By Martijn Bos in forum Macromedia Director 3D
    Replies: 5
    Last Post: November 12th, 01:41 PM
  4. Texture from object (swf movie)
    By Gildard Hache in forum Macromedia Director 3D
    Replies: 1
    Last Post: August 19th, 05:04 PM
  5. How do I ad video as a texture on my w3d-object ?
    By ama101 webforumsuser@macromedia.com in forum Macromedia Director 3D
    Replies: 0
    Last Post: July 10th, 08:50 AM

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