-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(geometry): add extra geometry package, extrude geometry and text…
… geometry (#442) Co-authored-by: ShuangLiu <liu.shuang@huasheng.io>
- Loading branch information
1 parent
7c18db5
commit 069e6d4
Showing
19 changed files
with
16,075 additions
and
1 deletion.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
packages/geometry/ExtrudeGeometry/Curve/CubicBezierCurve2D.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Vector2 } from "@orillusion/core"; | ||
import { Curve2D } from "./Curve2D"; | ||
|
||
export class CubicBezierCurve2D extends Curve2D { | ||
public v0: Vector2; | ||
public v1: Vector2; | ||
public v2: Vector2; | ||
public v3: Vector2; | ||
|
||
constructor(v0: Vector2, v1: Vector2, v2: Vector2, v3: Vector2) { | ||
super(); | ||
this.v0 = v0; | ||
this.v1 = v1; | ||
this.v2 = v2; | ||
this.v3 = v3; | ||
} | ||
|
||
public get points(): Vector2[] { | ||
return [this.v0, this.v1, this.v2, this.v3]; | ||
} | ||
|
||
public getPoint(t: number, result: Vector2 = new Vector2()): Vector2 { | ||
result.set( | ||
this.cubicBezier(t, this.v0.x, this.v1.x, this.v2.x, this.v3.x), | ||
this.cubicBezier(t, this.v0.y, this.v1.y, this.v2.y, this.v3.y) | ||
); | ||
return result; | ||
} | ||
|
||
public copyFrom(other: CubicBezierCurve2D) { | ||
this.v0.copyFrom(other.v0); | ||
this.v1.copyFrom(other.v1); | ||
this.v2.copyFrom(other.v2); | ||
this.v3.copyFrom(other.v3); | ||
} | ||
|
||
protected cubicBezierP0(t: number, p: number) { | ||
const k = 1 - t; | ||
return k * k * k * p; | ||
} | ||
|
||
protected cubicBezierP1(t: number, p: number) { | ||
const k = 1 - t; | ||
return 3 * k * k * t * p; | ||
} | ||
|
||
protected cubicBezierP2(t: number, p: number) { | ||
return 3 * (1 - t) * t * t * p; | ||
} | ||
|
||
protected cubicBezierP3(t: number, p: number) { | ||
return t * t * t * p; | ||
} | ||
|
||
protected cubicBezier(t: number, p0: number, p1: number, p2: number, p3: number) { | ||
return this.cubicBezierP0(t, p0) + this.cubicBezierP1(t, p1) + this.cubicBezierP2(t, p2) + this.cubicBezierP3(t, p3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Vector2 } from "@orillusion/core"; | ||
|
||
export enum CurveType { | ||
LineCurve, | ||
SplineCurve, | ||
EllipseCurve, | ||
QuadraticBezierCurve, | ||
} | ||
|
||
export class Curve2D { | ||
public curveType: CurveType; | ||
|
||
public get points(): Vector2[] { | ||
console.warn("points not implementation!"); | ||
return []; | ||
} | ||
|
||
public getPoint(t: number, result: Vector2 = new Vector2()): Vector2 { | ||
console.warn("getPoint not implementation!"); | ||
return result; | ||
} | ||
|
||
public getPoints(divisions = 5): Vector2[] { | ||
let points: Vector2[] = []; | ||
for (let d = 0; d <= divisions; d++) { | ||
points.push(this.getPoint(d / divisions)); | ||
} | ||
return points; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Vector2 } from "@orillusion/core"; | ||
import { Curve2D, CurveType } from "./Curve2D"; | ||
|
||
export class LineCurve2D extends Curve2D { | ||
public v0: Vector2; | ||
public v1: Vector2; | ||
|
||
constructor(v0: Vector2, v1: Vector2) { | ||
super(); | ||
this.v0 = v0; | ||
this.v1 = v1; | ||
this.curveType = CurveType.LineCurve; | ||
} | ||
|
||
public get points(): Vector2[] { | ||
return [this.v0, this.v1]; | ||
} | ||
|
||
public getPoint(t: number, result: Vector2 = new Vector2()): Vector2 { | ||
if (t >= 1) { | ||
result.copyFrom(this.v1); | ||
} else { | ||
this.v1.sub(this.v0, result); | ||
result.multiplyScaler(t).add(this.v0, result); | ||
} | ||
return result; | ||
} | ||
|
||
public getPointAt(u: number, result: Vector2 = new Vector2()): Vector2 { | ||
return this.getPoint(u, result); | ||
} | ||
|
||
public getTangent(t: number, result: Vector2 = new Vector2()): Vector2 { | ||
this.v1.sub(this.v0, result); | ||
result.normalize(); | ||
return result; | ||
} | ||
|
||
public getTangentAt(u: number, result: Vector2 = new Vector2()): Vector2 { | ||
return this.getTangent(u, result); | ||
} | ||
|
||
public copyFrom(other: LineCurve2D) { | ||
this.v0.copyFrom(other.v0); | ||
this.v1.copyFrom(other.v1); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/geometry/ExtrudeGeometry/Curve/QuadraticBezierCurve2D.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Vector2 } from "@orillusion/core"; | ||
import { Curve2D, CurveType } from "./Curve2D"; | ||
|
||
export class QuadraticBezierCurve2D extends Curve2D { | ||
public v0: Vector2; | ||
public v1: Vector2; | ||
public v2: Vector2; | ||
|
||
constructor(v0: Vector2, v1: Vector2, v2: Vector2) { | ||
super(); | ||
this.v0 = v0; | ||
this.v1 = v1; | ||
this.v2 = v2; | ||
this.curveType = CurveType.QuadraticBezierCurve; | ||
} | ||
|
||
public get points(): Vector2[] { | ||
return [this.v0, this.v1, this.v2]; | ||
} | ||
|
||
public getPoint(t: number, result: Vector2 = new Vector2()): Vector2 { | ||
result.set( | ||
this.quadraticBezier(t, this.v0.x, this.v1.x, this.v2.x), | ||
this.quadraticBezier(t, this.v0.y, this.v1.y, this.v2.y) | ||
); | ||
return result; | ||
} | ||
|
||
public copyFrom(other: QuadraticBezierCurve2D) { | ||
this.v0.copyFrom(other.v0); | ||
this.v1.copyFrom(other.v1); | ||
this.v2.copyFrom(other.v2); | ||
} | ||
|
||
protected quadraticBezierP0(t: number, p: number) { | ||
const k = 1 - t; | ||
return k * k * p; | ||
} | ||
|
||
protected quadraticBezierP1(t: number, p: number) { | ||
return 2 * (1 - t) * t * p; | ||
} | ||
|
||
protected quadraticBezierP2(t: number, p: number) { | ||
return t * t * p; | ||
} | ||
|
||
protected quadraticBezier(t: number, p0: number, p1: number, p2: number): number { | ||
return this.quadraticBezierP0(t, p0) + this.quadraticBezierP1(t, p1) + this.quadraticBezierP2(t, p2); | ||
} | ||
} |
Oops, something went wrong.