Skip to content

Commit

Permalink
Add ShapeJSON support to Object3D and Shape types (#1073)
Browse files Browse the repository at this point in the history
* Add ShapeJSON support to Object3D and Shape types

Added ShapeJSON support to Object3D's shapes record and updated Shape type with JSON conversion functions. This enhancement allows for easier handling and storage of 2D shapes with holes as JSON data. By integrating ShapeJSON in these types, it enables seamless import/export of complex 3D scenes with intricate shapes in a more efficient manner, improving overall compatibility and versatility.

* Format

* Shape

---------

Co-authored-by: Nathan Bierema <[email protected]>
  • Loading branch information
Hoodgail and Methuselah96 authored Jul 18, 2024
1 parent 12a22f8 commit 2c70739
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion types/three/src/core/Object3D.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AnimationClip, AnimationClipJSON } from "../animation/AnimationClip.js";
import { Camera } from "../cameras/Camera.js";
import { ShapeJSON } from "../extras/core/Shape.js";
import { Material, MaterialJSON } from "../materials/Material.js";
import { Euler } from "../math/Euler.js";
import { Matrix3 } from "../math/Matrix3.js";
Expand Down Expand Up @@ -52,7 +53,7 @@ export interface JSONMeta {
materials: Record<string, MaterialJSON>;
textures: Record<string, TextureJSON>;
images: Record<string, SourceJSON>;
shapes: Record<string, unknown>;
shapes: Record<string, ShapeJSON>;
skeletons: Record<string, SkeletonJSON>;
animations: Record<string, AnimationClipJSON>;
nodes: Record<string, unknown>;
Expand Down
10 changes: 9 additions & 1 deletion types/three/src/extras/core/Shape.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Vector2 } from "../../math/Vector2.js";
import { Path } from "./Path.js";
import { Path, PathJSON } from "./Path.js";

export interface ShapeJSON extends PathJSON {
uuid: string;
holes: PathJSON[];
}

/**
* Defines an arbitrary 2d {@link Shape} plane using paths with optional holes
Expand Down Expand Up @@ -75,4 +80,7 @@ export class Shape extends Path {
* @param divisions The fineness of the result. Expects a `Integer`
*/
getPointsHoles(divisions: number): Vector2[][];

toJSON(): ShapeJSON;
fromJSON(json: ShapeJSON): this;
}

0 comments on commit 2c70739

Please sign in to comment.