≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
How to Linepick Clones and animated Meshes??
Posted by:
(you are not logged in)
Enter the missing letter in: "Internation?l"
(you are not logged in)
Text:
[quote][b]csp-games[/b] wrote: Ok, I got it working, my way. It works with static meshes, also when positioned and scaled, however rotation is not taken into account. It works for walls etc, but for animated meshes one should tweak the code so it does also index a collision mesh that was parented to the animated mesh node, a low poly cylinder I'd suggest. Currently it parses only the direct children of the root scene. It could be made recursive, so it would call itself on any child, but a global recursion-depth limit should be used to prevent stack overflows and stuff. These are the main functions used: [code] // Reading all triangles and write them to one long list, containing vertex coords and the node id a triangle belongs to var Tri_l=0; // global counter for pickable triangles in the scene TriArr=new Array(); // array holding all triangle data //TriArr[0]=[0,0,0, 0,0,0, 0,0,0, 0,0,0]; // 3x vertex coords, node id, some reserved for: meshbuffer id, pickability // note: for now, nodes are ignored when their name contains: "_nopick" // note: this should be called at the end of the ingcomplete event handler, // Or called to refresh the data, but then Tri_l must be set to 0 first. function ReadAllTriangles(){ var mytype=""; var scene = engine.getScene(); var kids=scene.getRootSceneNode().getChildren(); var kids_length=kids.length; for(i=0;i<kids_length;i++){ // parse all children mytype=kids[i].getType; //return lin.indexOf(search,ii-1)+1; if((mytype == 'function(){return"mesh"}') && (kids[i].Name.indexOf("_nopick",0)<0)){ // if they are a mesh and name does not contain "_nopick" var mybuf=kids[i].getMesh().GetMeshBuffers(); var mybuf_length=mybuf.length; for(j=0;j<mybuf_length;j++){ // parse all their mesh buffers indices_length=mybuf[j].Indices.length; for(k=0;k<indices_length;k+=3){ // parse all triangles of a meshbuffer vx0=mybuf[j].Vertices[ mybuf[j].Indices[ k+0 ] ].Pos.X; vy0=mybuf[j].Vertices[ mybuf[j].Indices[ k+0 ] ].Pos.Y; vz0=mybuf[j].Vertices[ mybuf[j].Indices[ k+0 ] ].Pos.Z; vx1=mybuf[j].Vertices[ mybuf[j].Indices[ k+1 ] ].Pos.X; vy1=mybuf[j].Vertices[ mybuf[j].Indices[ k+1 ] ].Pos.Y; vz1=mybuf[j].Vertices[ mybuf[j].Indices[ k+1 ] ].Pos.Z; vx2=mybuf[j].Vertices[ mybuf[j].Indices[ k+2 ] ].Pos.X; vy2=mybuf[j].Vertices[ mybuf[j].Indices[ k+2 ] ].Pos.Y; vz2=mybuf[j].Vertices[ mybuf[j].Indices[ k+2 ] ].Pos.Z; TriArr[Tri_l]=new Array(); TriArr[Tri_l][0] = vx0; TriArr[Tri_l][1] = vy0; TriArr[Tri_l][2] = vz0; TriArr[Tri_l][3] = vx1; TriArr[Tri_l][4] = vy1; TriArr[Tri_l][5] = vz1; TriArr[Tri_l][6] = vx2; TriArr[Tri_l][7] = vy2; TriArr[Tri_l][8] = vz2; TriArr[Tri_l][9] = kids[i]; // store node id this triangle belongs to Tri_l++; } // k } // j } // if is mesh } // i } // eo function // globals to deliver last linepick coords var PickedX=0; var PickedY=0; var PickedZ=0; function LinePick(x0,y0,z0,x1,y1,z1){ // start point, end point. will return picked node or 0. var dist=100000000; var victim=0; // potentially hit node var currnod=0; // currently tested node // hitlist=new Array(); for(i=0;i<Tri_l;i++){ var nod=TriArr[i][9]; if(nod != currnod){ currnod=nod; var currpos=nod.getAbsolutePosition(); // take into account dynamic position+scale, but not rotation var ox=currpos.X; var oy=currpos.Y; var oz=currpos.Z; var currscale=nod.getAbsoluteTransformation().getScale() var scax=currscale.X; var scay=currscale.Y; var scaz=currscale.Z; } // if var vx0=TriArr[i][0]*scax+ox; var vy0=TriArr[i][1]*scay+oy; var vz0=TriArr[i][2]*scaz+oz; var vx1=TriArr[i][3]*scax+ox; var vy1=TriArr[i][4]*scay+oy; var vz1=TriArr[i][5]*scaz+oz; var vx2=TriArr[i][6]*scax+ox; var vy2=TriArr[i][7]*scay+oy; var vz2=TriArr[i][8]*scaz+oz; var intersect = rit(x0,y0,z0, x1-x0,y1-y0,[/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact