How to increase vertices / faces of standard meshes using the API?

Is there a way to increase the number of vertices / faces for standard components, using the API? I’m doing, for example

let mesh = new pc.Entity();
mesh.addComponent('render', {
  type: 'box',
});

The typescript definition for options is just object =/ so I’m not sure if there’s an available option for increasing vertices?

I searched for a few variations of “playcanvas increase vertices” but surprisingly didn’t find anyone else asking this question. I looked on RenderComponent | PlayCanvas API Reference and ModelComponent | PlayCanvas API Reference but don’t see anything related (also, I don’t know when I’m supposed to use render vs model)

The model/render components do not allow changing the amount of vertices. Instead you want to generate your own mesh using Mesh API. You can see an example here, where a custom plane is generated with many vertices:

https://playcanvas.github.io/#/graphics/mesh-generation

Similar principle for other shapes. There are some convenience methods for some common shapes, that can help if you don’t want to calculate vertex positions yourself (link for a box, but there are a few other shapes available from the left menu):

You would use it like

const mesh = pc.createBox(options);

Then use that mesh in your render component, like in the first example.

Thank you, I’m on the right track now. Do you know why this code fails?


      let entity = new pc.Entity();
      const mesh = pc.createBox(app.graphicsDevice, {
        widthSegments: 60,
        heightSegments: 60,
      });
      entity.addComponent('render', {
        meshInstances: [mesh],
      });

with

 mi[i].setLightmapped is not a function

on this line: https://github.com/playcanvas/engine/blob/128b0dfbe0d3cf7a75a0463169b6eccf0e3286a4/src/framework/components/render/component.js#L259

You need to pass mesh instance to the render component, not a mesh. They are different. Please, follow the first example to construct a mesh. Or use this one (on top of the page):

1 Like

Nice, thank you! Now there’s enough vertices so I can better see the output of vertex displacement.

(live Waves - Shaderfrog 2.0 Hybrid Graph Demo)

1 Like