Saturday, November 5, 2011

How to Morph (manipulate vertices) Proscenium Stage3D Molehil

 In Procenium you can't do something like this
(i-th v-vertex of some mesh)
v[i].x=0.5
v[i].y=0.5
v[i].z=0.3
as you would do in some others frameworks.
The above code in basic tough would mean creation of buffer for one vertex and upload modification into GPU. What about you need to modify many vertices (or all) of the mesh as you will do in the morphing???


After creation of the MeshElement from MeshData local buffer with 3 sets of data is created and uploaded VertexBuffer3DHandle.uploadFromVector(I couln't understand why is internal when uploadFromByteArray is public) and  to GPU.

Indices Set - contains indices of the vertex info in vertices setset  ex. index[0,1,2...]=30,10,12 ...
inx ex. 30 means 30-th group of vertices set actually vertexSet[30 * stride]

Vertices Set -contains vertex info for every primitive in successive order as defined
in primitive's index vector
.... v30posX,v30posY, v30posZ u30,v30,v30normXv30normY,v30normZ,...(stride=8)
 
Joints Set -...(think which vertices are connected to which joint)

Idea was changing the content of the verticesSet and upload to the bufffer.
 You could obtain copy Indices Set and Vertices Set thru MeshUtils.getCopy but I didn't find way to change their content. Other problem was there is no information about vector indices inside Vertices Set used  so you know which value inside vertices set belong to which vertex. Luckily I found local structure created during proccesing of MeshData of type IndexHashMap(simple but powerful packing) which actually contain just that information and expose it to subclasses.
            v[3]=[0,12,29..] //  3-th vertex is involved into face 0,12 and 29...
As much Adobe tried go more on speed and make easy for designers (of course no one want to reinvent the wheel), seems framework is very close by my opinion ,especially when you need for example create your custom MeshElement and MeshElementData or its super classes like MeshPolylistElementData, from one side from the other side back to writing assembler to make particles (of course for custom shader but let's write binary for other cases it will be more easy :)) when we have high level languages)   
           
Update 05.01.12.
      I found reference of this post on one Japanese blog about better solution by creation and removing MeshElements with every vertex change as cleaner solution. I agree (similar thing is done in my MD2 importer) but influence to performance is very big and sometimes thing must be ugly :))             
Source

4 comments:

  1. Thank you for sharing this.
    If you are so deep in proscenium - maybe you can help me enable normal maps? I am fighting with this problem for several days and can't make it work. Diffuse, specular and emmision maps are workin.
    regards, tra

    ReplyDelete
  2. NP. I've took overtime lot of code from everywhere by people sharing too. Post is about vertex manipulation not about texturizing but I'll help if I could.

    ReplyDelete
  3. Hi Alex,

    Have you some informations about Proscenium RoadMap ?
    I post on forum but no response, nobody of adobe team seems involved !

    Thanks for your response !

    ReplyDelete
  4. You are right. By my opinion Proscenium is dead before is born. Nothing is done from 0ct.3.2011. Whole Adobe is working to converting everything to f*** JS.

    ReplyDelete