Skip to content

Commit

Permalink
Revert "Allocate textures holding color and visibility to be big enou…
Browse files Browse the repository at this point in the history
…gh to hold the correct number of tree indices. (#313)"

This reverts commit 4ff309b.
  • Loading branch information
dragly committed Mar 26, 2020
1 parent 51cf181 commit fff8cb8
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 64 deletions.
16 changes: 0 additions & 16 deletions viewer/src/__tests__/utils/determinePowerOfTwoDimensions.test.ts

This file was deleted.

Expand Up @@ -10,7 +10,7 @@ import { createEmptySector } from '../../../models/cad/emptySector';
import { createMaterials } from '../../../../views/threejs/cad/materials';
import 'jest-extended';

const materials = createMaterials(10);
const materials = createMaterials();

describe('consumeSectorDetailed', () => {
const metadata: SectorMetadata = {
Expand Down
Expand Up @@ -9,7 +9,7 @@ import { consumeSectorSimple } from '../../../../views/threejs/cad/consumeSector
import { createMaterials } from '../../../../views/threejs/cad/materials';
import 'jest-extended';

const materials = createMaterials(64);
const materials = createMaterials();

describe('consumeSectorDetailed', () => {
const metadata: SectorMetadata = {
Expand Down
14 changes: 0 additions & 14 deletions viewer/src/__tests__/views/threejs/cad/materials.test.ts

This file was deleted.

3 changes: 2 additions & 1 deletion viewer/src/__tests__/views/threejs/cad/primitives.test.ts
Expand Up @@ -8,8 +8,9 @@ import { PrimitiveAttributes } from '../../../../workers/types/parser.types';
import { createEmptySector } from '../../../models/cad/emptySector';
import { createMaterials } from '../../../../views/threejs/cad/materials';

const materials = createMaterials();

describe('createPrimitives', () => {
const materials = createMaterials(64);
let emptySector: Sector;

beforeEach(() => {
Expand Down
18 changes: 0 additions & 18 deletions viewer/src/utils/determinePowerOfTwoDimensions.ts

This file was deleted.

3 changes: 1 addition & 2 deletions viewer/src/views/threejs/cad/CadNode.ts
Expand Up @@ -70,8 +70,7 @@ export class CadNode extends THREE.Object3D {
super();
this.type = 'CadNode';
this.name = 'Sector model';
const treeIndexCount = model.scene.maxTreeIndex + 1;
this._materialManager = new MaterialManager(treeIndexCount, options ? options.nodeAppearance : undefined);
this._materialManager = new MaterialManager(options ? options.nodeAppearance : undefined);

const rootSector = new RootSectorNode(model, this._materialManager.materials);
this._repository = new CachedRepository(model);
Expand Down
4 changes: 2 additions & 2 deletions viewer/src/views/threejs/cad/MaterialManager.ts
Expand Up @@ -26,8 +26,8 @@ export class MaterialManager {
public readonly materials: Readonly<Materials>;
private readonly _options?: NodeAppearance;

constructor(treeIndexCount: number, options?: NodeAppearance) {
this.materials = createMaterials(treeIndexCount);
constructor(options?: NodeAppearance) {
this.materials = createMaterials();
this._options = options;
this.setRenderMode(RenderMode.Color);
}
Expand Down
20 changes: 11 additions & 9 deletions viewer/src/views/threejs/cad/materials.ts
Expand Up @@ -5,7 +5,6 @@
import * as THREE from 'three';
import { sectorShaders, shaderDefines } from './shaders';
import { RenderMode } from '../materials';
import { determinePowerOfTwoDimensions } from '../../../utils/determinePowerOfTwoDimensions';

export interface Materials {
// Materials
Expand All @@ -29,15 +28,18 @@ export interface Materials {
overrideVisibilityPerTreeIndex: THREE.DataTexture;
}

export function createMaterials(treeIndexCount: number): Materials {
const textureDims = determinePowerOfTwoDimensions(treeIndexCount);
const textureElementCount = textureDims.width * textureDims.height;
export function createMaterials(): Materials {
const pixelCount = 2048;
const colorCount = pixelCount * pixelCount;
const visibilityCount = pixelCount * pixelCount;

const colors = new Uint8Array(4 * textureElementCount);
const visibility = new Uint8Array(4 * textureElementCount);
visibility.fill(255);
const overrideColorPerTreeIndex = new THREE.DataTexture(colors, textureDims.width, textureDims.height);
const overrideVisibilityPerTreeIndex = new THREE.DataTexture(visibility, textureDims.width, textureDims.height);
const colors = new Uint8Array(4 * colorCount);
const visibility = new Uint8Array(4 * visibilityCount);
for (let i = 0; i < 4 * visibilityCount; i++) {
visibility[i] = 255;
}
const overrideColorPerTreeIndex = new THREE.DataTexture(colors, pixelCount, pixelCount);
const overrideVisibilityPerTreeIndex = new THREE.DataTexture(visibility, pixelCount, pixelCount);

const boxMaterial = new THREE.ShaderMaterial({
name: 'Primitives (Box)',
Expand Down

0 comments on commit fff8cb8

Please sign in to comment.