From 5177ece709089e218b6814ca76e5914fdc056d82 Mon Sep 17 00:00:00 2001 From: gongzhen <517441540@qq.com> Date: Fri, 20 Oct 2023 17:37:54 +0800 Subject: [PATCH] feat: add recordSchemaToStore --- src/hooks/useCreateLine.ts | 6 ++++ src/type/SchemaType.ts | 10 ++++++ src/utils/lineDerivation.ts | 62 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/src/hooks/useCreateLine.ts b/src/hooks/useCreateLine.ts index 4b2c43b..95f15b9 100644 --- a/src/hooks/useCreateLine.ts +++ b/src/hooks/useCreateLine.ts @@ -34,6 +34,12 @@ const useCreateLine = () => { return geometry } + /** + * line first point helper show + * @param x + * @param y + * @param z + */ const drawPoint = (x: number, y: number, z: number) => { const geo = new BufferGeometry() const vertices = new Float32Array([x, y, z]) diff --git a/src/type/SchemaType.ts b/src/type/SchemaType.ts index 12311d4..1c128bb 100644 --- a/src/type/SchemaType.ts +++ b/src/type/SchemaType.ts @@ -10,9 +10,19 @@ export interface GeometryType { depthSegments?: number } +// material texture map +interface TextureMapType { + path?: string // image path + repeatX: number + repeatY: number + wrapS?: number + wrapT?: number +} export interface MaterialType { type: 'meshBasicMaterial' color?: string + map?: TextureMapType + side?: 'DoubleSide' | 'FrontSide' | 'BackSide' } // config json schema diff --git a/src/utils/lineDerivation.ts b/src/utils/lineDerivation.ts index 478a108..d41f69c 100644 --- a/src/utils/lineDerivation.ts +++ b/src/utils/lineDerivation.ts @@ -1,8 +1,68 @@ import { BoxGeometry, DoubleSide, Mesh, MeshBasicMaterial, Quaternion, RepeatWrapping, TextureLoader, Vector3 } from 'three' +import { v4 as uuidv4 } from 'uuid' + import wall from '@/assets/wall.jpg' +interface BoxGeometryParamsType { + position: Vector3 + width: number + height: number + depth: number +} + +interface BoxMaterialParamsType { + path?: string + color?: string + repeatX?: number + repeatY?: number + wrapS?: number + wrapT?: number +} + +/** + * record schema to store, target to push view update + * @param boxGeometryParams + * @param boxMaterialParams + * @returns + */ +const recordSchemaToStore = (boxGeometryParams: BoxGeometryParamsType, boxMaterialParams: BoxMaterialParamsType) => { + const { position, width, height, depth } = boxGeometryParams + const { color, path, repeatX, wrapS, repeatY, wrapT } = boxMaterialParams + + // geometry info + const geometry = { + type: 'boxGeometry', + width, + height, + depth, + } + + // material info + const material = { + type: 'meshBasicMaterial', + color, + map: { + path, + repeatX, + repeatY, + wrapS, + wrapT, + }, + } + + return { + uid: uuidv4(), + name: '墙体', + position, + rotation: new Quaternion(0, 0, 0, 0), + geometry, + material, + } +} + /** * create box geometry by two points + * just provide data not create mesh * @param a * @param b * @param height @@ -45,5 +105,7 @@ export const createBoxGeometryByPoints = (a: Vector3, b: Vector3, height = 1, de else mesh.rotateOnAxis(axis, -angle) + // recordSchemaToStore(mesh, 'boxGeometry') + return mesh }