Jump to content

Rendering outlines dynamically using UnigineScript


photo

Recommended Posts

I have a very basic set of scripts that create a cube rigid body every time the user clicks a mouse button.  I am looking for a way to highlight the edges (not the faces) between the vertices but *not* the whole wireframe: just the outline.

 

I am looking for a way to do this entirely using UngineScript (without loading the editor).  Say, have the edge highlight only the most recent cube created.  I am an experienced C++ developer but a very new Unigine developer.  What is the best way to do this?

 

The function used to create the cube looks like this:

Body create_cube(float radius, float density, float friction, float restitution, Mat4 transform, ObjectMeshDynamic rocks[]) {
string hash = string(radius) + " rock";
vec3 size = Vec3(radius, radius, radius);

// If a rock of this size doesn't exist in our map, create one
if (rocks.check(hash) == 0)
{
rocks.append(hash, Unigine::createBox(size));
}

Object mesh = add_editor(node_append(rocks[hash].clone()));
Body body = class_remove((density > 0.0f) ? new BodyRigid(mesh) : new BodyDummy(mesh));
ShapeBox shape = class_remove(new ShapeBox(body, size));

shape.setDensity(density);
shape.setFriction(friction);
shape.setRestitution(restitution);
mesh.setMaterial("mesh_base", "*");
mesh.setProperty("surface_base", "*");
mesh.setTransform(transform);

return body;
}

Thank you,

Andrew

Link to comment

Not sure if this is the best way, but at least an idea.

 

Usage of WidgetCanvas for final outline rendering. WidgetCanvas size equal to complete screen size. Probable problem: Unigine has no build-in support for thick lines. Could be overcome by rendering transparent object outline polygon. Alternatively ObjectMeshDynamic might be used for 3D line rendering (see your other post)

 

Outline edge calculation can be done in script or c++ by 'manual' transformation of all cube local coordinates to 2d screen space using object world transform and camera view matrix.

 

Detection of current cube outline edges based on fact that only one of the two cube faces the edge belongs to is visible (and the other is backfacing) -> cube faces normal calculation in camera space and edge-individual front-/backface testing.

 

Other outline rendering algorithms might be implemented based on outline object accumulation buffer rendering and some customized post-processing shader code.

Link to comment
×
×
  • Create New...