first draft of contents grid placing

This commit is contained in:
2020-09-14 15:56:44 +02:00
parent 41f558938a
commit 672af09e51
3 changed files with 149 additions and 75 deletions
+59 -35
View File
@@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<!-- <object3d ref="block3d" name="Content" :position="position"> --> <!-- <object3d ref="block3d" name="Content" :position="position"> -->
<!-- <mesh ref="block3d" name="ContentBlock" :position="position"> <!-- <mesh ref="block3d" name="ContentBlock" :position="position">
<geometry type="Box" :args="[size.x, size.y, size.z]" /> <geometry type="Box" :args="[size.x, size.y, size.z]" />
<material type="MeshLambert" :color="color" :options="opts" /> <material type="MeshLambert" :color="color" :options="opts" />
@@ -43,14 +43,16 @@
<script> <script>
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'
export default { export default {
name: 'ContentBlock', name: 'ContentBlock',
mixins: [mixins], mixins: [mixins],
props: { prtPosition: Object, prtSize: Object, type: String, data: Object }, props: { prtPosition: Object, prtSize: Object, prtIndex: Number, type: String, data: Object },
data: () => ({ data: () => ({
// block3d: null, // block3d: null,
size: { x: 4, y: 8 }, project: null,
size: { x: 0, y: 0 },
position: { x: 0, y: 0, z: 0 }, position: { x: 0, y: 0, z: 0 },
rotation: { x: 0, y: 0, z: 0 }, rotation: { x: 0, y: 0, z: 0 },
// opts: { // opts: {
@@ -84,6 +86,12 @@ export default {
face: null face: null
}), }),
computed: { computed: {
...mapState({
projects: state => state.Projects.projects
}),
...mapGetters({
getGridPos: 'Projects/getGridPos'
}),
color () { color () {
let color = 0x000000 let color = 0x000000
switch (this.type) { switch (this.type) {
@@ -119,6 +127,9 @@ export default {
} }
}, },
created () { created () {
this.project = this.projects[this.prtIndex]
this.size.x = this.project.wall.winW / 2
this.size.y = this.project.wall.winY / 2
// console.log('ContentBlock created', this.data) // console.log('ContentBlock created', this.data)
// let txtcolor = '#000000' // let txtcolor = '#000000'
// switch (this.type) { // switch (this.type) {
@@ -139,26 +150,27 @@ export default {
// this.size.x = this.label_size.x + 0.2 // this.size.x = this.label_size.x + 0.2
// this.size.y = this.label_size.y + 0.2 // this.size.y = this.label_size.y + 0.2
let y = 0 // let y = 0
let top = this.prtPosition.y + this.prtSize.y / 2 // let top = this.prtPosition.y + this.prtSize.y / 2
let floor = this.prtPosition.y - this.prtSize.y / 2 // let floor = this.prtPosition.y - this.prtSize.y / 2
switch (this.type) { // switch (this.type) {
case 'visible': // case 'visible':
y = top * Math.random() // y = top * Math.random()
break // break
case 'context': // case 'context':
y = floor / 3 * Math.random() // y = floor / 3 * Math.random()
break // break
case 'process': // case 'process':
y = floor / 3 + floor / 3 * Math.random() // y = floor / 3 + floor / 3 * Math.random()
break // break
case 'concept': // case 'concept':
y = (floor / 3) * 2 + floor / 3 * Math.random() // y = (floor / 3) * 2 + floor / 3 * Math.random()
break // break
} // }
this.position.y = y // this.position.y = y
let face = Math.random() // let face = Math.random()
// // USES 4 FACES
// if (face < 0.25) { // if (face < 0.25) {
// // gauche // // gauche
// this.face = 'left' // this.face = 'left'
@@ -183,19 +195,31 @@ export default {
// this.position.x = this.prtPosition.x - this.prtSize.x / 2 + this.size.x / 2 + Math.random() * (this.prtSize.x - this.size.x / 2) // this.position.x = this.prtPosition.x - this.prtSize.x / 2 + this.size.x / 2 + Math.random() * (this.prtSize.x - this.size.x / 2)
// this.rotation.y = 180 // this.rotation.y = 180
// } // }
if (face < 0.5) {
// gauche // // USES 2 FACES
this.face = 'left' // if (face < 0.5) {
this.position.x = this.prtPosition.x - this.prtSize.x / 2 + 0.1 // // gauche
this.position.z = this.prtPosition.z - this.prtSize.z / 2 + this.size.x / 2 + Math.random() * (this.prtSize.z - this.size.x / 2) // this.face = 'left'
this.rotation.y = 90 // this.position.x = this.prtPosition.x - this.prtSize.x / 2 + 0.1
} else { // this.position.z = this.prtPosition.z - this.prtSize.z / 2 + this.size.x / 2 + Math.random() * (this.prtSize.z - this.size.x / 2)
// droite // this.rotation.y = 90
this.face = 'right' // } else {
this.position.x = this.prtPosition.x + this.prtSize.x / 2 - 0.1 // // droite
this.position.z = this.prtPosition.z - this.prtSize.z / 2 + this.size.x / 2 + Math.random() * (this.prtSize.z - this.size.x / 2) // this.face = 'right'
this.rotation.y = -90 // this.position.x = this.prtPosition.x + this.prtSize.x / 2 - 0.1
} // this.position.z = this.prtPosition.z - this.prtSize.z / 2 + this.size.x / 2 + Math.random() * (this.prtSize.z - this.size.x / 2)
// this.rotation.y = -90
// }
// With GRID
this.face = 'left'
this.position.x = this.prtPosition.x - this.prtSize.x / 2 + 0.1
let pos = this.getGridPos(this.prtIndex)
console.log('pos', pos)
this.position.z = this.prtPosition.z - this.prtSize.z / 2 + pos.z
this.position.y = this.prtPosition.y - this.prtSize.y / 2 + pos.y
this.rotation.y = 90
// this.label_position.x = this.position.x - this.size.x / 2 + this.label_size.x / 2 + 0.1 // 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.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 // this.label_position.z = this.position.z + this.size.z / 2 + 0.01
+18 -39
View File
@@ -16,6 +16,7 @@
:key="item.id" :key="item.id"
:prtPosition="position" :prtPosition="position"
:prtSize="size" :prtSize="size"
:prtIndex="index"
type="visible" type="visible"
:data="item" :data="item"
/> />
@@ -24,6 +25,7 @@
:key="item.id" :key="item.id"
:prtPosition="position" :prtPosition="position"
:prtSize="size" :prtSize="size"
:prtIndex="index"
type="context" type="context"
:data="item" :data="item"
/> />
@@ -32,6 +34,7 @@
:key="item.id" :key="item.id"
:prtPosition="position" :prtPosition="position"
:prtSize="size" :prtSize="size"
:prtIndex="index"
type="process" type="process"
:data="item" :data="item"
/> />
@@ -40,6 +43,7 @@
:key="item.id" :key="item.id"
:prtPosition="position" :prtPosition="position"
:prtSize="size" :prtSize="size"
:prtIndex="index"
type="concept" type="concept"
:data="item" :data="item"
/> />
@@ -71,49 +75,23 @@ export default {
// get size and positions from project store // get size and positions from project store
let size = { ...this.data.size } let size = { ...this.data.size }
let position = { ...this.data.position } let position = { ...this.data.position }
let wall = { ...this.data.wall }
// http://learningthreejs.com/blog/2011/12/10/constructive-solid-geometry-with-csg-js/ // http://learningthreejs.com/blog/2011/12/10/constructive-solid-geometry-with-csg-js/
// console.log('ThreeBSP', ThreeBSP) // console.log('ThreeBSP', ThreeBSP)
let wallW = 0.001 let backGeom = new THREE.BoxGeometry(size.x, size.y, wall.wallW)
let backGeom = new THREE.BoxGeometry(size.x, size.y, wallW)
let backMesh = new THREE.Mesh(backGeom) let backMesh = new THREE.Mesh(backGeom)
backMesh.position.z = -0.5 * size.z backMesh.position.z = -0.5 * size.z
let backBSP = new ThreeBSP(backMesh) let backBSP = new ThreeBSP(backMesh)
// dig windows on face and back let winGeom = new THREE.BoxGeometry(wall.winW, wall.winH, wall.wallW)
let winW = 2 + Math.random() * 2 let winMesh = new THREE.Mesh(winGeom)
let winH = 4 + Math.random() * 4 let winBSP
let margin = 2 for (var i = 0; i < wall.nbrWinX; i++) {
let nbrWinX = 0 for (var j = 0; j < wall.nbrWinY; j++) {
let paddingX = 0
let a = 0
// removing windows until padding is enough
while (paddingX < 0.4) {
nbrWinX = Math.floor((size.x - 2 * margin) / winW) - a
paddingX = (size.x - 2 * margin - winW * nbrWinX) / (nbrWinX - 1)
a++
}
// console.log('paddingX', paddingX)
let nbrWinY = 0
let paddingY = 0
a = 0
// removing windows until padding is enough
while (paddingY < 0.4) {
nbrWinY = Math.floor((size.y - 2 * margin) / winH) - a
paddingY = (size.y - 2 * margin - winH * nbrWinY) / (nbrWinY - 1)
a++
}
let winGeom = new THREE.BoxGeometry(winW, winH, wallW)
let winMesh, winBSP
for (var i = 0; i < nbrWinX; i++) {
for (var j = 0; j < nbrWinY; j++) {
// back
winMesh = new THREE.Mesh(winGeom)
winMesh.position.z = -0.5 * size.z winMesh.position.z = -0.5 * size.z
winMesh.position.x = -0.5 * size.x + margin + winW * 0.5 + i * (winW + paddingX) winMesh.position.x = -0.5 * size.x + wall.margin + wall.winW * 0.5 + i * (wall.winW + wall.paddingX)
winMesh.position.y = 0.5 * size.y - margin - winH * 0.5 - j * (winH + paddingY) winMesh.position.y = 0.5 * size.y - wall.margin - wall.winH * 0.5 - j * (wall.winH + wall.paddingY)
winBSP = new ThreeBSP(winMesh) winBSP = new ThreeBSP(winMesh)
backBSP = backBSP.subtract(winBSP) backBSP = backBSP.subtract(winBSP)
} }
@@ -137,7 +115,7 @@ export default {
faceMesh.position.z = 0.5 * size.z faceMesh.position.z = 0.5 * size.z
let faceBSP = new ThreeBSP(faceMesh) let faceBSP = new ThreeBSP(faceMesh)
let rightGeom = new THREE.BoxGeometry(wallW, size.y, size.z) let rightGeom = new THREE.BoxGeometry(wall.wallW, size.y, size.z)
let rightMesh = new THREE.Mesh(rightGeom) let rightMesh = new THREE.Mesh(rightGeom)
rightMesh.position.x = 0.5 * size.x rightMesh.position.x = 0.5 * size.x
// rightMesh.position.z = 0.5 * size.z // rightMesh.position.z = 0.5 * size.z
@@ -216,10 +194,11 @@ export default {
let hFloor = Math.round(205 + Math.random() * 10) let hFloor = Math.round(205 + Math.random() * 10)
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)` let bottomColor = `hsla(${hFloor}, ${sFloor}%, ${lFloor}%, 1)`
let gradientTexture = new THREE.CanvasTexture(this.createGradientCanvas(topColor, bottomColor)) let gradientTexture = new THREE.CanvasTexture(this.createGradientCanvas(topColor, bottomColor))
let materialOpts = { let materialOpts = {
color: 0xffffff, color: 0xffffff,
side: THREE.DoubleSide, side: THREE.DoubleSide,
@@ -249,7 +228,7 @@ export default {
// var sun = new THREE.DirectionalLight(0xfcfcf9, 2) // var sun = new THREE.DirectionalLight(0xfcfcf9, 2)
// sun.position.set(-150, 200, 110) // sun.position.set(-150, 200, 110)
let topGeom = new THREE.BoxGeometry(size.x, wallW, size.z) let topGeom = new THREE.BoxGeometry(size.x, wall.wallW, size.z)
let topOpts = { let topOpts = {
color: new THREE.Color(`hsl(${hTop}, ${sTop}%, ${lTop}%)`), color: new THREE.Color(`hsl(${hTop}, ${sTop}%, ${lTop}%)`),
// side: THREE.DoubleSide, // side: THREE.DoubleSide,
@@ -260,7 +239,7 @@ export default {
let topPosition = { ...position } let topPosition = { ...position }
topPosition.y += 0.5 * size.y topPosition.y += 0.5 * size.y
let floorGeom = new THREE.BoxGeometry(size.x, wallW, size.z) let floorGeom = new THREE.BoxGeometry(size.x, wall.wallW, size.z)
let floorOpts = { let floorOpts = {
color: new THREE.Color(`hsl(${hFloor}, ${sFloor}%, ${lFloor}%)`), color: new THREE.Color(`hsl(${hFloor}, ${sFloor}%, ${lFloor}%)`),
// side: THREE.DoubleSide, // side: THREE.DoubleSide,
+72 -1
View File
@@ -9,7 +9,13 @@ export default {
}, },
// getters // getters
getters: {}, getters: {
getGridPos: (state) => (index) => {
let popped = state.projects[index].grid.pop()
console.log('getGridPos: popped', popped)
return popped
}
},
// mutations // mutations
mutations: { mutations: {
@@ -30,9 +36,15 @@ export default {
} }
// positioning buildings on x regarding the widths // positioning buildings on x regarding the widths
// & setting up the window sizing
// & setting up the content grid
let margin = 5 let margin = 5
totalW += margin * (state.projects.length - 1) totalW += margin * (state.projects.length - 1)
let wall, a
let grid
// fro each PROJECTS
for (var j = 0; j < state.projects.length; j++) { for (var j = 0; j < state.projects.length; j++) {
// X POS
let x = -1 * totalW / 2// + state.projects[0].size.x / 2 let x = -1 * totalW / 2// + state.projects[0].size.x / 2
for (var k = 0; k < j; k++) { for (var k = 0; k < j; k++) {
x += state.projects[k].size.x x += state.projects[k].size.x
@@ -44,6 +56,65 @@ export default {
y: -1 * state.projects[j].size.y / 2 + 10 + Math.random() * 30, // -10 + Math.random() * this.size.y / 2 y: -1 * state.projects[j].size.y / 2 + 10 + Math.random() * 30, // -10 + Math.random() * this.size.y / 2
z: -10 + Math.random() * 10 z: -10 + Math.random() * 10
} }
// WINDOWS
wall = {
wallW: 0.001,
// dig windows on face and back
winW: 2 + Math.random() * 2,
winH: 4 + Math.random() * 4,
margin: 2,
nbrWinX: 0,
paddingX: 0,
nbrWinY: 0,
paddingY: 0,
nbrWinZ: 0,
paddingZ: 0
}
// removing windows on X until padding is enough
a = 0
wall.nbrWinX = Math.floor((state.projects[j].size.x - 2 * wall.margin) / wall.winW)
while (wall.paddingX < 0.4) {
wall.nbrWinX -= a
wall.paddingX = (state.projects[j].size.x - 2 * wall.margin - wall.winW * wall.nbrWinX) / (wall.nbrWinX - 1)
a++
}
// removing windows on Y until padding is enough
a = 0
wall.nbrWinY = Math.floor((state.projects[j].size.y - 2 * wall.margin) / wall.winH)
while (wall.paddingY < 0.4) {
wall.nbrWinY -= a
wall.paddingY = (state.projects[j].size.y - 2 * wall.margin - wall.winH * wall.nbrWinY) / (wall.nbrWinY - 1)
a++
}
state.projects[j].wall = { ...wall }
// CONTENTS GRID
a = 0
wall.nbrWinZ = Math.floor((state.projects[j].size.z - 2 * wall.margin) / wall.winW)
while (wall.paddingZ < 0.4) {
wall.nbrWinZ -= a
wall.paddingZ = (state.projects[j].size.z - 2 * wall.margin - wall.winW * wall.nbrWinZ) / (wall.nbrWinZ - 1)
a++
}
grid = []
for (var l = 0; l < wall.nbrWinZ * 2; l++) { // cols
for (var m = 0; m < wall.nbrWinY * 2; m++) { // rows
grid.push({
z: margin + wall.winW / 2 * l,
y: margin + wall.winH / 2 * m
})
}
}
// shuffle the grid
for (let n = grid.length - 1; n > 0; n--) {
const o = Math.floor(Math.random() * n)
const temp = grid[n]
grid[n] = grid[o]
grid[o] = temp
}
state.projects[j].grid = [ ...grid ]
} }
} }
}, },