Entity dimensions
Blitz3D Forums/Blitz3D Programming/Entity dimensions
| ||
Is there a command in Blitz which will return the width, height and depth of an entity? thanks. |
| ||
simply multiply the meshsize*entityscaling. eg. thing=loadmesh() scaleentity thing,3,4,5 realwidth=meshwidth(thing)*3 realheight=meshheight(thing)*4 realdepth=meshdepth(thing)*5 requires to store the entity scaling parameters whenever used, of course. |
| ||
Is there a command in Blitz which will return the width, height and depth of an entity, which is a loaded in entity so doesnt have access to the Mesh commands? |
| ||
Protecting the endangered population of free spaces in the database, I see :P I believe MeshWidth/height/depth should work... doesn't it? If not, I guess you could always use this: http://www.blitzbasic.com/codearcs/codearcs.php?code=1364 |
| ||
Well, if you have scaled your entity, with scaleentity, then i don't believe mesh commands will return the correect results. You'll need to loop thru all the vertices in the mesh, and tform their points to the global 3d world command. That way you can find the left most, right most, highest, lowest, deepest and shallowest vertices and return some sort of dimensions from that :o) |
| ||
Of course, this now depends on how you've scaled your entity. If you use ScaleMesh, than the mesh itself is scaled so MeshWidth, etc will give you the scaled sizes. It's probably slower than ScaleEntity, though, and I would only recommend it if you're just scaling the mesh when it's loaded -- scaling at run-time (well... not that loading the mesh isn't in runtime... but run-time in the user sense) is best performed with ScaleEntity. |
| ||
Well, getting the vertex co-ords, works, taking into account entity scale. |
| ||
You can manually, and dynamically, do this by Larging 6 surfaces in box formation at the Entity in question and then measuring the distance between the opposing faces at the point of dynamic collision - ignoring the collision between the aformentioned dynamic surfaces. Effectively, you have created a box that contains the Entity at its widest/longest/deepest points. You may have to ponce about a bit as the centre of the calculations will not necessarily be the centre point you want - however, you will have very accurate dimensions for your entity. |
| ||
You could just use this code ;o) mesh.b3d is the mesh you want to measure :o) I use these functions to calculate my bounding boxes for my editor. Graphics3D 800,600 SetBuffer BackBuffer() Global mesh = LoadMesh("mesh.b3d") Global camera = CreateCamera() PositionEntity camera,0,0,-10 Global mesh_width = find_rightmost_vertex(mesh) - find_leftmost_vertex(mesh) Global mesh_height = find_highest_vertex(mesh) - find_lowest_vertex(mesh) Global mesh_depth = find_zmost_vertex(mesh) - find_zleast_vertex(mesh) While Not KeyHit(1) UpdateWorld RenderWorld Text 0,0," mesh width = "+mesh_width Text 0,10," mesh height = "+mesh_height Text 0,20," mesh depth = "+mesh_depth Flip Wend End Function find_lowest_vertex#(mesh) lowest# = 999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedY#() < lowest Then lowest = TFormedY#() End If Next Next Return lowest End Function Function find_highest_vertex#(mesh) highest# = -999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedY#() > highest Then highest = TFormedY#() End If Next Next Return highest End Function Function find_leftmost_vertex#(mesh) leftmost# = 999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedX#() < leftmost Then leftmost = TFormedX#() End If Next Next Return leftmost End Function Function find_rightmost_vertex#(mesh) rightmost# = -999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedX#() > rightmost Then rightmost = TFormedX#() End If Next Next Return rightmost End Function Function find_zmost_vertex#(mesh) ; the furthest away on the Z axis zmost# = -999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedZ#() > zmost Then zmost = TFormedZ#() End If Next Next Return zmost End Function Function find_zleast_vertex#(mesh) ; the closest on the Z axis zleast# = 999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedZ#() < zleast Then zleast = TFormedZ#() End If Next Next Return zleast End Function |
| ||
My way is cuter. |
| ||
lol |
| ||
>My way is cuter. Goto's cuter says the puker! Andy |
| ||
... deleted |
| ||
Cool, Its true if you post just before you go to bed, when you look the next day you have at least three differnt anwsers :) As I wanted the information for positioning and Colistion boundrybox createing. Im going to go with pikis. @mr pickleworth. loadMDS returns an enitity not a mesh, and meshheight# (at least) doesnt work Ps @Ross c, dosent work. It still says that the mds modle I have loaded is an entity, and not a mesh ;( |
| ||
My answer was the best. |
| ||
Puki, thats probably what I would have thought of doing myself (honest), I was just supprised that there isnt a command to do it. :) |
| ||
Arm raised aloft, "puki" waves to the millions of 'guests' that visit this site every day. You know who the 'daddy' is when you finally buy a Blitz product and join the community. |
| ||
In conjunction with the mesh dimension commands you may use GetMatElement to retrieve the scale-values: ------------------------- www.moonworx.de |
| ||
Ah, sorry, i didn't realise it was an MD2. |
| ||
Just curious... Since it's an MD2, you can only use sphere collsions with it. So, how big do you make your collision sphere? When you activate a collision in blitz, it defaults to a size of one. So, you now have the problem of determining the size of the entity, so you can set a collision mode, to determine the size of the entity. Can't you use a different model format for this? |
| ||
I use easyTok to set the collitions, so in reality its an invisable box round the MD2. (You can put tubes and stuff round arms and legs etc, but I generaly dont go that far) So as long as I know how wide/tall(and err the other one) it is, thats enough |
| ||
But, an MD2 isn't a mesh. So, how do you go about putting things round it, if you don't know it's dimensions? |
| ||
Well at the moment by eye. I load in the tris model, create the collition box, and make it smaller and smaller unto I can see the model. Thats why PUkis Idea is the one to go for, cos Im doing that anyway, just not automaticaly |
| ||
Wait a minute. I just noticed "H&K" didn't create the thread - he gate-crashed it like a large rodent after an even larger piece of cheese. He stole my idea. Mother!, mother!!! |
| ||
Thats because I did a search on my problem ie "Entity dimensions", and when I found that the anwser didnt sovle my problem, (ie Entity dimensions) I reposted the origional Question. Should I have started a new thread? |
| ||
Ah, sorry. I was confused about who started the thread :o) What i'm trying to say, is, if you had to do it automatically, is wouldn't really be possible :o) |
| ||
Oh, So is by eye the only way I can do it then? Now That Ive thought about it I see what you mean, is it impossible to set polygon collitions for md2 models. Cos yes if I cannot do that then pukis idea dosnt work. How about I keep making the model bigger and bigger, and when I get an error cos its too big, I can divide the biggests it can be, by how much I multiplied it, then I would know How big it was? If that would work, whats the biddest it could be? |
| ||
I don't think there is a limit really... One, really hacky way to do this, would be too... Position the camera at the entities position. Move away out. Render the model against a black backround, ensuring the model isn't black. Scan from the top, to the middle of the screen with readpixel commands. If only a few pixels are detect at the middle of the screen, then move the camera in and repeat. When a decent amount of pixels are read, you have a rough idea about the height of the mesh, based on how far out the camera is. Verrrrrry hacky way to do it tho... |
| ||
If I turned on orthographic projection there wouldnt be any distortion due to perspective, so I could start bigger, then make the model smaller and smaller, until the top line of the screen didnt have any model in it. (and so on for the bottom). Is there realy no easy way to do it? Or are you all winding me up, and theres a EntitySizeY() command? |
| ||
No, really. An MD2 isn't treated as a mesh. You cannot use any mesh commands on it. It's basically treated as a pivot. A tip when using orthographic mode. Camera zoom is the only way to move the camera back and forward. |