From 2c707394c7e5a87525deabdb6b84690f89527149 Mon Sep 17 00:00:00 2001 From: Drex Benjamin <45743294+Hoodgail@users.noreply.github.com> Date: Thu, 18 Jul 2024 08:38:05 -0400 Subject: [PATCH] Add ShapeJSON support to Object3D and Shape types (#1073) * 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 --- types/three/src/core/Object3D.d.ts | 3 ++- types/three/src/extras/core/Shape.d.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/types/three/src/core/Object3D.d.ts b/types/three/src/core/Object3D.d.ts index 90cc73872..1c35b6e09 100644 --- a/types/three/src/core/Object3D.d.ts +++ b/types/three/src/core/Object3D.d.ts @@ -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"; @@ -52,7 +53,7 @@ export interface JSONMeta { materials: Record; textures: Record; images: Record; - shapes: Record; + shapes: Record; skeletons: Record; animations: Record; nodes: Record; diff --git a/types/three/src/extras/core/Shape.d.ts b/types/three/src/extras/core/Shape.d.ts index a9e6082eb..84e5ff37f 100644 --- a/types/three/src/extras/core/Shape.d.ts +++ b/types/three/src/extras/core/Shape.d.ts @@ -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 @@ -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; }