Yes, my next 3D OGRE motion question ...

Everything related to 3D programming
marc_256
Addict
Addict
Posts: 842
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Yes, my next 3D OGRE motion question ...

Post by marc_256 »

Hello,

Yes, my next 3D OGRE motion question ... :)

For my next machine part, I need a open toothed rubber belt.
but this is a dynamic belt, it need to be bended around one drive shaft and one free running shaft.

If the motor is turning (forwards/backwards) the linear wagon is moving left/right but also the driver belt is moving.

The parts are still in BLENDER, is there a way to make them bendable in OGRE 3D ?
In BLENDER I can give the belt an ARMATURE with several BONES, one bone for every teeth of the belt ...
= 278 teeths on the belt = 278 bones to program :? !?

See some images (in BLENDER for now) below to explain more.


Greetings,
marc


Image



Image



Image
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
Piero
Addict
Addict
Posts: 923
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Yes, my next 3D OGRE motion question ...

Post by Piero »

I broke several parts of my lawnmower at the same time recently; I now think I found the right person to ask for tips about a structural fix
marc_256
Addict
Addict
Posts: 842
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Yes, my next 3D OGRE motion question ...

Post by marc_256 »

Maybe starting with something simpler ...

I uses also some chains in the project,
I think this must be easy er with 0nly 40 bones in the armature structure.

These chain links I position these by calculations
> Positions X,Y,Z
> Rotations X,Y,Z

But these are fixed chain links points.
To animate them I need the auto mode.

Is there in OGRE 3D or BULLET a path I can preprogram ?
Where the bones have to go along this path.

Thanks again,
(for the help with my very complex motion/gaming engine project)

marc



Image




Image
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 386
Joined: Thu Jul 09, 2015 9:07 am

Re: Yes, my next 3D OGRE motion question ...

Post by pf shadoko »

I made the chain in the same style as my previous example
it's a bit more complicated, since the section has an “H” shape
all the points are doubled to give angular edges (compared to normals)

of course it's fake, a simple texture scrolling, but it's light

otherwise, to make it clean, you have to use entities for each link (“entitydirection” to orient them)

Code: Select all

InitEngine3D():InitSprite():InitKeyboard():InitMouse()

Procedure copyimagetotexture(im,tx,freeimage.b=1)
  Protected n=CreateTexture(tx,ImageWidth(im),ImageHeight(im)):If tx=-1:tx=n:EndIf
  StartDrawing(TextureOutput(tx))
  DrawingMode(#PB_2DDrawing_AllChannels)
  DrawImage(ImageID(im),0,0)
  StopDrawing()
  If freeimage:FreeImage(im):EndIf
  ProcedureReturn tx
EndProcedure

ExamineDesktops()
OpenWindow(0, 0,0, DesktopWidth(0)*0.8,DesktopHeight(0)*0.8, "CreateShader - [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

Add3DArchive(#PB_Compiler_Home + "examples\3D\Data\Textures", #PB_3DArchive_FileSystem)
Add3DArchive(GetCurrentDirectory(), #PB_3DArchive_FileSystem )
Parse3DScripts()


CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,2,-2):CameraLookAt(0,0,0,0)
CreateLight(0,$ffffff, -100, 100, 100)
AmbientColor($111111*8)
CameraBackColor(0,$444488)

CreateImage(0,512,256,32,-1)
StartVectorDrawing(ImageVectorOutput(0))

AddPathBox(0,50,512,156)
VectorSourceColor($ff888888):FillPath()

AddPathCircle(150,128,127)
VectorSourceColor($ffaaaaaa):FillPath()
AddPathCircle(512-150,128,127)
VectorSourceColor($ffaaaaaa):FillPath()

AddPathCircle(150,128,50)
AddPathCircle(512-150,128,50)
VectorSourceColor($ff000000):StrokePath(3)

StopVectorDrawing()
copyimagetotexture(0,0)

CreateMaterial(0,TextureID(0))
MaterialShininess(0,64,$ffffff)
MaterialFilteringMode(0,#PB_Material_Anisotropic)
SetMaterialAttribute(0,#PB_Material_AlphaReject,128)
MaterialCullingMode(0,#PB_Material_NoCulling)
ScrollMaterial(0,1,0,#PB_Material_Animated)

;{----------------------------------------------------------------- mesh chain
Structure f2:x.f:y.f:EndStructure
Global Dim lpi.f2(1000)
Global Dim lpe.f2(1000)
Global n
Define.f x0,y0,r0,x1,y1,r1,x2,y2,r2,  la,  ai,af,a,da,u,r

Procedure.f lenght(*p0.f2,*p1.f2)
  Protected.f dx=*p1\x-*p0\x,dy=*p1\y-*p0\y
  ProcedureReturn Sqr(dx*dx+dy*dy)
EndProcedure

Procedure arc(x.f,y.f,r.f,ep.f,ai.f,af.f)
  Protected.f a,da=360/64
  a=ai
  While a=<af
    a+da  
    Lpi(n)\x=x+Cos(Radian(a))*r     :lpi(n)\y=y+Sin(Radian(a))*r
    Lpe(n)\x=x+Cos(Radian(a))*(r+ep):lpe(n)\y=y+Sin(Radian(a))*(r+ep)
    n+1
  Wend
EndProcedure

Procedure ameshvertex(*v.meshvertex, x.f,y.f,z.f,u.f,v.f)
    *v\x=x
    *v\y=y
    *v\z=z
    *v\u=u
    *v\v=v
EndProcedure

x0= 1:y0= 0  :r0=0.3;  coordinates x,y , radius cylinder
x1=-1:y1= 0  :r1=0.3
x2= 0:y2=-0.5:r2=0.3
la=0.1 ;chain width
ep.f=0.1; chain height

da=30
arc(x0,y0,r0,ep,-90+da,90)
arc(x1,y1,r1,ep,90,270-da)
arc(x2,y2,r2,ep,270-da,270+da)
arc(x0,y0,r0,ep,-90+da,-90+da)

Dim v.MeshVertex(n-1,23)
For i=0 To n-1
  If i:u+lenght(lpi(i-1),lpi(i)):EndIf
  j=0
  Macro lpx(r):lpi(i)\x*r+lpe(i)\x*(1-r):EndMacro
  Macro lpy(r):lpi(i)\y*r+lpe(i)\y*(1-r):EndMacro
  
  aMeshVertex(v(i,j),lpi(i)\x,lpi(i)\y,-la*0.5,u,0.0):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpi(i)\x,lpi(i)\y,-la*0.2,u,0.0):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpx(0.3),lpy(0.3),-la*0.5,u,0.5):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpx(0.3),lpy(0.3), la*0.5,u,0.5):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpi(i)\x,lpi(i)\y, la*0.2,u,0.0):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpi(i)\x,lpi(i)\y, la*0.5,u,0.0):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpe(i)\x,lpe(i)\y, la*0.5,u,1.0):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpe(i)\x,lpe(i)\y, la*0.2,u,1.0):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpx(0.7),lpy(0.7), la*0.5,u,0.5):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpx(0.7),lpy(0.7),-la*0.5,u,0.5):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpe(i)\x,lpe(i)\y,-la*0.2,u,1.0):v(i,j+1)=v(i,j):j+2
  aMeshVertex(v(i,j),lpe(i)\x,lpe(i)\y,-la*0.5,u,1.0):v(i,j+1)=v(i,0)
  ;Debug j
 Next
 CreateDataMesh(0,v(),8)
 
 ScaleMaterial(0,u/30,1) ; to match start and end of conveyor belt 
