Project.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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: { x: 35, y: 10, z: 10 },
  74. position: { x: 5, y: 5, z: 0 },
  75. label_position: { x: 5, y: 5, z: 6 },
  76. color: 0xffffff,
  77. label_canvas: null,
  78. label_size: null,
  79. isOpened: false
  80. }),
  81. computed: {
  82. label_texture_opts () {
  83. return {
  84. canvas: this.label_canvas,
  85. minFilter: THREE.LinearFilter,
  86. wrapS: THREE.ClampToEdgeWrapping,
  87. wrapT: THREE.ClampToEdgeWrapping
  88. }
  89. }
  90. },
  91. created () {
  92. console.log('Project created: data', this.data)
  93. // randomize size and positions
  94. this.size.y = 100 + Math.random() * 90
  95. this.size.z = 10 + Math.random() * 30
  96. this.position.x = (-this.len + 1) / 2 * (this.size.x + 5) + (this.size.x + 5) * this.index
  97. this.position.y = -1 * this.size.y / 2 + 10 + Math.random() * 30// -10 + Math.random() * this.size.y / 2
  98. this.position.z = -10 + Math.random() * 10
  99. this.label_canvas = this.createLabelCanvas(this.data.Titre.replace(/ /g, '\n').toUpperCase(), 48, 21, '#000000')
  100. this.label_position.x = this.position.x - this.size.x / 2 + this.label_size.x / 2 + 1
  101. this.label_position.y = this.position.y + this.size.y / 2 - this.label_size.y / 2 - 1
  102. this.label_position.z = this.position.z + this.size.z / 2 + 0.1
  103. // console.log('this.label_canvas', this.label_canvas)
  104. },
  105. mounted () {
  106. // console.log('project mounted', this)
  107. // mesh options
  108. this.block3d = this.$refs.block3d.curObj
  109. this.block3d.castShadow = true
  110. this.block3d.receiveShadow = true
  111. // record self references
  112. this.block3d.userData = {
  113. vnode: this
  114. }
  115. this.label3d = this.$refs.label3d.curObj
  116. // light
  117. // console.log('project mounted', this.$env3d)
  118. // var light = new THREE.AmbientLight(0xbf1a1a) // soft white light
  119. // this.$env3d.scene.add(light)
  120. }
  121. // ,
  122. // methods: {
  123. //
  124. // }
  125. }
  126. </script>