better top and floor, random buildings colors

This commit is contained in:
2020-09-14 11:39:11 +02:00
parent f73d3cceb7
commit 59623b3a3e
5 changed files with 209 additions and 101 deletions
+93 -45
View File
@@ -1,6 +1,9 @@
<template>
<div>
<object3d ref="block3d" name="Project" :obj="building" :position="building_position"/>
<object3d ref="top" :obj="top_mesh" :position="top_position"/>
<object3d ref="floor" :obj="floor_mesh" :position="floor_position"/>
<!-- <light :obj="light" :position="building_position" /> -->
<mesh ref="label3d" name="Label" :position="label_position">
<geometry type="Plane" :args="[label_size.x, label_size.y]" />
<material type="MeshLambert" :options="label_opts">
@@ -52,8 +55,8 @@ import { ThreeBSP } from 'three-js-csg-es6'
import mixins from 'components/mixins'
import ContentBlock from 'components/objects/ContentBlock'
import BgVertex from 'assets/glsl/BgVertex'
import BuildingFragment from 'assets/glsl/BuildingFragment'
// import BgVertex from 'assets/glsl/BgVertex'
// import BuildingFragment from 'assets/glsl/BuildingFragment'
export default {
name: 'Project',
@@ -74,24 +77,14 @@ export default {
let wallW = 0.001
let topGeom = new THREE.BoxGeometry(size.x, wallW, size.z)
let topMesh = new THREE.Mesh(topGeom)
topMesh.position.y = -0.5 * size.y
let topBSP = new ThreeBSP(topMesh)
let floorGeom = new THREE.BoxGeometry(size.x, wallW, size.z)
let floorMesh = new THREE.Mesh(floorGeom)
floorMesh.position.y = 0.5 * size.y
let floorBSP = new ThreeBSP(floorMesh)
let backGeom = new THREE.BoxGeometry(size.x, size.y, 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 = 4
let winH = 8
let winW = 2 + Math.random() * 2
let winH = 4 + Math.random() * 4
let margin = 2
let nbrWinX = 0
let paddingX = 0
@@ -172,48 +165,72 @@ export default {
leftMesh.position.x = -0.5 * size.x
// leftMesh.position.z = 0.5 * size.z
let leftBSP = new ThreeBSP(leftMesh)
//
// let topGeom = new THREE.BoxGeometry(size.x, wallW, size.z)
// let topMesh = new THREE.Mesh(topGeom)
// // topMesh.position.y = -0.5 * size.y
// // let topBSP = new ThreeBSP(topMesh)
//
// let floorGeom = new THREE.BoxGeometry(size.x, wallW, size.z)
// let floorMesh = new THREE.Mesh(floorGeom)
// // floorMesh.position.y = 0.5 * size.y
// // let floorBSP = new ThreeBSP(floorMesh)
let buildingBSP = backBSP.union(rightBSP)
buildingBSP = buildingBSP.union(faceBSP)
buildingBSP = buildingBSP.union(leftBSP)
buildingBSP = buildingBSP.union(topBSP)
buildingBSP = buildingBSP.union(floorBSP)
// buildingBSP = buildingBSP.union(topBSP)
// buildingBSP = buildingBSP.union(floorBSP)
// convert back to three.js mesh
let building = buildingBSP.toMesh()
console.log('building.faces', building)
// create a custom shaderMaterial to had gradian colors
var uniforms = THREE.UniformsUtils.merge([
THREE.UniformsLib['lights'],
{
'topColor': { value: new THREE.Color(0xffffff) },
'groundColor': { value: new THREE.Color(0xbcd6e4) },
'bottomColor': { value: new THREE.Color(0x07223b) },
// 'bottomColor': { value: new THREE.Color(0x000000) },
// 'groundColor': { value: new THREE.Color(0xff0000) },
// 'bottomColor': { value: new THREE.Color(0x00ff00) },
lightIntensity: { type: 'f', value: 1.0 }
}
])
var buildingMat = new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: BgVertex,
fragmentShader: BuildingFragment,
side: THREE.DoubleSide,
lights: true
})
building.material = buildingMat
// var uniforms = THREE.UniformsUtils.merge([
// THREE.UniformsLib['lights'],
// {
// 'topColor': { value: new THREE.Color(0xffffff) },
// 'groundColor': { value: new THREE.Color(0xbcd6e4) },
// 'bottomColor': { value: new THREE.Color(0x07223b) },
// // 'bottomColor': { value: new THREE.Color(0x000000) },
// // 'groundColor': { value: new THREE.Color(0xff0000) },
// // 'bottomColor': { value: new THREE.Color(0x00ff00) },
// lightIntensity: { type: 'f', value: 1.0 }
// }
// ])
// var buildingMat = new THREE.ShaderMaterial({
// uniforms: uniforms,
// vertexShader: BgVertex,
// fragmentShader: BuildingFragment,
// side: THREE.DoubleSide,
// lights: true
// })
// building.material = buildingMat
// create a classical material for building
// let materialOpts = {
// color: 0xffffff,
// side: THREE.DoubleSide
// // wireframe: true,
// // transparent: true,
// // opacity: 0.6
// // renderOrder: 0
// }
// building.material = new THREE.MeshLambertMaterial(materialOpts)
// let topColor = `hsla(201, 100%, 95%, 1)`
let hTop = Math.round(195 + Math.random() * 10)
let sTop = Math.round(100)
let lTop = Math.round(95)
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,
shininess: 30,
map: gradientTexture
// wireframe: true,
// transparent: true,
// opacity: 0.6
// renderOrder: 0
}
building.material = new THREE.MeshPhongMaterial(materialOpts)
// building.castShadow = true
// building.receiveShadow = true
@@ -228,6 +245,32 @@ export default {
let buildingPos = { ...position }
buildingPos.z -= 0.5 * size.z
// let light = new THREE.PointLight(0xfcfcf9, 1)
// var sun = new THREE.DirectionalLight(0xfcfcf9, 2)
// sun.position.set(-150, 200, 110)
let topGeom = new THREE.BoxGeometry(size.x, wallW, size.z)
let topOpts = {
color: new THREE.Color(`hsl(${hTop}, ${sTop}%, ${lTop}%)`),
// side: THREE.DoubleSide,
shininess: 30
}
let topMat = new THREE.MeshPhongMaterial(topOpts)
let topMesh = new THREE.Mesh(topGeom, topMat)
let topPosition = { ...position }
topPosition.y += 0.5 * size.y
let floorGeom = new THREE.BoxGeometry(size.x, wallW, size.z)
let floorOpts = {
color: new THREE.Color(`hsl(${hFloor}, ${sFloor}%, ${lFloor}%)`),
// side: THREE.DoubleSide,
shininess: 10
}
let floorMat = new THREE.MeshPhongMaterial(floorOpts)
let floorMesh = new THREE.Mesh(floorGeom, floorMat)
let floorPosition = { ...position }
floorPosition.y -= 0.5 * size.y
return {
block3d: null,
// block_opts: materialOpts,
@@ -244,8 +287,13 @@ export default {
position: position,
// geometry: geometry,
// light: light,
building: building,
building_position: buildingPos,
top_mesh: topMesh,
top_position: topPosition,
floor_mesh: floorMesh,
floor_position: floorPosition,
label_position: { x: 0, y: 0, z: 0 },
color: 0xffffff,
label_canvas: null,