render-mesh.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Copyright (c) 2019-2021 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 { MeshBuilder } from '../../mol-geo/geometry/mesh/mesh-builder';
  10. import { Mat4 } from '../../mol-math/linear-algebra';
  11. import { HexagonalPrismCage } from '../../mol-geo/primitive/prism';
  12. import { SpikedBall } from '../../mol-geo/primitive/spiked-ball';
  13. import { Mesh } from '../../mol-geo/geometry/mesh/mesh';
  14. import { Color } from '../../mol-util/color';
  15. import { createRenderObject } from '../../mol-gl/render-object';
  16. import { Representation } from '../../mol-repr/representation';
  17. import { Torus } from '../../mol-geo/primitive/torus';
  18. import { ParamDefinition } from '../../mol-util/param-definition';
  19. const parent = document.getElementById('app')!;
  20. parent.style.width = '100%';
  21. parent.style.height = '100%';
  22. const canvas = document.createElement('canvas');
  23. parent.appendChild(canvas);
  24. resizeCanvas(canvas, parent);
  25. const canvas3d = Canvas3D.create(Canvas3DContext.fromCanvas(canvas));
  26. canvas3d.animate();
  27. function meshRepr() {
  28. const builderState = MeshBuilder.createState();
  29. const t = Mat4.identity();
  30. Mat4.scaleUniformly(t, t, 10);
  31. MeshBuilder.addCage(builderState, t, HexagonalPrismCage(), 0.05, 2, 20);
  32. const t2 = Mat4.identity();
  33. Mat4.scaleUniformly(t2, t2, 1);
  34. MeshBuilder.addPrimitive(builderState, t2, SpikedBall(3));
  35. const t3 = Mat4.identity();
  36. Mat4.scaleUniformly(t3, t3, 8);
  37. MeshBuilder.addPrimitive(builderState, t3, Torus({ tubularSegments: 64, radialSegments: 32, tube: 0.1 }));
  38. const mesh = MeshBuilder.getMesh(builderState);
  39. const props = ParamDefinition.getDefaultValues(Mesh.Utils.Params);
  40. const values = Mesh.Utils.createValuesSimple(mesh, props, Color(0xFF4433), 1);
  41. const state = Mesh.Utils.createRenderableState(props);
  42. const renderObject = createRenderObject('mesh', values, state, -1);
  43. console.log('mesh', renderObject);
  44. const repr = Representation.fromRenderObject('mesh', renderObject);
  45. return repr;
  46. }
  47. canvas3d.add(meshRepr());
  48. canvas3d.requestCameraReset();