Is it possible to work with curves directly?

Hi guys ,

I would like to know if it’s possible to work directly with curves inside playcanvas.

for exemple :

  • import a group of static curves from an fbx file
  • import a group of animated curve from an fbx file where animation is store as a vertex attribute

the goal is to avoid to draw the geometry when it is not needed.
and to render lot of curves by simply using a constant color read as a webGL 2d element,
not as a geometry to shade in 3d.

Here is a sweet exemple in three.js :
http://threejs.org/examples/?q=spli#webgl_geometry_spline_editor

Cheers
Emmanuel

Not sure about getting line rendering from fbx, but surely you can make procedural mesh made of vertices, and then draw it using different mode, in particular gl.LINES. That will render your vertices as couples with lines in between. You could use index buffer to link vertices, that will allow to have pretty much twice less vertices as well.

Thanks you Max ! so in other word with some extra work it is possible.

Great ! :slight_smile:

Do you have any trivial exemple that illustrate this ?

Thanks
E

Not really.

But here is some directions:

  1. Code that creates procedural geometry: https://github.com/playcanvas/engine/blob/c32f63021c5b376671607c80a003435062e313c1/src/scene/procedural.js#L218
  2. Method that allows to draw for debugging purpose lines: http://developer.playcanvas.com/en/api/pc.Application.html#renderLine

Second is not meant to be performant or used in real games, just for drawing debugging gizmos, while first link shows how to create custom model.
Then you can create pc.MeshInstance with that mesh, and create pc.Model and attach it to entity.

I do not know any specifics about your needs, but there are even extra things where you could modify position of vertices in vertex shader dynamically, that would make curves performance very-very fast and allow dynamically change it with no much effort.

There are many options to explore :slight_smile:

Many thanks for the very detail answer Max !

I will investigate on this when i have some time.

To be more specific here is an exemple:
https://playcanvas.com/editor/scene/450117

you have an object that is build as curves object in houdini.
at the moment i have to convert it to poly but i would love to be able to export it directly as a spline,
and render it directly as a spline.

the point is that those curves are animated. so export an animated mesh of this will be very heavy.
in a perfect world something like the alembic file format would be perfect.

you can store with .abc

  • curves object
  • per point / vertex animation store in the object itself
  • per point attribute like color / transparency
  • connect those attribute to a shader

i know fbx can

  • store curves
  • per point attribute
  • but i am not sure it can store animation per vertex. UE4 and Unity for ex doesn’t offer this feature.
    It’s more a VFX workflow than a Game workflow i guess.

A good cure workflow allow you to keep things very light by avoiding the poly convert step
If you have any more suggestion i would be happy to study anything that point me in the right direction.

Here is a good ref done with three.js. Lot of curves with color + anim but prrety low geo.
http://mattdesl.github.io/codevember/21.html

Cheers
Emmanuel

There is no per-vertex animations, no.

Looking at scene you’ve posted, looks like it is a landscape, where lines are drawn only at certain elevation level?
What would animation be?

As for what you have now I can suggest if you actually have normal landscape, not lines, but full triangles, and then in pixel shader based on Y position of pixel can fill pixel with color or discard (transparent). That would make those lines, with way less geometry required. Animation wise, if you have landscape that changes, that can be tricky to be stored in a file, but can be done by proceduraly generating height map, and then moving Y of vertices of landscape based on heightmap.

That gives you procedural animation of landscape, you can drive parameters for height map generation based on some inputs, like music? Then you have lines rendering too using pixel shader.

This could be alternative direction to go. I do not know what you are trying to achieve, so it is hard to suggest directions. There are always creative ways to achieve different things, and sometimes little detail/feature might change approach a lot.

Thanks again for your feedback Max.

Indeed you are quite close animation is build upon

  • perlin noise apply on geo plane
  • then we extract cv from this
  • then cv are move in -Y with music

I think you are also right the most efficient way to do so would be to.

  • move point on a grid base on noise function
  • do the curves stuff in a glsl shader

the thing is that i am a beginner in glsl and js i come from a C / RSL background so this is still a new canvas for me.

i would be curious to know if vertex anim

  • would be doable in a real time canvas
  • if it can be done what would be the most effecient way.

because at his core from a VFX persp it look simple

  • you have an array with frame range and vertex id
  • you store a vector P per vertex per frame
  • you read this to display anim
    Might be more complex in real time …

Cheers
E

Manipulating buffer from CPU to GPU every frame - is expensive, very expensive if you have loads of vertices.
But it is cheap to do on GPU only, like using textures or calculating noise on gpu in real-time.

So start small - learn to make own shader or using shader chunks override vertex positioning part in standard shader. This will give you some idea.
Vertex shader - is essentially a conveyor that iterates through each vertex and allows you to pass some stuff to fragment shader and manipulate vertex position.
Start by stages, and it will get you pretty close to your needs :slight_smile:

Thanks again for your help Max. :slight_smile:

So there is a good reason if none of the big game engine implement vertex anim read from a geao cache, it’s too expensive and not GPU friendly in the workflow.

All procedural stuff must be think and executed directly in GLSL to be efficient in real time.
Time to learn GLSL …

1 Like

Shaders are really powerful tool to express visual logic, learning them will benefit you a lot working with creative challenges :slight_smile:

1 Like