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>
<div>
<!-- <object3d ref="block3d" name="Content" :position="position"> -->
<!-- <object3d ref="block3d" name="Content" :position="position"> -->
<!-- <mesh ref="block3d" name="ContentBlock" :position="position">
<geometry type="Box" :args="[size.x, size.y, size.z]" />
<material type="MeshLambert" :color="color" :options="opts" />
@@ -43,14 +43,16 @@
<script>
import * as THREE from 'three'
import mixins from 'components/mixins'
import { mapState, mapGetters } from 'vuex'
export default {
name: 'ContentBlock',
mixins: [mixins],
props: { prtPosition: Object, prtSize: Object, type: String, data: Object },
props: { prtPosition: Object, prtSize: Object, prtIndex: Number, type: String, data: Object },
data: () => ({
// block3d: null,
size: { x: 4, y: 8 },
project: null,
size: { x: 0, y: 0 },
position: { x: 0, y: 0, z: 0 },
rotation: { x: 0, y: 0, z: 0 },
// opts: {
@@ -84,6 +86,12 @@ export default {
face: null
}),
computed: {
...mapState({
projects: state => state.Projects.projects
}),
...mapGetters({
getGridPos: 'Projects/getGridPos'
}),
color () {
let color = 0x000000
switch (this.type) {
@@ -119,6 +127,9 @@ export default {
}
},
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)
// let txtcolor = '#000000'
// switch (this.type) {
@@ -139,26 +150,27 @@ export default {
// this.size.x = this.label_size.x + 0.2
// this.size.y = this.label_size.y + 0.2
let y = 0
let top = this.prtPosition.y + this.prtSize.y / 2
let floor = this.prtPosition.y - this.prtSize.y / 2
switch (this.type) {
case 'visible':
y = top * Math.random()
break
case 'context':
y = floor / 3 * Math.random()
break
case 'process':
y = floor / 3 + floor / 3 * Math.random()
break
case 'concept':
y = (floor / 3) * 2 + floor / 3 * Math.random()
break
}
this.position.y = y
// let y = 0
// let top = this.prtPosition.y + this.prtSize.y / 2
// let floor = this.prtPosition.y - this.prtSize.y / 2
// switch (this.type) {
// case 'visible':
// y = top * Math.random()
// break
// case 'context':
// y = floor / 3 * Math.random()
// break
// case 'process':
// y = floor / 3 + floor / 3 * Math.random()
// break
// case 'concept':
// y = (floor / 3) * 2 + floor / 3 * Math.random()
// break
// }
// this.position.y = y
let face = Math.random()
// let face = Math.random()
// // USES 4 FACES
// if (face < 0.25) {
// // gauche
// 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.rotation.y = 180
// }
if (face < 0.5) {
// gauche
this.face = 'left'
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
} else {
// droite
this.face = 'right'
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
}
// // USES 2 FACES
// if (face < 0.5) {
// // gauche
// this.face = 'left'
// 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
// } else {
// // droite
// this.face = 'right'
// 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.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
+18 -39
View File
@@ -16,6 +16,7 @@
:key="item.id"
:prtPosition="position"
:prtSize="size"
:prtIndex="index"
type="visible"
:data="item"
/>
@@ -24,6 +25,7 @@
:key="item.id"
:prtPosition="position"
:prtSize="size"
:prtIndex="index"
type="context"
:data="item"
/>
@@ -32,6 +34,7 @@
:key="item.id"
:prtPosition="position"
:prtSize="size"
:prtIndex="index"
type="process"
:data="item"
/>
@@ -40,6 +43,7 @@
:key="item.id"
:prtPosition="position"
:prtSize="size"
:prtIndex="index"
type="concept"
:data="item"
/>
@@ -71,49 +75,23 @@ export default {
// get size and positions from project store
let size = { ...this.data.size }
let position = { ...this.data.position }
let wall = { ...this.data.wall }
// http://learningthreejs.com/blog/2011/12/10/constructive-solid-geometry-with-csg-js/
// console.log('ThreeBSP', ThreeBSP)
let wallW = 0.001
let backGeom = new THREE.BoxGeometry(size.x, size.y, wallW)
let backGeom = new THREE.BoxGeometry(size.x, size.y, wall.wallW)
let backMesh = new THREE.Mesh(backGeom)
backMesh.position.z = -0.5 * size.z
let backBSP = new ThreeBSP(backMesh)
// dig windows on face and back
let winW = 2 + Math.random() * 2
let winH = 4 + Math.random() * 4
let margin = 2
let nbrWinX = 0
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)
let winGeom = new THREE.BoxGeometry(wall.winW, wall.winH, wall.wallW)
let winMesh = new THREE.Mesh(winGeom)
let winBSP
for (var i = 0; i < wall.nbrWinX; i++) {
for (var j = 0; j < wall.nbrWinY; j++) {
winMesh.position.z = -0.5 * size.z
winMesh.position.x = -0.5 * size.x + margin + winW * 0.5 + i * (winW + paddingX)
winMesh.position.y = 0.5 * size.y - margin - winH * 0.5 - j * (winH + paddingY)
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 - wall.margin - wall.winH * 0.5 - j * (wall.winH + wall.paddingY)
winBSP = new ThreeBSP(winMesh)
backBSP = backBSP.subtract(winBSP)
}
@@ -137,7 +115,7 @@ export default {
faceMesh.position.z = 0.5 * size.z
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)
rightMesh.position.x = 0.5 * size.x
// rightMesh.position.z = 0.5 * size.z
@@ -216,10 +194,11 @@ export default {
let hFloor = Math.round(205 + Math.random() * 10)
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(this.createGradientCanvas(topColor, bottomColor))
let materialOpts = {
color: 0xffffff,
side: THREE.DoubleSide,
@@ -249,7 +228,7 @@ export default {
// var sun = new THREE.DirectionalLight(0xfcfcf9, 2)
// 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 = {
color: new THREE.Color(`hsl(${hTop}, ${sTop}%, ${lTop}%)`),
// side: THREE.DoubleSide,
@@ -260,7 +239,7 @@ export default {
let topPosition = { ...position }
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 = {
color: new THREE.Color(`hsl(${hFloor}, ${sFloor}%, ${lFloor}%)`),
// side: THREE.DoubleSide,