Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ExtrudeGeometry): add anchor point offset #452

Merged
merged 27 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c85763d
chore: remove sample_candleflame maskMap
Codeboy-cn Jan 26, 2024
2cd0367
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn Jan 26, 2024
e92858c
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn Feb 26, 2024
392c204
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn Mar 21, 2024
469c572
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn Apr 24, 2024
9399745
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn May 22, 2024
31607d3
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn Jul 16, 2024
44d8bfb
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn Jul 18, 2024
6331261
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn Jul 25, 2024
bbca1ee
chore: remove carcut npm package
Codeboy-cn Jul 25, 2024
e4facf6
fix pnpm-lock
lslzl3000 Jul 25, 2024
25f7fd3
fix pnpm-lock
lslzl3000 Jul 25, 2024
20017e3
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn Aug 12, 2024
835b9ca
feat: add extrude geometry and text geometry
Codeboy-cn Aug 12, 2024
f627cf3
chore: fix types
lslzl3000 Aug 12, 2024
43a4f2f
chore: update samples
lslzl3000 Aug 12, 2024
579aab8
chore: add more shape2D samples
lslzl3000 Aug 13, 2024
a38371a
chore: opt font type
lslzl3000 Aug 13, 2024
9f56463
fix CylinderGeometry
Codeboy-cn Oct 8, 2024
7770b26
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn Oct 8, 2024
87b35d1
Delete packages/geometry/TextGeometry.ts
lslzl3000 Oct 8, 2024
1e22450
Update CylinderGeometry.ts
lslzl3000 Oct 8, 2024
64fd8ac
chore: add pick test sample
Codeboy-cn Oct 15, 2024
6115805
Merge branch 'dev' of github.com:Codeboy-cn/orillusion into dev
Codeboy-cn Oct 15, 2024
2d3498e
feat: add ExtrudeGeometry anchor point offset
Codeboy-cn Oct 22, 2024
f61250a
Merge branch 'dev' of github.com:Orillusion/orillusion into dev
Codeboy-cn Oct 22, 2024
4763683
chore: update geometry package
lslzl3000 Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 60 additions & 9 deletions packages/geometry/ExtrudeGeometry/ExtrudeGeometry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GeometryBase, Vector2, VertexAttributeName } from "@orillusion/core";
import { GeometryBase, Vector2, Vector3, VertexAttributeName } from "@orillusion/core";
import { Shape2D } from "./Shape2D";
import { ShapeUtils } from "./ShapeUtils";

Expand All @@ -11,6 +11,7 @@ export type ExtrudeGeometryArgs = {
bevelSize?: number;
bevelOffset?: number;
bevelSegments?: number;
anchorPoint?: Vector3;
}

export class ExtrudeGeometry extends GeometryBase {
Expand All @@ -28,12 +29,47 @@ export class ExtrudeGeometry extends GeometryBase {
}
}

protected getExtractPointsAndBoundingSize(shapes: Shape2D[], options: ExtrudeGeometryArgs): { BoundingSize: { min: Vector3; max: Vector3; }, ShapePoints: { shape: Vector2[]; holes: Vector2[][]; }[] } {
const depth: number = options.depth !== undefined ? options.depth : 1;
const curveSegments: number = options.curveSegments !== undefined ? options.curveSegments : 12;
let minPoint: Vector3 = new Vector3(Infinity, Infinity, depth > 0 ? 0 : depth);
let maxPoint: Vector3 = new Vector3(-Infinity, -Infinity, depth < 0 ? 0 : depth);
let shapePointsArray = [];
for (let shape of this.shapes) {
const shapePoints = shape.extractPoints(curveSegments);
shapePointsArray.push(shapePoints);
let vertices = shapePoints.shape;
for (let i = 0; i < vertices.length; i++) {
const p = vertices[i];
if (p.x < minPoint.x)
minPoint.x = p.x;
if (p.y < minPoint.y)
minPoint.y = p.y;

if (p.x > maxPoint.x)
maxPoint.x = p.x;
if (p.y > maxPoint.y)
maxPoint.y = p.y;
}
}

return {
ShapePoints: shapePointsArray,
BoundingSize: { min: minPoint, max: maxPoint },
}
}

protected buildGeometry(options: ExtrudeGeometryArgs) {
this.verticesArray = [];
this.uvArray = [];

let anchorPoint: Vector3 = options.anchorPoint !== undefined ? options.anchorPoint : new Vector3(0, 0, 0.5);
const result = this.getExtractPointsAndBoundingSize(this.shapes, options);
const offsetSize = result.BoundingSize.min.subtract(result.BoundingSize.max);
offsetSize.multiply(anchorPoint, offsetSize);

for (let shape of this.shapes) {
this.addShape(shape, options);
this.addShape(shape, options, offsetSize);
}

const indices = new Uint32Array(this.verticesArray.length / 3);
Expand Down Expand Up @@ -61,7 +97,7 @@ export class ExtrudeGeometry extends GeometryBase {
});
}

