render-spheres.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 './index.html';
  7. import { resizeCanvas } from '../../mol-canvas3d/util';
  8. import { Canvas3D, Canvas3DContext } from '../../mol-canvas3d/canvas3d';
  9. import { SpheresBuilder } from '../../mol-geo/geometry/spheres/spheres-builder';
  10. import { Spheres } from '../../mol-geo/geometry/spheres/spheres';
  11. import { Color } from '../../mol-util/color';
  12. import { createRenderObject } from '../../mol-gl/render-object';
  13. import { Representation } from '../../mol-repr/representation';
  14. import { ParamDefinition } from '../../mol-util/param-definition';
  15. const parent = document.getElementById('app')!;
  16. parent.style.width = '100%';
  17. parent.style.height = '100%';
  18. const canvas = document.createElement('canvas');
  19. parent.appendChild(canvas);
  20. resizeCanvas(canvas, parent);
  21. const canvas3d = Canvas3D.create(Canvas3DContext.fromCanvas(canvas));
  22. canvas3d.animate();
  23. function spheresRepr() {
  24. const spheresBuilder = SpheresBuilder.create(3, 1);
  25. spheresBuilder.add(0, 0, 0, 0);
  26. spheresBuilder.add(5, 0, 0, 0);
  27. spheresBuilder.add(-4, 1, 0, 0);
  28. const spheres = spheresBuilder.getSpheres();
  29. const props = ParamDefinition.getDefaultValues(Spheres.Utils.Params);
  30. const values = Spheres.Utils.createValuesSimple(spheres, {}, Color(0xFF0000), 1);
  31. const state = Spheres.Utils.createRenderableState(props);
  32. const renderObject = createRenderObject('spheres', values, state, -1);
  33. console.log(renderObject);
  34. const repr = Representation.fromRenderObject('spheres', renderObject);
  35. return repr;
  36. }
  37. canvas3d.add(spheresRepr());
  38. canvas3d.requestCameraReset();