diff --git a/src/00-welcome-and-example/demo.ts b/src/00-welcome-and-example/demo.ts index 82158af6b4e24d607cbc0e56b4e047f05a102284..83f6d07d70d3fd53de3d8bffdbe654745b6ee021 100644 --- a/src/00-welcome-and-example/demo.ts +++ b/src/00-welcome-and-example/demo.ts @@ -1,4 +1,3 @@ -import * as THREE from 'three'; import { SpinningCube } from "./spinningCube"; import { PipelineData } from "../core/Pipeline"; @@ -8,11 +7,7 @@ class Demo extends PipelineData { data(): void { const spinningCube = new SpinningCube(); this.scene.add(spinningCube.object3d); - this.observers.push(spinningCube); - const light = new THREE.PointLight(0xffffff, 10, 100); - light.position.set(10, 0, 10); - this.scene.add(light); - + this.addShape(spinningCube, true, false); } } diff --git a/src/00-welcome-and-example/example.ts b/src/00-welcome-and-example/example.ts index 8bf6ce0cfdedced97d67bd341ec9b3e7dde42348..858c7edc17b79188832fdcc27ccc646d76eb4331 100644 --- a/src/00-welcome-and-example/example.ts +++ b/src/00-welcome-and-example/example.ts @@ -22,37 +22,24 @@ class Example extends PipelineData { const line2d = new Line2d(pointsB, .001, new THREE.Color(0xffffff)); const mesh = new Mesh("../assets/suzanne.obj", new THREE.Color(0xffffff)); + this.addShape(point2d, true, true); + this.addShape(point3d, true, true); + this.addShape(line1d, true, true); // gives a waring + this.addShape(line2d, true, false); + this.addShape(mesh, true, true); + const debugHelper = new DebugHelper(); + this.observers.push(debugHelper); + debugHelper.add(point2d); debugHelper.add(point3d); debugHelper.add(line1d); debugHelper.add(line2d); debugHelper.add(mesh); - this.scene.add(point2d.object3d); - this.scene.add(point3d.object3d); - this.scene.add(line1d.object3d); - this.scene.add(line2d.object3d); - this.scene.add(mesh.object3d); - debugHelper.debug.forEach(object => { this.scene.add(object); }); - - this.observers.push(point2d); - this.observers.push(point3d); - this.observers.push(line1d); - this.observers.push(line2d); - this.observers.push(mesh); - this.observers.push(debugHelper); - - - this.draggables.push(point2d.object3d); - this.draggables.push(point3d.object3d); - this.draggables.push(mesh.object3d); - - // will give a warning - this.draggables.push(line1d.object3d); } } diff --git a/src/01-bezierCurves/demoBezier.ts b/src/01-bezierCurves/demoBezier.ts index 3f977fecdc6e52e11bdeecb41eb7a82a319c4b46..7589d58160e880f51021430d0975e510aebb133e 100644 --- a/src/01-bezierCurves/demoBezier.ts +++ b/src/01-bezierCurves/demoBezier.ts @@ -1,10 +1,13 @@ +import * as THREE from 'three'; import { PipelineData } from "../core/Pipeline"; +import { Point2d } from "../core/Shapes"; class BezierDemo extends PipelineData { public constructor() { super(); } data(): void { - /* INIT DATA HERE */ + const point = new Point2d(.1, 36, new THREE.Color(0x00ff00)); + this.addShape(point, true, true); } } diff --git a/src/core/Pipeline.ts b/src/core/Pipeline.ts index 18ffb3f40b8afda8f72bc53401e1dabd4d4acee9..60178015278e3257c10b8127e6fb559f1ea50eff 100644 --- a/src/core/Pipeline.ts +++ b/src/core/Pipeline.ts @@ -2,6 +2,7 @@ import * as THREE from "three"; import { DragControls } from "three/examples/jsm/controls/DragControls"; import { OrbitControls } from "three/examples/jsm/controls/OrbitControls"; +import { Shape } from "./Shapes"; interface PipelineObserver { /** @@ -26,6 +27,16 @@ abstract class PipelineData { this.data(); } + protected addShape(shape: Shape, observer: boolean = true, draggable: boolean = false) { + this.scene.add(shape.object3d); + if (observer) { + this.observers.push(shape); + } + if (draggable) { + this.draggables.push(shape.object3d); + } + } + /** * @brief Should define a scenario with observers, draggables and scene. * It initializes the scene and adds the draggables to the scene.