;}

CreateEntity(0,MeshID(0),MaterialID(0))


Define.f MouseX,Mousey,depx,depz,dist,val,blend

Repeat
	While WindowEvent():Wend
	ExamineKeyboard()
	ExamineMouse()
	If KeyboardPushed(#PB_Key_Space)=0:RotateEntity(0,0.2,0.2,0.2, #PB_Relative):EndIf
	
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)
marc_256
Addict
Addict
Posts: 842
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Yes, my next 3D OGRE motion question ...

Post by marc_256 »

Hi pf shadoko,

I have the impression, you are one of the few who understands my work and problems.
So thanks for your help, this is much appreciated.

I tested your program today, and I needed to change some stuff to adapt to PB5.73x64 and it works now.
Nice stuff you did here.
But I'm working with meshes and entity's.

Yesterday (to early this morning), :?
I made an array of all the possible positions and rotations of each chain link.
As the gears are different in teethes and diameter (gear1 = T16, gear2 = T14)
so there is a ratio (difference) between the gears.
I first started with a static environment, and later I started with the dynamic environment.
next step is to find out the mathematical solution.
So, I'm writing a part for find out the tangential points on two circles.
To build the correct chain link path.


By testing the dynamical motions:
Again, I lost a lot of time with the Documentations...
- RotateEntity (Entity, RotX, RotY, RotZ, Options)
- MoveEntity (Entity, PosX, PosY, PosZ, Options)

The options of these commands are not ok at all, and are NOT working correctly.

Greetings,
marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
SMaag
Enthusiast
Enthusiast
Posts: 325
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: Yes, my next 3D OGRE motion question ...

Post by SMaag »

Hello marc_256,

as you know I work sometimes on similar things as you.
I can't give you a code, but:
What you want to do is same as like in professional CAD like SolidWorks, where you have a chain an belt function.

I would not do it with a lot of Entities. I guess the way is to create a Spline as base for the chain.
Then calculate all the tooth along the spline. Thats the way a CAD Systen do it!

For the motion effect precalculate 3 Meshes with a little difference in the tooth postions and switch between this meshes.
If this will be possible with a ready mesh from Blender???

For motion effects splines are the way to go. Thre are different type of splines to get different effects.
marc_256
Addict
Addict
Posts: 842
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Yes, my next 3D OGRE motion question ...

Post by marc_256 »

@ SMaag,