protected addShape(shape: Shape2D, options: ExtrudeGeometryArgs) {
protected addShape(shape: Shape2D, options: ExtrudeGeometryArgs, offsetSize: Vector3) {
const verticesArray = this.verticesArray;
const uvArray = this.uvArray;
const self = this;
Expand Down Expand Up @@ -89,6 +125,21 @@ export class ExtrudeGeometry extends GeometryBase {
const holes = shapePoints.holes;
const reverse = !ShapeUtils.isClockWise(vertices);

for (let i = 0; i < vertices.length; i++) {
const p = vertices[i];
p.x += offsetSize.x;
p.y += offsetSize.y;
}
for (let i = 0; i < holes.length; i++) {
const holeV = holes[i];
for (let j = 0; j < holeV.length; j++) {
const p = holeV[j];
p.x += offsetSize.x;
p.y += offsetSize.y;
}
}


if (reverse) {
vertices = vertices.reverse();
for (let i = 0; i < holes.length; i++) {
Expand Down Expand Up @@ -137,29 +188,29 @@ export class ExtrudeGeometry extends GeometryBase {

for (let i = 0; i < contour.length; i++) {
const vert = this.scalePoint2(contour[i], contourMovements[i], bs);
v(vert.x, vert.y, - z);
v(vert.x, vert.y, - z + offsetSize.z);
}

for (let h = 0, hl = holes.length; h < hl; h++) {
const ahole = holes[h];
oneHoleMovements = holesMovements[h];
for (let i = 0; i < ahole.length; i++) {
const vert = this.scalePoint2(ahole[i], oneHoleMovements[i], bs);
v(vert.x, vert.y, - z);
v(vert.x, vert.y, - z + offsetSize.z);
}
}
}

const bs = bevelSize + bevelOffset;
for (let i = 0; i < vlen; i++) {
const vert = bevelEnabled ? this.scalePoint2(vertices[i], verticesMovements[i], bs) : vertices[i];
v(vert.x, vert.y, 0);
v(vert.x, vert.y, 0 + offsetSize.z);
}

for (let s = 1; s <= steps; s++) {
for (let i = 0; i < vlen; i++) {
const vert = bevelEnabled ? this.scalePoint2(vertices[i], verticesMovements[i], bs) : vertices[i];
v(vert.x, vert.y, depth / steps * s);
v(vert.x, vert.y, depth / steps * s + offsetSize.z);
}
}

Expand All @@ -170,15 +221,15 @@ export class ExtrudeGeometry extends GeometryBase {

for (let i = 0, il = contour.length; i < il; i++) {
const vert = this.scalePoint2(contour[i], contourMovements[i], bs);
v(vert.x, vert.y, depth + z);
v(vert.x, vert.y, depth + z + offsetSize.z);
}

for (let h = 0, hl = holes.length; h < hl; h++) {
const ahole = holes[h];
oneHoleMovements = holesMovements[h];
for (let i = 0, il = ahole.length; i < il; i++) {
const vert = this.scalePoint2(ahole[i], oneHoleMovements[i], bs);
v(vert.x, vert.y, depth + z);
v(vert.x, vert.y, depth + z + offsetSize.z);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/geometry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orillusion/geometry",
"version": "0.2.4",
"version": "0.2.5",
"author": "Orillusion",
"description": "Orillusion Geometry Plugin",
"main": "./dist/geometry.umd.js",
Expand Down
9 changes: 4 additions & 5 deletions samples/geometry/Sample_TextGeometry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Engine3D, View3D, Scene3D, CameraUtil, AtmosphericComponent, webGPUContext, HoverCameraController, Object3D, DirectLight, KelvinUtil, LitMaterial, MeshRenderer } from "@orillusion/core";
import { Engine3D, View3D, Scene3D, CameraUtil, AtmosphericComponent, webGPUContext, HoverCameraController, Object3D, DirectLight, KelvinUtil, LitMaterial, MeshRenderer, Vector3 } from "@orillusion/core";
import { TextGeometry, FontParser } from "@orillusion/geometry";
import { Graphic3D } from "@orillusion/graphic";

Expand Down Expand Up @@ -32,9 +32,10 @@ class Sample_TextGeometry {
mr.geometry = new TextGeometry("Hello, Orillusion!", {
font: font, // required
fontSize: 16, // required
depth: 2.5,
depth: 5,
steps: 1,
bevelEnabled: false
bevelEnabled: false,
anchorPoint: new Vector3(0.5, 0.5, 0.5),
});

let mats = [];
Expand All @@ -44,8 +45,6 @@ class Sample_TextGeometry {
}
mr.materials = mats;

obj.x = mr.geometry.bounds.size.x * -0.5;

scene.addChild(obj);
}

Expand Down
Loading