change the indices generation a bit

This commit is contained in:
Evert Prants 2020-04-01 17:34:24 +03:00
parent 5565be120c
commit bdb2ad6697
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 49 additions and 19 deletions

View File

@ -10,9 +10,9 @@ class Atmosphere extends MeshInstance {
this.innerRadius = innerRadius
this.wavelength = wavelength
this.Kr = 0.0020
this.Km = 0.0010
this.ESun = 20.0
this.Kr = 0.0025
this.Km = 0.0015
this.ESun = 15.0
this.g = -0.950
this.scaleDepth = 0.25
this.mieScaleDepth = 0.1

View File

@ -3,7 +3,7 @@ import { mat4, vec3 } from 'gl-matrix'
import { subv3, mulv3, addv3, divv3, normalv3, crossv3 } from '../../utility'
import Screen from '../../screen'
const lodMax = 8
const lodMax = 11
class PlanetGenerator {
constructor (resolution, radius, noise) {
@ -67,7 +67,8 @@ class CubeFace {
// Normalize and multiply by radius to create a spherical mesh
const normal = normalv3(vertex)
const pos = mulv3(normal, (this.generator.noise.getNoise3D(this.level + 1, normal[0], normal[1], normal[2]) + radius))
const pointHeight = this.generator.noise.getNoise3D(this.level + 1, normal[0], normal[1], normal[2])
const pos = mulv3(normal, (pointHeight - 1) + radius)
vertices[vertexPointer * 3] = pos[0]
vertices[vertexPointer * 3 + 1] = pos[1]
@ -78,24 +79,47 @@ class CubeFace {
textureCoords[vertexPointer * 2] = j * (1 / VERTICES)
textureCoords[vertexPointer * 2 + 1] = i * (1 / VERTICES)
if (i === VERTICES / 2 && j === VERTICES / 2) {
if (i === Math.floor(VERTICES / 2) && j === Math.floor(VERTICES / 2)) {
this.center = pos
}
}
}
for (let gz = 0, pointer = 0; gz < VERTICES - 1; gz++) {
for (let gz = 0; gz < VERTICES - 1; gz++) {
for (let gx = 0; gx < VERTICES - 1; gx++) {
const topLeft = (gz * VERTICES) + gx
const topRight = topLeft + 1
const bottomLeft = ((gz + 1) * VERTICES) + gx
const bottomRight = bottomLeft + 1
indices[pointer++] = topLeft
indices[pointer++] = bottomLeft
indices[pointer++] = topRight
indices[pointer++] = topRight
indices[pointer++] = bottomLeft
indices[pointer++] = bottomRight
if (gx % 2 !== 0) {
if (gz % 2 === 0) {
// x-x
// |/
// x x
indices.push(topRight, topLeft, bottomLeft)
indices.push(bottomLeft, bottomRight, topRight)
} else {
// x-x
// \|
// x x
indices.push(bottomRight, topRight, topLeft)
indices.push(topLeft, bottomLeft, bottomRight)
}
} else {
if (gz % 2 === 0) {
// x x
// |\
// x-x
indices.push(topLeft, bottomLeft, bottomRight)
indices.push(bottomRight, topRight, topLeft)
} else {
// x x
// /|
// x-x
indices.push(bottomLeft, bottomRight, topRight)
indices.push(topRight, topLeft, bottomLeft)
}
}
}
}

View File

@ -15,9 +15,9 @@ import { Material, Texture } from './engine/mesh/material'
import { GUIRenderer, GUIImage, Dim4 } from './engine/gui'
import { FontRenderer, GUIText, Font } from './engine/gui/font'
import { VoxelWorld, VoxelGenerator } from './engine/voxel'
import Atmosphere from './engine/components/planet/atmosphere'
import { CubePlanet, PlanetGenerator } from './engine/components/planet'
import Atmosphere from './engine/components/planet/atmosphere'
const game = Engine
const env = new Environment()
@ -82,22 +82,24 @@ async function pipeline () {
// terrain.setMaterial(material)
// Create and initialize the camera
const cam = new Camera([-1300.0, 1325.0, -1300.0], [0.8, -0.6, 0.0])
// [-1300.0, 1325.0, -1300.0], [0.8, -0.6, 0.0]
const cam = new Camera([-37, 1107, -1583], [1.5, -0.6, 0])
cam.updateProjection(game.gl)
// Create skybox
const skybox = new Skybox('skybox', cam.farPlane / 2)
// const skybox = new Skybox('skybox', cam.farPlane / 2)
// Load textures and generate a mesh
await skybox.initialize(game.gl)
// await skybox.initialize(game.gl)
// Voxel test
// let voxgen = new VoxelGenerator(hmap, material)
// let block = new VoxelWorld(voxgen)
// Planet test
const planet = new CubePlanet([0.0, 0.0, 0.0], new PlanetGenerator(16, 1000, hmap))
const atmosphere = new Atmosphere([0.0, 0.0, 0.0], 1000, 1025, [0.650, 0.570, 0.475])
const planet = new CubePlanet([0.0, 0.0, 0.0], new PlanetGenerator(15, 1000, hmap))
const atmosphere = new Atmosphere([0.0, 0.0, 0.0], 1000, 1050, [0.650, 0.570, 0.475])
planet.material = material
// Update function for camera and terrain
@ -115,6 +117,10 @@ async function pipeline () {
cam.processKeyboard(3, dt)
}
if (game.input.isPressed('c')) {
console.log(cam.pos, cam.rotation)
}
// Panning
if (game.input.mouseMoved && game.input.mouse.btn0) {
cam.processMouseMove(game.input.mouseOffset)