render-mesh.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder';
  9. import { Mat4 } from 'mol-math/linear-algebra';
  10. import { Mesh } from 'mol-geo/geometry/mesh/mesh';
  11. import { Representation } from 'mol-repr/representation';
  12. import { Color } from 'mol-util/color';
  13. import { createRenderObject } from 'mol-gl/render-object';
  14. import { SpikedBall } from 'mol-geo/primitive/spiked-ball';
  15. import { HexagonalPrismCage } from 'mol-geo/primitive/prism';
  16. const parent = document.getElementById('app')!
  17. parent.style.width = '100%'
  18. parent.style.height = '100%'
  19. const canvas = document.createElement('canvas')
  20. canvas.style.width = '100%'
  21. canvas.style.height = '100%'
  22. parent.appendChild(canvas)
  23. const canvas3d = Canvas3D.create(canvas)
  24. canvas3d.animate()
  25. function meshRepr() {
  26. const builderState = MeshBuilder.createState()
  27. const t = Mat4.identity()
  28. MeshBuilder.addCage(builderState, t, HexagonalPrismCage(), 0.005, 2)
  29. const t2 = Mat4.identity()
  30. Mat4.scaleUniformly(t2, t2, 0.1)
  31. MeshBuilder.addPrimitive(builderState, t2, SpikedBall(3))
  32. const mesh = MeshBuilder.getMesh(builderState)
  33. const values = Mesh.Utils.createValuesSimple(mesh, {}, Color(0xFF0000), 1)
  34. const state = Mesh.Utils.createRenderableState({})
  35. const renderObject = createRenderObject('mesh', values, state, -1)
  36. const repr = Representation.fromRenderObject('mesh', renderObject)
  37. return repr
  38. }
  39. canvas3d.add(meshRepr())
  40. canvas3d.resetCamera()