Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
28 changes: 19 additions & 9 deletions build/ros3d.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -58677,8 +58677,9 @@ var Viewer = function Viewer(options) {
options = options || {};
var divID = options.divID;
var elem = options.elem;
var width = options.width;
var height = options.height;
var canvas = options.canvas;
var width = options.width || options.canvas && options.canvas.width;
var height = options.height || options.canvas && options.canvas.height;
var background = options.background || '#111111';
var antialias = options.antialias;
var intensity = options.intensity || 0.66;
Expand All @@ -58695,10 +58696,17 @@ var Viewer = function Viewer(options) {
var lineTypePanAndZoomFrame = options.lineTypePanAndZoomFrame || 'full';

// create the canvas to render to
this.renderer = new THREE.WebGLRenderer({
antialias : antialias,
alpha: true
});
this.renderer = canvas ?
new THREE.WebGLRenderer({
antialias : antialias,
alpha: true,
canvas: canvas
})
:
new THREE.WebGLRenderer({
antialias : antialias,
alpha: true,
});
this.renderer.setClearColor(parseInt(background.replace('#', '0x'), 16), alpha);
this.renderer.sortObjects = false;
this.renderer.setSize(width, height);
Expand Down Expand Up @@ -58745,9 +58753,11 @@ var Viewer = function Viewer(options) {
this.stopped = true;
this.animationRequestId = undefined;

// add the renderer to the page
var node = elem || document.getElementById(divID);
node.appendChild(this.renderer.domElement);
// add the renderer to the page if canvas is not passed into the option
if( !canvas ) {
var node = elem || document.getElementById(divID);
node.appendChild(this.renderer.domElement);
}

// begin the render loop
this.start();
Expand Down
28 changes: 19 additions & 9 deletions build/ros3d.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -58653,8 +58653,9 @@ var Viewer = function Viewer(options) {
options = options || {};
var divID = options.divID;
var elem = options.elem;
var width = options.width;
var height = options.height;
var canvas = options.canvas;
var width = options.width || options.canvas && options.canvas.width;
var height = options.height || options.canvas && options.canvas.height;
var background = options.background || '#111111';
var antialias = options.antialias;
var intensity = options.intensity || 0.66;
Expand All @@ -58671,10 +58672,17 @@ var Viewer = function Viewer(options) {
var lineTypePanAndZoomFrame = options.lineTypePanAndZoomFrame || 'full';

// create the canvas to render to
this.renderer = new THREE.WebGLRenderer({
antialias : antialias,
alpha: true
});
this.renderer = canvas ?
new THREE.WebGLRenderer({
antialias : antialias,
alpha: true,
canvas: canvas
})
:
new THREE.WebGLRenderer({
antialias : antialias,
alpha: true,
});
this.renderer.setClearColor(parseInt(background.replace('#', '0x'), 16), alpha);
this.renderer.sortObjects = false;
this.renderer.setSize(width, height);
Expand Down Expand Up @@ -58721,9 +58729,11 @@ var Viewer = function Viewer(options) {
this.stopped = true;
this.animationRequestId = undefined;

// add the renderer to the page
var node = elem || document.getElementById(divID);
node.appendChild(this.renderer.domElement);
// add the renderer to the page if canvas is not passed into the option
if( !canvas ) {
var node = elem || document.getElementById(divID);
node.appendChild(this.renderer.domElement);
}

// begin the render loop
this.start();
Expand Down
31 changes: 21 additions & 10 deletions build/ros3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -59203,6 +59203,7 @@ var ROS3D = (function (exports, ROSLIB) {
*
* * divID - the ID of the div to place the viewer in
* * elem - the elem to place the viewer in (overrides divID if provided)
* * canvas (optional) - the canvas to render the viewer (overrides divID and elem if provided)
* * width - the initial width, in pixels, of the canvas
* * height - the initial height, in pixels, of the canvas
* * background (optional) - the color to render the background, like '#efefef'
Expand All @@ -59216,12 +59217,13 @@ var ROS3D = (function (exports, ROSLIB) {
* * panning/zooming. Only has effect when
* * displayPanAndZoomFrame is set to true.
*/
constructor(options) {
constructor(options) {
options = options || {};
var divID = options.divID;
var elem = options.elem;
var width = options.width;
var height = options.height;
var canvas = options.canvas;
var width = options.width || options.canvas && options.canvas.width;
var height = options.height || options.canvas && options.canvas.height;
var background = options.background || '#111111';
var antialias = options.antialias;
var intensity = options.intensity || 0.66;
Expand All @@ -59238,10 +59240,17 @@ var ROS3D = (function (exports, ROSLIB) {
var lineTypePanAndZoomFrame = options.lineTypePanAndZoomFrame || 'full';

// create the canvas to render to
this.renderer = new THREE.WebGLRenderer({
antialias : antialias,
alpha: true
});
this.renderer = canvas ?
new THREE.WebGLRenderer({
antialias : antialias,
alpha: true,
canvas: canvas
})
:
new THREE.WebGLRenderer({
antialias : antialias,
alpha: true,
});
this.renderer.setClearColor(parseInt(background.replace('#', '0x'), 16), alpha);
this.renderer.sortObjects = false;
this.renderer.setSize(width, height);
Expand Down Expand Up @@ -59288,9 +59297,11 @@ var ROS3D = (function (exports, ROSLIB) {
this.stopped = true;
this.animationRequestId = undefined;

// add the renderer to the page
var node = elem || document.getElementById(divID);
node.appendChild(this.renderer.domElement);
// add the renderer to the page if canvas is not passed into the option
if( !canvas ) {
var node = elem || document.getElementById(divID);
node.appendChild(this.renderer.domElement);
}

// begin the render loop
this.start();
Expand Down
2 changes: 1 addition & 1 deletion build/ros3d.min.js

Large diffs are not rendered by default.

33 changes: 22 additions & 11 deletions src/visualization/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* * divID - the ID of the div to place the viewer in
* * elem - the elem to place the viewer in (overrides divID if provided)
* * canvas (optional) - the canvas to render the viewer (overrides divID and elem if provided)
* * width - the initial width, in pixels, of the canvas
* * height - the initial height, in pixels, of the canvas
* * background (optional) - the color to render the background, like '#efefef'
Expand All @@ -26,12 +27,13 @@
* * panning/zooming. Only has effect when
* * displayPanAndZoomFrame is set to true.
*/
ROS3D.Viewer = function(options) {
ROS3D.Viewer = function(options) {
options = options || {};
var divID = options.divID;
var elem = options.elem;
var width = options.width;
var height = options.height;
var canvas = options.canvas;
var width = options.width || options.canvas && options.canvas.width;
var height = options.height || options.canvas && options.canvas.height;
var background = options.background || '#111111';
var antialias = options.antialias;
var intensity = options.intensity || 0.66;
Expand All @@ -48,10 +50,17 @@ ROS3D.Viewer = function(options) {
var lineTypePanAndZoomFrame = options.lineTypePanAndZoomFrame || 'full';

// create the canvas to render to
this.renderer = new THREE.WebGLRenderer({
antialias : antialias,
alpha: true
});
this.renderer = canvas ?
new THREE.WebGLRenderer({
antialias : antialias,
alpha: true,
canvas: canvas
})
:
new THREE.WebGLRenderer({
antialias : antialias,
alpha: true,
});
this.renderer.setClearColor(parseInt(background.replace('#', '0x'), 16), alpha);
this.renderer.sortObjects = false;
this.renderer.setSize(width, height);
Expand Down Expand Up @@ -98,9 +107,11 @@ ROS3D.Viewer = function(options) {
this.stopped = true;
this.animationRequestId = undefined;

// add the renderer to the page
var node = elem || document.getElementById(divID);
node.appendChild(this.renderer.domElement);
// add the renderer to the page if canvas is not passed into the option
if( !canvas ) {
var node = elem || document.getElementById(divID);
node.appendChild(this.renderer.domElement);
}

// begin the render loop
this.start();
Expand Down Expand Up @@ -176,4 +187,4 @@ ROS3D.Viewer.prototype.resize = function(width, height) {
this.camera.aspect = width / height;
this.camera.updateProjectionMatrix();
this.renderer.setSize(width, height);
};
};
17 changes: 17 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ var assert = chai.assert;

describe('Initialization', function() {

describe('Viewer', () => {
it('initializes correctly with canvas passed in as argument', () => {
const WIDTH = 500;
const HEIGHT = 300;
const canvas = document.createElement('canvas');
canvas.width = WIDTH;
canvas.height = HEIGHT;
const viewer = new ROS3D.Viewer({
canvas: canvas,
});

assert.isTrue(viewer.renderer.domElement === canvas);
assert.isTrue(viewer.renderer.getSize().width === WIDTH);
assert.isTrue(viewer.renderer.getSize().height === HEIGHT);
});

});

describe('Arrow', function() {
var arrow = new ROS3D.Arrow();
Expand Down