智慧水务管理系统 - 精河县供水工程综合管理平台

createTangentSpaceDebugPrimitive.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js";
  2. import Frozen from "../Core/Frozen.js";
  3. import defined from "../Core/defined.js";
  4. import DeveloperError from "../Core/DeveloperError.js";
  5. import GeometryInstance from "../Core/GeometryInstance.js";
  6. import GeometryPipeline from "../Core/GeometryPipeline.js";
  7. import Matrix4 from "../Core/Matrix4.js";
  8. import PerInstanceColorAppearance from "./PerInstanceColorAppearance.js";
  9. import Primitive from "./Primitive.js";
  10. /**
  11. * Creates a {@link Primitive} to visualize well-known vector vertex attributes:
  12. * <code>normal</code>, <code>tangent</code>, and <code>bitangent</code>. Normal
  13. * is red; tangent is green; and bitangent is blue. If an attribute is not
  14. * present, it is not drawn.
  15. *
  16. * @function
  17. *
  18. * @param {object} options Object with the following properties:
  19. * @param {Geometry} options.geometry The <code>Geometry</code> instance with the attribute.
  20. * @param {number} [options.length=10000.0] The length of each line segment in meters. This can be negative to point the vector in the opposite direction.
  21. * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The model matrix that transforms to transform the geometry from model to world coordinates.
  22. * @returns {Primitive} A new <code>Primitive</code> instance with geometry for the vectors.
  23. *
  24. * @example
  25. * scene.primitives.add(Cesium.createTangentSpaceDebugPrimitive({
  26. * geometry : instance.geometry,
  27. * length : 100000.0,
  28. * modelMatrix : instance.modelMatrix
  29. * }));
  30. */
  31. function createTangentSpaceDebugPrimitive(options) {
  32. options = options ?? Frozen.EMPTY_OBJECT;
  33. const instances = [];
  34. let geometry = options.geometry;
  35. //>>includeStart('debug', pragmas.debug);
  36. if (!defined(geometry)) {
  37. throw new DeveloperError("options.geometry is required.");
  38. }
  39. //>>includeEnd('debug');
  40. if (!defined(geometry.attributes) || !defined(geometry.primitiveType)) {
  41. // to create the debug lines, we need the computed attributes.
  42. // compute them if they are undefined.
  43. geometry = geometry.constructor.createGeometry(geometry);
  44. }
  45. const attributes = geometry.attributes;
  46. const modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY);
  47. const length = options.length ?? 10000.0;
  48. if (defined(attributes.normal)) {
  49. instances.push(
  50. new GeometryInstance({
  51. geometry: GeometryPipeline.createLineSegmentsForVectors(
  52. geometry,
  53. "normal",
  54. length,
  55. ),
  56. attributes: {
  57. color: new ColorGeometryInstanceAttribute(1.0, 0.0, 0.0, 1.0),
  58. },
  59. modelMatrix: modelMatrix,
  60. }),
  61. );
  62. }
  63. if (defined(attributes.tangent)) {
  64. instances.push(
  65. new GeometryInstance({
  66. geometry: GeometryPipeline.createLineSegmentsForVectors(
  67. geometry,
  68. "tangent",
  69. length,
  70. ),
  71. attributes: {
  72. color: new ColorGeometryInstanceAttribute(0.0, 1.0, 0.0, 1.0),
  73. },
  74. modelMatrix: modelMatrix,
  75. }),
  76. );
  77. }
  78. if (defined(attributes.bitangent)) {
  79. instances.push(
  80. new GeometryInstance({
  81. geometry: GeometryPipeline.createLineSegmentsForVectors(
  82. geometry,
  83. "bitangent",
  84. length,
  85. ),
  86. attributes: {
  87. color: new ColorGeometryInstanceAttribute(0.0, 0.0, 1.0, 1.0),
  88. },
  89. modelMatrix: modelMatrix,
  90. }),
  91. );
  92. }
  93. if (instances.length > 0) {
  94. return new Primitive({
  95. asynchronous: false,
  96. geometryInstances: instances,
  97. appearance: new PerInstanceColorAppearance({
  98. flat: true,
  99. translucent: false,
  100. }),
  101. });
  102. }
  103. return undefined;
  104. }
  105. export default createTangentSpaceDebugPrimitive;