threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BlendLoadPlugin.ts 1.3KB

123456789101112131415161718192021222324252627282930313233
  1. import {AnyOptions, BaseImporterPlugin, FileLoader, ILoader, Importer, Object3D, Scene} from 'threepipe'
  2. import {parseBlend} from './js-blend/main.js'
  3. import {createObjects} from './loader'
  4. /**
  5. * Adds support for loading Blend `.blend`, `application/x-blender` files and data uris
  6. */
  7. export class BlendLoadPlugin extends BaseImporterPlugin {
  8. public static readonly PluginType = 'BlendLoadPlugin'
  9. constructor() {
  10. super()
  11. }
  12. protected _importer = new Importer(class extends FileLoader implements ILoader {
  13. async loadAsync(url: string, onProgress?: (event: ProgressEvent) => void): Promise<any> {
  14. this.setResponseType('arraybuffer')
  15. const res = (await super.loadAsync(url, onProgress)) as ArrayBuffer
  16. const blend = await parseBlend(res)
  17. const objects = await createObjects(blend)
  18. const root = new Object3D()
  19. root.add(...objects)
  20. // console.log(res, blend, root)
  21. blend.scene = root
  22. return blend
  23. }
  24. transform(res: any, _: AnyOptions): Scene {
  25. // console.log(res)
  26. // res.scene.userData.kinematics = res.kinematics
  27. // res.scene.userData.library = res.library
  28. return res.scene
  29. }
  30. }, ['blend'], ['application/x-blender'], true)
  31. }