Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the vertex bus and index bus for meshes. #6748

Closed
AlexAPPi opened this issue Jun 24, 2024 · 3 comments
Closed

Using the vertex bus and index bus for meshes. #6748

AlexAPPi opened this issue Jun 24, 2024 · 3 comments
Assignees
Labels
area: graphics Graphics related issue

Comments

@AlexAPPi
Copy link

AlexAPPi commented Jun 24, 2024

When writing a terrain system, I need to reuse buffers, it would be nice to implement this for the mesh API.

const maxNumIndex = 123;
const indexArray = new Uint32Array(maxNumIndex);

....
const indexBufferOptions = undefined; // TODO for webgpu support
const indexBuffer  = new pc.IndexBuffer(
    app.graphicsDevice,
    pc.INDEXFORMAT_UINT32,
    indexArray.length,
    pc.BUFFER_STATIC,
    indexArray,
    indexBufferOptions
);

const mesh = new pc.Mesh(app.graphicsDevice);
mesh.indexBuffer[0] = indexBuffer;

....

mesh.setIndices(indexArray, 10); // <- here i use 1 buffer
mesh.update(pc.PRIMITIVE_TRIANGLES, false);

indexBuffer.writeData(srcIndices, this._geometryData.indexCount);

const indices = this._lockTypedArray();

  • A similar situation with vertices
@mvaligursky
Copy link
Contributor

Hi @AlexAPPi .. could please provide more details of what you're trying to do? I'm not sure I understand this issue.

@AlexAPPi
Copy link
Author

Hi @AlexAPPi .. could please provide more details of what you're trying to do? I'm not sure I understand this issue.

Hi! I use the same buffer for the model, and modify it, every time it is unloaded to the GPU, the engine makes a copy of the same buffer, although there is no point in doing this, because this is the same buffer.

@mvaligursky
Copy link
Contributor

The Mesh has two possible ways to use it, see here: https://api.playcanvas.com/classes/Engine.Mesh.html

  • a simple way - see example at that link
  • a more manual way of using Vertex and Index buffer directly

What you can do is to create Vertex and Index buffer yourself and upload data to them as needed. In this case, you would not use mesh.setIndices() and mesh.update(), but manage buffers yourself.

I'll close this as I believe this is what you need, but please re-open if I missed something.

@mvaligursky mvaligursky self-assigned this Jun 25, 2024
@mvaligursky mvaligursky added the area: graphics Graphics related issue label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue
Projects
None yet
Development

No branches or pull requests

2 participants