ContentBlock.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <mesh ref="block3d" name="ContentBlock" :position="position">
  3. <geometry type="Box" :args="[size.x, size.y, size.z]" />
  4. <material type="MeshLambert" :color="color" :options="opts" />
  5. </mesh>
  6. </template>
  7. <script>
  8. import * as THREE from 'three'
  9. export default {
  10. name: 'ContentBlock',
  11. // mixins: [Object3D],
  12. props: { prtPosition: Object, prtSize: Object },
  13. data: () => ({
  14. block3d: null,
  15. size: { x: 2, y: 3, z: 0.1 },
  16. position: { x: 0, y: 0, z: 0 },
  17. opts: {
  18. side: THREE.DoubleSide
  19. // wireframe: false,
  20. // transparent: false,
  21. // opacity: 0.6
  22. },
  23. isOpened: false
  24. }),
  25. computed: {
  26. color () {
  27. return this.opened ? 0xff0000 : 0x0000ff
  28. }
  29. },
  30. created () {
  31. console.log('ContentBlock created', this.prtSize)
  32. this.position.x = this.prtPosition.x - this.prtSize.x / 2 + Math.random() * this.prtSize.x
  33. this.position.y = this.prtPosition.y - this.prtSize.y / 2 + Math.random() * this.prtSize.y
  34. this.position.z = this.prtPosition.z - this.prtSize.z / 2 + Math.random() * this.prtSize.z
  35. },
  36. mounted () {
  37. this.block3d = this.$refs.block3d.curObj
  38. // this.block3d.castShadow = true
  39. // this.block3d.receiveShadow = true
  40. // record self references
  41. this.block3d.userData = {
  42. vnode: this
  43. }
  44. }
  45. }
  46. </script>