Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ export const DEFAULT_CYLINDER_HEIGHT = 1;
export const DEFAULT_CYLINDER_RADIUS = 1;
export const DEFAULT_RADIAL_SEGMENTS = 32;

export const DEFAULT_SCALE = 0.00001; // To prevent: can't invert matrix, determinant is 0

export const DEFAULT_CONE_HEIGHT = 1;
export const DEFAULT_CONE_RADIUS = 1;

Expand Down
14 changes: 14 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Quaternion,
TorusGeometry,
Vector3,
MeshStandardMaterial,
} from 'three';

import {
Expand Down Expand Up @@ -176,3 +177,16 @@ export function assertIsBufferAttribute(
throw new Error('the provided attribute must be an BufferAttribute');
}
}

export function assertMaterialWithColorSettable(
val: any,
): asserts val is MeshBasicMaterial | MeshStandardMaterial {
if (
!(val instanceof MeshBasicMaterial) &&
!(val instanceof MeshStandardMaterial)
) {
throw new TypeError(
`Expected 'val' to be MeshBasicMaterial | MeshStandardMaterial. Color not settable on material.`,
);
}
}
4 changes: 3 additions & 1 deletion src/utils/interactiveMarkerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
INTERACTIVE_MARKER_INTERACTION_MODES,
INTERACTIVE_MARKER_ORIENTATION_MODES,
UNSUPPORTED_INTERACTIVE_MARKER_ORIENTATION_MODES,
DEFAULT_SCALE,
} from './constants';
import Controls from 'three-freeform-controls/dist/types/controls';
import TfViewer from '../viewers/Tf';
Expand Down Expand Up @@ -122,7 +123,8 @@ export default class InteractiveMarkerManager {
.hideOtherControlsInstancesOnSelect,
showHelperPlane: true,
});
controls.scale.set(scale, scale, scale);
const newScale = scale || DEFAULT_SCALE;
controls.scale.set(newScale, newScale, newScale);
controls.visible = visible;

InteractiveMarkerManager.enableControls(
Expand Down
7 changes: 6 additions & 1 deletion src/utils/markerManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import getNewPrimitive, { MarkerObjectType } from './markerTypes';
import { DEFAULT_SCALE } from '../utils/constants';
import MarkerLifetime from './markerLifetime';
import { Object3D } from 'three';

Expand Down Expand Up @@ -85,7 +86,11 @@ export default class MarkerManager {

// To avoid settings these properties for list types: LINE, TRIANGLE, CUBELIST etc
if (markerObject.setScale && !markerObject.updatePoints) {
markerObject.setScale({ x: scale.x, y: scale.y, z: scale.z });
markerObject.setScale({
x: scale.x || DEFAULT_SCALE,
y: scale.y || DEFAULT_SCALE,
z: scale.z || DEFAULT_SCALE,
});
}
if (markerObject.setColor && colors.length <= 0) {
markerObject.setColor(color);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/transform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color, Mesh, Object3D, Quaternion } from 'three';
import { assertIsMeshBasicMaterial } from './helpers';
import { Color, Mesh, Object3D, Quaternion, MeshStandardMaterial } from 'three';
import { assertMaterialWithColorSettable } from './helpers';
import Line from '../primitives/Line';
import LineSegments from '../primitives/LineSegment';

Expand Down Expand Up @@ -28,7 +28,7 @@ export const setColor = (
object: Mesh | Line | LineSegments,
color: string | number | RosMessage.Color,
) => {
assertIsMeshBasicMaterial(object.material);
assertMaterialWithColorSettable(object.material);
if (typeof color === 'string' || typeof color === 'number') {
object.material.color = new Color(color);
} else {
Expand Down