From dc2e6dadc56d6d1d138afd9ade95deb2a51d74f4 Mon Sep 17 00:00:00 2001 From: Jamie Temple <jamie-temple@live.de> Date: Tue, 5 Jul 2022 11:08:26 +0200 Subject: [PATCH] feat: interface update to add shapes comfortable --- src/00-welcome-and-example/demo.ts | 7 +------ src/00-welcome-and-example/example.ts | 29 ++++++++------------------- src/01-bezierCurves/demoBezier.ts | 5 ++++- src/core/Pipeline.ts | 11 ++++++++++ 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/00-welcome-and-example/demo.ts b/src/00-welcome-and-example/demo.ts index 82158af..83f6d07 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 8bf6ce0..858c7ed 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 3f977fe..7589d58 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 18ffb3f..6017801 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. -- GitLab