first try at creating avatar
Blitz3D Forums/Blitz3D Beginners Area/first try at creating avatar
| ||
i m trying to create a simple avatar the blitz3d comands do not work as expected Include "shapes.bb" Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-200 light=CreateLight() RotateEntity light,90,0,0 ;body pivots body = CreatePivot( 0 ) setbox( 0,0,0 , 20,30,10 ) lijf = createbox() EntityParent lijf , body sholder_l = CreatePivot( body ) PositionEntity sholder_l , 30,30,0 setbox( 0,-10,0 , 5,10,5 ) arm = createbox() EntityParent arm , sholder_l elbow_l = CreatePivot( sholder_l ) PositionEntity elbow_l , 0,-20,0 uarm = createbox() EntityParent uarm , elbow_l wrist_l = CreatePivot( elbow_l ) PositionEntity wrist_l , 0,0,-20 setbox( 0,-7,0 , 3,7,7 ) hand = createbox() EntityParent hand , wrist_l neck = CreatePivot( body ) bekken_l = CreatePivot( body ) knee_l = CreatePivot( bekken_l ) enkle_l = CreatePivot( knee_l ) While Not KeyDown( 1 ) TurnEntity body , 0 , 1 , 0 RotateEntity sholder_l , 30 , 0 , 0 UpdateWorld RenderWorld Flip Wend shapes.bb : Type tbox Field mx# Field my# Field mz# Field dx# Field dy# Field dz# End Type Global box.tbox = New tbox Function setbox( mx# , my# , mz# , dx# , dy# , dz# ) box\mx = mx box\my = my box\mz = mz box\dx = dx box\dy = dy box\dz = dz End Function Function CreateBox() mesh = CreateCube() PositionEntity mesh , box\mx , box\my , box\mz ScaleEntity mesh , box\dx , box\dy , box\dz Return mesh End Function |
| ||
All the functions that you have used work properly so it is your code which has errors. Try to use scalemesh(), positionmesh(), rotatemesh(), when building your meshes, because if you use scaleentity(), the childs (pivot or mesh) can be affected by the scale of the parent. |
| ||
i solved the error : - i switched positionmesh and scalemesh in createbox() update : - try at a torus new error : - j is not a function [ in createtorus ] - [ look at REMed code ] question : - how do i create a avatar-function out of this - so i can create more avatars main : Include "shapes.bb" Graphics3D 640,480,16,1 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-200 light=CreateLight() RotateEntity light,90,0,0 ;body pivots + parts body = CreatePivot( 0 ) lijf = createbox( 0,0,0 , 20,30,5 ) EntityParent lijf , body sholder_l = CreatePivot( body ) PositionEntity sholder_l , 30,30,0 arm = createbox( 0,-15,0 , 5,10,5 ) EntityParent arm , sholder_l , False elbow_l = CreatePivot( sholder_l ) PositionEntity elbow_l , 0,-30,0 uarm = createbox( 0,-15,0 , 5,10,5 ) EntityParent uarm , elbow_l , False wrist_l = CreatePivot( elbow_l ) PositionEntity wrist_l , 0,-30,0 hand = createbox( 0,-7,0 , 3,7,7 ) EntityParent hand , wrist_l , False sholder_r = CreatePivot( body ) PositionEntity sholder_r , -30,30,0 arm = createbox( 0,-15,0 , 5,10,5 ) EntityParent arm , sholder_r , False elbow_r = CreatePivot( sholder_r ) PositionEntity elbow_r , 0,-30,0 uarm = createbox( 0,-15,0 , 5,10,5 ) EntityParent uarm , elbow_r , False wrist_r = CreatePivot( elbow_r ) PositionEntity wrist_r , 0,-30,0 hand = createbox( 0,-7,0 , 3,7,7 ) EntityParent hand , wrist_r , False neck = CreatePivot( body ) PositionEntity neck , 0,50,0 ;setbox( 0,0,0 , 10,10,10 ) ;head = createtorus() head = createbox( 0,0,0 , 10,10,10 ) EntityParent head , neck , False bekken_l = CreatePivot( body ) PositionEntity bekken_l , 15,-30,0 leg = createbox( 0,-15,0 , 5,10,5 ) EntityParent leg , bekken_l , False knee_l = CreatePivot( bekken_l ) PositionEntity knee_l , 0,-30,0 uleg = createbox( 0,-15,0 , 5,10,5 ) EntityParent uleg , knee_l , False enkle_l = CreatePivot( knee_l ) PositionEntity enkle_l , 0,-30,0 foot = createbox( 0,-5,-7 , 5,5,10 ) EntityParent foot , enkle_l , False bekken_r = CreatePivot( body ) PositionEntity bekken_r, -15,-30,0 leg = createbox( 0,-15,0 , 5,10,5 ) EntityParent leg , bekken_r, False knee_r= CreatePivot( bekken_r) PositionEntity knee_r , 0,-30,0 uleg = createbox( 0,-15,0 , 5,10,5 ) EntityParent uleg , knee_r, False enkle_r = CreatePivot( knee_r) PositionEntity enkle_r, 0,-30,0 foot = createbox( 0,-5,-7 , 5,5,10 ) EntityParent foot , enkle_r, False angle = 0 While Not KeyDown( 1 ) TurnEntity body , 0 , 1 , 0 RotateEntity sholder_l , pend( angle , 30 ) , 0 , 0 RotateEntity elbow_l , 30 , 0 , 0 RotateEntity bekken_l , pend( angle + 180 , 30 ) , 0 , 0 RotateEntity knee_l , pend( angle + 90 , 30 ) - 30 , 0 , 0 RotateEntity sholder_r , pend( angle + 180 , 30 ) , 0 , 0 RotateEntity elbow_r , 30 , 0 , 0 RotateEntity bekken_r , pend( angle , 30 ) , 0 , 0 RotateEntity knee_r , pend( angle - 90 , 30 ) - 30 , 0 , 0 angle = angle + 5 UpdateWorld RenderWorld Flip Wend shapes.bb : Type tbox Field mx# Field my# Field mz# Field dx# Field dy# Field dz# End Type Global box.tbox = New tbox Function setbox( mx# , my# , mz# , dx# , dy# , dz# ) box\mx = mx box\my = my box\mz = mz box\dx = dx box\dy = dy box\dz = dz End Function Function CreateBox( mx# , my# , mz# , dx# , dy# , dz# ) mesh = CreateCube() ScaleMesh mesh , dx , dy , dz PositionMesh mesh , mx , my , mz Return mesh End Function Function createtorus() mesh = CreateMesh() surface = CreateSurface( mesh ) mx = box\mx my = box\my mz = box\mz dx = box\dx dy = box\dy dz = box\dz ; For i = -180 To 180 Step 360 / 12 ; i2 = i + 360 / 12 ; For j = -180 To 180 Step 360 / 12 ; j2 = j + 360 / 12 ; x = mx + ( dx + dy * Cos( i ) ) * Cos( j ) ; y = my + ( dx + dy * Cos( i ) ) * Sin( j ) ; z = mz + Sin( i ) * dz ; v0 = AddVertex( surface , x , y , z ) ; x = mx + ( dx + dy * Cos( i ) ) * Cos( j2 ) ; y = my + ( dx + dy * Cos( i ) ) * Sin( j2 ) ; z = mz + Sin( i ) * dz ; v1 = AddVertex( surface , x , y , z ) ; x = mx + ( dx + dy * Cos( i2 ) ) * Cos( j2 ) ; y = my + ( dx + dy * Cos( i2 ) ) * Sin( j2 ) ; z = mz + Sin( i ) * dz ; v2 = AddVertex( surface , x , y , z ) ; x = mx + ( dx + dy * Cos( i2 ) ) * Cos( j ) ; y = my + ( dx + dy * Cos( i2 ) ) * Sin( j ) ; z = mz + Sin( i ) * dz ; v3 = AddVertex( surface , x , y , z ) ; AddTriangle( suface , v0 , v1 , v2 ) ; AddTriangle( suface , v0 , v2 , v3 ) ; Next j ; Next i Return mesh End Function Function pend#( fase# , amp# ) Return Sin( fase ) * amp End Function |
| ||
you've got some errors in the syntax "next" is the end of the "For/Next" statement. You can't iterate the variable after take care of your variable names : Surface is mispelled on the Addtriangle (suface) And I don't know how you intend to get a torus with this, but anyway, here is a valid function. by the way : nice job on the procedural animation :) |
| ||
update : - avatar function [ now i can create lots of avatars ] - animation function main : Include "shapes.bb" Graphics3D 640,480,16,1 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-200 light=CreateLight() RotateEntity light,90,0,0 human1.human = New human createhuman( human1 ) PositionEntity human1\body , -50,0,0 human2.human = New human createhuman( human2 ) PositionEntity human2\body , 50,0,0 angle = 0 While Not KeyDown( 1 ) TurnEntity human1\body , 0 , 1 , 0 human_walk( human1 , angle * 4 , 30 ) human_walk( human2 , angle * 5 , 30 ) angle = ( angle + 1 ) Mod 360 UpdateWorld RenderWorld Flip Wend shapes.bb Type tbox Field mx# Field my# Field mz# Field dx# Field dy# Field dz# End Type Global box.tbox = New tbox Function setbox( mx# , my# , mz# , dx# , dy# , dz# ) box\mx = mx box\my = my box\mz = mz box\dx = dx box\dy = dy box\dz = dz End Function Function CreateBox( mx# , my# , mz# , dx# , dy# , dz# ) mesh = CreateCube() ScaleMesh mesh , dx , dy , dz PositionMesh mesh , mx , my , mz Return mesh End Function Function createtorus() local mesh = CreateMesh() local surface = CreateSurface( mesh ) local mx# = box\mx local my# = box\my local mz# = box\mz local dx# = box\dx local dy# = box\dy local dz# = box\dz ; For i = -180 To 180 Step 360 / 12 ; local i2 = i + 360 / 12 ; For j = -180 To 180 Step 360 / 12 ; local j2 = j + 360 / 12 ; local x# = mx + ( dx + dy * Cos( i ) ) * Cos( j ) ; local y# = my + ( dx + dy * Cos( i ) ) * Sin( j ) ; local z# = mz + Sin( i ) * dz ; local v0 = AddVertex( surface , x , y , z ) ; x = mx + ( dx + dy * Cos( i ) ) * Cos( j2 ) ; y = my + ( dx + dy * Cos( i ) ) * Sin( j2 ) ; z = mz + Sin( i ) * dz ; local v1 = AddVertex( surface , x , y , z ) ; x = mx + ( dx + dy * Cos( i2 ) ) * Cos( j2 ) ; y = my + ( dx + dy * Cos( i2 ) ) * Sin( j2 ) ; z = mz + Sin( i ) * dz ; local v2 = AddVertex( surface , x , y , z ) ; x = mx + ( dx + dy * Cos( i2 ) ) * Cos( j ) ; y = my + ( dx + dy * Cos( i2 ) ) * Sin( j ) ; z = mz + Sin( i ) * dz ; local v3 = AddVertex( surface , x , y , z ) ; AddTriangle( surface , v0 , v1 , v2 ) ; AddTriangle( surface , v0 , v2 , v3 ) ; Next ; j ; Next ; i Return mesh End Function Function pend#( fase# , amp# ) Return Sin( fase ) * amp End Function Type human Field body Field sholder_l , sholder_r Field elbow_l , elbow_r Field wrist_l , wrist_r Field neck Field bekken_l , bekken_r Field knee_l , knee_r Field enkle_l , enkle_r End Type Function createhuman( h.human ) h\body = CreatePivot( 0 ) lijf = createbox( 0,0,0 , 20,30,5 ) EntityParent lijf , h\body h\sholder_l = CreatePivot( h\body ) PositionEntity h\sholder_l , 30,30,0 arm = createbox( 0,-15,0 , 5,10,5 ) EntityParent arm , h\sholder_l , False h\elbow_l = CreatePivot( h\sholder_l ) PositionEntity h\elbow_l , 0,-30,0 uarm = createbox( 0,-15,0 , 5,10,5 ) EntityParent uarm , h\elbow_l , False h\wrist_l = CreatePivot( h\elbow_l ) PositionEntity h\wrist_l , 0,-30,0 hand = createbox( 0,-7,0 , 3,7,7 ) EntityParent hand , h\wrist_l , False h\sholder_r = CreatePivot( h\body ) PositionEntity h\sholder_r , -30,30,0 arm = createbox( 0,-15,0 , 5,10,5 ) EntityParent arm , h\sholder_r , False h\elbow_r = CreatePivot( h\sholder_r ) PositionEntity h\elbow_r , 0,-30,0 uarm = createbox( 0,-15,0 , 5,10,5 ) EntityParent uarm , h\elbow_r , False h\wrist_r = CreatePivot( h\elbow_r ) PositionEntity h\wrist_r , 0,-30,0 hand = createbox( 0,-7,0 , 3,7,7 ) EntityParent hand , h\wrist_r , False h\neck = CreatePivot( h\body ) PositionEntity h\neck , 0,50,0 ;setbox( 0,0,0 , 10,10,10 ) ;head = createtorus() head = createbox( 0,0,0 , 10,10,10 ) EntityParent head , h\neck , False h\bekken_l = CreatePivot( h\body ) PositionEntity h\bekken_l , 15,-30,0 leg = createbox( 0,-15,0 , 5,10,5 ) EntityParent leg , h\bekken_l , False h\knee_l = CreatePivot( h\bekken_l ) PositionEntity h\knee_l , 0,-30,0 uleg = createbox( 0,-15,0 , 5,10,5 ) EntityParent uleg , h\knee_l , False h\enkle_l = CreatePivot( h\knee_l ) PositionEntity h\enkle_l , 0,-30,0 foot = createbox( 0,-5,-7 , 5,5,10 ) EntityParent foot , h\enkle_l , False h\bekken_r = CreatePivot( h\body ) PositionEntity h\bekken_r, -15,-30,0 leg = createbox( 0,-15,0 , 5,10,5 ) EntityParent leg , h\bekken_r, False h\knee_r= CreatePivot( h\bekken_r) PositionEntity h\knee_r , 0,-30,0 uleg = createbox( 0,-15,0 , 5,10,5 ) EntityParent uleg , h\knee_r, False h\enkle_r = CreatePivot( h\knee_r) PositionEntity h\enkle_r, 0,-30,0 foot = createbox( 0,-5,-7 , 5,5,10 ) EntityParent foot , h\enkle_r, False End Function Function human_walk( h.human , angle# , a# ) RotateEntity h\sholder_l , pend( angle , a ) , 0 , 0 RotateEntity h\elbow_l , a , 0 , 0 RotateEntity h\bekken_l , pend( angle + 180 , a ) , 0 , 0 RotateEntity h\knee_l , pend( angle + 90 , a ) - a , 0 , 0 RotateEntity h\sholder_r , pend( angle + 180 , a ) , 0 , 0 RotateEntity h\elbow_r , a , 0 , 0 RotateEntity h\bekken_r , pend( angle , a ) , 0 , 0 RotateEntity h\knee_r , pend( angle - 90 , a ) - a , 0 , 0 End Function |
| ||
update : - now whit torus function error : - where are my normals ? main : Include "shapes.bb" Graphics3D 640,480,16,1 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-200 light=CreateLight() RotateEntity light,90,0,0 human1.human = New human createhuman( human1 ) PositionEntity human1\body , -70,0,0 human2.human = New human createhuman( human2 ) PositionEntity human2\body , 70,0,0 setbox( 0,0,0 , 15,5,5 ) torus = createtorus() angle = 0 While Not KeyDown( 1 ) TurnEntity human1\body , 0 , 1 , 0 human_walk( human1 , angle * 4 , 30 ) human_walk( human2 , angle * 5 , 30 ) angle = ( angle + 1 ) Mod 360 TurnEntity torus , 1 , 0 , 0 UpdateWorld RenderWorld Flip Wend shapes.bb : Type tbox Field mx# Field my# Field mz# Field dx# Field dy# Field dz# End Type Global box.tbox = New tbox Function setbox( mx# , my# , mz# , dx# , dy# , dz# ) box\mx = mx box\my = my box\mz = mz box\dx = dx box\dy = dy box\dz = dz End Function Function CreateBox( mx# , my# , mz# , dx# , dy# , dz# ) mesh = CreateCube() ScaleMesh mesh , dx , dy , dz PositionMesh mesh , mx , my , mz Return mesh End Function Function createtorus() Local mesh = CreateMesh() local surface = CreateSurface( mesh ) local mx# = box\mx local my# = box\my local mz# = box\mz local dx# = box\dx local dy# = box\dy local dz# = box\dz For i = -180 To 180 Step 360 / 12 Local i2 = i + 360 / 12 For j = -180 To 180 Step 360 / 12 Local j2 = j + 360 / 12 Local x# = mx + ( dx + dy * Cos( i ) ) * Cos( j ) Local y# = my + ( dx + dy * Cos( i ) ) * Sin( j ) Local z# = mz + Sin( i ) * dz Local v0 = AddVertex( surface , x , y , z ) x = mx + ( dx + dy * Cos( i ) ) * Cos( j2 ) y = my + ( dx + dy * Cos( i ) ) * Sin( j2 ) z = mz + Sin( i ) * dz Local v1 = AddVertex( surface , x , y , z ) x = mx + ( dx + dy * Cos( i2 ) ) * Cos( j2 ) y = my + ( dx + dy * Cos( i2 ) ) * Sin( j2 ) z = mz + Sin( i2 ) * dz Local v2 = AddVertex( surface , x , y , z ) x = mx + ( dx + dy * Cos( i2 ) ) * Cos( j ) y = my + ( dx + dy * Cos( i2 ) ) * Sin( j ) z = mz + Sin( i2 ) * dz Local v3 = AddVertex( surface , x , y , z ) AddTriangle( surface , v0 , v1 , v2 ) AddTriangle( surface , v0 , v2 , v3 ) Next ; j Next ; i Return mesh End Function Function pend#( fase# , amp# ) Return Sin( fase ) * amp End Function Type human Field body Field sholder_l , sholder_r Field elbow_l , elbow_r Field wrist_l , wrist_r Field neck Field bekken_l , bekken_r Field knee_l , knee_r Field enkle_l , enkle_r End Type Function createhuman( h.human ) h\body = CreatePivot( 0 ) lijf = createbox( 0,0,0 , 20,30,5 ) EntityParent lijf , h\body h\sholder_l = CreatePivot( h\body ) PositionEntity h\sholder_l , 30,30,0 arm = createbox( 0,-15,0 , 5,10,5 ) EntityParent arm , h\sholder_l , False h\elbow_l = CreatePivot( h\sholder_l ) PositionEntity h\elbow_l , 0,-30,0 uarm = createbox( 0,-15,0 , 5,10,5 ) EntityParent uarm , h\elbow_l , False h\wrist_l = CreatePivot( h\elbow_l ) PositionEntity h\wrist_l , 0,-30,0 hand = createbox( 0,-7,0 , 3,7,7 ) EntityParent hand , h\wrist_l , False h\sholder_r = CreatePivot( h\body ) PositionEntity h\sholder_r , -30,30,0 arm = createbox( 0,-15,0 , 5,10,5 ) EntityParent arm , h\sholder_r , False h\elbow_r = CreatePivot( h\sholder_r ) PositionEntity h\elbow_r , 0,-30,0 uarm = createbox( 0,-15,0 , 5,10,5 ) EntityParent uarm , h\elbow_r , False h\wrist_r = CreatePivot( h\elbow_r ) PositionEntity h\wrist_r , 0,-30,0 hand = createbox( 0,-7,0 , 3,7,7 ) EntityParent hand , h\wrist_r , False h\neck = CreatePivot( h\body ) PositionEntity h\neck , 0,50,0 ;setbox( 0,0,0 , 10,5,5 ) ;head = createtorus() head = createbox( 0,0,0 , 10,10,10 ) EntityParent head , h\neck , False h\bekken_l = CreatePivot( h\body ) PositionEntity h\bekken_l , 15,-30,0 leg = createbox( 0,-15,0 , 5,10,5 ) EntityParent leg , h\bekken_l , False h\knee_l = CreatePivot( h\bekken_l ) PositionEntity h\knee_l , 0,-30,0 uleg = createbox( 0,-15,0 , 5,10,5 ) EntityParent uleg , h\knee_l , False h\enkle_l = CreatePivot( h\knee_l ) PositionEntity h\enkle_l , 0,-30,0 foot = createbox( 0,-5,-7 , 5,5,10 ) EntityParent foot , h\enkle_l , False h\bekken_r = CreatePivot( h\body ) PositionEntity h\bekken_r, -15,-30,0 leg = createbox( 0,-15,0 , 5,10,5 ) EntityParent leg , h\bekken_r, False h\knee_r= CreatePivot( h\bekken_r) PositionEntity h\knee_r , 0,-30,0 uleg = createbox( 0,-15,0 , 5,10,5 ) EntityParent uleg , h\knee_r, False h\enkle_r = CreatePivot( h\knee_r) PositionEntity h\enkle_r, 0,-30,0 foot = createbox( 0,-5,-7 , 5,5,10 ) EntityParent foot , h\enkle_r, False End Function Function human_walk( h.human , angle# , a# ) RotateEntity h\sholder_l , pend( angle , a ) , 0 , 0 RotateEntity h\elbow_l , a , 0 , 0 RotateEntity h\bekken_l , pend( angle + 180 , a ) , 0 , 0 RotateEntity h\knee_l , pend( angle + 90 , a ) - a , 0 , 0 RotateEntity h\sholder_r , pend( angle + 180 , a ) , 0 , 0 RotateEntity h\elbow_r , a , 0 , 0 RotateEntity h\bekken_r , pend( angle , a ) , 0 , 0 RotateEntity h\knee_r , pend( angle - 90 , a ) - a , 0 , 0 End Function |
| ||
You can use the [ codebox ] [ /codebox ] tags to create a scrollable text area that displays your code. This way it's easier to follow the thread. |
| ||
There is another way to create rigged, skinned (only with a 100% influence of a joint over a mesh), animated, characters in code : First step : create a skeleton with joints (pivots) ->There must be one root joint which will be parent of all others joints ->Each other joint must be a child of the root joint or of another joint ->each body part (mesh) will be child of the root joint or of another joint ->The root joint will then be used to turn/move the entity in the world and all others child joints and child meshes will turn/move with it. Second step : create the different body parts (meshes) and set each body part as a child of a joint Third step : create an animation : ->each animation is composed of several animation frames (poses) ->to prepare an animation frame, you can use rotateentity/positionentity to rotate/position each joint as you want ->to save the animation frame you can use SetAnimKey(RootJoint,FrameId) ->when you have finished to create all animation frames, you can use AddAnimSeq(RootJoint,FramesCount) Fourth Step : extract an animation ->you can use AnimationX = extractanimseq(RootJoint,StartFrameId,EndFrameId) Fifth step : play/stop the animation ->you can use Animate(RootJoint,Mode%,Speed#,AnimationX) Then you can also use CharacterCopy = copyentity(RooJoint) to create many others characters. I have an old example somewhere on a dvd-r i will try to find it. |
| ||
Use UpdateNormals (torus), it will calculate them for you. Else, manually use VertexNormal(surface, vertexIndex, nx,ny,nz) for each vertices to set the normals. |
| ||
Example of what i meant : |