render-spheres.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 { Canvas3D } from 'mol-canvas3d/canvas3d';
  8. import { SpheresBuilder } from 'mol-geo/geometry/spheres/spheres-builder';
  9. import { Representation } from 'mol-repr/representation';
  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. const parent = document.getElementById('app')!
  14. parent.style.width = '100%'
  15. parent.style.height = '100%'
  16. const canvas = document.createElement('canvas')
  17. canvas.style.width = '100%'
  18. canvas.style.height = '100%'
  19. parent.appendChild(canvas)
  20. const canvas3d = Canvas3D.create(canvas, parent)
  21. canvas3d.animate()
  22. function spheresRepr() {
  23. const spheresBuilder = SpheresBuilder.create(3, 1)
  24. spheresBuilder.add(0, 0, 0, 0)
  25. spheresBuilder.add(5, 0, 0, 0)
  26. spheresBuilder.add(-4, 1, 0, 0)
  27. const spheres = spheresBuilder.getSpheres()
  28. const values = Spheres.Utils.createValuesSimple(spheres, {}, Color(0xFF0000), 1)
  29. const state = Spheres.Utils.createRenderableState({})
  30. const renderObject = createRenderObject('spheres', values, state, -1)
  31. console.log(renderObject)
  32. const repr = Representation.fromRenderObject('spheres', renderObject)
  33. return repr
  34. }
  35. canvas3d.add(spheresRepr())
  36. canvas3d.resetCamera()