Skip to content

Commit

Permalink
feat(scenegraph): add ICopy impls for Node2/3
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 28, 2020
1 parent 15213e2 commit fd6ffdb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
17 changes: 14 additions & 3 deletions packages/scenegraph/src/node2.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { deref, IToHiccup, Nullable } from "@thi.ng/api";
import { deref, ICopy, IToHiccup, Nullable } from "@thi.ng/api";
import { isFunction, isNumber } from "@thi.ng/checks";
import { invert23, mulM23, mulV23, transform23 } from "@thi.ng/matrices";
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
import { ReadonlyVec, set2, Vec } from "@thi.ng/vectors";
import { ANode } from "./anode";
import type { ISceneNode } from "./api";

export class Node2D extends ANode<Node2D>
implements ISceneNode<Node2D>, IToHiccup {
implements ICopy<Node2D>, ISceneNode<Node2D>, IToHiccup {
translate: Vec;
rotate: number;
scale: Vec | number;
Expand All @@ -26,6 +26,17 @@ export class Node2D extends ANode<Node2D>
this.update();
}

copy() {
return new Node2D(
this.id,
this.parent,
set2([], this.translate),
this.rotate,
set2([], <Vec>this.scale),
this.body
);
}

deleteChild(node: number | Node2D) {
return this._deleteChild(node, Node2D);
}
Expand Down
19 changes: 15 additions & 4 deletions packages/scenegraph/src/node3.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { deref, IToHiccup, Nullable } from "@thi.ng/api";
import { deref, ICopy, IToHiccup, Nullable } from "@thi.ng/api";
import { isFunction, isNumber } from "@thi.ng/checks";
import { invert44, mulM44, mulV344, transform44 } from "@thi.ng/matrices";
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
import { ReadonlyVec, set3, Vec } from "@thi.ng/vectors";
import { ANode } from "./anode";
import type { ISceneNode } from "./api";

export class Node3D extends ANode<Node3D>
implements ISceneNode<Node3D>, IToHiccup {
implements ICopy<Node3D>, ISceneNode<Node3D>, IToHiccup {
translate: Vec;
rotate: Vec;
scale: Vec | number;
Expand All @@ -15,7 +15,7 @@ export class Node3D extends ANode<Node3D>
id: string,
parent?: Nullable<Node3D>,
translate: Vec = [0, 0, 0],
rotate = [0, 0, 0],
rotate: Vec = [0, 0, 0],
scale: Vec | number = 1,
body?: any
) {
Expand All @@ -26,6 +26,17 @@ export class Node3D extends ANode<Node3D>
this.update();
}

copy() {
return new Node3D(
this.id,
this.parent,
set3([], this.translate),
set3([], this.rotate),
set3([], <Vec>this.scale),
this.body
);
}

deleteChild(node: number | Node3D) {
return this._deleteChild(node, Node3D);
}
Expand Down

0 comments on commit fd6ffdb

Please sign in to comment.