From 15ad778ce2dd885796e762b5e25ea32c8b654093 Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Wed, 16 Sep 2020 16:06:18 +0200 Subject: [PATCH] loading graphql project contents --- src/App.vue | 10 ++-- src/components/objects/ContentBlock.vue | 24 +++++--- src/components/objects/Project.vue | 50 ++++++++-------- src/store/modules/project.js | 76 +++++++++++++++++++++++-- src/store/modules/projects.js | 2 +- 5 files changed, 119 insertions(+), 43 deletions(-) diff --git a/src/App.vue b/src/App.vue index 1bfe3bc..eeaa0c1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -303,7 +303,7 @@ export default { // INTERACTIONS 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) { // update the picking ray with the camera and mouse position this.raycaster.setFromCamera(this.mouse, this.camera) @@ -311,11 +311,11 @@ export default { var intersects = this.raycaster.intersectObjects(this.interactive_objects) // console.log('intersects', intersects) + // if we clicked on 3Dobject if (intersects.length) { let cam = this.camera let camPos = { ...this.camera.position } console.log('onDocMouseUp intersects', intersects) - // for (var i = 0; i < intersects.length; i++) { let object = intersects[0].object console.log('object[0].name', object.name) let vnode = object.userData.vnode @@ -328,11 +328,13 @@ export default { // console.log('opened_vnode', this.opened_vnode) this.opened_vnode.isOpened = false } - // opene current vnode - vnode.isOpened = true + // open current vnode + // vnode.isOpened = true + vnode.open() // recorde vnode as precedent vnode this.opened_vnode = vnode + // get new camera target pos let toPos = { ...object.position } if (object.name === 'Content') { switch (vnode.face) { diff --git a/src/components/objects/ContentBlock.vue b/src/components/objects/ContentBlock.vue index d5d324b..449ab0a 100644 --- a/src/components/objects/ContentBlock.vue +++ b/src/components/objects/ContentBlock.vue @@ -41,14 +41,20 @@ diff --git a/src/store/modules/project.js b/src/store/modules/project.js index 9dbe624..de56a9c 100644 --- a/src/store/modules/project.js +++ b/src/store/modules/project.js @@ -3,6 +3,7 @@ // import qs from 'querystring' // import { REST } from 'api/rest-axios' +import { GRAPHQL } from 'api/graphql-axios' import * as THREE from 'three' import { ThreeBSP } from 'three-js-csg-es6' @@ -19,8 +20,10 @@ export default { wallsPos: null, top3dObj: null, topPos: null, + topColor: null, floor3dObj: null, floorPos: null, + florrColor: null, wall: { wallW: 0.001, // dig windows on face and back @@ -34,6 +37,7 @@ export default { nbrWinZ: 0, paddingZ: 0 }, + contents: {}, grid: [] }, @@ -71,7 +75,9 @@ export default { setTop3dObj: (state, obj) => { state.top3dObj = obj }, setTopPos: (state, pos) => { state.topPos = pos }, 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 @@ -114,7 +120,8 @@ export default { // console.log('x', x) commit('setPosition', { 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 }) @@ -235,8 +242,10 @@ export default { let sFloor = Math.round(40 + Math.random() * 20) let lFloor = Math.round(5 + Math.random() * 15) let topColor = `hsla(${hTop}, ${sTop}%, ${lTop}%, 1)` - let bottomColor = `hsla(${hFloor}, ${sFloor}%, ${lFloor}%, 1)` - let gradientTexture = new THREE.CanvasTexture(getters.createGradientCanvas(topColor, bottomColor)) + commit('setTopColor', topColor) + let floorColor = `hsla(${hFloor}, ${sFloor}%, ${lFloor}%, 1)` + commit('setFloorColor', floorColor) + let gradientTexture = new THREE.CanvasTexture(getters.createGradientCanvas(topColor, floorColor)) let materialOpts = { color: 0xffffff, side: THREE.DoubleSide, @@ -287,6 +296,65 @@ export default { // } // let levelMat = new THREE.MeshPhongMaterial(levelOpts) // 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) + }) } } } diff --git a/src/store/modules/projects.js b/src/store/modules/projects.js index a3cc16e..6abbe99 100644 --- a/src/store/modules/projects.js +++ b/src/store/modules/projects.js @@ -98,7 +98,7 @@ export default { commit('increaseTotalW', w) size = { x: w, - y: Math.round(150 + Math.random() * 50), + y: Math.round(110 + Math.random() * 100), z: Math.round(10 + Math.random() * 30) } // convert to number the project id