VertexBoneAssignment does not have an effect

All bugs related to the 3D engine
miso
Enthusiast
Enthusiast
Posts: 462
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

VertexBoneAssignment does not have an effect

Post by miso »

6.21 beta 9
Skeleton creation seems to be all right, but the weights does not affect the vertices.
Semi-official example provided works on earlier releases. (6.11 beta 2 tested to be fine)

Code: Select all

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

OpenWindow(0, 0,0, 1280,720, "Test 3d - [F12] Wireframe/Solid   [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,2,8):CameraLookAt(0,0,2,0):CameraBackColor(0,$446666)
CreateLight(0,$ffffff, -1000, 1000, 0)
AmbientColor($444444)

CreateShaderMaterial(0,#PB_Material_ColorShader)
SetMaterialColor(0,#PB_Material_AmbientColor|#PB_Material_DiffuseColor,$ff):MaterialShininess(0,64,$ffffff)
MaterialCullingMode(0,#PB_Material_NoCulling)

Define ns=4     ; section number (joint)
Define lgs=2    ; section lenght
Define r.f=0.2  ; section radius
Define ni=8 ,nj=16, w.f,pos.f,ai.f

; ----------- mesh creation
Dim t.MeshVertex((nj+1)*(ns)-1,ni)
For s=0 To ns-1
  For j=0 To nj
    For i=0 To ni
      With t(s*(nj+1)+j,i) 
        ai=i/ni*2*#PI
        \x=-Cos(ai)*r
        \z=Sin(ai)*r
        \y=(0.0+s+j/nj)*lgs
        \u=i/4
        \v=j/16
        \Color=$ffffff
        \NormalX=\x
        \Normaly=0
        \Normalz=\z
      EndWith 
    Next
  Next
Next
CreateDataMesh(0,t())

; ----------- skeleton/joints creation
Define joint.s,pjoint.s
CreateSphere(100,0.05)
CreateMaterial(100,0,$ffffff)

CreateSkeleton(0)
For s=0 To ns
  pjoint=joint
  joint="joint"+s
  CreateBone(0,joint,pjoint,0,lgs*s,0,0,0,0,0,0)
  CreateEntity(100+s,MeshID(100),MaterialID(100))
Next

; ----------- Vertex Bone Assignment
For s=0 To ns
  For j=0 To nj
    For i=0 To ni
      vi=(s*(nj+1)+j)*(ni+1)+i
      v.f=s+j/nj-0.5:If v<0:v=0:EndIf
      w=Mod(v,1)
      bi=Int(v)
      VertexBoneAssignment(0,0,vi,bi+0,1-w)
      VertexBoneAssignment(0,0,vi,bi+1,w)
    Next
  Next
Next
FinishBoneAssignment(0,0)

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

Define.f MouseX,Mousey,depx,depz,dist,rotx,fdf=1,a.f

Repeat
  While WindowEvent():Wend
  ExamineKeyboard()
  ExamineMouse()
  depx=(-Bool(KeyboardPushed(#PB_Key_Left))+Bool(KeyboardPushed(#PB_Key_Right)))*0.1
  depz=(-Bool(KeyboardPushed(#PB_Key_Down))+Bool(KeyboardPushed(#PB_Key_Up   )))*0.1+MouseWheel()*5
  If KeyboardReleased(#PB_Key_F12):fdf=1-fdf:EndIf:If fdf:MaterialShadingMode(0, #PB_Material_Wireframe):Else:MaterialShadingMode(0,#PB_Material_Solid):EndIf
  MouseX = -MouseDeltaX() *  0.05
  MouseY = -MouseDeltaY() *  0.05
  RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
  dist+(depz-dist)*0.05:MoveCamera  (0, depX, 0, -dist)
  a+0.01
  
  rotx+(-Bool(KeyboardPushed(#PB_Key_Pad1))+Bool(KeyboardPushed(#PB_Key_Pad4)))
  For s=0 To ns
    joint="joint"+Str(s)
    EnableManualEntityBoneControl(0, joint, #True, #True)
    a+0.0002:rotx=Sin(a+s*0)*90
    If s & 1:sens=1:Else:sens=-1:EndIf
    RotateEntityBone(0, joint, 0,0,sens*rotx, #PB_Absolute)
    MoveEntity(100+s,EntityBoneX(0,joint),EntityBoneY(0,joint),EntityBoneZ(0,joint),#PB_Absolute)
  Next
  
  RenderWorld()
  FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 386
Joined: Thu Jul 09, 2015 9:07 am

Re: VertexBoneAssignment does not have an effect

Post by pf shadoko »

I've deactivated software animation in shader materials to allow material animation (much faster)
as soon as 6.21 is released, I'll give you a function for dynamic shader creation, taking into account animation, shadows and so on

In the meantime, in the example, replace :
CreateShaderMaterial(0,#PB_Material_ColorShader)
by :
CreateMaterial(0,0)
miso
Enthusiast
Enthusiast
Posts: 462
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: VertexBoneAssignment does not have an effect

Post by miso »

Ah, thanks for the clarification, it works that way. ;)
Post Reply