Skip to content

Commit

Permalink
feat: add recordSchemaToStore
Browse files Browse the repository at this point in the history
  • Loading branch information
gong9 committed Oct 20, 2023
1 parent 9ef1078 commit 5177ece
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/hooks/useCreateLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
10 changes: 10 additions & 0 deletions src/type/SchemaType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions src/utils/lineDerivation.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -45,5 +105,7 @@ export const createBoxGeometryByPoints = (a: Vector3, b: Vector3, height = 1, de
else
mesh.rotateOnAxis(axis, -angle)

// recordSchemaToStore(mesh, 'boxGeometry')

return mesh
}

0 comments on commit 5177ece

Please sign in to comment.