refactored grid placement, now up to 4 faces available
This commit is contained in:
@@ -101,7 +101,7 @@ export default {
|
|||||||
projSize: state => state.size,
|
projSize: state => state.size,
|
||||||
projPos: state => state.position,
|
projPos: state => state.position,
|
||||||
projWall: state => state.wall,
|
projWall: state => state.wall,
|
||||||
gridContentPlaced: state => state.gridContentPlaced,
|
gridsContentPlaced: state => state.gridsContentPlaced,
|
||||||
contents_size_factor: state => state.contents_size_factor
|
contents_size_factor: state => state.contents_size_factor
|
||||||
}),
|
}),
|
||||||
color () {
|
color () {
|
||||||
@@ -214,39 +214,65 @@ export default {
|
|||||||
// this.rotation.y = 180
|
// this.rotation.y = 180
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// // USES 2 FACES
|
// RANDOMLY USE 2 FACES
|
||||||
if (face < 0.5) {
|
if (face < 0.5) {
|
||||||
// gauche
|
|
||||||
this.face = 'left'
|
this.face = 'left'
|
||||||
this.position.x = this.projPos.x - this.projSize.x / 2 + 0.1
|
|
||||||
// this.position.z = this.projPos.z - this.projSize.z / 2 + this.size.x / 2 + Math.random() * (this.projSize.z - this.size.x / 2)
|
|
||||||
this.rotation.y = 90
|
|
||||||
} else {
|
} else {
|
||||||
// droite
|
|
||||||
this.face = 'right'
|
this.face = 'right'
|
||||||
this.position.x = this.projPos.x + this.projSize.x / 2 - 0.1
|
|
||||||
// this.position.z = this.projPos.z - this.projSize.z / 2 + this.size.x / 2 + Math.random() * (this.projSize.z - this.size.x / 2)
|
|
||||||
this.rotation.y = -90
|
|
||||||
}
|
}
|
||||||
|
// define side
|
||||||
// With GRID
|
let side
|
||||||
// this.face = 'left'
|
switch (this.face) {
|
||||||
// this.position.x = this.projPos.x - this.projSize.x / 2 + 0.1
|
case 'back':
|
||||||
// this.rotation.y = 90
|
case 'front':
|
||||||
if (typeof this.gridContentPlaced[this.type] === 'undefined' ||
|
side = 'x'
|
||||||
typeof this.gridContentPlaced[this.type][this.id] === 'undefined') {
|
break
|
||||||
|
case 'left':
|
||||||
|
case 'right':
|
||||||
|
side = 'z'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// Get GRID's CEL
|
||||||
|
if (typeof this.gridsContentPlaced[side] === 'undefined' ||
|
||||||
|
typeof this.gridsContentPlaced[side][this.face] === 'undefined' ||
|
||||||
|
typeof this.gridsContentPlaced[side][this.face][this.type] === 'undefined' ||
|
||||||
|
typeof this.gridsContentPlaced[side][this.face][this.type][this.id] === 'undefined') {
|
||||||
// First shift grid place (will transfer it from free places to occupied places)
|
// First shift grid place (will transfer it from free places to occupied places)
|
||||||
this.shiftGrid({ type: this.type, id: this.id })
|
this.shiftGrid({ face: this.face, type: this.type, id: this.id })
|
||||||
|
}
|
||||||
|
// rotation and position
|
||||||
|
let gridPos = this.gridsContentPlaced[side][this.face][this.type][this.id]
|
||||||
|
console.log('gridPos', gridPos)
|
||||||
|
switch (side) {
|
||||||
|
case 'x':
|
||||||
|
this.position.x = this.projPos.x - this.projSize.x / 2 + gridPos.x
|
||||||
|
this.position.y = this.projPos.y - this.projSize.y / 2 + gridPos.y
|
||||||
|
switch (this.face) {
|
||||||
|
case 'face':
|
||||||
|
this.position.z = this.projPos.z + this.projSize.z / 2 - 0.1
|
||||||
|
this.rotation.y = 180
|
||||||
|
break
|
||||||
|
case 'back':
|
||||||
|
this.position.z = this.projPos.z - this.projSize.z / 2 + 0.1
|
||||||
|
this.rotation.y = 0
|
||||||
|
break
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'z':
|
||||||
|
this.position.z = this.projPos.z - this.projSize.z / 2 + gridPos.z
|
||||||
|
this.position.y = this.projPos.y - this.projSize.y / 2 + gridPos.y
|
||||||
|
switch (this.face) {
|
||||||
|
case 'left':
|
||||||
|
this.position.x = this.projPos.x - this.projSize.x / 2 + 0.1
|
||||||
|
this.rotation.y = 90
|
||||||
|
break
|
||||||
|
case 'right':
|
||||||
|
this.position.x = this.projPos.x + this.projSize.x / 2 - 0.1
|
||||||
|
this.rotation.y = -90
|
||||||
|
break
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
// Then get the right place for the current content
|
|
||||||
let pos = this.gridContentPlaced[this.type][this.id]
|
|
||||||
console.log('pos', pos)
|
|
||||||
this.position.z = this.projPos.z - this.projSize.z / 2 + pos.z
|
|
||||||
this.position.y = this.projPos.y - this.projSize.y / 2 + pos.y
|
|
||||||
|
|
||||||
// this.label_position.x = this.position.x - this.size.x / 2 + this.label_size.x / 2 + 0.1
|
|
||||||
// this.label_position.y = this.position.y + this.size.y / 2 - this.label_size.y / 2 - 0.1
|
|
||||||
// this.label_position.z = this.position.z + this.size.z / 2 + 0.01
|
|
||||||
|
|
||||||
// console.log(this.data.Media[0].url)
|
// console.log(this.data.Media[0].url)
|
||||||
// create image object with a promise (async img loading)
|
// create image object with a promise (async img loading)
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ export default {
|
|||||||
contents: {},
|
contents: {},
|
||||||
contents_size_factor: 1, // factor to get the contents (grid) size proportional to windows
|
contents_size_factor: 1, // factor to get the contents (grid) size proportional to windows
|
||||||
contentTypes: ['visible', 'context', 'process', 'concept'],
|
contentTypes: ['visible', 'context', 'process', 'concept'],
|
||||||
grid: { visible: [], context: [], process: [], concept: [] },
|
grids: null,
|
||||||
gridContentPlaced: {},
|
gridsContentPlaced: {},
|
||||||
activeLevel: 'visibles'
|
activeLevel: 'visibles'
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -90,13 +90,31 @@ export default {
|
|||||||
setLevels3dObj: (state, obj) => { state.levels3dObj = obj },
|
setLevels3dObj: (state, obj) => { state.levels3dObj = obj },
|
||||||
setLevelsPos: (state, pos) => { state.levelsPos = pos },
|
setLevelsPos: (state, pos) => { state.levelsPos = pos },
|
||||||
setContents: (state, contents) => { state.contents = contents },
|
setContents: (state, contents) => { state.contents = contents },
|
||||||
setGrid: (state, grid) => { state.grid = grid },
|
setGrids: (state, grids) => { state.grids = grids },
|
||||||
shiftGrid: (state, c) => {
|
shiftGrid: (state, c) => {
|
||||||
let p = state.grid[c.type].shift()
|
console.log('shiftGrid c:', c)
|
||||||
if (!state.gridContentPlaced[c.type]) {
|
let side
|
||||||
state.gridContentPlaced[c.type] = {}
|
switch (c.face) {
|
||||||
|
case 'back':
|
||||||
|
case 'front':
|
||||||
|
side = 'x'
|
||||||
|
break
|
||||||
|
case 'left':
|
||||||
|
case 'right':
|
||||||
|
side = 'z'
|
||||||
|
break
|
||||||
}
|
}
|
||||||
state.gridContentPlaced[c.type][c.id] = p
|
let p = state.grids[side][c.face][c.type].shift()
|
||||||
|
if (!state.gridsContentPlaced[side]) {
|
||||||
|
state.gridsContentPlaced[side] = {}
|
||||||
|
}
|
||||||
|
if (!state.gridsContentPlaced[side][c.face]) {
|
||||||
|
state.gridsContentPlaced[side][c.face] = {}
|
||||||
|
}
|
||||||
|
if (!state.gridsContentPlaced[side][c.face][c.type]) {
|
||||||
|
state.gridsContentPlaced[side][c.face][c.type] = {}
|
||||||
|
}
|
||||||
|
state.gridsContentPlaced[side][c.face][c.type][c.id] = p
|
||||||
},
|
},
|
||||||
setActiveLevel: (state, l) => {
|
setActiveLevel: (state, l) => {
|
||||||
state.activeLevel = l
|
state.activeLevel = l
|
||||||
@@ -175,43 +193,75 @@ export default {
|
|||||||
a++
|
a++
|
||||||
}
|
}
|
||||||
|
|
||||||
let grid = {}
|
// create grids for right/left & face/back
|
||||||
let rows = state.wall.nbrWinY / state.contents_size_factor
|
let grids = {
|
||||||
let cols = state.wall.nbrWinZ / state.contents_size_factor
|
x: { front: {}, back: {} },
|
||||||
let t
|
z: { left: {}, right: {} }
|
||||||
for (var m = 0; m < rows; m++) { // rows
|
|
||||||
if (m > rows / 4 * 3 + 1) {
|
|
||||||
t = state.contentTypes[0]
|
|
||||||
} else if (m > rows / 4 * 2 + 1) {
|
|
||||||
t = state.contentTypes[1]
|
|
||||||
} else if (m > rows / 4 + 1) {
|
|
||||||
t = state.contentTypes[2]
|
|
||||||
} else {
|
|
||||||
t = state.contentTypes[3]
|
|
||||||
}
|
|
||||||
if (!grid[t]) {
|
|
||||||
grid[t] = []
|
|
||||||
}
|
|
||||||
for (var l = 0; l < cols; l++) { // cols
|
|
||||||
grid[t].push({
|
|
||||||
z: margin + state.wall.winW * state.contents_size_factor * l,
|
|
||||||
y: margin + state.wall.winH * state.contents_size_factor * m
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
console.log('grid', grid)
|
// console.log('grids', grids)
|
||||||
// shuffle the grids
|
let grid, rows, cols, t, cel
|
||||||
for (var i = 0; i < state.contentTypes.length; i++) {
|
// console.log('Object.keys(grids)', Object.keys(grids))
|
||||||
for (let n = grid[state.contentTypes[i]].length - 1; n > 0; n--) {
|
Object.keys(grids).map(function (side) {
|
||||||
const o = Math.floor(Math.random() * n)
|
// console.log('GRID side:', side)
|
||||||
const temp = grid[state.contentTypes[i]][n]
|
grid = {}
|
||||||
grid[state.contentTypes[i]][n] = grid[state.contentTypes[i]][o]
|
// calculate cols nbr regarding the face orientation
|
||||||
grid[state.contentTypes[i]][o] = temp
|
switch (side) {
|
||||||
|
case 'z':
|
||||||
|
cols = state.wall.nbrWinZ / state.contents_size_factor
|
||||||
|
break
|
||||||
|
case 'x':
|
||||||
|
cols = state.wall.nbrWinX / state.contents_size_factor
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
// calculate rows
|
||||||
console.log('shuffeld grid', grid)
|
rows = state.wall.nbrWinY / state.contents_size_factor
|
||||||
commit('setGrid', grid)
|
// dispatch grid rows on to 4 levels (t)
|
||||||
console.log('state.grid', state.grid)
|
for (var m = 0; m < rows; m++) { // rows
|
||||||
|
if (m > rows / 4 * 3 + 1) {
|
||||||
|
t = state.contentTypes[0]
|
||||||
|
} else if (m > rows / 4 * 2 + 1) {
|
||||||
|
t = state.contentTypes[1]
|
||||||
|
} else if (m > rows / 4 + 1) {
|
||||||
|
t = state.contentTypes[2]
|
||||||
|
} else {
|
||||||
|
t = state.contentTypes[3]
|
||||||
|
}
|
||||||
|
// create level if not exists
|
||||||
|
if (!grid[t]) {
|
||||||
|
grid[t] = []
|
||||||
|
}
|
||||||
|
// create cols for each rows
|
||||||
|
for (var l = 0; l < cols; l++) { // cols
|
||||||
|
cel = { y: margin + state.wall.winH * state.contents_size_factor * m }
|
||||||
|
switch (side) {
|
||||||
|
case 'z':
|
||||||
|
cel.z = margin + state.wall.winW * state.contents_size_factor * l
|
||||||
|
break
|
||||||
|
case 'x':
|
||||||
|
cel.x = margin + state.wall.winW * state.contents_size_factor * l
|
||||||
|
break
|
||||||
|
}
|
||||||
|
grid[t].push(cel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// console.log('grid', grid)
|
||||||
|
// clown and shuffle the grids (one by face)
|
||||||
|
// console.log('Object.keys(grids[side])', Object.keys(grids[side]))
|
||||||
|
Object.keys(grids[side]).map(function (face) {
|
||||||
|
for (var i = 0; i < state.contentTypes.length; i++) {
|
||||||
|
for (let n = grid[state.contentTypes[i]].length - 1; n > 0; n--) {
|
||||||
|
const o = Math.floor(Math.random() * n)
|
||||||
|
const temp = grid[state.contentTypes[i]][n]
|
||||||
|
grid[state.contentTypes[i]][n] = grid[state.contentTypes[i]][o]
|
||||||
|
grid[state.contentTypes[i]][o] = temp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// console.log('shuffeld grid', grid)
|
||||||
|
grids[side][face] = { ...grid }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
commit('setGrids', grids)
|
||||||
|
console.log('state.grids', state.grids)
|
||||||
},
|
},
|
||||||
build3dObjs ({ dispatch, commit, state, getters, rootGetters }) {
|
build3dObjs ({ dispatch, commit, state, getters, rootGetters }) {
|
||||||
console.log('build3dObjs')
|
console.log('build3dObjs')
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export default {
|
|||||||
|
|
||||||
// actions
|
// actions
|
||||||
actions: {
|
actions: {
|
||||||
// async get authors
|
// async load projects
|
||||||
loadProjects ({ dispatch, commit, state }) {
|
loadProjects ({ dispatch, commit, state }) {
|
||||||
// GRAPHQL
|
// GRAPHQL
|
||||||
GRAPHQL.post('', { query: `query {
|
GRAPHQL.post('', { query: `query {
|
||||||
@@ -56,7 +56,7 @@ export default {
|
|||||||
dispatch('computeProjects', projects)
|
dispatch('computeProjects', projects)
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.warn('Issue with getProjects', error)
|
console.warn('Issue with loadProjects', error)
|
||||||
Promise.reject(error)
|
Promise.reject(error)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user