I'm working on a 3D game/motion engine and I'm writing a Belt/Chain motion algorithm,
and the first results are very good,
but I have a bug somewhere in the synchronization ratio between the belt and the belt gear and I can't find it. :twisted:
It will take some time like all my 3D algorithm's stuff. :wink:
But we will succeed ...

Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 386
Joined: Thu Jul 09, 2015 9:07 am

Re: Yes, my next 3D OGRE motion question ...

Post by pf shadoko »

here, I've made you a version to use your mesh
(replace CreateCylinder with your mesh)

it should work with PB 5.73

Code: Select all

EnableExplicit

Structure f2:x.f:y.f:EndStructure

Global Dim lp.f2(1000); pos
Global Dim ll.f(1000); lenth
Global n=-1
Global nm=80 ;link number
Global l.f ;chain length
Global lm.f;link length
Global Dim m.f2(nm); link pos

InitEngine3D():InitSprite():InitKeyboard():InitMouse()

ExamineDesktops()
OpenWindow(0, 0,0, DesktopWidth(0)*0.8,DesktopHeight(0)*0.8, "chain - [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,1,-2):CameraLookAt(0,0,0,0)
CreateLight(0,$ffffff, -100, 100, 100)
AmbientColor($111111*8)
CameraBackColor(0,$444488)

CreateMaterial(0,0,$00ff):MaterialShininess(0,64):SetMaterialColor(0,#PB_Material_SpecularColor,$ffffff)
CreateMaterial(1,0,$ff00):MaterialShininess(1,64):SetMaterialColor(1,#PB_Material_SpecularColor,$ffffff)

CreateCylinder(0,0.01,0.01):TransformMesh(0,0,0,0,6,4,4,90,0,0):NormalizeMesh(0)
CreateCylinder(1,0.01,0.01):TransformMesh(1,0,0,0,6,2,4,90,0,0):NormalizeMesh(1)

Define j
For j=0 To nm-1
  CreateEntity(j,MeshID(j&1),MaterialID(j&1))
Next

Procedure.f lenght2D(*p0.f2,*p1.f2)
  Protected.f dx=*p1\x-*p0\x,dy=*p1\y-*p0\y
  ProcedureReturn Sqr(dx*dx+dy*dy)
EndProcedure

Procedure Mix2D(*R.f2, *V1.f2, *V2.f2, r.f)
  *R\x = *V1\x + r * (*V2\x - *V1\x)
  *R\y = *V1\y + r * (*V2\y - *V1\y)
EndProcedure

Macro sub2D(p,p1,p2)
	p\x=p1\x-p2\x
	p\y=p1\y-p2\y
EndMacro

Procedure arc(x.f,y.f,r.f,ai.f,af.f)
  Protected.f a,da=360/64
  a=ai
  While a=<af
    a+da  
    n+1
    Lp(n)\x=x+Cos(Radian(a))*r
    lp(n)\y=y+Sin(Radian(a))*r
  Wend
EndProcedure

Define i
Define.f x0,y0,r0,x1,y1,r1,x2,y2,r2,  da
x0= 1:y0= 0  :r0=0.3;  coordinates x,y , radius cylinder
x1=-1:y1= 0  :r1=0.3
x2= 0:y2=-0.5:r2=0.3

da=30
arc(x0,y0,r0,-90+da,90)
arc(x1,y1,r1,90,270-da)
arc(x2,y2,r2,270-da,270+da)
arc(x0,y0,r0,-90+da,-90+da)

; chain length
For i=0 To n-1
  ll(i)=lenght2d(lp(i),lp(i+1))
  l+ll(i)
Next
lm=l/nm

Procedure chaine(pos.f); caution: too high a pos value will slow down execution 
  Protected.f r,ali,li,almi,lmi,seg.f2
  Protected i,i0m,i1m,j,linkt
  
  lmi=pos
  i=-1
  Repeat
    While li<=lmi
      i+1:ali=li
      i0m=(i+n+0) % n
      i1m=(i+n+1) % n
      li+ll(i0m)
    Wend
    r=(lmi-ali)/ll(i0m)
    Mix2D(m(j),lp(i0m),lp(i1m),r);:Debug "ali:"+ali+#TAB$+"li:"+li+#TAB$+"lmi:"+lmi+"  "+i+"  "+r
    linkt=j & 1
    sub2d(seg,lp(i1m),lp(i0m))
    MoveEntity(j,m(j)\x,m(j)\y,0,#PB_Absolute)
    ;EntityDirection(j,seg\x,seg\y,0,#PB_World ,#PB_Vector_X)
    RotateEntity(j,0,0,Degree(ATan2(seg\x,seg\y)),#PB_Absolute) ; for PB 5.73
    j+1
    almi=lmi:lmi+lm
  Until j=nm
EndProcedure

Define.f MouseX,Mousey,depx,depz,dist,val,blend

Repeat
	While WindowEvent():Wend
	ExamineKeyboard()
	ExamineMouse()
  chaine(ElapsedMilliseconds()/5000)
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)
Post Reply