Project.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 v-for="n in 10" :key="n" :prtPosition="position" :prtSize="size" />
  17. </div>
  18. </div>
  19. </template>
  20. <script>
  21. import * as THREE from 'three'
  22. // import { Base } from 'vue-threejs'
  23. import mixins from 'components/mixins'
  24. import ContentBlock from 'components/objects/ContentBlock'
  25. export default {
  26. name: 'Project',
  27. components: {
  28. ContentBlock
  29. },
  30. mixins: [mixins],
  31. // props: { size: Object, texture: String, position: Object, color: Number },
  32. props: { data: Object, len: Number, index: Number },
  33. data: () => ({
  34. block3d: null,
  35. block_opts: {
  36. side: THREE.DoubleSide
  37. // wireframe: true,
  38. // transparent: true,
  39. // opacity: 0.6
  40. // renderOrder: 0
  41. },
  42. label3d: null,
  43. label_opts: {
  44. side: THREE.DoubleSide,
  45. // wireframe: false,
  46. transparent: true
  47. // opacity: 0.6
  48. // renderOrder: 0
  49. },
  50. size: { x: 35, y: 10, z: 10 },
  51. position: { x: 5, y: 5, z: 0 },
  52. label_position: { x: 5, y: 5, z: 6 },
  53. color: 0xffffff,
  54. label_canvas: null,
  55. label_size: null,
  56. isOpened: false
  57. }),
  58. computed: {
  59. label_texture_opts () {
  60. return {
  61. canvas: this.label_canvas,
  62. minFilter: THREE.LinearFilter,
  63. wrapS: THREE.ClampToEdgeWrapping,
  64. wrapT: THREE.ClampToEdgeWrapping
  65. }
  66. }
  67. },
  68. created () {
  69. // console.log('this.index', this.index)
  70. // randomize size and positions
  71. this.size.y = 100 + Math.random() * 90
  72. this.size.z = 10 + Math.random() * 30
  73. this.position.x = (-this.len + 1) / 2 * (this.size.x + 5) + (this.size.x + 5) * this.index
  74. this.position.y = -1 * this.size.y / 2 + 10 + Math.random() * 30// -10 + Math.random() * this.size.y / 2
  75. this.position.z = -10 + Math.random() * 10
  76. this.label_canvas = this.createLabelCanvas(this.data.Titre.replace(/ /g, '\n').toUpperCase(), 48)
  77. this.label_position.x = this.position.x - this.size.x / 2 + this.label_size.x / 2 + 1
  78. this.label_position.y = this.position.y + this.size.y / 2 - this.label_size.y / 2 - 1
  79. this.label_position.z = this.position.z + this.size.z / 2 + 0.1
  80. // console.log('this.label_canvas', this.label_canvas)
  81. },
  82. mounted () {
  83. // console.log('project mounted', this)
  84. // mesh options
  85. this.block3d = this.$refs.block3d.curObj
  86. this.block3d.castShadow = true
  87. this.block3d.receiveShadow = true
  88. // record self references
  89. this.block3d.userData = {
  90. vnode: this
  91. }
  92. this.label3d = this.$refs.label3d.curObj
  93. // light
  94. // console.log('project mounted', this.$env3d)
  95. // var light = new THREE.AmbientLight(0xbf1a1a) // soft white light
  96. // this.$env3d.scene.add(light)
  97. }
  98. // ,
  99. // methods: {
  100. //
  101. // }
  102. }
  103. </script>