ContentBlock.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. <mesh
  23. v-if="img_canvas"
  24. ref="img3d"
  25. name="Content"
  26. :position="img_position"
  27. :rotation="{
  28. x:deg2rad(rotation.x),
  29. y:deg2rad(rotation.y),
  30. z:deg2rad(rotation.z)
  31. }"
  32. >
  33. <geometry type="Plane" :args="[img_size.x, img_size.y]" />
  34. <material type="MeshLambert" :options="img_opts">
  35. <texture :options="img_texture_opts" />
  36. </material>
  37. </mesh>
  38. </div>
  39. </template>
  40. <script>
  41. import * as THREE from 'three'
  42. import mixins from 'components/mixins'
  43. export default {
  44. name: 'ContentBlock',
  45. mixins: [mixins],
  46. props: { prtPosition: Object, prtSize: Object, type: String, data: Object },
  47. data: () => ({
  48. // block3d: null,
  49. size: { x: 2, y: 3, z: 0.1 },
  50. position: { x: 0, y: 0, z: 0 },
  51. rotation: { x: 0, y: 0, z: 0 },
  52. // opts: {
  53. // side: THREE.DoubleSide
  54. // // wireframe: false,
  55. // // transparent: false,
  56. // // opacity: 0.6
  57. // },
  58. isOpened: false,
  59. label3d: null,
  60. label_opts: {
  61. side: THREE.DoubleSide,
  62. // wireframe: false,
  63. transparent: true
  64. // opacity: 0.6
  65. // renderOrder: 0
  66. },
  67. img_opts: {
  68. // side: THREE.DoubleSide,
  69. // wireframe: false,
  70. // transparent: true
  71. // opacity: 0.6
  72. // renderOrder: 0
  73. },
  74. // label_position: { x: 5, y: 5, z: 6 },
  75. label_canvas: null,
  76. label_size: null,
  77. img_canvas: null,
  78. img_size: { x: 2, y: 3, z: 0.1 },
  79. img_position: { x: 0, y: 0, z: 0 },
  80. face: null
  81. }),
  82. computed: {
  83. color () {
  84. let color = 0x000000
  85. switch (this.type) {
  86. case 'visible':
  87. color = 0x0000ff
  88. break
  89. case 'context':
  90. color = 0x00ffff
  91. break
  92. case 'process':
  93. color = 0xff00ff
  94. break
  95. default:
  96. color = 0xdddddd
  97. }
  98. return color
  99. },
  100. label_texture_opts () {
  101. return {
  102. canvas: this.label_canvas,
  103. minFilter: THREE.LinearFilter,
  104. wrapS: THREE.ClampToEdgeWrapping,
  105. wrapT: THREE.ClampToEdgeWrapping
  106. }
  107. },
  108. img_texture_opts () {
  109. return {
  110. canvas: this.img_canvas,
  111. minFilter: THREE.LinearFilter,
  112. wrapS: THREE.ClampToEdgeWrapping,
  113. wrapT: THREE.ClampToEdgeWrapping
  114. }
  115. }
  116. },
  117. created () {
  118. // console.log('ContentBlock created', this.data)
  119. let txtcolor = '#000000'
  120. // switch (this.type) {
  121. // case 'visible':
  122. // txtcolor = '#0000ff'
  123. // break
  124. // case 'context':
  125. // txtcolor = '#ff0000'
  126. // break
  127. // case 'process':
  128. // txtcolor = '#00ff00'
  129. // break
  130. // default:
  131. // }
  132. this.label_canvas = this.createLabelCanvas(this.data.Name.replace(/ /g, '\n').toUpperCase(), 60, 150, txtcolor)
  133. this.size.x = this.label_size.x + 0.2
  134. this.size.y = this.label_size.y + 0.2
  135. let y = 0
  136. let top = this.prtPosition.y + this.prtSize.y / 2
  137. let floor = this.prtPosition.y - this.prtSize.y / 2
  138. switch (this.type) {
  139. case 'visible':
  140. y = top * Math.random()
  141. break
  142. case 'context':
  143. y = floor / 3 * Math.random()
  144. break
  145. case 'process':
  146. y = floor / 3 + floor / 3 * Math.random()
  147. break
  148. case 'concept':
  149. y = (floor / 3) * 2 + floor / 3 * Math.random()
  150. break
  151. }
  152. this.position.y = y
  153. let face = Math.random()
  154. // if (face < 0.25) {
  155. // // gauche
  156. // this.face = 'left'
  157. // this.position.x = this.prtPosition.x - this.prtSize.x / 2 + 0.1
  158. // this.position.z = this.prtPosition.z - this.prtSize.z / 2 + this.size.x / 2 + Math.random() * (this.prtSize.z - this.size.x / 2)
  159. // this.rotation.y = 90
  160. // } else if (face >= 0.25 && face < 0.5) {
  161. // // fond
  162. // this.face = 'back'
  163. // this.position.z = this.prtPosition.z - this.prtSize.z / 2 + 0.1
  164. // this.position.x = this.prtPosition.x - this.prtSize.x / 2 + this.size.x / 2 + Math.random() * (this.prtSize.x - this.size.x / 2)
  165. // } else if (face >= 0.5 && face < 0.75) {
  166. // // droite
  167. // this.face = 'right'
  168. // this.position.x = this.prtPosition.x + this.prtSize.x / 2 - 0.1
  169. // this.position.z = this.prtPosition.z - this.prtSize.z / 2 + this.size.x / 2 + Math.random() * (this.prtSize.z - this.size.x / 2)
  170. // this.rotation.y = -90
  171. // } else {
  172. // // face
  173. // this.face = 'front'
  174. // this.position.z = this.prtPosition.z + this.prtSize.z / 2 - 0.1
  175. // this.position.x = this.prtPosition.x - this.prtSize.x / 2 + this.size.x / 2 + Math.random() * (this.prtSize.x - this.size.x / 2)
  176. // this.rotation.y = 180
  177. // }
  178. if (face < 0.5) {
  179. // gauche
  180. this.face = 'left'
  181. this.position.x = this.prtPosition.x - this.prtSize.x / 2 + 0.1
  182. this.position.z = this.prtPosition.z - this.prtSize.z / 2 + this.size.x / 2 + Math.random() * (this.prtSize.z - this.size.x / 2)
  183. this.rotation.y = 90
  184. } else {
  185. // droite
  186. this.face = 'right'
  187. this.position.x = this.prtPosition.x + this.prtSize.x / 2 - 0.1
  188. this.position.z = this.prtPosition.z - this.prtSize.z / 2 + this.size.x / 2 + Math.random() * (this.prtSize.z - this.size.x / 2)
  189. this.rotation.y = -90
  190. }
  191. // this.label_position.x = this.position.x - this.size.x / 2 + this.label_size.x / 2 + 0.1
  192. // this.label_position.y = this.position.y + this.size.y / 2 - this.label_size.y / 2 - 0.1
  193. // this.label_position.z = this.position.z + this.size.z / 2 + 0.01
  194. // console.log()
  195. if (this.data.Media && this.data.Media.length) {
  196. console.log(this.data.Media[0].url)
  197. this.createImgCanvas(`https://api.anarchive-muntadas.figli.io${this.data.Media[0].url}`)
  198. .then(({ img, canvas }) => {
  199. // console.log('THEN img loaded ok', this, img, canvas)
  200. let f = 3 / canvas.width
  201. this.img_size.x = canvas.width * f
  202. this.img_size.y = canvas.height * f
  203. this.img_position.y = this.position.y - this.size.y / 2 - this.img_size.y / 2
  204. switch (this.face) {
  205. case 'left':
  206. this.img_position.z = this.position.z + this.size.x / 2 - this.img_size.x / 2
  207. this.img_position.x = this.position.x
  208. break
  209. case 'back':
  210. this.img_position.x = this.position.x - this.size.x / 2 + this.img_size.x / 2
  211. this.img_position.z = this.position.z
  212. break
  213. case 'right':
  214. this.img_position.z = this.position.z - this.size.x / 2 + this.img_size.x / 2
  215. this.img_position.x = this.position.x
  216. break
  217. case 'front':
  218. this.img_position.x = this.position.x + this.size.x / 2 - this.img_size.x / 2
  219. this.img_position.z = this.position.z
  220. break
  221. }
  222. this.img_canvas = canvas
  223. })
  224. .catch(function () {
  225. console.warn('CATCH img load ERROR')
  226. })
  227. }
  228. // this.img_position = { ...this.position }
  229. // this.img_position.y -= this.size.y
  230. },
  231. mounted () {
  232. // this.block3d = this.$refs.block3d.curObj
  233. // this.block3d.castShadow = true
  234. // this.block3d.receiveShadow = true
  235. this.label3d = this.$refs.label3d.curObj
  236. // record self references
  237. this.label3d.userData = {
  238. vnode: this
  239. }
  240. }
  241. }
  242. </script>