deform an entity
Blitz3D Forums/Blitz3D Programming/deform an entity
| ||
hi.. i can find how can i deform and entity.. i use car = loadmesh("car.b3d") now i want to crash and deform the car vertexs, how can i do that?.. i wan't something like move vertexs, but i can't find how do that... any advice? |
| ||
Oh someone (sorry I can;t remember who...) Did something for me a while back... let me find it :) ______________ Here it is: http://www.blitzbasic.com/codearcs/codearcs.php?code=1120 |
| ||
This is not universal though; especially as I expect he wants impact damage for his cars. Unfortunatley, this is going to be a custom job. There will probably be examples somewhere of deforming a cube or a plane, etc; however, this is really a custom job in the way that AI is custom to a game. EDIT: Having thought about it - you'll want to zone your car meshes. Either separate them into separate meshes first, if they are a solid mesh. Or be prepared to have to deal with the entire mesh as though it was made of separate meshes (in the way that a car is constructed). You cannot possibly just loop through all the vertices every time - based on the fact that you have already modified your source code to grab more speed. |
| ||
i made this little program to make it works.. nothing yeat... ups, i fix an error in function ;trying to deform an mesh ;by latatoy Graphics3D 640,480 HidePointer() ;scenary Global cam = CreateCamera() CameraClsColor cam,200,200,255 Global zero = CreateSphere(4) EntityColor zero,255,0,0 PositionEntity cam,0,5,-9 luz = CreateLight(2) PositionEntity luz,0,120,0 LightRange luz,100 piso = CreatePlane(4) EntityColor piso,200,255,160 ;original mesh Global original = CreateCylinder(16) PositionEntity original,-3,0,0 EntityColor original,100,255,100 ;this is the mesh i wont to deform Global target = CopyEntity(original) PositionEntity target,3,0,0 EntityColor target,100,100,255 Type vert Field mesh Field id Field surface Field x# Field y# Field z# End Type prepared(target) Color 0,0,0 While Not KeyHit(1) UpdateWorld() RenderWorld() cams() If MouseDown(1) Then deform(target) Text 10,10,"Press MOUSE BOTTON 1 to deform the blue mesh" Flip Wend End Function prepared(mesh) surf=GetSurface(mesh,1) vertices=CountVertices(surf) ;an error was here For i=0 To vertices-1 a.vert=New vert a\mesh=mesh a\id=i a\surface=surf a\x = VertexX(surf,i) a\y = VertexY(surf,i) a\z = VertexZ(surf,i) Next End Function Function deform(mesh) Text GraphicsWidth()*.5,GraphicsHeight()-20,"Deforming...",1,1 For a.vert = Each vert VertexCoords surf,a\id,Rnd(-1,1),Rnd(-1,1),Rnd(-1,1) ;here deform the mesh??? Next End Function Function cams() MoveEntity cam,MouseXSpeed()*.1,0,-MouseYSpeed()*.1 PositionEntity cam,EntityX(cam),5,EntityZ(cam) MoveMouse 200,200 PointEntity cam,zero End Function |
| ||
now works a little more;trying to deform an mesh ;by latatoy Graphics3D 640,480 HidePointer() ;scenary Global cam = CreateCamera() CameraClsColor cam,200,200,255 Global zero = CreateSphere(4) EntityColor zero,255,0,0 PositionEntity cam,0,5,-9 luz = CreateLight(2) PositionEntity luz,0,120,0 LightRange luz,100 piso = CreatePlane(4) EntityColor piso,200,255,160 ;original mesh Global original = CreateCylinder(16) PositionEntity original,-3,0,0 EntityColor original,100,255,100 ;this is the mesh i wont to deform Global target = CopyEntity(original) PositionEntity target,3,0,0 EntityColor target,100,100,255 Type vert Field mesh Field id Field surface Field x# Field y# Field z# End Type prepared(target) Color 0,0,0 While Not KeyHit(1) UpdateWorld() RenderWorld() cams() If MouseDown(1) Then deform(target) v= 0 For a.vert = Each vert v= v + 1 Next Text 10,30,"VERTICES : " + v Text 10,10,"Press MOUSE BOTTON 1 to deform the blue mesh" Flip Wend End Function prepared(mesh) surf=GetSurface(target,1) vertices=CountVertices(surf) For i=0 To vertices-1 a.vert=New vert a\mesh=mesh a\id=i a\surface=surf a\x = VertexX(surf,i) a\y = VertexY(surf,i) a\z = VertexZ(surf,i) Next End Function Function deform(mesh) Text GraphicsWidth()*.5,GraphicsHeight()-20,"Deforming...",1,1 For a.vert = Each vert VertexCoords a\surface,a\id,Rnd(-1,1),Rnd(-1,1),Rnd(-1,1) Next End Function Function cams() MoveEntity cam,MouseXSpeed()*.1,0,-MouseYSpeed()*.1 PositionEntity cam,EntityX(cam),5,EntityZ(cam) MoveMouse 200,200 PointEntity cam,zero End Function |
| ||
I would advise your initial route to be to store look-up tables for damage - ie don't real-time calc it. If a car is going to hit a post/column then you can pretty much know the size and shape of the impact - the only factor is the velocity of the impact as the post/column is static. If you are going to start calculating a car hitting another car, then this is a different kettle of fish. An option is collision zones on the cars - imagine your cars as having lots of scaled cubes attached to them - ie collision zones. Once you have the collision zone, then you can apply the damage to the section of vertices assigned to the collision zone - of course, these are in a look-up table - you don't realtime calculate the actual vertice zone. Personally, the whole thing is likely to be a bit fiddly - which is why many commercial racing games don't have mesh deformation. |
| ||
yeap... thanks puki.. my intention is to know what tools i have for future version of the game.. for the moment, the car is like fantastic car, never deform... one option is, make a 3d car brake layers... other, deform vertexs.. now, i know how can deform vertexs.. 20 min ago, don't know where to start. |
| ||
i wouldnt advise any of the above.. instead put a few crash bones in the cars and load them via "LOADANIMMESH" then you can just move the bone slightly for deformation. This way you can create all of your crash damage sectors in your modeller easily, you dont have to manually cycle verts or set them up in code. the psuedo code below assumes you also made a custom entity to xyz distance checker. Somthing like Function CrashDamage(colx#,coly#,colz#,car_entity) local cdist#=999999 local this_dist# local chosenchild%=0 local child,cc,c cc=countchildren(car_entity) for c=1 to cc Child=getchild(Car_entity,c) if entityname$(child)="crashbone" then this_dist#=distance(Colx,coly,colz,child)<cdist if this_dist<cdist then chosenchild=child cdist= this_dist endif endif next If chosenchild then ;move the chosenchild here ;you could pass the collide normals into the function as well to move ;the child in a specific direction. also put in limiters here so that you ;dont move the child so far from its origins that it looks weird endif end function |
| ||
riraf... that is a very good optiones... the only problem i noted, i change my game, in reason, becouse loadanimmesh is realy very slow to process, i change loadmesh, and use diferent meshes to avoid use childs... is more than 50 % of speed of the game is reduce if i use loadanimmesh. anyway, is a good way to do the crash... |
| ||
Lat, i think you misunderstand. The LoadAminMesh will not slow you down if you arent always animating the model. Otherwise from what I can tell its just as fast as X amount of non amimated entities.. I would think 4 - 5 crash bones per car wouldnt slow you down much. And you would only be animating them when they have hard hits so not every frame. Moving a crash bone once and letting blitz handle the verts on the backend will be faster than moving the verts yourself. |
| ||
Not if he pre-calcs them. |
| ||
Even if he precalcs them, letting blitz do it with a few bones should be faster. |
| ||
It is kind of swings and roundabouts - the bone idea is good for impact damage, ie parts of the car coming loose etc - not necessarily deformed, but kind of flapping about and loose, etc. We will see soon - I am itching to play it. |
| ||
Strange as it may sound using a mesh loaded with load anim mesh will have a performance hit even if not animating. I remember this from when I used to use my old Win98 box which was not very powerful, although not sure how significant it will be on a modern PC. |
| ||
use a verlet system if you want high realism with the crunch of the metal... you may have to write an entire physics engine as a dll but IMO it is worth it. |
| ||
Since the collision is immediate, you could also think of replacing the mesh with progressively damaged ones. Load a series of progressively damaged car parts to be the sources, and whenever the car crashes, replace a part of the car with a clone of the appropriate source part, and of course freeing the old undamaged car part. If you want to do deformation in a per vertex level, your car would need tons of polys to achieve a good (and visible!) result. |
| ||
If you want to do deformation in a per vertex level, your car would need tons of polys to achieve a good (and visible!) result Ive never done realtime damage, but what I was trying to explain was modifying the car in the modelling application specifically the vertex positions,, not just subdividing the car until you have millions of faces. rather taking the time to make the faces just right for a damage sector then applying a bone to that sector I guess the higher vert count the cars have already would determine how hard it would be to make these adjustments.. im not artist so I dont have a clue on the difficulty of retrofitting these things into models. a crude sketch here to illustrate what I meant. ![]() |
| ||
that bone option is a good one.. but i have this simple problem... i made the next test.. 32 cars... 1280x1024 graphics (full details game) if i load only the body of the car using: opt 1 : car_mesh = loadanimmesh(car.b3d) --> 15 to 25 fps opt 2 : car_mesh = loadmesh(car.b3d) --> 30 to 60 fps car.car = new car car\mesh = copyentity (car_mesh) bla blabla... maibe if i make a diferent b3d, the loadanimmesh no reduce the game speed. another thing i noted... if i use copyentity(car_mesh) when i modify one car, don't modify all? or something like that? if i only have 4 cars, or less 10 cars, the bone option is a realy good one... i am using ODE for physics, i have the exactly point where is the collision, i thing i can use that, but, derform... don't know. |
| ||
Copy entity will not allow you to modify each car. What are you currently using bones for? turning wheels, wiper blades, headlamps? I wouldnt use them on anything that you dont need to tranlate vertices for animation. otherwise the verts are recalculated all the time, even when you spin the wheel, that is if verts are assigned.. Edit: You can also load grouped models with LoadAniMesh , they dont have any bones but each group is loaded as a child then you can access that group entity and manipulate it like any other entity. I do this alot with 3DS models |
| ||
I think it's remarkable you have 32 cars going in the fast place. You may have to reduce the amount of cars slightly, in order to pull this off though. |