loading graphql project contents

This commit is contained in:
2020-09-16 16:06:18 +02:00
parent 7c566a67d9
commit 15ad778ce2
5 changed files with 119 additions and 43 deletions
+6 -4
View File
@@ -303,7 +303,7 @@ export default {
// INTERACTIONS // INTERACTIONS
this.updatedInteractiveObjects() this.updatedInteractiveObjects()
// check if draging // check if not draging
if (Math.hypot(e.clientX - this.controls.mouse_start.x, e.clientY - this.controls.mouse_start.y) < 5) { if (Math.hypot(e.clientX - this.controls.mouse_start.x, e.clientY - this.controls.mouse_start.y) < 5) {
// update the picking ray with the camera and mouse position // update the picking ray with the camera and mouse position
this.raycaster.setFromCamera(this.mouse, this.camera) this.raycaster.setFromCamera(this.mouse, this.camera)
@@ -311,11 +311,11 @@ export default {
var intersects = this.raycaster.intersectObjects(this.interactive_objects) var intersects = this.raycaster.intersectObjects(this.interactive_objects)
// console.log('intersects', intersects) // console.log('intersects', intersects)
// if we clicked on 3Dobject
if (intersects.length) { if (intersects.length) {
let cam = this.camera let cam = this.camera
let camPos = { ...this.camera.position } let camPos = { ...this.camera.position }
console.log('onDocMouseUp intersects', intersects) console.log('onDocMouseUp intersects', intersects)
// for (var i = 0; i < intersects.length; i++) {
let object = intersects[0].object let object = intersects[0].object
console.log('object[0].name', object.name) console.log('object[0].name', object.name)
let vnode = object.userData.vnode let vnode = object.userData.vnode
@@ -328,11 +328,13 @@ export default {
// console.log('opened_vnode', this.opened_vnode) // console.log('opened_vnode', this.opened_vnode)
this.opened_vnode.isOpened = false this.opened_vnode.isOpened = false
} }
// opene current vnode // open current vnode
vnode.isOpened = true // vnode.isOpened = true
vnode.open()
// recorde vnode as precedent vnode // recorde vnode as precedent vnode
this.opened_vnode = vnode this.opened_vnode = vnode
// get new camera target pos
let toPos = { ...object.position } let toPos = { ...object.position }
if (object.name === 'Content') { if (object.name === 'Content') {
switch (vnode.face) { switch (vnode.face) {
+17 -7
View File
@@ -41,14 +41,20 @@
</template> </template>
<script> <script>
import { mapInstanceState } from '@urbn/vuex-helpers'
// import { mapState, mapGetters } from 'vuex'
import * as THREE from 'three' import * as THREE from 'three'
import mixins from 'components/mixins' import mixins from 'components/mixins'
import { mapState, mapGetters } from 'vuex'
// We'll determine our module based on the moduleName prop on this component
// https://www.npmjs.com/package/@urbn/vuex-helpers
const getModuleName = cmp => `project:${cmp.prtId}`
export default { export default {
name: 'ContentBlock', name: 'ContentBlock',
mixins: [mixins], mixins: [mixins],
props: { prtPosition: Object, prtSize: Object, prtIndex: Number, type: String, data: Object }, props: { prtId: Number, prtIndex: Number, type: String, data: Object },
data: () => ({ data: () => ({
// block3d: null, // block3d: null,
project: null, project: null,
@@ -86,11 +92,15 @@ export default {
face: null face: null
}), }),
computed: { computed: {
...mapState({ // ...mapState({
projects: state => state.Projects.projects // projects: state => state.Projects.projects
}), // }),
...mapGetters({ // ...mapGetters({
getGridPos: 'Projects/getGridPos' // getGridPos: 'Projects/getGridPos'
// }),
...mapInstanceState(getModuleName, {
size: state => state.size,
position: state => state.position
}), }),
color () { color () {
let color = 0x000000 let color = 0x000000
+23 -27
View File
@@ -10,9 +10,9 @@
<texture :options="label_texture_opts" /> <texture :options="label_texture_opts" />
</material> </material>
</mesh> </mesh>
<!-- <div v-if="isOpened"> <div v-if="isOpened">
<ContentBlock <ContentBlock
v-for="item in data.visibles" v-for="item in contents.visibles"
:key="item.id" :key="item.id"
:prtPosition="position" :prtPosition="position"
:prtSize="size" :prtSize="size"
@@ -21,7 +21,7 @@
:data="item" :data="item"
/> />
<ContentBlock <ContentBlock
v-for="item in data.contexts" v-for="item in contents.contexts"
:key="item.id" :key="item.id"
:prtPosition="position" :prtPosition="position"
:prtSize="size" :prtSize="size"
@@ -30,7 +30,7 @@
:data="item" :data="item"
/> />
<ContentBlock <ContentBlock
v-for="item in data.processes" v-for="item in contents.processes"
:key="item.id" :key="item.id"
:prtPosition="position" :prtPosition="position"
:prtSize="size" :prtSize="size"
@@ -39,7 +39,7 @@
:data="item" :data="item"
/> />
<ContentBlock <ContentBlock
v-for="item in data.concepts" v-for="item in contents.concepts"
:key="item.id" :key="item.id"
:prtPosition="position" :prtPosition="position"
:prtSize="size" :prtSize="size"
@@ -47,20 +47,20 @@
type="concept" type="concept"
:data="item" :data="item"
/> />
</div> --> </div>
</div> </div>
</template> </template>
<script> <script>
import { mapInstanceState } from '@urbn/vuex-helpers' import { mapInstanceState, mapInstanceActions } from '@urbn/vuex-helpers'
import * as THREE from 'three' import * as THREE from 'three'
// import { ThreeBSP } from 'three-js-csg-es6' // import { ThreeBSP } from 'three-js-csg-es6'
import mixins from 'components/mixins' import mixins from 'components/mixins'
// import ContentBlock from 'components/objects/ContentBlock' import ContentBlock from 'components/objects/ContentBlock'
// import BgVertex from 'assets/glsl/BgVertex' // import BgVertex from 'assets/glsl/BgVertex'
// import BuildingFragment from 'assets/glsl/BuildingFragment' // import BuildingFragment from 'assets/glsl/BuildingFragment'
@@ -72,25 +72,23 @@ const getModuleName = cmp => `project:${cmp.id}`
export default { export default {
name: 'Project', name: 'Project',
components: { components: {
// ContentBlock ContentBlock
}, },
mixins: [mixins], mixins: [mixins],
props: { id: Number }, props: { id: Number },
data () { data () {
console.log('Project data()') console.log('Project data()')
return { return {
isOpened: false, isOpened: false,
block3d: null, block3d: null,
label3d: null, label3d: null,
label_opts: { label_opts: {
side: THREE.DoubleSide, side: THREE.DoubleSide,
// wireframe: false,
transparent: true transparent: true
// wireframe: false,
// opacity: 0.6 // opacity: 0.6
// renderOrder: 0 // renderOrder: 0
}, },
color: 0xffffff,
label_canvas: null, label_canvas: null,
label_size: null, label_size: null,
label_position: { x: 0, y: 0, z: 0 } label_position: { x: 0, y: 0, z: 0 }
@@ -107,8 +105,10 @@ export default {
wallsPos: state => state.wallsPos, wallsPos: state => state.wallsPos,
top3dObj: state => state.top3dObj, top3dObj: state => state.top3dObj,
topPos: state => state.topPos, topPos: state => state.topPos,
topColor: state => state.topColor,
floor3dObj: state => state.floor3dObj, floor3dObj: state => state.floor3dObj,
floorPos: state => state.floorPos floorPos: state => state.floorPos,
contents: state => state.contents
}), }),
label_texture_opts () { label_texture_opts () {
return { return {
@@ -120,7 +120,7 @@ export default {
} }
}, },
created () { created () {
this.label_canvas = this.createLabelCanvas(this.title.replace(/ /g, '\n').toUpperCase(), 48, 21, '#000000', '#ffffff') this.label_canvas = this.createLabelCanvas(this.title.replace(/ /g, '\n').toUpperCase(), 48, 21, '#000000', this.topColor)
this.label_position.x = this.position.x - this.size.x / 2 + this.label_size.x / 2 + 1 this.label_position.x = this.position.x - this.size.x / 2 + this.label_size.x / 2 + 1
this.label_position.y = this.position.y + this.size.y / 2 - this.label_size.y / 2 - 1 this.label_position.y = this.position.y + this.size.y / 2 - this.label_size.y / 2 - 1
this.label_position.z = this.position.z + this.size.z / 2 + 0.5 this.label_position.z = this.position.z + this.size.z / 2 + 0.5
@@ -129,22 +129,18 @@ export default {
mounted () { mounted () {
console.log('project mounted', this) console.log('project mounted', this)
// record self references // record self references
this.block3d = this.$refs.block3d.curObj this.block3d = this.$refs.block3d.curObj
// this.block3d.castShadow = true this.block3d.userData.vnode = this
// this.block3d.receiveShadow = true this.label3d = this.$refs.label3d.curObj
this.block3d.userData = {
vnode: this
}
// this.label3d = this.$refs.label3d.curObj
// light
// console.log('project mounted', this.$env3d)
// var light = new THREE.AmbientLight(0xbf1a1a) // soft white light
// this.$env3d.scene.add(light)
}, },
methods: { methods: {
...mapInstanceActions(getModuleName, {
loadContents: 'loadContents'
}),
open () {
this.isOpened = true
this.loadContents()
}
} }
} }
</script> </script>
+72 -4
View File
@@ -3,6 +3,7 @@
// import qs from 'querystring' // import qs from 'querystring'
// import { REST } from 'api/rest-axios' // import { REST } from 'api/rest-axios'
import { GRAPHQL } from 'api/graphql-axios'
import * as THREE from 'three' import * as THREE from 'three'
import { ThreeBSP } from 'three-js-csg-es6' import { ThreeBSP } from 'three-js-csg-es6'
@@ -19,8 +20,10 @@ export default {
wallsPos: null, wallsPos: null,
top3dObj: null, top3dObj: null,
topPos: null, topPos: null,
topColor: null,
floor3dObj: null, floor3dObj: null,
floorPos: null, floorPos: null,
florrColor: null,
wall: { wall: {
wallW: 0.001, wallW: 0.001,
// dig windows on face and back // dig windows on face and back
@@ -34,6 +37,7 @@ export default {
nbrWinZ: 0, nbrWinZ: 0,
paddingZ: 0 paddingZ: 0
}, },
contents: {},
grid: [] grid: []
}, },
@@ -71,7 +75,9 @@ export default {
setTop3dObj: (state, obj) => { state.top3dObj = obj }, setTop3dObj: (state, obj) => { state.top3dObj = obj },
setTopPos: (state, pos) => { state.topPos = pos }, setTopPos: (state, pos) => { state.topPos = pos },
setFloor3dObj: (state, obj) => { state.floor3dObj = obj }, setFloor3dObj: (state, obj) => { state.floor3dObj = obj },
setFloorPos: (state, pos) => { state.floorPos = pos } setFloorPos: (state, pos) => { state.floorPos = pos },
setTopColor: (state, col) => { state.topColor = col },
setFloorColor: (state, col) => { state.floorColor = col }
}, },
// actions // actions
@@ -114,7 +120,8 @@ export default {
// console.log('x', x) // console.log('x', x)
commit('setPosition', { commit('setPosition', {
x: x, x: x,
y: -1 * state.size.y / 2 + 10 + Math.random() * 30, // -10 + Math.random() * this.size.y / 2 // y: -1 * state.size.y / 2 + 10 + Math.random() * 30, // -10 + Math.random() * this.size.y / 2
y: -state.size.y / 4,
z: -10 + Math.random() * 10 z: -10 + Math.random() * 10
}) })
@@ -235,8 +242,10 @@ export default {
let sFloor = Math.round(40 + Math.random() * 20) let sFloor = Math.round(40 + Math.random() * 20)
let lFloor = Math.round(5 + Math.random() * 15) let lFloor = Math.round(5 + Math.random() * 15)
let topColor = `hsla(${hTop}, ${sTop}%, ${lTop}%, 1)` let topColor = `hsla(${hTop}, ${sTop}%, ${lTop}%, 1)`
let bottomColor = `hsla(${hFloor}, ${sFloor}%, ${lFloor}%, 1)` commit('setTopColor', topColor)
let gradientTexture = new THREE.CanvasTexture(getters.createGradientCanvas(topColor, bottomColor)) let floorColor = `hsla(${hFloor}, ${sFloor}%, ${lFloor}%, 1)`
commit('setFloorColor', floorColor)
let gradientTexture = new THREE.CanvasTexture(getters.createGradientCanvas(topColor, floorColor))
let materialOpts = { let materialOpts = {
color: 0xffffff, color: 0xffffff,
side: THREE.DoubleSide, side: THREE.DoubleSide,
@@ -287,6 +296,65 @@ export default {
// } // }
// let levelMat = new THREE.MeshPhongMaterial(levelOpts) // let levelMat = new THREE.MeshPhongMaterial(levelOpts)
// levelMesh.material = levelMat // levelMesh.material = levelMat
},
loadContents ({ dispatch, commit, state }) {
console.log('loadContents')
GRAPHQL.post('', { query: `query {
project(id: "${state.id}") {
visibles(where: { Published: "true" }){
id
Name
Media {
url
size
}
Text2
Vimeo
Url
categories
}
contexts(where: { Published: "true" }){
id
Name
Images {
url
size
}
Text2
Vimeo
Url
}
processes(where: { Published: "true" }){
id
Name
Media {
url
size
}
Text2
Vimeo
Url
}
concepts(where: { Published: "true" }){
id
Name
Images {
url
size
}
Text2
Vimeo
}
}
}` })
.then(({ data: { data: { project } = null } }) => {
console.log('graphql visibles', project)
// dispatch('computeProjects', projects)
})
.catch((error) => {
console.warn('Issue with getProjects', error)
Promise.reject(error)
})
} }
} }
} }
+1 -1
View File
@@ -98,7 +98,7 @@ export default {
commit('increaseTotalW', w) commit('increaseTotalW', w)
size = { size = {
x: w, x: w,
y: Math.round(150 + Math.random() * 50), y: Math.round(110 + Math.random() * 100),
z: Math.round(10 + Math.random() * 30) z: Math.round(10 + Math.random() * 30)
} }
// convert to number the project id // convert to number the project id