@threepipe/plugin-blend-importer 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ import {PointLight} from 'threepipe'
2
+
3
+ const blenderLightTypes = {
4
+ point: 0,
5
+ sun: 1,
6
+ spot: 0,
7
+ hemi: 0,
8
+ area: 0,
9
+ }
10
+
11
+ export function createLight(lamp: any) {
12
+ const ldata = lamp.data
13
+
14
+ const position = [lamp.loc[0], lamp.loc[2], -lamp.loc[1]]
15
+
16
+ const color = ldata.r * 255 << 16 | ldata.g * 255 << 8 | ldata.b * 255 << 0
17
+ const intensity = ldata.energy
18
+ const distance = 0
19
+
20
+ let light = null
21
+
22
+ switch (ldata.type) {
23
+ case blenderLightTypes.point:
24
+ light = new PointLight(color, intensity, distance)
25
+ light.position.fromArray(position, 0)
26
+ light.castShadow = true
27
+ break
28
+ case blenderLightTypes.sun:
29
+ light = new PointLight(color, intensity, distance)
30
+ light.position.fromArray(position, 0)
31
+ light.castShadow = true
32
+ light.shadow.mapSize.width = 1024
33
+ light.shadow.mapSize.height = 1024
34
+ light.shadow.camera.near = 0.01
35
+ light.shadow.camera.far = 500
36
+ break
37
+ default:
38
+ console.warn('Unsupported light type', ldata.type)
39
+ }
40
+
41
+ return light
42
+ }
@@ -0,0 +1,12 @@
1
+ import {MeshPhysicalMaterial} from 'threepipe'
2
+
3
+ // todo see blender gltf exporter and convert to js. structure is the same
4
+ export function createMaterial(mat: any) {
5
+ const material = new MeshPhysicalMaterial()
6
+ material.color.setRGB(mat.r, mat.g, mat.b)
7
+ material.roughness = mat.roughness !== undefined ? mat.roughness : 0.4
8
+ material.metalness = mat.metallic !== undefined ? mat.metallic : 0.0
9
+ material.opacity = mat.alpha !== undefined ? mat.alpha : 0.0
10
+ material.transparent = material.opacity < 1.0
11
+ return material
12
+ }
@@ -0,0 +1,26 @@
1
+ import {Mesh} from 'threepipe'
2
+ import {createBufferGeometry} from './geometry'
3
+ import {createMaterial} from './material'
4
+
5
+ export function createMesh(object: any) {
6
+ if (!object.data) return null
7
+
8
+ const geometry = createBufferGeometry(object.data, [0, 0, 0])
9
+
10
+ const mat = object.data.mat[0]
11
+
12
+ const material = mat ? createMaterial(mat) : undefined
13
+ const mesh = new Mesh(geometry, material)
14
+
15
+ mesh.castShadow = true
16
+ mesh.receiveShadow = true
17
+
18
+ mesh.rotateZ(object.rot[2])
19
+ mesh.rotateY(object.rot[1])
20
+ mesh.rotateX(object.rot[0])
21
+
22
+ mesh.scale.fromArray(object.size, 0)
23
+ mesh.position.fromArray([object.loc[0], object.loc[2], -object.loc[1]], 0)
24
+
25
+ return mesh
26
+ }