Skip to content

Commit

Permalink
Add pen optional rendering to the web proto viewer (#5635)
Browse files Browse the repository at this point in the history
* abstract camera

* buggy

* advance but still buggy

* working frustum

* always enable

* fix scrollbar and improve style

* improvement (linescale + list of cameras)

* enable and disable optional rendering

* all parameters

* display correctly rows

* Update toolbar.css

* style

* cleanup

* Update ProtoCamera.proto

* Update ProtoCamera.proto

* Update resources/web/wwi/nodes/WbAbstractCamera.js

Co-authored-by: ad-daniel <[email protected]>

* Update resources/web/wwi/nodes/WbCamera.js

Co-authored-by: ad-daniel <[email protected]>

* change color

* parent

* split in two methods

* click and co

* rangefinder

* sanitize abstract camera

* Revert "rangefinder"

This reverts commit 8d43b63.

* sanitize

* renable hover correctly

* Revert "Revert "rangefinder""

This reverts commit 83804e5.

* fix near sanitization

* color

* improve style

* correct color

* progress lidar

* progress

* progress

* progress

* progress

* finish lidar

* const

* cleanup lidar and abstract camera

* code done, but not working

* style

* working

* udpates

* lightSensor

* name

* cleanup

* pen

Co-authored-by: ad-daniel <[email protected]>
Co-authored-by: Olivier Michel <[email protected]>
  • Loading branch information
3 people authored Dec 7, 2022
1 parent 15360f2 commit fcab6e4
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 13 deletions.
3 changes: 2 additions & 1 deletion resources/web/wwi/FloatingProtoParameterWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import WbCamera from './nodes/WbCamera.js';
import WbHingeJoint from './nodes/WbHingeJoint.js';
import WbLidar from './nodes/WbLidar.js';
import WbLightSensor from './nodes/WbLightSensor.js';
import WbPen from './nodes/WbPen.js';
import WbRadar from './nodes/WbRadar.js';
import WbWorld from './nodes/WbWorld.js';
import WbRangeFinder from './nodes/WbRangeFinder.js';
Expand Down Expand Up @@ -508,7 +509,7 @@ export default class FloatingProtoParameterWindow extends FloatingWindow {
const device = nodes.get(key);
// TODO once all the optional rendering are implemented, replace this list by device instanceof WbDevice
if (device instanceof WbCamera || device instanceof WbRangeFinder || device instanceof WbLidar ||
device instanceof WbRadar || device instanceof WbLightSensor) {
device instanceof WbRadar || device instanceof WbLightSensor || device instanceof WbPen) {
numberOfDevices++;

let div = document.createElement('div');
Expand Down
7 changes: 4 additions & 3 deletions resources/web/wwi/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,10 @@ export default class Parser {
numberOfLayers, tiltAngle, verticalFieldOfView, horizontalResolution);
} else if (node.tagName === 'LightSensor')
newNode = new WbLightSensor(id, translation, scale, rotation, name === '' ? 'light sensor' : name);
else if (node.tagName === 'Pen')
newNode = new WbPen(id, translation, scale, rotation, name === '' ? 'pen' : name);
else if (node.tagName === 'Radar') {
else if (node.tagName === 'Pen') {
const write = getNodeAttribute(node, 'write', 'true').toLowerCase() === 'true';
newNode = new WbPen(id, translation, scale, rotation, name === '' ? 'pen' : name, write);
} else if (node.tagName === 'Radar') {
const horizontalFieldOfView = parseFloat(getNodeAttribute(node, 'horizontalFieldOfView', '0.78'));
const verticalFieldOfView = parseFloat(getNodeAttribute(node, 'verticalFieldOfView', '0.1'));
const maxRange = parseFloat(getNodeAttribute(node, 'maxRange', '50'));
Expand Down
6 changes: 5 additions & 1 deletion resources/web/wwi/X3dScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import WbBox from './nodes/WbBox.js';
import WbCadShape from './nodes/WbCadShape.js';
import WbCamera from './nodes/WbCamera.js';
import WbCapsule from './nodes/WbCapsule.js';
import WbColor from './nodes/WbColor.js';
import WbCone from './nodes/WbCone.js';
import WbCoordinate from './nodes/WbCoordinate.js';
import WbCylinder from './nodes/WbCylinder.js';
Expand All @@ -21,10 +22,10 @@ import WbLidar from './nodes/WbLidar.js';
import WbLight from './nodes/WbLight.js';
import WbMaterial from './nodes/WbMaterial.js';
import WbMesh from './nodes/WbMesh.js';
import WbPen from './nodes/WbPen.js';
import WbPbrAppearance from './nodes/WbPbrAppearance.js';
import WbPlane from './nodes/WbPlane.js';
import WbPointLight from './nodes/WbPointLight.js';
import WbColor from './nodes/WbColor.js';
import WbRadar from './nodes/WbRadar.js';
import WbSphere from './nodes/WbSphere.js';
import WbTextureCoordinate from './nodes/WbTextureCoordinate.js';
Expand Down Expand Up @@ -424,6 +425,9 @@ export default class X3dScene {
object.verticalFieldOfView = parseFloat(pose[key]);
else if (key === 'horizontalFieldOfView')
object.horizontalFieldOfView = parseFloat(pose[key]);
} else if (object instanceof WbPen) {
if (key === 'write')
object.write = pose[key].toLowerCase() === 'true';
}

if (object instanceof WbLight) {
Expand Down
1 change: 0 additions & 1 deletion resources/web/wwi/nodes/WbAbstractCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import WbWrenShaders from '../wren/WbWrenShaders.js';
import WbWrenRenderingContext from '../wren/WbWrenRenderingContext.js';
import {arrayXPointerFloat} from './utils/utils.js';

// This class is used to retrieve the type of device
export default class WbAbstractCamera extends WbSolid {
#fieldOfView;
#height;
Expand Down
1 change: 0 additions & 1 deletion resources/web/wwi/nodes/WbCamera.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import WbAbstractCamera from './WbAbstractCamera.js';

// This class is used to retrieve the type of device
export default class WbCamera extends WbAbstractCamera {
#near;
#far;
Expand Down
1 change: 0 additions & 1 deletion resources/web/wwi/nodes/WbLidar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import WbWrenShaders from '../wren/WbWrenShaders.js';
import WbWrenRenderingContext from '../wren/WbWrenRenderingContext.js';
import {arrayXPointerFloat} from './utils/utils.js';

// This class is used to retrieve the type of device
export default class WbLidar extends WbAbstractCamera {
#frustumMaterial;
#frustumMesh;
Expand Down
1 change: 0 additions & 1 deletion resources/web/wwi/nodes/WbLightSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import WbWrenRenderingContext from '../wren/WbWrenRenderingContext.js';
import WbWrenShaders from '../wren/WbWrenShaders.js';
import {arrayXPointerFloat} from './utils/utils.js';

// This class is used to retrieve the type of device
export default class WbLightSensor extends WbSolid {
#transform;
#material;
Expand Down
77 changes: 77 additions & 0 deletions resources/web/wwi/nodes/WbPen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,82 @@
import WbSolid from './WbSolid.js';
import WbWrenRenderingContext from '../wren/WbWrenRenderingContext.js';
import WbWrenShaders from '../wren/WbWrenShaders.js';
import {arrayXPointerFloat} from './utils/utils.js';

// This class is used to retrieve the type of device
export default class WbPen extends WbSolid {
#material;
#mesh;
#renderable;
#transform;
#write;
constructor(id, translation, scale, rotation, name, write) {
super(id, translation, scale, rotation, name);
this.#write = write;
}

get write() {
return this.#write;
}

set write(newWrite) {
this.#write = newWrite;
this.#update();
}

createWrenObjects() {
super.createWrenObjects();

const coords = [0, 0, -1, 0, 0, 0];
const coordsPointer = arrayXPointerFloat(coords);
this.#transform = _wr_transform_new();
this.#renderable = _wr_renderable_new();
this.#material = _wr_phong_material_new();

this.#mesh = _wr_static_mesh_line_set_new(2, coordsPointer, undefined);
_free(coordsPointer);

const color = _wrjs_array3(0.5, 0.5, 0.5);
_wr_phong_material_set_color(this.#material, color);
_wr_material_set_default_program(this.#material, WbWrenShaders.lineSetShader());

_wr_renderable_set_drawing_mode(this.#renderable, Enum.WR_RENDERABLE_DRAWING_MODE_LINES);
_wr_renderable_set_mesh(this.#renderable, this.#mesh);
_wr_renderable_set_material(this.#renderable, this.#material, undefined);
_wr_renderable_set_cast_shadows(this.#renderable, false);
_wr_renderable_set_receive_shadows(this.#renderable, false);
_wr_renderable_set_visibility_flags(this.#renderable, WbWrenRenderingContext.VM_REGULAR);

_wr_transform_attach_child(this.#transform, this.#renderable);
_wr_transform_attach_child(this.wrenNode, this.#transform);
_wr_node_set_visible(this.#transform, false);

this.#applyOptionalRenderingToWren();
}

applyOptionalRendering(enable) {
_wr_node_set_visible(this.#transform, enable);
}

#applyOptionalRenderingToWren() {
if (!this.wrenObjectsCreatedCalled)
return;

const lineScale = _wr_config_get_line_scale();
const scale = _wrjs_array3(lineScale, lineScale, lineScale);
_wr_transform_set_scale(this.#transform, scale);

if (this.#write) {
const enabledColor = _wrjs_array3(0.5, 0, 1);
_wr_phong_material_set_color(this.#material, enabledColor);
} else {
const disabledColor = _wrjs_array3(0.5, 0.5, 0.5);
_wr_phong_material_set_color(this.#material, disabledColor);
}
}

#update() {
if (this.wrenObjectsCreatedCalled)
this.#applyOptionalRenderingToWren();
}
}
1 change: 0 additions & 1 deletion resources/web/wwi/nodes/WbRadar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import WbWrenShaders from '../wren/WbWrenShaders.js';
import WbWrenRenderingContext from '../wren/WbWrenRenderingContext.js';
import {arrayXPointerFloat} from './utils/utils.js';

// This class is used to retrieve the type of device
export default class WbRadar extends WbSolid {
#horizontalFieldOfView;
#material;
Expand Down
1 change: 0 additions & 1 deletion resources/web/wwi/nodes/WbRangeFinder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import WbAbstractCamera from './WbAbstractCamera.js';

// This class is used to retrieve the type of device
export default class WbRangeFinder extends WbAbstractCamera {
#maxRange;
#minRange;
Expand Down
9 changes: 7 additions & 2 deletions resources/web/wwi/protos/ProtoSensor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2022b/projects/appearances/protos/Asphalt.proto"

PROTO ProtoSensor [
field SFVec3f translation 0 0 0.3
field SFRotation rotation 0 0 1 1.5708
field SFVec3f translation 0 0 0.3
field SFRotation rotation 0 0 1 1.5708
field SFBool write TRUE
]
{
Robot {
Expand All @@ -20,6 +21,10 @@ field SFRotation rotation 0 0 1 1.5708
}
]
}
Pen {
translation IS translation
write IS write
}
]
}
}

0 comments on commit fcab6e4

Please sign in to comment.