App.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div id="root">
  3. <!-- <header role="banner">
  4. <div class="wrapper">
  5. <h1
  6. class="site-title"
  7. tabindex="0"
  8. >
  9. </h1>
  10. </div>
  11. </header> -->
  12. <section role="main-content">
  13. <div class="wrapper">
  14. <renderer :obj="myRenderer" :size="size">
  15. <scene :obj="myScene" @update:obj="handleScene">
  16. <orbit-controls :position="{x:0,y:150,z:0}" :rotation="{ x: -90, y: 0, z: 0 }">
  17. <camera />
  18. </orbit-controls>
  19. <!-- <camera :position="{x:0, y:300, z:0}" :rotation="{x:deg2rad(-90), y:0, z:0}"/> -->
  20. <!-- <camera :position="{x:0,y:50,z:0}" :lookat="{x:0,y:0,z:0}" /> -->
  21. <!-- <light :hex="0xff0000" :intensity="10" :position="{x:-100}" /> -->
  22. <!-- <mesh :obj="mesh" :position="{ y: -200 }" /> -->
  23. <!-- <animation :fn="animate" :speed="3" /> -->
  24. <plan :size="{w:5000,h:5000}" :position="{x:0,y:0,z:0}" :color="0xffffff" :rotation="{x:90,y:0,z:0}" />
  25. <template v-if="debug">
  26. <cube :size="{x:30,y:1,z:1}" :position="{x:15,y:0,z:0}" :color="0x992222" />
  27. <cube :size="{x:1,y:30,z:1}" :position="{x:0,y:15,z:0}" :color="0x00BBFF" />
  28. <cube :size="{x:1,y:1,z:30}" :position="{x:0,y:0,z:15}" :color="0x17d100" />
  29. </template>
  30. <template v-if="projects.length">
  31. <project
  32. v-for="(project, index) in projects"
  33. :key="project.id"
  34. :data="project"
  35. :len="projects.length"
  36. :index="index"
  37. />
  38. </template>
  39. <line />
  40. </scene>
  41. </renderer>
  42. </div>
  43. </section>
  44. <footer />
  45. </div>
  46. </template>
  47. <script>
  48. import { mapState, mapActions } from 'vuex'
  49. import mixins from 'components/mixins'
  50. import * as THREE from 'three'
  51. import Plan from './components/objects/Plan'
  52. import Cube from './components/objects/Cube'
  53. import Project from './components/objects/Project'
  54. export default {
  55. metaInfo: {
  56. // if no subcomponents specify a metaInfo.title, this title will be used
  57. title: 'Home',
  58. // all titles will be injected into this template
  59. titleTemplate: '%s | Muntadas'
  60. },
  61. components: {
  62. Cube,
  63. Project,
  64. Plan
  65. },
  66. mixins: [mixins],
  67. data () {
  68. // const envcolor = 0xffffff
  69. let renderer = new THREE.WebGLRenderer({ alpha: false, antialias: true })
  70. renderer.setClearColor(0x000000, 0)
  71. // scene obj is well overwrited but background color not visible
  72. let scene = new THREE.Scene()
  73. scene.background = new THREE.Color(0x000000)
  74. scene.fog = new THREE.Fog(scene.background, 50, 200)
  75. console.log('myScene', scene)
  76. return {
  77. debug: true,
  78. myRenderer: renderer,
  79. myScene: scene,
  80. mouse: new THREE.Vector2(),
  81. camera: null,
  82. raycaster: new THREE.Raycaster(),
  83. interactive_objects: []
  84. }
  85. },
  86. computed: {
  87. ...mapState({
  88. projects: state => state.Projects.projects
  89. }),
  90. size () {
  91. return {
  92. w: window.innerWidth,
  93. h: window.innerHeight
  94. }
  95. }
  96. },
  97. created () {
  98. if (!this.projects.length) {
  99. this.getProjects()
  100. }
  101. },
  102. mounted () {
  103. console.log('mounted', this)
  104. this.camera = this.$children[0].global.camera
  105. this.updatedInteractiveObjects()
  106. document.addEventListener('mousemove', this.onMouseMove, false)
  107. document.addEventListener('click', this.onDocumentClick, false)
  108. },
  109. updated () {
  110. this.updatedInteractiveObjects()
  111. },
  112. methods: {
  113. ...mapActions({
  114. getProjects: 'Projects/getProjects'
  115. }),
  116. handleScene (scene) {
  117. console.log('handlescene', scene)
  118. },
  119. onMouseMove (e) {
  120. // update the mouse variable
  121. this.mouse.x = (e.clientX / window.innerWidth) * 2 - 1
  122. this.mouse.y = -(e.clientY / window.innerHeight) * 2 + 1
  123. },
  124. updatedInteractiveObjects () {
  125. this.interactive_objects = []
  126. for (var i = 0; i < this.myScene.children.length; i++) {
  127. if (this.myScene.children[i].name === 'Project') {
  128. this.interactive_objects.push(this.myScene.children[i])
  129. }
  130. }
  131. console.log('this.interactive_objects', this.interactive_objects)
  132. },
  133. onDocumentClick (e) {
  134. console.log('onDocumentClick', e)
  135. // update the picking ray with the camera and mouse position
  136. this.raycaster.setFromCamera(this.mouse, this.camera)
  137. // calculate objects intersecting the picking ray
  138. var intersects = this.raycaster.intersectObjects(this.interactive_objects)
  139. for (var i = 0; i < intersects.length; i++) {
  140. intersects[i].object.material.color.set(0xff0000)
  141. }
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .container{
  148. // font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  149. max-width: 1200px;
  150. }
  151. </style>