You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to filament and wanna render a 3D lane using filament with an array of 3d points in android fragment follow the example. I have a list of points called routeData which size is 150, each points has x,y attribute(z is default by 0). Here is my implementation:
// doFrame
override fun doFrame(frameTimeNanos: Long) {
// Schedule the next frame
choreographer.postFrameCallback(this)
//o This check guarantees that we have a swap chain
if (uiHelper.isReadyToRender) {
updateVertexBuffer()
// If beginFrame() returns false you should skip the frame
// This means you are sending frames too quickly to the GPU
if (renderer.beginFrame(swapChain!!, frameTimeNanos)) {
renderer.render(view)
renderer.endFrame()
}
}
}
// updateVertexBuffer
fun updateVertexBuffer() {
val entityManager = EntityManager.get()
if(entityManager != null) {
entityManager.destroy(renderable) // render the most recent data
}
addRoadLine(0.0f)
}
// addRoadLine
fun addRoadLine(pos: Float) {
val vertexArray = mutableListOf()
vertexArray.addAll(this.routeData)
val vertexSize = 3 * 4 // 3 float data and 4 byte for each data
val vertexCount = this.routeData.size;
val vertexData = ByteBuffer.allocate(vertexArray.size * vertexSize)
.order(ByteOrder.nativeOrder())
for (point in vertexArray) {
vertexData.putFloat(point.x)
vertexData.putFloat(point.y + pos)
vertexData.putFloat(0.0f)
}
// x,y,z sequence to be confirm
vertexData.flip()
vertexBuffer = VertexBuffer.Builder()
.bufferCount(1)
.vertexCount(vertexCount)
.attribute(VertexAttribute.POSITION, 0, AttributeType.FLOAT3, 0, vertexSize)
.attribute(VertexAttribute.COLOR, 0, AttributeType.UBYTE4, 3 * 4, 0)
// We store colors as unsigned bytes but since we want values between 0 and 1
// in the material (shaders), we must mark the attribute as normalized
.normalized(VertexAttribute.COLOR)
.build(engine)
vertexBuffer.setBufferAt(engine, 0, vertexData)
val indexCount = vertexCount
val indexSize = 4
val indexData = ByteBuffer.allocate(2*indexCount * indexSize)
.order(ByteOrder.nativeOrder())
for (i in 0 until vertexCount) {
indexData.putInt(i)
indexData.putInt(i+1)
}
indexData.flip()
indexBuffer = IndexBuffer.Builder()
.indexCount(indexCount)
.bufferType(IndexBuffer.Builder.IndexType.USHORT)
.build(engine)
indexBuffer.setBuffer(engine, indexData)
renderable = EntityManager.get().create()
RenderableManager.Builder(1)
.boundingBox(Box(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.01f))
.geometry(0, PrimitiveType.LINE_STRIP, vertexBuffer, indexBuffer, 0, indexCount)
.material(0, material.defaultInstance)
.build(engine, renderable)
scene.addEntity(renderable)
}
I wanna use LINE_STRIP to render the 3d lines and add vertices and index data to VertexBuffer and IndexBuffer follow the geometry inside RenderableManager.java class. But it seems that the line is construct from the first and the last element of routeData. May I know what's wrong with my implementation. Would be thankful for any help!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am new to filament and wanna render a 3D lane using filament with an array of 3d points in android fragment follow the example. I have a list of points called routeData which size is 150, each points has x,y attribute(z is default by 0). Here is my implementation:
// doFrame
override fun doFrame(frameTimeNanos: Long) {
// Schedule the next frame
// updateVertexBuffer
fun updateVertexBuffer() {
val entityManager = EntityManager.get()
if(entityManager != null) {
entityManager.destroy(renderable) // render the most recent data
}
addRoadLine(0.0f)
}
// addRoadLine
fun addRoadLine(pos: Float) {
val vertexArray = mutableListOf()
vertexArray.addAll(this.routeData)
val vertexSize = 3 * 4 // 3 float data and 4 byte for each data
val vertexCount = this.routeData.size;
val vertexData = ByteBuffer.allocate(vertexArray.size * vertexSize)
.order(ByteOrder.nativeOrder())
for (point in vertexArray) {
vertexData.putFloat(point.x)
vertexData.putFloat(point.y + pos)
vertexData.putFloat(0.0f)
}
// x,y,z sequence to be confirm
vertexData.flip()
I wanna use LINE_STRIP to render the 3d lines and add vertices and index data to VertexBuffer and IndexBuffer follow the geometry inside RenderableManager.java class. But it seems that the line is construct from the first and the last element of routeData. May I know what's wrong with my implementation. Would be thankful for any help!
Beta Was this translation helpful? Give feedback.
All reactions