/packages/webviz-core/src/panels/ThreeDimensionalViz/commands/PoseMarkers.stories.js

https://github.com/cruise-automation/webviz · JavaScript · 85 lines · 71 code · 7 blank · 7 comment · 0 complexity · 9da8acf43b6db1a3948593d232f2e843 MD5 · raw file

  1. // @flow
  2. //
  3. // Copyright (c) 2019-present, Cruise LLC
  4. //
  5. // This source code is licensed under the Apache License, Version 2.0,
  6. // found in the LICENSE file in the root directory of this source tree.
  7. // You may not use this file except in compliance with the License.
  8. import { storiesOf } from "@storybook/react";
  9. import * as React from "react";
  10. import { Worldview, DEFAULT_CAMERA_STATE, type Color } from "regl-worldview";
  11. import PoseMarkers from "./PoseMarkers";
  12. const MARKER_DATA = {
  13. header: { seq: 26967, stamp: { sec: 1516929048, nsec: 413347495 }, frame_id: "" },
  14. pose: {
  15. position: { x: -1937.7028138723192, y: 1770.5034239982174, z: 52.870026489273044 },
  16. orientation: { x: 0, y: 0, z: -0.9928242172830276, w: 0.11958291506876588 },
  17. },
  18. scale: { x: 1, y: 1, z: 1 },
  19. color: { r: 1, g: 1, b: 1, a: 0.5 },
  20. settings: { color: undefined },
  21. };
  22. const targetPosition = MARKER_DATA.pose.position;
  23. const targetOffset = [targetPosition.x, targetPosition.y, targetPosition.z];
  24. function Example({ alpha = 0.3, color = { r: 0.2, g: 0.59, b: 0.2, a: 0.3 } }: { alpha?: number, color?: Color }) {
  25. const marker = MARKER_DATA;
  26. const markerWithoutColor = {
  27. ...MARKER_DATA,
  28. color: undefined,
  29. pose: {
  30. position: { x: -1937.7028138723192, y: 1775.5034239982174, z: 52.870026489273044 },
  31. orientation: { x: 0, y: 0, z: -0.9928242172830276, w: 0.11958291506876588 },
  32. },
  33. };
  34. const markerWithSettings = {
  35. ...MARKER_DATA,
  36. pose: {
  37. position: { x: -1947.7028138723192, y: 1770.5034239982174, z: 52.870026489273044 },
  38. orientation: { x: -0.9928242172830276, y: 0, z: 0, w: 0.11958291506876588 },
  39. },
  40. settings: {
  41. color,
  42. size: {
  43. shaftWidth: 0.5,
  44. headWidth: 2,
  45. headLength: 2,
  46. },
  47. },
  48. };
  49. const markerWithCarModel = {
  50. ...MARKER_DATA,
  51. pose: {
  52. position: { x: -1951.7028138723192, y: 1770.5034239982174, z: 52.870026489273044 },
  53. orientation: { x: 0, y: 0, z: -0.9928242172830276, w: 0.11958291506876588 },
  54. },
  55. settings: {
  56. modelType: "car-model",
  57. alpha,
  58. },
  59. };
  60. return (
  61. <Worldview
  62. defaultCameraState={{ ...DEFAULT_CAMERA_STATE, distance: 50, targetOffset, perspective: false }}
  63. cameraMode="perspective"
  64. hideDebug>
  65. <PoseMarkers>{[marker, markerWithoutColor, markerWithSettings, markerWithCarModel]}</PoseMarkers>
  66. </Worldview>
  67. );
  68. }
  69. storiesOf("<3DViz> / PoseMarkers", module)
  70. .addParameters({
  71. screenshot: {
  72. delay: 3000,
  73. },
  74. })
  75. .add("alpha_0.3", () => <Example alpha={0.3} />)
  76. .add("alpha_0.5, color_50,200,50,0.8", () => <Example alpha={0.5} color={{ r: 0.2, g: 0.78, b: 0.2, a: 0.8 }} />)
  77. .add("alpha 0.8", () => <Example alpha={0.8} />)
  78. .add("alpha 1", () => <Example alpha={1} />);