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

Add pen optional rendering to the web proto viewer #5635

Merged
merged 60 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
f83d523
abstract camera
Nov 11, 2022
48ee281
buggy
Nov 11, 2022
cb7578c
advance but still buggy
Nov 11, 2022
d47f2c3
Merge branch 'feature-web-proto' into enhancement-display-camera
Nov 21, 2022
4204652
working frustum
Nov 29, 2022
ae74249
Merge branch 'feature-web-proto' into enhancement-display-camera
Nov 30, 2022
a26a10c
Merge branch 'feature-web-proto' into enhancement-display-camera
Nov 30, 2022
ad13b9c
always enable
Nov 30, 2022
d26b333
fix scrollbar and improve style
Nov 30, 2022
4315a6b
improvement (linescale + list of cameras)
Nov 30, 2022
9fd5707
enable and disable optional rendering
Nov 30, 2022
ca40d77
all parameters
Nov 30, 2022
1bd6c49
display correctly rows
Dec 1, 2022
8e07a39
Update toolbar.css
Dec 1, 2022
89ca908
style
Dec 1, 2022
68ebbfd
cleanup
Dec 1, 2022
1cfb7bc
Update ProtoCamera.proto
Dec 1, 2022
d685569
Update ProtoCamera.proto
Dec 1, 2022
d5bb2a5
Update resources/web/wwi/nodes/WbAbstractCamera.js
Dec 1, 2022
61a2aca
Update resources/web/wwi/nodes/WbCamera.js
Dec 1, 2022
abe8b24
change color
Dec 1, 2022
a165905
Merge branch 'feature-web-proto' into enhancement-display-camera
ad-daniel Dec 1, 2022
791b6b8
parent
Dec 1, 2022
07a9631
split in two methods
Dec 1, 2022
2afe108
Merge branch 'feature-web-proto' into enhancement-display-camera
Dec 1, 2022
b1185d1
click and co
Dec 1, 2022
8d43b63
rangefinder
Dec 1, 2022
b0efefd
sanitize abstract camera
Dec 1, 2022
83804e5
Revert "rangefinder"
Dec 2, 2022
f47631f
sanitize
Dec 2, 2022
f3b0c6c
renable hover correctly
Dec 2, 2022
4f50824
Revert "Revert "rangefinder""
Dec 2, 2022
a13a850
fix near sanitization
Dec 2, 2022
82fa96f
color
Dec 2, 2022
033e3f9
improve style
Dec 2, 2022
eebde50
correct color
Dec 2, 2022
a28172e
Merge branch 'enhancement-display-camera' into enhancement-display-ra…
Dec 2, 2022
a77f133
progress lidar
Dec 2, 2022
3ed76a2
fix conflicts
Dec 2, 2022
6edda44
progress
Dec 2, 2022
0d36573
progress
Dec 2, 2022
afe2934
Merge branch 'feature-web-proto' into enhancement-display-rangefinder
Dec 2, 2022
8abf7af
progress
Dec 2, 2022
73dba7f
progress
Dec 5, 2022
606e80a
Merge branch 'feature-web-proto' into enhancement-display-rangefinder
Dec 5, 2022
ad65155
finish lidar
Dec 5, 2022
2cd106b
const
Dec 5, 2022
dc43e61
cleanup lidar and abstract camera
Dec 5, 2022
d1ccd26
code done, but not working
Dec 5, 2022
9babc89
style
Dec 5, 2022
c64e4f5
working
Dec 5, 2022
a7aaa6b
udpates
Dec 6, 2022
b6375b9
fix conflicts
Dec 6, 2022
6e42b85
lightSensor
Dec 6, 2022
1c57cf1
fix conflicts
Dec 6, 2022
95aec41
name
Dec 6, 2022
cc2a598
cleanup
Dec 6, 2022
81ff1f6
pen
Dec 6, 2022
f0fddf3
fix conflicts
Dec 7, 2022
cee177c
Merge branch 'feature-web-proto' into enhancement-display-pen
omichel Dec 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
]
}
}