Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hbcarlos committed Jun 12, 2020
1 parent 207d6e1 commit 270e5c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Material,
Mesh,
MeshBasicMaterial,
MeshStandardMaterial,
Object3D,
Quaternion,
TorusGeometry,
Expand Down Expand Up @@ -133,6 +134,14 @@ export function assertIsMeshBasicMaterial(
}
}

export function assertIsMaterialWithColor(
val: any,
): asserts val is MeshBasicMaterial {
if (!('color' in val)) {
throw new TypeError(`Expected 'val' to be MeshBasicMaterial with color`);
}
}

export function assertBehavesLikeArray<T>(val: any): asserts val is Array<T> {
if (val.length === undefined) {
throw new TypeError(`Expected 'val' to be an array`);
Expand Down
7 changes: 5 additions & 2 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 { assertIsMaterial } from './helpers';
import { assertIsMaterialWithColor } from './helpers';
import Line from '../primitives/Line';
import LineSegments from '../primitives/LineSegment';

Expand Down Expand Up @@ -28,7 +28,10 @@ export const setColor = (
object: Mesh | Line | LineSegments,
color: string | number | RosMessage.Color,
) => {
assertIsMaterial(object.material);
console.log("¡¡¡¡ assertIsMeshBasicMaterial !!!!")
console.log(object)
assertIsMaterialWithColor(object.material);

if (typeof color === 'string' || typeof color === 'number') {
object.material.color = new Color(color);
} else {
Expand Down

0 comments on commit 270e5c6

Please sign in to comment.