mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2025-04-12 15:00:22 +08:00
Removed Atlas
, moved occlusion
from Core to Editor
This commit is contained in:
parent
00389813bf
commit
a7838305ca
@ -1,4 +1,4 @@
|
||||
import { Atlas, TAtlasBlock } from './atlas';
|
||||
import { Atlas, TAtlasBlock } from '../../Editor/src/atlas';
|
||||
import { RGBA, RGBA_255, RGBAUtil } from './colour';
|
||||
import { AppMath } from './math';
|
||||
import { OtS_FaceVisibility } from './ots_voxel_mesh_neighbourhood';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Atlas, TAtlasBlock } from './atlas';
|
||||
import { Atlas, TAtlasBlock } from '../../Editor/src/atlas';
|
||||
import { AtlasPalette } from './block_assigner';
|
||||
import { BlockInfo } from './block_atlas';
|
||||
import { RGBA_255, RGBAUtil } from './colour';
|
||||
|
23
Core/src/block_registry.ts
Normal file
23
Core/src/block_registry.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { RGBA } from "./colour"
|
||||
|
||||
export type OtS_BlockData = {
|
||||
north: RGBA,
|
||||
south: RGBA,
|
||||
up: RGBA,
|
||||
down: RGBA,
|
||||
east: RGBA,
|
||||
west: RGBA,
|
||||
};
|
||||
|
||||
export class OtS_BlockRegistry {
|
||||
private _blocks: Map<string, OtS_BlockData>;
|
||||
|
||||
public constructor() {
|
||||
this._blocks = new Map();
|
||||
}
|
||||
|
||||
public register(blockName: string, blockData: OtS_BlockData) {
|
||||
this._blocks.set(blockName, blockData);
|
||||
return this;
|
||||
}
|
||||
}
|
@ -24,12 +24,12 @@ test('rayIntersectTriangle x-axis #2', () => {
|
||||
origin: new Vector3(1, 0, 0),
|
||||
axis: Axes.x,
|
||||
};
|
||||
const tri = new Triangle(
|
||||
new Vector3(0, -1, -1),
|
||||
new Vector3(0, 0, 1),
|
||||
new Vector3(0, 1, -1),
|
||||
);
|
||||
const intersects = rayIntersectTriangle(ray, tri.v0, tri.v1, tri.v2);
|
||||
|
||||
const v0 = new Vector3(0, -1, -1);
|
||||
const v1 = new Vector3(0, 0, 1);
|
||||
const v2 = new Vector3(0, 1, -1);
|
||||
|
||||
const intersects = rayIntersectTriangle(ray, v0, v1, v2);
|
||||
expect(intersects).toBeUndefined();
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { RGBA } from './colour';
|
||||
import { AppTypes, AppUtil, UV } from './util';
|
||||
import { ASSERT } from './util/error_util';
|
||||
import { RGBA } from '../../Core/src/colour';
|
||||
import { AppTypes, AppUtil, UV } from '../../Core/src/util';
|
||||
import { ASSERT } from '../../Core/src/util/error_util';
|
||||
|
||||
export type TAtlasBlockFace = {
|
||||
name: string,
|
@ -1,31 +1,23 @@
|
||||
import { OtS_Offset, OtS_VoxelMesh_Neighbourhood } from './ots_voxel_mesh_neighbourhood';
|
||||
import { ASSERT } from './util/error_util';
|
||||
import { Vector3 } from './vector';
|
||||
import { OtS_Offset, OtS_VoxelMesh_Neighbourhood } from '../../../Core/src/ots_voxel_mesh_neighbourhood';
|
||||
import { ASSERT } from '../../../Core/src/util/error_util';
|
||||
import { Vector3 } from '../../../Core/src/vector';
|
||||
|
||||
export class OcclusionManager {
|
||||
export class OtSE_AmbientOcclusion {
|
||||
private _occlusionNeighboursIndices!: number[]; // Ew
|
||||
private _occlusions: number[];
|
||||
private _localNeighbourhoodCache: number[];
|
||||
private _occlusionsSetup: boolean;
|
||||
|
||||
private static _instance: OcclusionManager;
|
||||
public static get Get() {
|
||||
private static _instance: OtSE_AmbientOcclusion;
|
||||
private static get _Get() {
|
||||
return this._instance || (this._instance = new this());
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
this._occlusionsSetup = false;
|
||||
this._setupOcclusions();
|
||||
this._occlusions = new Array<number>(6 * 4 * 4);
|
||||
this._localNeighbourhoodCache = Array<number>(27);
|
||||
}
|
||||
|
||||
public getBlankOcclusions() {
|
||||
return new Array<number>(96).fill(1.0);
|
||||
}
|
||||
|
||||
// Assume's buffer is of length 96
|
||||
public getOcclusions(buffer: Float32Array, centre: Vector3, voxelMeshNeighbourhood: OtS_VoxelMesh_Neighbourhood): void {
|
||||
public static GetOcclusions(buffer: Float32Array, centre: Vector3, voxelMeshNeighbourhood: OtS_VoxelMesh_Neighbourhood): void {
|
||||
// Cache local neighbours
|
||||
const neighbourData = voxelMeshNeighbourhood.getNeighbours(centre.x, centre.y, centre.z);
|
||||
if (neighbourData === undefined) {
|
||||
@ -34,8 +26,9 @@ export class OcclusionManager {
|
||||
return;
|
||||
}
|
||||
|
||||
const localNeighbourhoodCache = new Array<number>(27);
|
||||
for (let i = 0; i < 27; ++i) {
|
||||
this._localNeighbourhoodCache[i] = (neighbourData & (1 << i)) > 0 ? 1 : 0;
|
||||
localNeighbourhoodCache[i] = (neighbourData & (1 << i)) > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
// For each face
|
||||
@ -44,8 +37,8 @@ export class OcclusionManager {
|
||||
let numNeighbours = 0;
|
||||
let occlusionValue = 1.0;
|
||||
for (let i = 0; i < 2; ++i) {
|
||||
const neighbourIndex = this._occlusionNeighboursIndices[this._getOcclusionMapIndex(f, v, i)];
|
||||
numNeighbours += this._localNeighbourhoodCache[neighbourIndex];
|
||||
const neighbourIndex = this._Get._occlusionNeighboursIndices[this._GetOcclusionMapIndex(f, v, i)];
|
||||
numNeighbours += localNeighbourhoodCache[neighbourIndex];
|
||||
}
|
||||
// If both edge blocks along this vertex exist,
|
||||
// assume corner exists (even if it doesnt)
|
||||
@ -54,25 +47,21 @@ export class OcclusionManager {
|
||||
if (numNeighbours == 2) {
|
||||
++numNeighbours;
|
||||
} else {
|
||||
const neighbourIndex = this._occlusionNeighboursIndices[this._getOcclusionMapIndex(f, v, 2)];
|
||||
numNeighbours += this._localNeighbourhoodCache[neighbourIndex];
|
||||
const neighbourIndex = this._Get._occlusionNeighboursIndices[this._GetOcclusionMapIndex(f, v, 2)];
|
||||
numNeighbours += localNeighbourhoodCache[neighbourIndex];
|
||||
}
|
||||
|
||||
// Convert from occlusion denoting the occlusion factor to the
|
||||
// attenuation in light value: 0 -> 1.0, 1 -> 0.8, 2 -> 0.6, 3 -> 0.4
|
||||
occlusionValue = 1.0 - 0.2 * numNeighbours;
|
||||
|
||||
|
||||
const baseIndex = f * 16 + v;
|
||||
this._occlusions[baseIndex + 0] = occlusionValue;
|
||||
this._occlusions[baseIndex + 4] = occlusionValue;
|
||||
this._occlusions[baseIndex + 8] = occlusionValue;
|
||||
this._occlusions[baseIndex + 12] = occlusionValue;
|
||||
buffer[baseIndex + 0] = occlusionValue;
|
||||
buffer[baseIndex + 4] = occlusionValue;
|
||||
buffer[baseIndex + 8] = occlusionValue;
|
||||
buffer[baseIndex + 12] = occlusionValue;
|
||||
}
|
||||
}
|
||||
|
||||
buffer.set(this._occlusions, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
private _setupOcclusions() {
|
||||
@ -134,7 +123,7 @@ export class OcclusionManager {
|
||||
for (let i = 0; i < 6; ++i) {
|
||||
for (let j = 0; j < 4; ++j) {
|
||||
for (let k = 0; k < 3; ++k) {
|
||||
const index = this._getOcclusionMapIndex(i, j, k);
|
||||
const index = OtSE_AmbientOcclusion._GetOcclusionMapIndex(i, j, k);
|
||||
const neighbour = occlusionNeighbours[i][j][k];
|
||||
this._occlusionNeighboursIndices[index] = OtS_VoxelMesh_Neighbourhood.getNeighbourIndex(neighbour.x as OtS_Offset, neighbour.y as OtS_Offset, neighbour.z as OtS_Offset);
|
||||
}
|
||||
@ -144,7 +133,7 @@ export class OcclusionManager {
|
||||
this._occlusionsSetup = true;
|
||||
}
|
||||
|
||||
private _getOcclusionMapIndex(faceIndex: number, vertexIndex: number, offsetIndex: number): number {
|
||||
private static _GetOcclusionMapIndex(faceIndex: number, vertexIndex: number, offsetIndex: number): number {
|
||||
return (12 * faceIndex) + (3 * vertexIndex) + offsetIndex;
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ import { GeometryTemplates } from "./geometry";
|
||||
import { AttributeData } from "./render_buffer";
|
||||
import { AppUtil, TOptional } from "../../../Core/src/util";
|
||||
import { AppConstants } from "../../../Core/src/constants";
|
||||
import { OcclusionManager } from "../../../Core/src/occlusion";
|
||||
import { OtSE_AmbientOcclusion } from "./ambient_occlusion";
|
||||
import { OtS_Voxel, OtS_VoxelMesh } from '../../../Core/src/ots_voxel_mesh';
|
||||
import { OtS_VoxelMesh_Neighbourhood } from '../../../Core/src/ots_voxel_mesh_neighbourhood';
|
||||
|
||||
@ -109,7 +109,7 @@ export class BufferGenerator_VoxelMesh {
|
||||
|
||||
for (let i = 0; i < numBufferVoxels; ++i) {
|
||||
const voxel = this._voxels[i + voxelsStartIndex];
|
||||
OcclusionManager.Get.getOcclusions(voxelOcclusionArray, voxel.position, this._neighbourhood);
|
||||
OtSE_AmbientOcclusion.GetOcclusions(voxelOcclusionArray, voxel.position, this._neighbourhood);
|
||||
|
||||
newBuffer.occlusion.data.set(voxelOcclusionArray, i * AppConstants.VoxelMeshBufferComponentOffsets.OCCLUSION);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import { Vector3 } from '../../../Core/src/vector';
|
||||
import { RenderMeshParams, RenderNextBlockMeshChunkParams, RenderNextVoxelMeshChunkParams } from '../worker/worker_types';
|
||||
import { UIUtil } from '../util/ui_util';
|
||||
import { TAxis } from '../../../Core/src/util/type_util';
|
||||
import { Atlas } from '../../../Core/src/atlas';
|
||||
import { Atlas } from '../atlas';
|
||||
import { Material } from '../../../Core/src/materials';
|
||||
|
||||
/* eslint-disable */
|
||||
|
Loading…
x
Reference in New Issue
Block a user