I just figured out the right way to do it (and the framerate is mostly stable with just a few drops to 45 frames per second on the android device)
EgonOlsens code helped me a lot (a huge thanks). To help people who will stumble across this I want to share the code I used to get an Endless Version of the code (and not continuing like EgonsOlsens version).
Beware when using this: With everything that looks like it is endless in programming there is a point where things break. So far I do not have a solution for this.
This code is taking two scalable lists of vectors (called leftLine and rightLine) and create the data to follow by these two lists. The rest is kind of copy pasted or slightly changed.
EgonOlsens code helped me a lot (a huge thanks). To help people who will stumble across this I want to share the code I used to get an Endless Version of the code (and not continuing like EgonsOlsens version).
Beware when using this: With everything that looks like it is endless in programming there is a point where things break. So far I do not have a solution for this.
This code is taking two scalable lists of vectors (called leftLine and rightLine) and create the data to follow by these two lists. The rest is kind of copy pasted or slightly changed.
Code Select
import com.threed.jpct.*
class EndlessTrackArea(private val leftLine: EndlessTrackLine, private val rightLine: EndlessTrackLine) {
private var trackObject = Object3D(TRACK_POLYGONS)
private var trackCreator = TrackCreator(leftLine, rightLine)
private var world: World? = null
private var color = RGBColor(0,255,255,100)
fun moveTrackArea(){
if (trackCreator.pos >= trackCreator.destinationMesh.size -1){
trackCreator = TrackCreator(leftLine, rightLine)
setTrackArea()
}
trackObject.mesh.applyVertexController()
trackObject.touch()
}
fun setAreaVariables(world: World, color: RGBColor = RGBColor(0,255,255,100)){
this.world = world
this.color = color
setTrackArea()
}
private fun setTrackArea(){
Logger.log("Creating Track Object")
val trackObject = Object3D(TRACK_POLYGONS)
for (i in 0 until TRACK_POLYGONS / 2){
trackObject.addTriangle(
SimpleVector(
(-1100000 + i).toDouble(), (-1200000 + i).toDouble(),
(-1300000 + i).toDouble()
), SimpleVector(
(-1400000 + i).toDouble(), (-1500000 + i).toDouble(),
(-1600000 + i).toDouble()
), SimpleVector(
(-1700000 + i).toDouble(), (-1800000 + i).toDouble(), (-1900000 + i).toDouble()
)
)
trackObject.addTriangle(
SimpleVector(
(2000000 + i).toDouble(),
(2100000 + i).toDouble(), (2200000 + i).toDouble()
), SimpleVector(
(2300000 + i).toDouble(), (2400000 + i).toDouble(),
(2500000 + i).toDouble()
), SimpleVector(
(2600000 + i).toDouble(),
(2700000 + i).toDouble(), (2800000 + i).toDouble()
)
)
}
trackObject.calcNormals()
trackObject.mesh.setVertexController(trackCreator, false)
trackObject.forceGeometryIndices(false)
trackObject.compile(true)
trackObject.build()
trackObject.additionalColor = color
trackObject.culling = Object3D.CULLING_DISABLED
trackObject.transparency = 10
world!!.addObject(trackObject)
this.trackObject = trackObject
}
companion object{
const val TRACK_POLYGONS = 100
}
private class TrackCreator(private val leftLine: EndlessTrackLine,private val rightLine: EndlessTrackLine): GenericVertexController(){
var pos = 0
override fun apply() {
//this is some crazy testing
//lines
val left = leftLine.line
val right = rightLine.line
if (left.size > 2 && right.size > 2){
//points of the lines
val backLeft = left[left.size -2]
val backRight = right[right.size -2]
val frontLeft = left[left.size -1]
val frontRight = right[right.size -1]
if (pos + 4 >= destinationMesh.size -1){
pos = 0
}
destinationMesh[pos++].set(backLeft) //0
destinationMesh[pos++].set(backRight) //1
destinationMesh[pos++].set(frontRight) //3
destinationMesh[pos++].set(frontLeft) //2
destinationMesh[pos++].set(backLeft) //0
destinationMesh[pos++].set(frontRight) //3
}
}
companion object {
private const val serialVersionUID = 1L
}
}
}