Project.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div>
  3. <mesh ref="block3d" name="Project" :position="position">
  4. <geometry type="Box" :args="[size.x, size.y, size.z]" />
  5. <material type="MeshLambert" :color="color" :options="block_opts">
  6. <!-- <texture :options="label_texture_opts" /> -->
  7. </material>
  8. </mesh>
  9. <mesh ref="label3d" name="Label" :position="label_position">
  10. <geometry type="Plane" :args="[label_size.x, label_size.y]" />
  11. <material type="MeshLambert" :options="label_opts">
  12. <texture :options="label_texture_opts" />
  13. </material>
  14. </mesh>
  15. <div v-if="isOpened">
  16. <ContentBlock
  17. v-for="item in data.visibles"
  18. :key="item.id"
  19. :prtPosition="position"
  20. :prtSize="size"
  21. type="visible"
  22. :data="item"
  23. />
  24. <ContentBlock
  25. v-for="item in data.contexts"
  26. :key="item.id"
  27. :prtPosition="position"
  28. :prtSize="size"
  29. type="context"
  30. :data="item"
  31. />
  32. <ContentBlock
  33. v-for="item in data.processes"
  34. :key="item.id"
  35. :prtPosition="position"
  36. :prtSize="size"
  37. type="process"
  38. :data="item"
  39. />
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import * as THREE from 'three'
  45. // import { Base } from 'vue-threejs'
  46. import mixins from 'components/mixins'
  47. import ContentBlock from 'components/objects/ContentBlock'
  48. export default {
  49. name: 'Project',
  50. components: {
  51. ContentBlock
  52. },
  53. mixins: [mixins],
  54. // props: { size: Object, texture: String, position: Object, color: Number },
  55. props: { data: Object, len: Number, index: Number },
  56. data: () => ({
  57. block3d: null,
  58. block_opts: {
  59. side: THREE.DoubleSide
  60. // wireframe: true,
  61. // transparent: true,
  62. // opacity: 0.6
  63. // renderOrder: 0
  64. },
  65. label3d: null,
  66. label_opts: {
  67. side: THREE.DoubleSide,
  68. // wireframe: false,
  69. transparent: true
  70. // opacity: 0.6
  71. // renderOrder: 0
  72. },
  73. // size and positions are defined in store project
  74. size: { x: 0, y: 0, z: 0 },
  75. position: { x: 0, y: 0, z: 0 },
  76. label_position: { x: 0, y: 0, z: 0 },
  77. color: 0xffffff,
  78. label_canvas: null,
  79. label_size: null,
  80. isOpened: false
  81. }),
  82. computed: {
  83. label_texture_opts () {
  84. return {
  85. canvas: this.label_canvas,
  86. minFilter: THREE.LinearFilter,
  87. wrapS: THREE.ClampToEdgeWrapping,
  88. wrapT: THREE.ClampToEdgeWrapping
  89. }
  90. }
  91. },
  92. created () {
  93. console.log('Project created: data', this.data)
  94. // randomize size and positions
  95. // this.size.x = ... // it's
  96. this.size = { ...this.data.size }
  97. // this.size.y = 100 + Math.random() * 90
  98. // this.size.z = 10 + Math.random() * 30
  99. this.position.x = this.data.position.x// (-this.len + 1) / 2 * (this.size.x + 5) + (this.size.x + 5) * this.index
  100. this.position.y = -1 * this.size.y / 2 + 10 + Math.random() * 30// -10 + Math.random() * this.size.y / 2
  101. this.position.z = -10 + Math.random() * 10
  102. this.label_canvas = this.createLabelCanvas(this.data.Titre.replace(/ /g, '\n').toUpperCase(), 48, 21, '#000000')
  103. this.label_position.x = this.position.x - this.size.x / 2 + this.label_size.x / 2 + 1
  104. this.label_position.y = this.position.y + this.size.y / 2 - this.label_size.y / 2 - 1
  105. this.label_position.z = this.position.z + this.size.z / 2 + 0.1
  106. // console.log('this.label_canvas', this.label_canvas)
  107. },
  108. mounted () {
  109. // console.log('project mounted', this)
  110. // mesh options
  111. this.block3d = this.$refs.block3d.curObj
  112. this.block3d.castShadow = true
  113. this.block3d.receiveShadow = true
  114. // record self references
  115. this.block3d.userData = {
  116. vnode: this
  117. }
  118. this.label3d = this.$refs.label3d.curObj
  119. // light
  120. // console.log('project mounted', this.$env3d)
  121. // var light = new THREE.AmbientLight(0xbf1a1a) // soft white light
  122. // this.$env3d.scene.add(light)
  123. }
  124. // ,
  125. // methods: {
  126. //
  127. // }
  128. }
  129. </script>