App.vue 4.9 KB

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