ID the index of a mesh surface?

Blitz3D Forums/Blitz3D Programming/ID the index of a mesh surface?

Slomas(Posted 2011) [#1]
I have simple cubes created from 6 individual surfaces each-

I want to be able to identify which of the 6 surfaces the
camera is looking at (camerapick()) - but GetSurface-
appears to return the surface's handle- unique to each surface of each cube

- how do I identify the surafce ' index' i.e. side 1 thru 6
for any cube?

any help much appreciated!


Yasha(Posted 2011) [#2]
You could loop over the list of surfaces and compare handles with the one returned by PickedSurface:

Local s = PickedSurface(), i
For i = 1 to CountSurfaces(cube)
    if GetSurface(cube, i) = s Then Exit
Next
;i now equals the surface index


Be aware however that the number of surfaces in a scene is one of the more important factors affecting how long it takes to draw. If you intend to render these cubes, you'd do better to 1) construct each cube out of a single surface, and base your side-calculation on the triangles, and 2) share that one surface across all cubes, by using CopyEntity to create new cubes.


Slomas(Posted 2011) [#3]
OK-thanks- that should work-

I see what you mean on surface rendering-
I found another way to ID the sides just for reference....

- position a hidden object at the coords returned by PickedX,Y,Z-
parent it to the cube, temporarily rotate the cube to 0,0,0-
then check which side of the cube's center the child object sits...

the ultimate goal here is breaking down the shape of a boat's hull
into cubes to calculate boyancy v. drag etc- hopefully with real time results... so i'm looking for the fastest method.