Project.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. console.log('Project data() : data', this.data)
  58. // get size and positions from project store
  59. let size = { ...this.data.size }
  60. let position = { ...this.data.position }
  61. let geometry = new THREE.BoxBufferGeometry(size.x, size.y, size.z)
  62. return {
  63. block3d: null,
  64. block_opts: {
  65. side: THREE.DoubleSide
  66. // wireframe: true,
  67. // transparent: true,
  68. // opacity: 0.6
  69. // renderOrder: 0
  70. },
  71. label3d: null,
  72. label_opts: {
  73. side: THREE.DoubleSide,
  74. // wireframe: false,
  75. transparent: true
  76. // opacity: 0.6
  77. // renderOrder: 0
  78. },
  79. // size and positions are defined in store project
  80. size: size,
  81. position: position,
  82. geometry: geometry,
  83. label_position: { x: 0, y: 0, z: 0 },
  84. color: 0xffffff,
  85. label_canvas: null,
  86. label_size: null,
  87. isOpened: false
  88. }
  89. },
  90. computed: {
  91. label_texture_opts () {
  92. return {
  93. canvas: this.label_canvas,
  94. minFilter: THREE.LinearFilter,
  95. wrapS: THREE.ClampToEdgeWrapping,
  96. wrapT: THREE.ClampToEdgeWrapping
  97. }
  98. }
  99. },
  100. created () {
  101. console.log('Project created: data', this, this.data)
  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.geometry = this.geometry
  113. this.block3d.castShadow = true
  114. this.block3d.receiveShadow = true
  115. // record self references
  116. this.block3d.userData = {
  117. vnode: this
  118. }
  119. this.label3d = this.$refs.label3d.curObj
  120. // light
  121. // console.log('project mounted', this.$env3d)
  122. // var light = new THREE.AmbientLight(0xbf1a1a) // soft white light
  123. // this.$env3d.scene.add(light)
  124. }
  125. // ,
  126. // methods: {
  127. //
  128. // }
  129. }
  130. </script>