ContentBlock.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div>
  3. <!-- <mesh ref="block3d" name="ContentBlock" :position="position">
  4. <geometry type="Box" :args="[size.x, size.y, size.z]" />
  5. <material type="MeshLambert" :color="color" :options="opts" />
  6. </mesh> -->
  7. <mesh
  8. ref="label3d"
  9. name="Content"
  10. :position="position"
  11. :rotation="{
  12. x:deg2rad(rotation.x),
  13. y:deg2rad(rotation.y),
  14. z:deg2rad(rotation.z)
  15. }"
  16. >
  17. <geometry type="Plane" :args="[size.x, size.y]" />
  18. <material type="MeshLambert" :options="label_opts">
  19. <texture :options="label_texture_opts" />
  20. </material>
  21. </mesh>
  22. </div>
  23. </template>
  24. <script>
  25. import * as THREE from 'three'
  26. import mixins from 'components/mixins'
  27. export default {
  28. name: 'ContentBlock',
  29. mixins: [mixins],
  30. props: { prtPosition: Object, prtSize: Object, type: String, data: Object },
  31. data: () => ({
  32. // block3d: null,
  33. size: { x: 2, y: 3, z: 0.1 },
  34. position: { x: 0, y: 0, z: 0 },
  35. rotation: { x: 0, y: 0, z: 0 },
  36. // opts: {
  37. // side: THREE.DoubleSide
  38. // // wireframe: false,
  39. // // transparent: false,
  40. // // opacity: 0.6
  41. // },
  42. isOpened: false,
  43. label3d: null,
  44. label_opts: {
  45. side: THREE.DoubleSide,
  46. // wireframe: false,
  47. transparent: true
  48. // opacity: 0.6
  49. // renderOrder: 0
  50. },
  51. // label_position: { x: 5, y: 5, z: 6 },
  52. label_canvas: null,
  53. label_size: null,
  54. face: null
  55. }),
  56. computed: {
  57. color () {
  58. let color = 0x000000
  59. switch (this.type) {
  60. case 'visible':
  61. color = 0x0000ff
  62. break
  63. case 'context':
  64. color = 0x00ffff
  65. break
  66. case 'process':
  67. color = 0xff00ff
  68. break
  69. default:
  70. color = 0xdddddd
  71. }
  72. return color
  73. },
  74. label_texture_opts () {
  75. return {
  76. canvas: this.label_canvas,
  77. minFilter: THREE.LinearFilter,
  78. wrapS: THREE.ClampToEdgeWrapping,
  79. wrapT: THREE.ClampToEdgeWrapping
  80. }
  81. }
  82. },
  83. created () {
  84. console.log('ContentBlock created', this.prtSize)
  85. let txtcolor = '#000000'
  86. switch (this.type) {
  87. case 'visible':
  88. txtcolor = '#0000ff'
  89. break
  90. case 'context':
  91. txtcolor = '#ff0000'
  92. break
  93. case 'process':
  94. txtcolor = '#00ff00'
  95. break
  96. default:
  97. }
  98. this.label_canvas = this.createLabelCanvas(this.data.Name.replace(/ /g, '\n').toUpperCase(), 60, 150, txtcolor)
  99. this.size.x = this.label_size.x + 0.2
  100. this.size.y = this.label_size.y + 0.2
  101. let y = 0
  102. switch (this.type) {
  103. case 'visible':
  104. y = (this.prtPosition.y + this.prtSize.y / 2) * Math.random()
  105. break
  106. case 'context':
  107. y = (this.prtPosition.y - this.prtSize.y / 2) * Math.random()
  108. break
  109. case 'process':
  110. y = (this.prtPosition.y - this.prtSize.y / 2) * Math.random()
  111. break
  112. default:
  113. }
  114. this.position.y = y
  115. let face = Math.random()
  116. if (face < 0.25) {
  117. // gauche
  118. this.face = 'left'
  119. this.position.x = this.prtPosition.x - this.prtSize.x / 2 + 0.1
  120. this.position.z = this.prtPosition.z - this.prtSize.z / 2 + this.size.x / 2 + Math.random() * (this.prtSize.z - this.size.x / 2)
  121. this.rotation.y = 90
  122. } else if (face >= 0.25 && face < 0.5) {
  123. // fond
  124. this.face = 'back'
  125. this.position.z = this.prtPosition.z - this.prtSize.z / 2 + 0.1
  126. this.position.x = this.prtPosition.x - this.prtSize.x / 2 + this.size.x / 2 + Math.random() * (this.prtSize.x - this.size.x / 2)
  127. } else if (face >= 0.5 && face < 0.75) {
  128. // droite
  129. this.face = 'right'
  130. this.position.x = this.prtPosition.x + this.prtSize.x / 2 - 0.1
  131. this.position.z = this.prtPosition.z - this.prtSize.z / 2 + this.size.x / 2 + Math.random() * (this.prtSize.z - this.size.x / 2)
  132. this.rotation.y = -90
  133. } else {
  134. // face
  135. this.face = 'front'
  136. this.position.z = this.prtPosition.z + this.prtSize.z / 2 - 0.1
  137. this.position.x = this.prtPosition.x - this.prtSize.x / 2 + this.size.x / 2 + Math.random() * (this.prtSize.x - this.size.x / 2)
  138. this.rotation.y = 180
  139. }
  140. // this.label_position.x = this.position.x - this.size.x / 2 + this.label_size.x / 2 + 0.1
  141. // this.label_position.y = this.position.y + this.size.y / 2 - this.label_size.y / 2 - 0.1
  142. // this.label_position.z = this.position.z + this.size.z / 2 + 0.01
  143. },
  144. mounted () {
  145. // this.block3d = this.$refs.block3d.curObj
  146. // this.block3d.castShadow = true
  147. // this.block3d.receiveShadow = true
  148. this.label3d = this.$refs.label3d.curObj
  149. // record self references
  150. this.label3d.userData = {
  151. vnode: this
  152. }
  153. }
  154. }
  155. </script>