shape.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { PluginContext } from '../../../mol-plugin/context';
  7. import { State, StateBuilder } from '../../../mol-state';
  8. import { Task } from '../../../mol-task';
  9. import { FileInfo } from '../../../mol-util/file-info';
  10. import { PluginStateObject } from '../objects';
  11. import { StateTransforms } from '../transforms';
  12. import { DataFormatProvider, DataFormatBuilderOptions } from './data-format';
  13. export const PlyProvider: DataFormatProvider<any> = {
  14. label: 'PLY',
  15. description: 'PLY',
  16. stringExtensions: ['ply'],
  17. binaryExtensions: [],
  18. isApplicable: (info: FileInfo, data: string) => {
  19. return info.ext === 'ply'
  20. },
  21. getDefaultBuilder: (ctx: PluginContext, data: StateBuilder.To<PluginStateObject.Data.String>, options: DataFormatBuilderOptions, state: State) => {
  22. return Task.create('PLY default builder', async taskCtx => {
  23. let tree: StateBuilder.To<any> = data.apply(StateTransforms.Data.ParsePly)
  24. .apply(StateTransforms.Model.ShapeFromPly)
  25. if (options.visuals) {
  26. tree = tree.apply(StateTransforms.Representation.ShapeRepresentation3D)
  27. }
  28. await state.updateTree(tree).runInContext(taskCtx)
  29. })
  30. }
  31. }