@threepipe/plugins-extra-importers 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.
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@threepipe/plugins-extra-importers",
3
+ "description": "Sample Threepipe plugin using rollup",
4
+ "version": "0.0.1",
5
+ "dependencies": {
6
+ "threepipe": "^0.0.14"
7
+ },
8
+ "type": "module",
9
+ "main": "dist/index.js",
10
+ "module": "dist/index.mjs",
11
+ "types": "dist/index.d.ts",
12
+ "files": [
13
+ "dist",
14
+ "src"
15
+ ],
16
+ "author": "repalash <palash@shaders.app>",
17
+ "license": "Apache-2.0",
18
+ "keywords": [
19
+ "three",
20
+ "three.js",
21
+ "threepipe",
22
+ "tweakpane",
23
+ "editor",
24
+ "plugin"
25
+ ],
26
+ "bugs": {
27
+ "url": "https://github.com/repalash/threepipe/issues"
28
+ },
29
+ "homepage": "https://github.com/repalash/threepipe#readme",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git://github.com/repalash/threepipe.git"
33
+ }
34
+ }
@@ -0,0 +1,36 @@
1
+ declare module '*.txt' {
2
+ const content: string
3
+ export default content
4
+ }
5
+ declare module '*.glsl' {
6
+ const content: string
7
+ export default content
8
+ }
9
+ declare module '*.vert' {
10
+ const content: string
11
+ export default content
12
+ }
13
+ declare module '*.frag' {
14
+ const content: string
15
+ export default content
16
+ }
17
+ declare module '*.module.scss' {
18
+ const content: any
19
+ export default content
20
+ export const stylesheet: string
21
+ }
22
+ declare module '*.module.css' {
23
+ const content: any
24
+ export default content
25
+ export const stylesheet: string
26
+ }
27
+ declare module '*.css' {
28
+ const content: string
29
+ export default content
30
+ }
31
+
32
+ // export {}
33
+
34
+ // hack for typedoc
35
+ // eslint-disable-next-line @typescript-eslint/naming-convention
36
+ // declare type OffscreenCanvas = HTMLCanvasElement
package/src/index.ts ADDED
@@ -0,0 +1,244 @@
1
+ import {
2
+ AnyOptions,
3
+ BaseImporterPlugin,
4
+ BoxGeometry,
5
+ BufferGeometry,
6
+ Color,
7
+ Group,
8
+ ILoader,
9
+ Importer,
10
+ Mesh,
11
+ Object3D,
12
+ PhysicalMaterial,
13
+ Points,
14
+ PointsMaterial,
15
+ Scene,
16
+ SkeletonHelper,
17
+ } from 'threepipe'
18
+ import {TDSLoader} from 'three/examples/jsm/loaders/TDSLoader.js'
19
+ import {ThreeMFLoader} from 'three/examples/jsm/loaders/3MFLoader.js'
20
+ import {Collada, ColladaLoader} from 'three/examples/jsm/loaders/ColladaLoader.js'
21
+ import {AMFLoader} from 'three/examples/jsm/loaders/AMFLoader.js'
22
+ import {GCodeLoader} from 'three/examples/jsm/loaders/GCodeLoader.js'
23
+ import {BVH, BVHLoader} from 'three/examples/jsm/loaders/BVHLoader.js'
24
+ import {Chunk, VOXLoader, VOXMesh} from 'three/examples/jsm/loaders/VOXLoader.js'
25
+ import {MDD, MDDLoader} from 'three/examples/jsm/loaders/MDDLoader.js'
26
+ import {PCDLoader} from 'three/examples/jsm/loaders/PCDLoader.js'
27
+ import {TiltLoader} from 'three/examples/jsm/loaders/TiltLoader.js'
28
+ import {VRMLLoader} from 'three/examples/jsm/loaders/VRMLLoader.js'
29
+ import {LDrawLoader} from 'three/examples/jsm/loaders/LDrawLoader.js'
30
+ import {VTKLoader} from 'three/examples/jsm/loaders/VTKLoader.js'
31
+ import {XYZLoader} from 'three/examples/jsm/loaders/XYZLoader.js'
32
+
33
+ // 3ds
34
+ /**
35
+ * Adds support for loading Autodesk 3ds `.3ds`, `application/x-3ds` files and data uris
36
+ */
37
+ export class TDSLoadPlugin extends BaseImporterPlugin {
38
+ public static readonly PluginType = 'TDSLoadPlugin'
39
+ protected _importer = new Importer(TDSLoader, ['3ds'], ['image/x-3ds', 'application/x-3ds'], false)
40
+ }
41
+
42
+ // 3mf
43
+ /**
44
+ * Adds support for loading `.3mf`, `model/3mf` files and data uris
45
+ */
46
+ export class ThreeMFLoadPlugin extends BaseImporterPlugin {
47
+ public static readonly PluginType = 'ThreeMFLoadPlugin'
48
+ protected _importer = new Importer(ThreeMFLoader, ['3mf'], ['model/3mf'], false)
49
+ }
50
+
51
+ // collada
52
+ /**
53
+ * Adds support for loading Collada `.dae`, `model/vnd.collada+xml` files and data uris
54
+ */
55
+ export class ColladaLoadPlugin extends BaseImporterPlugin {
56
+ public static readonly PluginType = 'ColladaLoadPlugin'
57
+ protected _importer = new Importer(class extends ColladaLoader implements ILoader {
58
+ transform(res: Collada, _: AnyOptions): Scene {
59
+ res.scene.userData.kinematics = res.kinematics
60
+ res.scene.userData.library = res.library
61
+ return res.scene
62
+ }
63
+ }, ['dae'], ['model/vnd.collada+xml'], false)
64
+ }
65
+
66
+ // amf
67
+ /**
68
+ * Adds support for loading Additive Manufacturing files `.amf`, `application/amf` files and data uris
69
+ */
70
+ export class AMFLoadPlugin extends BaseImporterPlugin {
71
+ public static readonly PluginType = 'AMFLoadPlugin'
72
+ protected _importer = new Importer(AMFLoader, ['amf'], ['application/amf'], false)
73
+ }
74
+
75
+ // gcode
76
+ /**
77
+ * Adds support for loading `.gcode`, `application/gcode` files and data uris
78
+ */
79
+ export class GCodeLoadPlugin extends BaseImporterPlugin {
80
+ public static readonly PluginType = 'GCodeLoadPlugin'
81
+ protected _importer = new Importer(GCodeLoader, ['gcode'], ['application/gcode'], false)
82
+ }
83
+
84
+ // bvh
85
+ /**
86
+ * Adds support for loading `.bvh`, `application/bvh` files and data uris
87
+ */
88
+ export class BVHLoadPlugin extends BaseImporterPlugin {
89
+ public static readonly PluginType = 'BVHLoadPlugin'
90
+ protected _importer = new Importer(class extends BVHLoader implements ILoader {
91
+ transform(res: BVH, _: AnyOptions): Object3D {
92
+ const obj = new Object3D()
93
+ const helper = new SkeletonHelper(res.skeleton.bones[0])
94
+ obj.add(res.skeleton.bones[0])
95
+ obj.add(helper)
96
+ obj.animations = [res.clip]
97
+ obj.scale.set(0.1, 0.1, 0.1) // todo: autoScale and autoCenter not working
98
+ return obj
99
+ }
100
+ }, ['bvh'], ['application/bvh'], false)
101
+ }
102
+
103
+ // vox
104
+ /**
105
+ * Adds support for loading Magica Voxel `.vox` files and data uris
106
+ */
107
+ export class VOXLoadPlugin extends BaseImporterPlugin {
108
+ public static readonly PluginType = 'VOXLoadPlugin'
109
+ protected _importer = new Importer(class extends VOXLoader implements ILoader {
110
+ transform(chunks: Chunk[], _: AnyOptions): Object3D {
111
+ const obj = new Object3D()
112
+ for (const chunk of chunks) {
113
+ // displayPalette( chunk.palette );
114
+ const mesh = new VOXMesh(chunk)
115
+ mesh.scale.setScalar(0.0015)
116
+ obj.add(mesh)
117
+ }
118
+ return obj
119
+ }
120
+ }, ['vox'], [''], false)
121
+ }
122
+
123
+
124
+ // mdd
125
+ /**
126
+ * Adds support for loading animation `.mdd`, `application/mdd` files and data uris
127
+ */
128
+ export class MDDLoadPlugin extends BaseImporterPlugin {
129
+ public static readonly PluginType = 'MDDLoadPlugin'
130
+ protected _importer = new Importer(class extends MDDLoader implements ILoader {
131
+ transform(res: MDD, _: AnyOptions): Object3D {
132
+ const morphTargets = res.morphTargets
133
+ const geometry = new BoxGeometry()
134
+ geometry.morphAttributes.position = morphTargets // apply morph targets
135
+ const mesh = new Mesh(geometry, new PhysicalMaterial())
136
+ const obj = new Object3D()
137
+ obj.add(mesh)
138
+ res.clip.tracks.forEach(track=> track.name = mesh.uuid + track.name)
139
+ obj.animations = [res.clip]
140
+ return obj
141
+ }
142
+ }, ['mdd'], ['application/mdd'], false)
143
+ }
144
+
145
+ // pcd
146
+ /**
147
+ * Adds support for loading Point cloud data `.pcd`, `application/pcd` files and data uris
148
+ */
149
+ export class PCDLoadPlugin extends BaseImporterPlugin {
150
+ public static readonly PluginType = 'PCDLoadPlugin'
151
+ protected _importer = new Importer(class extends PCDLoader implements ILoader {
152
+ transform(points: Points, options: AnyOptions): any {
153
+ if (options.autoCenter) points.geometry.center()
154
+ points.geometry.rotateX(Math.PI)
155
+ return points
156
+ }
157
+ }, ['pcd'], ['application/pcd'], false)
158
+ }
159
+
160
+ // tilt
161
+ /**
162
+ * Adds support for loading Tilt brush `.tilt`, `application/tilt` files and data uris
163
+ */
164
+ export class TiltLoadPlugin extends BaseImporterPlugin {
165
+ public static readonly PluginType = 'TiltLoadPlugin'
166
+ protected _importer = new Importer(TiltLoader, ['tilt'], ['application/tilt'], false)
167
+ }
168
+
169
+ // vrml
170
+ /**
171
+ * Adds support for loading VRML `.wrl`, `model/vrml` files and data uris
172
+ */
173
+ export class VRMLLoadPlugin extends BaseImporterPlugin {
174
+ public static readonly PluginType = 'VRMLLoadPlugin'
175
+ protected _importer = new Importer(VRMLLoader, ['wrl'], ['model/vrml'], false)
176
+ }
177
+
178
+ // ldraw
179
+ /**
180
+ * Adds support for loading LDraw `.mpd`, `application/mpd` files and data uris. see https://ldraw.org
181
+ */
182
+ export class LDrawLoadPlugin extends BaseImporterPlugin {
183
+ public static readonly PluginType = 'LDrawLoadPlugin'
184
+ protected _importer = new Importer(class extends LDrawLoader implements ILoader {
185
+ transform(res: Group, _: AnyOptions): any {
186
+ // Convert from LDraw coordinates: rotate 180 degrees around OX
187
+ res.rotation.x = Math.PI
188
+ return res
189
+ }
190
+ }, ['mpd'], ['application/ldraw'], false)
191
+ }
192
+
193
+ // vtk
194
+ /**
195
+ * Adds support for loading VTK `.vtk`, '.vtp', `application/vtk` files and data uris
196
+ **/
197
+ export class VTKLoadPlugin extends BaseImporterPlugin {
198
+ public static readonly PluginType = 'VTKLoadPlugin'
199
+ protected _importer = new Importer(class extends VTKLoader implements ILoader {
200
+ transform(res: BufferGeometry, _: AnyOptions): Mesh|undefined {
201
+ if (!res.attributes?.normal) res.computeVertexNormals()
202
+ // todo set mesh name from options/path
203
+ return res ? new Mesh(res, new PhysicalMaterial({
204
+ color: new Color(1, 1, 1),
205
+ vertexColors: res.hasAttribute('color'),
206
+ })) : undefined
207
+ }
208
+ }, ['vtk', 'vtp'], ['application/vtk'], false)
209
+ }
210
+
211
+ // xyz
212
+ /**
213
+ * Adds support for loading XYZ `.xyz`, `text/plain+xyz` files and data uris
214
+ */
215
+ export class XYZLoadPlugin extends BaseImporterPlugin {
216
+ public static readonly PluginType = 'XYZLoadPlugin'
217
+ protected _importer = new Importer(class extends XYZLoader implements ILoader {
218
+ transform(res: BufferGeometry, options: AnyOptions): Points|undefined {
219
+ if (!res.attributes?.normal) res.computeVertexNormals()
220
+ if (options.autoCenter) res.center()
221
+ return res ? new Points(res, new PointsMaterial({
222
+ size: 0.1,
223
+ vertexColors: res.hasAttribute('color'),
224
+ })) : undefined
225
+ }
226
+ }, ['xyz'], ['text/plain+xyz'], false)
227
+ }
228
+
229
+ export const extraImportPlugins = [
230
+ TDSLoadPlugin,
231
+ ThreeMFLoadPlugin,
232
+ ColladaLoadPlugin,
233
+ AMFLoadPlugin,
234
+ GCodeLoadPlugin,
235
+ BVHLoadPlugin,
236
+ VOXLoadPlugin,
237
+ MDDLoadPlugin,
238
+ PCDLoadPlugin,
239
+ TiltLoadPlugin,
240
+ VRMLLoadPlugin,
241
+ LDrawLoadPlugin,
242
+ VTKLoadPlugin,
243
+ XYZLoadPlugin,
244
+ ] as const