B4J Library jPCT3d (partial wrap)

A bit old ,non complete ,not tested and unsupported (sorry for that ) wrap for jPCT3d library

Reference is very long it needs many posts :D you can generate it yourself from here http://b4a.martinpearman.co.uk/xml2bb/

A small sample (library is very huge ) worked for me on Windows 7 64bit
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Dim jpct As SMMjPCT3d
    Private world As World
   
    Private boxtex As Texture
'    Private obj As Object3D
    Private buffer As FrameBuffer
    Dim irender As IRenderer
    Private imagebuffer As ImageView
    Private Primitives As Primitives
    Dim yRot As Float = 0
    Dim loader As Loader
    Dim body , rightFront,leftFront,rightRear,leftRear As Object3D
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    imagebuffer.Initialize("imagebuffer")
   
    MainForm.Show
    MainForm.RootPane.AddNode(imagebuffer,0,0,MainForm.Width,MainForm.Height)
'   

    jpct.Initialize("jpct",File.DirApp&"\lwjgl64.dll")
    world.Initialize("world")
    irender.Initialize("",MainForm.Width,MainForm.Height,32,32,60)
   

   
   
    If Not(File.Exists(File.DirApp,"box.jpg")) Then
        File.Copy(File.DirAssets,"box.jpg",File.DirApp,"box.jpg")
    End If
   
    If Not(File.Exists(File.DirApp,"rocks.jpg")) Then
        File.Copy(File.DirAssets,"rocks.jpg",File.DirApp,"rocks.jpg")
    End If
       
    If Not(File.Exists(File.DirApp,"spot.jpg")) Then
        File.Copy(File.DirAssets,"spot.jpg",File.DirApp,"spot.jpg")
    End If   
   
   
    If Not(File.Exists(File.DirApp,"terascene.3ds")) Then
        File.Copy(File.DirAssets,"terascene.3ds",File.DirApp,"terascene.3ds")
    End If
   
   
    boxtex.Initialize("boxtex","box.jpg")
    jpct.addTexture2("boxte" ,boxtex)
    boxtex.Initialize("car", "spot.jpg")
    jpct.addTexture2("car"  ,boxtex)
   
    boxtex.Initialize("rocks", "rocks.jpg")
    jpct.addTexture2("rocks"  ,boxtex)
    Dim objz() As Object3D =loader.load3DS("terascene.3ds", 8)
        world.addObjects(objz)
'        Log(objz.Length)
    objz(0).rotateY(360)
    objz(0).SetTexture("rocks")
'    obj= car
'    obj.SetTexture("boxte")
'   
'    obj.SetEnvmapped(True)
    '    obj.build
    world.setWorldAmbientLight(0,255,255)
    '    world.addObject( car)
   
   
    body=    Primitives.getBox(8, 0.25f)
    Log(body.isSelectable)
    rightFront=Primitives.getSphere2(5, 4)
    leftFront=Primitives.getSphere2(5, 4)
    rightRear=Primitives.getSphere2(5, 4)
    leftRear=Primitives.getSphere2(5, 4)

    '    /**
    '    * The wheels are parts, i.e. children of the car
    '    */
    body.addChild(rightFront)
    body.addChild(leftFront)
    body.addChild(rightRear)
    body.addChild(leftRear)

    '    /**
    '    * Initialize the car And the wheels
    '    */
    body.setTexture("car")
    rightFront.setTexture("car")
    leftFront.setTexture("car")
    rightRear.setTexture("car")
    leftRear.setTexture("car")

    body.setEnvmapped(True)
    rightFront.setEnvmapped(True)
    leftFront.setEnvmapped(True)
    rightRear.setEnvmapped(True)
    leftRear.setEnvmapped(True)

    '    /**
    '    * We need To offset the wheels a little...
    '    */
    Dim SimpleVector As SimpleVector
    SimpleVector.Initialize("",-8, 4, 8)
    Dim dropDown As SimpleVector
    dropDown.Initialize("",0, 1, 0)
    rightFront.translate( SimpleVector)
    SimpleVector.Initialize("",-8, 4, -8)
    rightRear.translate( SimpleVector)
    SimpleVector.Initialize("",8, 4, 8)
    leftFront.translate(SimpleVector)
    SimpleVector.Initialize("",8, 4, -8)
    leftRear.translate(SimpleVector)
    rightFront.translateMesh()
    rightRear.translateMesh()
    leftFront.translateMesh()
    leftRear.translateMesh()
    Dim matrix As Matrix
    matrix.Initialize("")
    rightFront.setTranslationMatrix( matrix)
    rightRear.setTranslationMatrix( matrix)
    leftFront.setTranslationMatrix( matrix)
    leftRear.setTranslationMatrix(matrix)

    '    /**
    '    * ...the wheels are now in place. We can now build the car.
    '    */
   
    body.build()
    rightRear.build()
    rightFront.build()
    leftRear.build()
    leftFront.build()
    Dim ground As Object3D
    ground = Primitives.GetPlane(8 ,8)
    ground.rotatey(90)
    world.addObject(ground)
   
   
    world.addObject(body)
   
    world.addObject(rightFront)
    world.addObject(rightRear)
    world.addObject(leftFront)
    world.addObject(leftRear)
    body.rotateY(yRot)
    body.translate2(0, -10, 0)
   
    Dim rotMat As Matrix
   
   
    Dim rightFrontHeight As  Float =ground.calcMinDistance2( rightFront.getTransformedCenter(), dropDown, 4*30)
   
   
    body.translate2(0 , 10, 0)
    rotMat=body.getRotationMatrix()
'    rotMat.setIdentity()
    body.setRotationMatrix(rotMat)
    world.GetCamera.setposition(10, -80, -30)
   
    world.GetCamera.lookAt(body.getTransformedCenter)
'    world.GetCamera.rotateCameraAxis(body.getTransformedCenter, 0)
buffer.Initialize("frame",640,480,buffer.SAMPLINGMODE_NORMAL)
'    buffer.disableRenderer(irender.RENDERER_SOFTWARE)
'    buffer.enableRenderer(irender.RENDERER_OPENGL)
    Do While MainForm.Showing
        buffer.clear2( fx.Colors.To32Bit(fx.Colors.Magenta))
        world.renderScene(  buffer)
        world.draw(buffer)
        buffer.update
        imagebuffer.SetImage(jpct.toFXImage( buffer.GetOutputBuffer,Null))
        Sleep(10)
    Loop
    buffer.disableRenderer(irender.RENDERER_OPENGL)
    buffer.dispose()
    
End Sub


Dependencies
https://drive.google.com/file/d/1qOWb5i_Kne2pRhiw3rne3K8sLjUzi4LK/view?usp=sharing
 

Attachments

  • jpct3d.zip
    87 KB · Views: 376

sn_nn

Member
Licensed User
Longtime User
Loader for 3DS models Body.mergeAll(Loader.load3DS("model.3ds", 2.0)) takes error for Merging:
java.lang.ArrayStoreException: arraycopy: type mismatch: can not copy smm.jpct.Object3DWrapper[] into com.threed.jpct.Object3D[]
 

amorosik

Expert
Licensed User
Hi, I am very interested in trying the indicated code to test the functionality of the jPCT library
Despite having tried, I still haven't been able to figure out how to make a working basic example using the code you posted
Could you indicate a sequence of steps to complete to make the code work on the first post?
 
Top