From e146916be355dc521e2ddd220506df21e222beb0 Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Mon, 26 Jun 2023 18:38:28 +0000 Subject: [PATCH 1/8] Added Types for Renderer.ts Signed-off-by: Adithya Krishna --- package-lock.json | 1 + src/WebGL/Renderer.ts | 88 +++++++++++++++++++++---------------------- tsconfig.json | 3 +- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index ba60e82c7..4c9354884 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "3dmol", "version": "2.0.3", + "hasInstallScript": true, "license": "BSD-3-Clause", "dependencies": { "iobuffer": "^5.3.1", diff --git a/src/WebGL/Renderer.ts b/src/WebGL/Renderer.ts index 7eecef78e..b516e2e77 100644 --- a/src/WebGL/Renderer.ts +++ b/src/WebGL/Renderer.ts @@ -18,7 +18,7 @@ import { } from "./materials"; import { Matrix4, Vector3, Matrix3 } from "./math"; import { Mesh, Line, Sprite } from "./objects"; -import { ShaderLib, ShaderUtils } from "./shaders"; +import { Shader, ShaderLib, ShaderUtils, Uniform } from "./shaders"; import { SpritePlugin } from "./SpritePlugin"; export class Renderer { @@ -26,7 +26,7 @@ export class Renderer { col: any; rows: any; cols: any; - context = null; + context = null as RenderingContext; devicePixelRatio = 1.0; //set in setSize domElement: HTMLCanvasElement; autoClear = true; @@ -57,23 +57,23 @@ export class Renderer { // webgl rednering context private _gl: WebGLRenderingContext | WebGL2RenderingContext; // internal properties - private _programs = []; + private _programs: any[] = []; private _programs_counter = 0; private _webglversion = 1; // internal state cache - private _currentProgram = null; + private _currentProgram: Shader = null; private _currentMaterialId = -1; - private _currentGeometryGroupHash = null; - private _currentCamera = null; + private _currentGeometryGroupHash: number = null; + private _currentCamera: Camera = null ; private _geometryGroupCounter = 0; // GL state cache - private _oldDoubleSided = -1 as number | boolean; - private _oldFlipSided = -1 as number | boolean; - private _oldBlending = -1; - private _oldDepthTest = -1; - private _oldDepthWrite = -1; - private _oldPolygonOffset = null; - private _oldLineWidth = null; + private _oldDoubleSided: number | boolean = -1; + private _oldFlipSided: number | boolean = -1; + private _oldBlending: number | boolean = -1; + private _oldDepthTest: number | boolean = -1; + private _oldDepthWrite: number | boolean = -1; + private _oldPolygonOffset: number = null; + private _oldLineWidth: number = null; private _viewportWidth = 0; private _viewportHeight = 0; private _currentWidth = 0; @@ -120,15 +120,15 @@ export class Renderer { sprites = new SpritePlugin(); - //screensshader related variables - private _screenshader = null; - private _vertexattribpos = null; - private _screenQuadVBO = null; + // ScreenShader related variables + private _screenshader = null as Shader; + private _vertexattribpos: number = null; + private _screenQuadVBO: WebGLBuffer = null; //framebuffer variables - private _fb = null; - private _targetTexture = null; - private _depthTexture = null; + private _fb: WebGLFramebuffer = null; + private _targetTexture: WebGLTexture = null; + private _depthTexture: WebGLTexture = null; private _canvas: any; private _precision: any; private _alpha: any; @@ -143,11 +143,11 @@ export class Renderer { private _outlineStickImposterMaterial: StickImposterOutlineMaterial; private _outlineEnabled: boolean; private _extInstanced: any; - private _extFragDepth: ReturnType; - private _extFloatLinear: ReturnType; - private _extColorBufferFloat: ReturnType; + private _extFragDepth: Partial>; + private _extFloatLinear: Partial>; + private _extColorBufferFloat: Partial>; - constructor(parameters) { + constructor(parameters: { antialias?: any; preserveDrawingBuffer?: any; premultipliedAlpha?: any; id?: any; row?: any; col?: any; rows?: any; cols?: any; canvas?: any; containerWidth?: number; containerHeight?: number; precision?: any; alpha?: any; stencil?: any; clearColor?: any; clearAlpha?: any; outline?: any; }) { parameters = parameters || {}; this.row = parameters.row; this.col = parameters.col; @@ -231,14 +231,14 @@ export class Renderer { return this._precision; } - setClearColorHex(hex, alpha) { + setClearColorHex(hex: number, alpha: number) { this._clearColor.setHex(hex); this._clearAlpha = alpha; this._gl.clearColor(this._clearColor.r, this._clearColor.g, this._clearColor.b, this._clearAlpha); } - enableOutline(parameters) { + enableOutline(parameters: Record & { width?: number; pushback?: number; }) { this._outlineMaterial = new MeshOutlineMaterial(parameters); this._outlineSphereImposterMaterial = new SphereImposterOutlineMaterial( parameters @@ -272,7 +272,7 @@ export class Renderer { } } - setSize(width, height) { + setSize(width: number, height: number) { //zooming (in the browser) changes the pixel ratio and width/height this.devicePixelRatio = window.devicePixelRatio !== undefined ? window.devicePixelRatio : 1; @@ -310,7 +310,7 @@ export class Renderer { this.initFrameBuffer(); } - clear(color, depth, stencil) { + clear(color: boolean, depth: boolean, stencil: boolean) { var bits = 0; if (color === undefined || color) bits |= this._gl.COLOR_BUFFER_BIT; if (depth === undefined || depth) bits |= this._gl.DEPTH_BUFFER_BIT; @@ -318,11 +318,11 @@ export class Renderer { this._gl.clear(bits); } - clearTarget(color, depth, stencil) { + clearTarget(color: boolean, depth: boolean, stencil: boolean) { this.clear(color, depth, stencil); } - setMaterialFaces(material, reflected) { + setMaterialFaces(material: { side: number; imposter: any; }, reflected: any) { var doubleSided = material.side === DoubleSide; var flipSided = material.side === BackSide; @@ -353,7 +353,7 @@ export class Renderer { this._gl.cullFace(this._gl.BACK); } - setDepthTest(depthTest) { + setDepthTest(depthTest: number | boolean) { if (this._oldDepthTest !== depthTest) { if (depthTest) { this._gl.enable(this._gl.DEPTH_TEST); @@ -365,14 +365,14 @@ export class Renderer { } } - setDepthWrite(depthWrite) { + setDepthWrite(depthWrite: number | boolean) { if (this._oldDepthWrite !== depthWrite) { this._gl.depthMask(depthWrite); this._oldDepthWrite = depthWrite; } } - setBlending(blending) { + setBlending(blending: number | boolean) { if (!blending) { this._gl.disable(this._gl.BLEND); } else { @@ -392,7 +392,7 @@ export class Renderer { // material object after attaching prgm // We need to attach appropriate uniform variables to material after shaders // have been chosen - initMaterial(material, lights, fog, objects) { + initMaterial(material: { addEventListener: (arg0: string, arg1: any) => void; shaderID: any; vertexShader: string; fragmentShader: string; uniforms: Uniform; wireframe: any; imposter: any; volumetric: any; program: any; }, lights: any, fog: any, objects: any) { material.addEventListener("dispose", this.onMaterialDispose.bind(this)); var parameters, shaderID; @@ -421,7 +421,7 @@ export class Renderer { ); } - renderBuffer(camera, lights, fog, material, geometryGroup, object) { + renderBuffer(camera: any, lights: any, fog: any, material: MeshOutlineMaterial | SphereImposterOutlineMaterial | StickImposterOutlineMaterial, geometryGroup: { id: number; __webglVertexBuffer: WebGLBuffer; __webglColorBuffer: WebGLBuffer; __webglNormalBuffer: WebGLBuffer; __webglOffsetBuffer: WebGLBuffer; __webglRadiusBuffer: WebGLBuffer; __webglFaceBuffer: WebGLBuffer; radiusArray: string | any[]; lineidx: any; __webglLineBuffer: WebGLBuffer; faceidx: any; vertices: any; }, object: any) { if (!material.visible) return; var program, attributes; @@ -571,7 +571,7 @@ export class Renderer { } } - render(scene, camera, forceClear?) { + render(scene: { __lights: any; fog: any; updateMatrixWorld: () => void; __webglObjects: any; }, camera: Camera, forceClear?: undefined) { if (camera instanceof Camera === false) { console.error("Renderer.render: camera is not an instance of Camera."); return; @@ -872,7 +872,7 @@ export class Renderer { this._gl.drawArrays(this._gl.TRIANGLES, 0, 6); } - initWebGLObjects(scene) { + initWebGLObjects(scene: { __lights?: any; fog?: any; updateMatrixWorld?: () => void; __webglObjects: any; __webglObjectsImmediate?: any; __webglSprites?: any; __webglFlares?: any; __objectsAdded?: any; __objectsRemoved?: any; }) { if (!scene.__webglObjects) { scene.__webglObjects = []; scene.__webglObjectsImmediate = []; @@ -915,7 +915,7 @@ export class Renderer { return 1; } - getAspect(width, height) { + getAspect(width: number, height: number) { if (width == undefined || height == undefined) { width = this._canvas.width; height = this._canvas.height; @@ -934,7 +934,7 @@ export class Renderer { return aspect; } - setTexture(texture, slot, is3D) { + setTexture(texture: { needsUpdate: boolean; __webglInit: boolean; addEventListener: (arg0: string, arg1: any) => void; __webglTexture: WebGLTexture; flipY: number | boolean; premultiplyAlpha: number | boolean; unpackAlignment: number | boolean; format: any; type: any; image: any; onUpdate: () => void; }, slot: number, is3D: any) { if (texture.needsUpdate) { if (!texture.__webglInit) { texture.__webglInit = true; @@ -1024,7 +1024,7 @@ export class Renderer { return !this.isWebGL1(); } - private enableAttribute(attribute) { + private enableAttribute(attribute: number) { if (!this._enabledAttributes[attribute]) { this._gl.enableVertexAttribArray(attribute); this._enabledAttributes[attribute] = true; @@ -1040,7 +1040,7 @@ export class Renderer { } } - private setPolygonOffset(polygonOffset, offsetFactor, offsetUnits) { + private setPolygonOffset(polygonOffset: number, offsetFactor: any, offsetUnits: any) { if (this._oldPolygonOffset !== polygonOffset) { if (polygonOffset) this._gl.enable(this._gl.POLYGON_OFFSET_FILL); else this._gl.disable(this._gl.POLYGON_OFFSET_FILL); @@ -1054,7 +1054,7 @@ export class Renderer { } } - private deallocateGeometry(geometry) { + private deallocateGeometry(geometry: { __webglInit: any; __webglVertexBuffer: WebGLBuffer; __webglColorBuffer: WebGLBuffer; geometryGroups: any[]; groups: any; }) { geometry.__webglInit = undefined; if (geometry.__webglVertexBuffer !== undefined) @@ -1085,7 +1085,7 @@ export class Renderer { } } - private deallocateMaterial(material) { + private deallocateMaterial(material: { program: any; }) { var program = material.program; if (program === undefined) return; @@ -1136,7 +1136,7 @@ export class Renderer { } } - private deallocateTexture(texture) { + private deallocateTexture(texture: { image: { __webglTextureCube: WebGLTexture; }; __webglInit: boolean; __webglTexture: WebGLTexture; }) { if (texture.image && texture.image.__webglTextureCube) { // cube texture diff --git a/tsconfig.json b/tsconfig.json index 96533d9ed..b065b19d0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "declarationDir": "build/types", - "noImplicitAny": false, + "noImplicitAny": true, "outDir": "tmp", "module": "esnext", "target": "ES2015", @@ -9,6 +9,7 @@ "sourceMap": true, "declaration": true, "suppressImplicitAnyIndexErrors": true, + "ignoreDeprecations": "5.0", "noUnusedLocals": false, "moduleResolution": "node", "lib": [ From 1db86dfc2e7970fc6a9bd1ea6572e32545e71450 Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Tue, 27 Jun 2023 16:28:35 +0000 Subject: [PATCH 2/8] Types For RendererTS Signed-off-by: Adithya Krishna --- src/WebGL/Renderer.ts | 108 +++++++++++++++++--------------- src/WebGL/core/Geometry.ts | 7 +++ src/WebGL/materials/Material.ts | 6 ++ tsconfig.json | 3 +- 4 files changed, 71 insertions(+), 53 deletions(-) diff --git a/src/WebGL/Renderer.ts b/src/WebGL/Renderer.ts index b516e2e77..96f342292 100644 --- a/src/WebGL/Renderer.ts +++ b/src/WebGL/Renderer.ts @@ -9,9 +9,10 @@ import { RGBAFormat, NearestFilter, } from "./constants/TextureConstants"; -import { Light } from "./core"; +import { GeometryGroup, Light, Scene } from "./core"; import { Color } from "../colors"; import { + Material, MeshOutlineMaterial, SphereImposterOutlineMaterial, StickImposterOutlineMaterial, @@ -92,29 +93,29 @@ export class Renderer { ambient: [0, 0, 0], directional: { length: 0, - colors: [], - positions: [], + colors: Color, + positions: Array, }, point: { length: 0, - colors: [], - positions: [], - distances: [], + colors: Color, + positions: Array, + distances: Array, }, spot: { length: 0, - colors: [], - positions: [], - distances: [], - directions: [], - anglesCos: [], - exponents: [], + colors: Color, + positions: Array, + distances: Array, + directions: Array, + anglesCos: Array, + exponents: Array, }, hemi: { length: 0, - skyColors: [], - groundColors: [], - positions: [], + skyColors: Color, + groundColors: Color, + positions: Array, }, }; @@ -365,7 +366,7 @@ export class Renderer { } } - setDepthWrite(depthWrite: number | boolean) { + setDepthWrite(depthWrite: boolean) { if (this._oldDepthWrite !== depthWrite) { this._gl.depthMask(depthWrite); this._oldDepthWrite = depthWrite; @@ -404,7 +405,12 @@ export class Renderer { material.vertexShader = shader.vertexShader; material.fragmentShader = shader.fragmentShader; material.uniforms = ShaderUtils.clone(shader.uniforms); - // TODO: set material uniforms to shader uniform variables + // Set material uniforms to shader uniform variables + for (var uniformName in material.uniforms) { + if (shader.uniforms.hasOwnProperty(uniformName)) { + shader.uniforms[uniformName].value = material.uniforms[uniformName].value; + } + } } parameters = { @@ -426,8 +432,7 @@ export class Renderer { var program, attributes; - // Sets up proper vertex and fragment shaders and attaches them to webGL - // program + // Sets up proper vertex and fragment shaders and attaches them to webGL program // Also sets appropriate uniform variables program = this.setProgram(camera, lights, fog, material, object, this); if(!program) return; @@ -444,8 +449,7 @@ export class Renderer { updateBuffers = true; } - // rebind shader attributes to appropriate (and already initialized) gl - // buffers + // Rebind shader attributes to appropriate (and already initialized) gl buffers if (updateBuffers) { this.disableAttributes(); @@ -858,7 +862,7 @@ export class Renderer { this._currentProgram = this._screenshader; // disable depth test this.setDepthTest(-1); - this.setDepthWrite(-1); + this.setDepthWrite(false); // bind vertexarray buffer and texture this._gl.bindBuffer(this._gl.ARRAY_BUFFER, this._screenQuadVBO); @@ -1151,7 +1155,7 @@ export class Renderer { } } - private onGeometryDispose(event) { + private onGeometryDispose(event: { target: any; }) { var geometry = event.target; geometry.removeEventListener("dispose", this.onGeometryDispose); @@ -1160,7 +1164,7 @@ export class Renderer { this.info.memory.geometries--; } - private onTextureDispose(event) { + private onTextureDispose(event: { target: any; }) { var texture = event.target; texture.removeEventListener("dispose", this.onTextureDispose); @@ -1170,7 +1174,7 @@ export class Renderer { this.info.memory.textures--; } - private onMaterialDispose(event) { + private onMaterialDispose(event: { target: any; }) { var material = event.target; material.removeEventListener("dispose", this.onMaterialDispose); @@ -1178,7 +1182,7 @@ export class Renderer { } // Compile and return shader - private getShader(type, str) { + private getShader(type: string, str: string) { var shader; if (!this.isWebGL1() && !str.startsWith("#version")) { @@ -1214,7 +1218,7 @@ export class Renderer { // Compile appropriate shaders (if necessary) from source code and attach to // gl program. - private buildProgram(fragmentShader, vertexShader, uniforms, parameters) { + private buildProgram(fragmentShader: string, vertexShader: string, uniforms: Record, parameters: { [x: string]: any; wireframe?: any; fragdepth?: any; volumetric?: any; }) { var p, pl, program, code; var chunks = []; @@ -1344,7 +1348,7 @@ export class Renderer { return program; } - private setProgram(camera, lights, fog, material, object, renderer) { + private setProgram(camera: Camera, lights: Light, fog: { color: any; near: any; far: any; }, material: any | Material, object: { _modelViewMatrix: Matrix4; _normalMatrix: { elements: Iterable; }; material: { texmatrix: { elements: any; }; unit: number; maxdepth: number; transfermax: any; transfermin: any; subsamples: any; transferfn: any; map: any; }; }, renderer: this) { if (material.needsUpdate) { if (material.program) this.deallocateMaterial(material); @@ -1507,7 +1511,7 @@ export class Renderer { // Objects adding - private addObject(object, scene) { + private addObject(object: Texture.properties, scene: { fog?: any; updateMatrixWorld?: () => void; }) { var g, gl, geometry, material, geometryGroup; if (!object.__webglInit) { @@ -1567,7 +1571,7 @@ export class Renderer { } } - private updateObject(object) { + private updateObject(object: { geometry: any; }) { var geometry = object.geometry, geometryGroup; @@ -1594,7 +1598,7 @@ export class Renderer { } } - private removeObject(object, scene) { + private removeObject(object: Mesh | Line | Sprite, scene: { fog?: any; updateMatrixWorld?: () => void; }) { if (object instanceof Mesh || object instanceof Line) this.removeInstances(scene.__webglObjects, object); else if (object instanceof Sprite) @@ -1603,19 +1607,19 @@ export class Renderer { object.__webglActive = false; } - private removeInstances(objList, object) { + private removeInstances(objList: any[], object: Mesh | Line) { for (var o = objList.length - 1; o >= 0; --o) { if (objList[o].object === object) objList.splice(o, 1); } } - private removeInstancesDirect(objList, object) { + private removeInstancesDirect(objList: any[], object: Sprite) { for (var o = objList.length - 1; o >= 0; --o) { if (objList[o] === object) objList.splice(o, 1); } } - private unrollBufferMaterial(globject) { + private unrollBufferMaterial(globject: { object: any; opaque: any; transparent: any; volumetric: any; blank: any; }) { var object = globject.object; var material = object.material; @@ -1639,7 +1643,7 @@ export class Renderer { } } - private setBuffers(geometryGroup, hint) { + private setBuffers(geometryGroup: GeometryGroup, hint: number) { var vertexArray = geometryGroup.vertexArray; var colorArray = geometryGroup.colorArray; @@ -1699,7 +1703,7 @@ export class Renderer { // Creates appropriate gl buffers for geometry chunk // TODO: do we need line buffer for mesh objects? // Also, can we integrate this with createLineBuffers? - private createMeshBuffers(geometryGroup) { + private createMeshBuffers(geometryGroup: GeometryGroup) { if (geometryGroup.radiusArray) { geometryGroup.__webglRadiusBuffer = this._gl.createBuffer(); } @@ -1716,14 +1720,14 @@ export class Renderer { this.info.memory.geometries++; } - private createLineBuffers(geometry) { + private createLineBuffers(geometry: GeometryGroup) { geometry.__webglVertexBuffer = this._gl.createBuffer(); geometry.__webglColorBuffer = this._gl.createBuffer(); this.info.memory.geometries++; } - private addBuffer(objlist, buffer, object) { + private addBuffer(objlist: { buffer: any; object: any; opaque: any; transparent: any; }[], buffer: GeometryGroup, object: Mesh | Line) { objlist.push({ buffer: buffer, object: object, @@ -1732,7 +1736,7 @@ export class Renderer { }); } - private setupMatrices(object, camera) { + private setupMatrices(object: { _modelViewMatrix: { multiplyMatrices: (arg0: any, arg1: any) => void; }; matrixWorld: any; _normalMatrix: { getInverse: (arg0: any) => void; transpose: () => void; }; }, camera: Camera) { object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld @@ -1743,11 +1747,11 @@ export class Renderer { } // Fallback filters for non-power-of-2 textures - private filterFallback(filter) { + private filterFallback(filter: any) { return this._gl.LINEAR; } - private setTextureParameters(textureType, texture) { + private setTextureParameters(textureType: number, texture: { needsUpdate?: boolean; addEventListener?: (arg0: string, arg1: any) => void; flipY?: number | boolean; premultiplyAlpha?: number | boolean; unpackAlignment?: number | boolean; format?: any; type?: any; image?: any; onUpdate?: () => void; magFilter?: any; minFilter?: any; }) { if (textureType == this._gl.TEXTURE_2D) { this._gl.texParameteri(textureType, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE); this._gl.texParameteri(textureType, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE); @@ -1780,7 +1784,7 @@ export class Renderer { // Map constants to WebGL constants - private paramToGL(p) { + private paramToGL(p: number) { if (p === UnsignedByteType) return this._gl.UNSIGNED_BYTE; if (p === RGBAFormat) return this._gl.RGBA; if (p === NearestFilter) return this._gl.NEAREST; @@ -1788,7 +1792,7 @@ export class Renderer { return 0; } - private setupLights(program, lights) { + private setupLights(program: any, lights: any) { var l, ll, light, @@ -1911,14 +1915,14 @@ export class Renderer { // rendering private renderObjects( - renderList, - reverse, - materialType, - camera, - lights, - fog, - useBlending, - material + renderList: string | any[], + reverse: boolean, + materialType: string, + camera: Camera, + lights: any, + fog: any, + useBlending: boolean, + material: MeshOutlineMaterial | SphereImposterOutlineMaterial | StickImposterOutlineMaterial ) { var webglObject, object, buffer, material, start, end, delta; @@ -1997,7 +2001,7 @@ export class Renderer { } } - private renderSprites(scene, camera, inFront) { + private renderSprites(scene: Scene, camera: Camera, inFront: boolean) { // Reset state once regardless // This should also fix cartoon render bug (after transparent surface // render) diff --git a/src/WebGL/core/Geometry.ts b/src/WebGL/core/Geometry.ts index fc41a8002..23fc6a915 100644 --- a/src/WebGL/core/Geometry.ts +++ b/src/WebGL/core/Geometry.ts @@ -17,6 +17,13 @@ export class GeometryGroup { lineidx: number = 0; __inittedArrays = false; useOffset: unknown; + __webglVertexBuffer: WebGLBuffer; + __webglColorBuffer: WebGLBuffer; + __webglNormalBuffer: WebGLBuffer; + __webglOffsetBuffer: WebGLBuffer; + __webglRadiusBuffer: WebGLBuffer; + __webglFaceBuffer: WebGLBuffer; + __webglLineBuffer: WebGLBuffer; constructor(id = 0) { this.id = id; diff --git a/src/WebGL/materials/Material.ts b/src/WebGL/materials/Material.ts index fb566d549..848995862 100644 --- a/src/WebGL/materials/Material.ts +++ b/src/WebGL/materials/Material.ts @@ -3,6 +3,7 @@ import { EventDispatcher } from "../core"; import type { Texture } from "../core"; import { Vector2, Vector3 } from "../math"; import { Color } from "../../colors"; +import { Sphere } from "WebGL/shapes"; /* * Line and Mesh material types * @constructor @@ -34,6 +35,11 @@ export class Material extends EventDispatcher { visible = true; needsUpdate = true; outline = false; + wireframe: any; + shaderID = null as string | null; + wireframeLinewidth?: number; + linewidth?: number; + sphere?: Sphere; setValues( values: Partial> = {} as any diff --git a/tsconfig.json b/tsconfig.json index b065b19d0..b94af1c56 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -35,5 +35,6 @@ "./src/WebGL/shaders/shaders.d.ts" ], "out": "doc/typescript" - } + }, + "skipLibCheck": true, } From b126ad32ec8cd0db4f773eb648858ddd4bbe4c1c Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Sun, 9 Jul 2023 11:44:59 +0000 Subject: [PATCH 3/8] Updated RendererTS Signed-off-by: Adithya Krishna --- src/WebGL/Renderer.ts | 94 +++++++++++++++++---------------- src/WebGL/materials/Material.ts | 5 -- tsconfig.json | 3 +- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/WebGL/Renderer.ts b/src/WebGL/Renderer.ts index 96f342292..feacff10a 100644 --- a/src/WebGL/Renderer.ts +++ b/src/WebGL/Renderer.ts @@ -9,9 +9,10 @@ import { RGBAFormat, NearestFilter, } from "./constants/TextureConstants"; -import { GeometryGroup, Light, Scene } from "./core"; +import { GeometryGroup, Light, Scene, Texture } from "./core"; import { Color } from "../colors"; import { + InstancedMaterial, Material, MeshOutlineMaterial, SphereImposterOutlineMaterial, @@ -19,7 +20,7 @@ import { } from "./materials"; import { Matrix4, Vector3, Matrix3 } from "./math"; import { Mesh, Line, Sprite } from "./objects"; -import { Shader, ShaderLib, ShaderUtils, Uniform } from "./shaders"; +import { Shader, ShaderLib, ShaderUtils, sprite, Uniform } from "./shaders"; import { SpritePlugin } from "./SpritePlugin"; export class Renderer { @@ -64,15 +65,15 @@ export class Renderer { // internal state cache private _currentProgram: Shader = null; private _currentMaterialId = -1; - private _currentGeometryGroupHash: number = null; + private _currentGeometryGroupHash: number = undefined; private _currentCamera: Camera = null ; private _geometryGroupCounter = 0; // GL state cache - private _oldDoubleSided: number | boolean = -1; - private _oldFlipSided: number | boolean = -1; - private _oldBlending: number | boolean = -1; - private _oldDepthTest: number | boolean = -1; - private _oldDepthWrite: number | boolean = -1; + private _oldDoubleSided: number | boolean = undefined; + private _oldFlipSided: number | boolean = undefined; + private _oldBlending: number | boolean = undefined; + private _oldDepthTest: number | boolean = undefined; + private _oldDepthWrite: number | boolean = undefined; private _oldPolygonOffset: number = null; private _oldLineWidth: number = null; private _viewportWidth = 0; @@ -354,7 +355,7 @@ export class Renderer { this._gl.cullFace(this._gl.BACK); } - setDepthTest(depthTest: number | boolean) { + setDepthTest(depthTest: boolean | undefined) { if (this._oldDepthTest !== depthTest) { if (depthTest) { this._gl.enable(this._gl.DEPTH_TEST); @@ -427,7 +428,7 @@ export class Renderer { ); } - renderBuffer(camera: any, lights: any, fog: any, material: MeshOutlineMaterial | SphereImposterOutlineMaterial | StickImposterOutlineMaterial, geometryGroup: { id: number; __webglVertexBuffer: WebGLBuffer; __webglColorBuffer: WebGLBuffer; __webglNormalBuffer: WebGLBuffer; __webglOffsetBuffer: WebGLBuffer; __webglRadiusBuffer: WebGLBuffer; __webglFaceBuffer: WebGLBuffer; radiusArray: string | any[]; lineidx: any; __webglLineBuffer: WebGLBuffer; faceidx: any; vertices: any; }, object: any) { + renderBuffer(camera: any, lights: any, fog: any, material: MeshOutlineMaterial | SphereImposterOutlineMaterial | StickImposterOutlineMaterial | InstancedMaterial, geometryGroup: { id: number; __webglVertexBuffer: WebGLBuffer; __webglColorBuffer: WebGLBuffer; __webglNormalBuffer: WebGLBuffer; __webglOffsetBuffer: WebGLBuffer; __webglRadiusBuffer: WebGLBuffer; __webglFaceBuffer: WebGLBuffer; radiusArray: string | any[]; lineidx: any; __webglLineBuffer: WebGLBuffer; faceidx: any; vertices: any; }, object: any) { if (!material.visible) return; var program, attributes; @@ -494,7 +495,7 @@ export class Renderer { // lambert shaders - draw triangles // TODO: make sure geometryGroup's face count is setup correctly if (object instanceof Mesh) { - if (material.shaderID === "instanced") { + if (material.shaderID === "instanced" && material instanceof InstancedMaterial) { var sphereGeometryGroup = material.sphere.geometryGroups[0]; if (updateBuffers) { this._gl.bindBuffer(this._gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer); @@ -537,7 +538,7 @@ export class Renderer { this._extInstanced.vertexAttribDivisorANGLE(attributes.offset, 0); this._extInstanced.vertexAttribDivisorANGLE(attributes.radius, 0); this._extInstanced.vertexAttribDivisorANGLE(attributes.color, 0); - } else if (material.wireframe) { + } else if (material.wireframe && material instanceof InstancedMaterial) { lineCount = geometryGroup.lineidx; this.setLineWidth(material.wireframeLinewidth); @@ -565,10 +566,10 @@ export class Renderer { } // basic shaders - draw lines - else if (object instanceof Line) { + else if (object instanceof Line && material instanceof InstancedMaterial) { lineCount = geometryGroup.vertices; - this.setLineWidth(material.linewidth); + this.setLineWidth(material.wireframeLinewidth); this._gl.drawArrays(this._gl.LINES, 0, lineCount); this.info.render.calls++; @@ -591,7 +592,7 @@ export class Renderer { // reset caching for this frame - this._currentMaterialId = -1; + this._currentMaterialId = undefined; this._lightsNeedUpdate = true; // update scene graph @@ -609,6 +610,7 @@ export class Renderer { camera.projectionMatrix, camera.matrixWorldInverse ); + scene.__webglObjects = []; // update WebGL objects @@ -667,7 +669,6 @@ export class Renderer { lights, fog, false, - material ); // Render embedded labels (sprites) @@ -682,7 +683,6 @@ export class Renderer { lights, fog, true, - material ); // transparent pass (back-to-front order) @@ -695,7 +695,6 @@ export class Renderer { lights, fog, true, - material ); //volumetric is separate @@ -710,7 +709,6 @@ export class Renderer { lights, fog, true, - material ); } @@ -861,7 +859,7 @@ export class Renderer { this._gl.useProgram(this._screenshader); this._currentProgram = this._screenshader; // disable depth test - this.setDepthTest(-1); + this.setDepthTest(undefined); this.setDepthWrite(false); // bind vertexarray buffer and texture @@ -894,7 +892,7 @@ export class Renderer { // Force buffer update during render // Hackish fix for initial cartoon-render-then-transparent-surface // bug - this._currentGeometryGroupHash = -1; + this._currentGeometryGroupHash = undefined; } while (scene.__objectsRemoved.length) { @@ -1511,7 +1509,7 @@ export class Renderer { // Objects adding - private addObject(object: Texture.properties, scene: { fog?: any; updateMatrixWorld?: () => void; }) { + private addObject(object: Record, scene: { fog?: any; updateMatrixWorld?: () => void; __webglSprites?: Sprite[]; __webglObjects?: any[] }) { var g, gl, geometry, material, geometryGroup; if (!object.__webglInit) { @@ -1599,12 +1597,19 @@ export class Renderer { } private removeObject(object: Mesh | Line | Sprite, scene: { fog?: any; updateMatrixWorld?: () => void; }) { - if (object instanceof Mesh || object instanceof Line) - this.removeInstances(scene.__webglObjects, object); - else if (object instanceof Sprite) - this.removeInstancesDirect(scene.__webglSprites, object); - - object.__webglActive = false; + if (object instanceof Mesh || object instanceof Line) { + if ('__webglObjects' in scene) { + this.removeInstances(scene.__webglObjects as any[], object); + } + } else if (object instanceof Sprite) { + if ('__webglSprites' in scene) { + this.removeInstancesDirect(scene.__webglSprites as any[], object); + } + } + + if ('__webglActive' in object) { + object['__webglActive'] = false; + } } private removeInstances(objList: any[], object: Mesh | Line) { @@ -1922,7 +1927,6 @@ export class Renderer { lights: any, fog: any, useBlending: boolean, - material: MeshOutlineMaterial | SphereImposterOutlineMaterial | StickImposterOutlineMaterial ) { var webglObject, object, buffer, material, start, end, delta; @@ -1930,8 +1934,8 @@ export class Renderer { if (reverse) { start = renderList.length - 1; - end = -1; - delta = -1; + end = undefined; + delta = undefined; } else { start = 0; end = renderList.length; @@ -2006,28 +2010,28 @@ export class Renderer { // This should also fix cartoon render bug (after transparent surface // render) - this._currentGeometryGroupHash = -1; + this._currentGeometryGroupHash = undefined; this._currentProgram = null; this._currentCamera = null; - this._oldBlending = -1; - this._oldDepthWrite = -1; - this._oldDepthTest = -1; - this._oldDoubleSided = -1; - this._currentMaterialId = -1; - this._oldFlipSided = -1; + this._oldBlending = undefined; + this._oldDepthWrite = undefined; + this._oldDepthTest = undefined; + this._oldDoubleSided = undefined; + this._currentMaterialId = undefined; + this._oldFlipSided = undefined; this._lightsNeedUpdate = true; this.sprites.render(scene, camera, this._currentWidth, this._currentHeight, inFront); // Reset state a - this._currentGeometryGroupHash = -1; + this._currentGeometryGroupHash = undefined; this._currentProgram = null; this._currentCamera = null; - this._oldBlending = -1; - this._oldDepthWrite = -1; - this._oldDepthTest = -1; - this._oldDoubleSided = -1; - this._currentMaterialId = -1; - this._oldFlipSided = -1; + this._oldBlending = undefined; + this._oldDepthWrite = undefined; + this._oldDepthTest = undefined; + this._oldDoubleSided = undefined; + this._currentMaterialId = undefined; + this._oldFlipSided = undefined; } } diff --git a/src/WebGL/materials/Material.ts b/src/WebGL/materials/Material.ts index 848995862..7c037cf88 100644 --- a/src/WebGL/materials/Material.ts +++ b/src/WebGL/materials/Material.ts @@ -35,11 +35,6 @@ export class Material extends EventDispatcher { visible = true; needsUpdate = true; outline = false; - wireframe: any; - shaderID = null as string | null; - wireframeLinewidth?: number; - linewidth?: number; - sphere?: Sphere; setValues( values: Partial> = {} as any diff --git a/tsconfig.json b/tsconfig.json index b94af1c56..bcbf7cda1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "declarationDir": "build/types", - "noImplicitAny": true, + "noImplicitAny": false, "outDir": "tmp", "module": "esnext", "target": "ES2015", @@ -37,4 +37,5 @@ "out": "doc/typescript" }, "skipLibCheck": true, + "stats.errorDetails": true, } From 256007ab1525136f6ecc469df62548a66b25b43d Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Sun, 9 Jul 2023 18:29:36 +0000 Subject: [PATCH 4/8] Updated Types in WebGL Signed-off-by: Adithya Krishna --- src/WebGL/materials/ImposterMaterial.ts | 11 ++++++----- src/WebGL/materials/InstancedMaterial.ts | 13 +++++++------ src/WebGL/materials/Material.ts | 1 + src/WebGL/materials/MeshLambertMaterial.ts | 11 ++++++----- src/WebGL/materials/VolumetricMaterial.ts | 9 +++++---- src/WebGL/shaders/lib/instanced/uniforms.ts | 4 ++-- src/WebGL/shaders/lib/lambertdouble/uniforms.ts | 4 ++-- src/WebGL/shaders/lib/sphereimposter/uniforms.ts | 4 ++-- src/WebGL/shaders/lib/stickimposter/uniforms.ts | 4 ++-- src/WebGL/shaders/lib/volumetric/uniforms.ts | 5 +++-- 10 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/WebGL/materials/ImposterMaterial.ts b/src/WebGL/materials/ImposterMaterial.ts index 7c8620a9e..d352dc530 100644 --- a/src/WebGL/materials/ImposterMaterial.ts +++ b/src/WebGL/materials/ImposterMaterial.ts @@ -3,6 +3,7 @@ import { Shading } from "./../constants/Shading"; import { Color } from "../../colors"; import { Vector3 } from "../math"; import { Material } from "./Material"; +import { Texture } from "WebGL/core"; //Imposter material /* @constructor */ export class ImposterMaterial extends Material { @@ -14,13 +15,13 @@ export class ImposterMaterial extends Material { emissive = new Color(0x000000); imposter = true; - //TODO: Which of these instance variables do I really need? + // TODO: Which of these instance variables do I really need? wrapAround = false; wrapRGB = new Vector3(1, 1, 1); - map = undefined; - lightMap = null; - specularMap = null; - envMap = null; + map: any = undefined; + lightMap: any = null; + specularMap: any = null; + envMap: any = null; reflectivity = 1; refractionRatio = 0.98; fog = true; diff --git a/src/WebGL/materials/InstancedMaterial.ts b/src/WebGL/materials/InstancedMaterial.ts index f2bb60970..48018157e 100644 --- a/src/WebGL/materials/InstancedMaterial.ts +++ b/src/WebGL/materials/InstancedMaterial.ts @@ -3,6 +3,7 @@ import { Shading } from "../constants/Shading"; import { Color } from "../../colors"; import { Vector3 } from "../math"; import { Material } from "./Material"; +import { Texture } from "WebGL/core"; export class InstancedMaterial extends Material { combine: any; @@ -13,13 +14,13 @@ export class InstancedMaterial extends Material { ambient = new Color(0xfffff); emissive = new Color(0x000000); - //TODO: Which of these instance variables do I really need? + // TODO: Which of these instance variables do I really need? wrapAround = false; wrapRGB = new Vector3(1, 1, 1); - map = undefined; - lightMap = null; - specularMap = null; - envMap = null; + map: Texture = undefined; + lightMap: any = null; + specularMap: any = null; + envMap: any = null; reflectivity = 1; refractionRatio = 0.98; fog = true; @@ -31,7 +32,7 @@ export class InstancedMaterial extends Material { shaderID = "instanced"; vertexColors = Coloring.NoColors; skinning = false; - sphere = null; + sphere: { geometryGroups: any[]; } = null; constructor(parameters?: any) { super(); this.setValues(parameters); diff --git a/src/WebGL/materials/Material.ts b/src/WebGL/materials/Material.ts index 7c037cf88..6df8a8fbd 100644 --- a/src/WebGL/materials/Material.ts +++ b/src/WebGL/materials/Material.ts @@ -35,6 +35,7 @@ export class Material extends EventDispatcher { visible = true; needsUpdate = true; outline = false; + [key: string]: any; setValues( values: Partial> = {} as any diff --git a/src/WebGL/materials/MeshLambertMaterial.ts b/src/WebGL/materials/MeshLambertMaterial.ts index d27749deb..fec6868a3 100644 --- a/src/WebGL/materials/MeshLambertMaterial.ts +++ b/src/WebGL/materials/MeshLambertMaterial.ts @@ -5,6 +5,7 @@ import { Material } from "./Material"; import { Color } from "../../colors"; import { Vector3 } from "../math"; +import { Texture } from "WebGL/core"; /* @constructor */ export class MeshLambertMaterial extends Material { @@ -16,13 +17,13 @@ export class MeshLambertMaterial extends Material { ambient = new Color(0xfffff); emissive = new Color(0x000000); - //TODO: Which of these instance variables do I really need? + // TODO: Which of these instance variables do I really need? wrapAround = false; wrapRGB = new Vector3(1, 1, 1); - map = undefined; - lightMap = null; - specularMap = null; - envMap = null; + map: Texture = undefined; + lightMap: any = null; + specularMap: any = null; + envMap: any = null; reflectivity = 1; refractionRatio = 0.98; fog = true; diff --git a/src/WebGL/materials/VolumetricMaterial.ts b/src/WebGL/materials/VolumetricMaterial.ts index 6049b13ce..52e2a7baa 100644 --- a/src/WebGL/materials/VolumetricMaterial.ts +++ b/src/WebGL/materials/VolumetricMaterial.ts @@ -3,18 +3,19 @@ import { FrontSide } from "../constants/Sides"; import { Color } from "../../colors"; import { Material } from "./Material"; +import { Texture } from "WebGL/core"; /* @constructor */ export class VolumetricMaterial extends Material { transparent = false; volumetric = true; color = new Color(0xffffff); - transferfn = null; - map = undefined; - extent = []; + transferfn: any = null; + map: Texture = undefined; + extent: any[] = []; maxdepth = 100.0; unit = 0; - texmatrix = null; + texmatrix: any = null; transfermin = -1.0; transfermax = 1.0; subsamples = 5.0; diff --git a/src/WebGL/shaders/lib/instanced/uniforms.ts b/src/WebGL/shaders/lib/instanced/uniforms.ts index 9f09cc11e..d78916d11 100644 --- a/src/WebGL/shaders/lib/instanced/uniforms.ts +++ b/src/WebGL/shaders/lib/instanced/uniforms.ts @@ -5,6 +5,6 @@ export const uniforms = { fogColor: { type: 'c', value: new Color(1.0, 1.0, 1.0) }, fogNear: { type: 'f', value: 1.0 }, fogFar: { type: 'f', value: 2000}, - directionalLightColor: { type: 'fv', value: [] }, - directionalLightDirection: { type: 'fv', value: [] } + directionalLightColor: { type: 'fv', value: [] as number[] }, + directionalLightDirection: { type: 'fv', value: [] as number[] } } \ No newline at end of file diff --git a/src/WebGL/shaders/lib/lambertdouble/uniforms.ts b/src/WebGL/shaders/lib/lambertdouble/uniforms.ts index 9f09cc11e..d78916d11 100644 --- a/src/WebGL/shaders/lib/lambertdouble/uniforms.ts +++ b/src/WebGL/shaders/lib/lambertdouble/uniforms.ts @@ -5,6 +5,6 @@ export const uniforms = { fogColor: { type: 'c', value: new Color(1.0, 1.0, 1.0) }, fogNear: { type: 'f', value: 1.0 }, fogFar: { type: 'f', value: 2000}, - directionalLightColor: { type: 'fv', value: [] }, - directionalLightDirection: { type: 'fv', value: [] } + directionalLightColor: { type: 'fv', value: [] as number[] }, + directionalLightDirection: { type: 'fv', value: [] as number[] } } \ No newline at end of file diff --git a/src/WebGL/shaders/lib/sphereimposter/uniforms.ts b/src/WebGL/shaders/lib/sphereimposter/uniforms.ts index 9f09cc11e..d78916d11 100644 --- a/src/WebGL/shaders/lib/sphereimposter/uniforms.ts +++ b/src/WebGL/shaders/lib/sphereimposter/uniforms.ts @@ -5,6 +5,6 @@ export const uniforms = { fogColor: { type: 'c', value: new Color(1.0, 1.0, 1.0) }, fogNear: { type: 'f', value: 1.0 }, fogFar: { type: 'f', value: 2000}, - directionalLightColor: { type: 'fv', value: [] }, - directionalLightDirection: { type: 'fv', value: [] } + directionalLightColor: { type: 'fv', value: [] as number[] }, + directionalLightDirection: { type: 'fv', value: [] as number[] } } \ No newline at end of file diff --git a/src/WebGL/shaders/lib/stickimposter/uniforms.ts b/src/WebGL/shaders/lib/stickimposter/uniforms.ts index 9f09cc11e..d78916d11 100644 --- a/src/WebGL/shaders/lib/stickimposter/uniforms.ts +++ b/src/WebGL/shaders/lib/stickimposter/uniforms.ts @@ -5,6 +5,6 @@ export const uniforms = { fogColor: { type: 'c', value: new Color(1.0, 1.0, 1.0) }, fogNear: { type: 'f', value: 1.0 }, fogFar: { type: 'f', value: 2000}, - directionalLightColor: { type: 'fv', value: [] }, - directionalLightDirection: { type: 'fv', value: [] } + directionalLightColor: { type: 'fv', value: [] as number[] }, + directionalLightDirection: { type: 'fv', value: [] as number[] } } \ No newline at end of file diff --git a/src/WebGL/shaders/lib/volumetric/uniforms.ts b/src/WebGL/shaders/lib/volumetric/uniforms.ts index 58fa379bb..52370f317 100644 --- a/src/WebGL/shaders/lib/volumetric/uniforms.ts +++ b/src/WebGL/shaders/lib/volumetric/uniforms.ts @@ -1,3 +1,4 @@ +import { Matrix4 } from "WebGL/math"; import { Color } from "../../../../colors"; export const uniforms = { @@ -11,8 +12,8 @@ export const uniforms = { step: { type: 'f', value: 1.0 }, //length of a step maxdepth: {type: 'f',value: 100.0}, //how far to step along ray before stopping subsamples: { type: 'f', value: 5.0}, //how many substeps to take - textmat: { type: 'mat4', value: []}, - projinv: { type: 'mat4', value: []}, + textmat: { type: 'mat4', value: [] as Matrix4[] }, + projinv: { type: 'mat4', value: [] as Matrix4[] }, transfermin: {type: 'f', value: -0.2 }, transfermax: {type: 'f', value: 0.2}, From fbabf76560b3bcc98cdfb7bcf5ee66bc62aa9d89 Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Sun, 9 Jul 2023 18:30:20 +0000 Subject: [PATCH 5/8] Reverted TSConfig Change Signed-off-by: Adithya Krishna --- tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index bcbf7cda1..aed7ae9ae 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -37,5 +37,4 @@ "out": "doc/typescript" }, "skipLibCheck": true, - "stats.errorDetails": true, } From 03efbb41c9c863f684155a1b69446f56bdc7beaf Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Mon, 10 Jul 2023 18:49:51 +0000 Subject: [PATCH 6/8] Revert Changes to WebGL Shaders Signed-off-by: Adithya Krishna --- src/WebGL/shaders/lib/instanced/uniforms.ts | 4 ++-- src/WebGL/shaders/lib/lambertdouble/uniforms.ts | 4 ++-- src/WebGL/shaders/lib/sphereimposter/uniforms.ts | 4 ++-- src/WebGL/shaders/lib/stickimposter/uniforms.ts | 4 ++-- src/WebGL/shaders/lib/volumetric/uniforms.ts | 5 ++--- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/WebGL/shaders/lib/instanced/uniforms.ts b/src/WebGL/shaders/lib/instanced/uniforms.ts index d78916d11..9f09cc11e 100644 --- a/src/WebGL/shaders/lib/instanced/uniforms.ts +++ b/src/WebGL/shaders/lib/instanced/uniforms.ts @@ -5,6 +5,6 @@ export const uniforms = { fogColor: { type: 'c', value: new Color(1.0, 1.0, 1.0) }, fogNear: { type: 'f', value: 1.0 }, fogFar: { type: 'f', value: 2000}, - directionalLightColor: { type: 'fv', value: [] as number[] }, - directionalLightDirection: { type: 'fv', value: [] as number[] } + directionalLightColor: { type: 'fv', value: [] }, + directionalLightDirection: { type: 'fv', value: [] } } \ No newline at end of file diff --git a/src/WebGL/shaders/lib/lambertdouble/uniforms.ts b/src/WebGL/shaders/lib/lambertdouble/uniforms.ts index d78916d11..9f09cc11e 100644 --- a/src/WebGL/shaders/lib/lambertdouble/uniforms.ts +++ b/src/WebGL/shaders/lib/lambertdouble/uniforms.ts @@ -5,6 +5,6 @@ export const uniforms = { fogColor: { type: 'c', value: new Color(1.0, 1.0, 1.0) }, fogNear: { type: 'f', value: 1.0 }, fogFar: { type: 'f', value: 2000}, - directionalLightColor: { type: 'fv', value: [] as number[] }, - directionalLightDirection: { type: 'fv', value: [] as number[] } + directionalLightColor: { type: 'fv', value: [] }, + directionalLightDirection: { type: 'fv', value: [] } } \ No newline at end of file diff --git a/src/WebGL/shaders/lib/sphereimposter/uniforms.ts b/src/WebGL/shaders/lib/sphereimposter/uniforms.ts index d78916d11..9f09cc11e 100644 --- a/src/WebGL/shaders/lib/sphereimposter/uniforms.ts +++ b/src/WebGL/shaders/lib/sphereimposter/uniforms.ts @@ -5,6 +5,6 @@ export const uniforms = { fogColor: { type: 'c', value: new Color(1.0, 1.0, 1.0) }, fogNear: { type: 'f', value: 1.0 }, fogFar: { type: 'f', value: 2000}, - directionalLightColor: { type: 'fv', value: [] as number[] }, - directionalLightDirection: { type: 'fv', value: [] as number[] } + directionalLightColor: { type: 'fv', value: [] }, + directionalLightDirection: { type: 'fv', value: [] } } \ No newline at end of file diff --git a/src/WebGL/shaders/lib/stickimposter/uniforms.ts b/src/WebGL/shaders/lib/stickimposter/uniforms.ts index d78916d11..9f09cc11e 100644 --- a/src/WebGL/shaders/lib/stickimposter/uniforms.ts +++ b/src/WebGL/shaders/lib/stickimposter/uniforms.ts @@ -5,6 +5,6 @@ export const uniforms = { fogColor: { type: 'c', value: new Color(1.0, 1.0, 1.0) }, fogNear: { type: 'f', value: 1.0 }, fogFar: { type: 'f', value: 2000}, - directionalLightColor: { type: 'fv', value: [] as number[] }, - directionalLightDirection: { type: 'fv', value: [] as number[] } + directionalLightColor: { type: 'fv', value: [] }, + directionalLightDirection: { type: 'fv', value: [] } } \ No newline at end of file diff --git a/src/WebGL/shaders/lib/volumetric/uniforms.ts b/src/WebGL/shaders/lib/volumetric/uniforms.ts index 52370f317..58fa379bb 100644 --- a/src/WebGL/shaders/lib/volumetric/uniforms.ts +++ b/src/WebGL/shaders/lib/volumetric/uniforms.ts @@ -1,4 +1,3 @@ -import { Matrix4 } from "WebGL/math"; import { Color } from "../../../../colors"; export const uniforms = { @@ -12,8 +11,8 @@ export const uniforms = { step: { type: 'f', value: 1.0 }, //length of a step maxdepth: {type: 'f',value: 100.0}, //how far to step along ray before stopping subsamples: { type: 'f', value: 5.0}, //how many substeps to take - textmat: { type: 'mat4', value: [] as Matrix4[] }, - projinv: { type: 'mat4', value: [] as Matrix4[] }, + textmat: { type: 'mat4', value: []}, + projinv: { type: 'mat4', value: []}, transfermin: {type: 'f', value: -0.2 }, transfermax: {type: 'f', value: 0.2}, From dfc3a147b572417e40d048cfdc10181aebc72987 Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Mon, 10 Jul 2023 19:03:56 +0000 Subject: [PATCH 7/8] Reverted Changes to WebGL Material Signed-off-by: Adithya Krishna --- src/WebGL/materials/ImposterMaterial.ts | 11 +++++------ src/WebGL/materials/InstancedMaterial.ts | 13 ++++++------- src/WebGL/materials/Material.ts | 1 - src/WebGL/materials/MeshLambertMaterial.ts | 11 +++++------ src/WebGL/materials/VolumetricMaterial.ts | 9 ++++----- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/WebGL/materials/ImposterMaterial.ts b/src/WebGL/materials/ImposterMaterial.ts index d352dc530..7c8620a9e 100644 --- a/src/WebGL/materials/ImposterMaterial.ts +++ b/src/WebGL/materials/ImposterMaterial.ts @@ -3,7 +3,6 @@ import { Shading } from "./../constants/Shading"; import { Color } from "../../colors"; import { Vector3 } from "../math"; import { Material } from "./Material"; -import { Texture } from "WebGL/core"; //Imposter material /* @constructor */ export class ImposterMaterial extends Material { @@ -15,13 +14,13 @@ export class ImposterMaterial extends Material { emissive = new Color(0x000000); imposter = true; - // TODO: Which of these instance variables do I really need? + //TODO: Which of these instance variables do I really need? wrapAround = false; wrapRGB = new Vector3(1, 1, 1); - map: any = undefined; - lightMap: any = null; - specularMap: any = null; - envMap: any = null; + map = undefined; + lightMap = null; + specularMap = null; + envMap = null; reflectivity = 1; refractionRatio = 0.98; fog = true; diff --git a/src/WebGL/materials/InstancedMaterial.ts b/src/WebGL/materials/InstancedMaterial.ts index 48018157e..f2bb60970 100644 --- a/src/WebGL/materials/InstancedMaterial.ts +++ b/src/WebGL/materials/InstancedMaterial.ts @@ -3,7 +3,6 @@ import { Shading } from "../constants/Shading"; import { Color } from "../../colors"; import { Vector3 } from "../math"; import { Material } from "./Material"; -import { Texture } from "WebGL/core"; export class InstancedMaterial extends Material { combine: any; @@ -14,13 +13,13 @@ export class InstancedMaterial extends Material { ambient = new Color(0xfffff); emissive = new Color(0x000000); - // TODO: Which of these instance variables do I really need? + //TODO: Which of these instance variables do I really need? wrapAround = false; wrapRGB = new Vector3(1, 1, 1); - map: Texture = undefined; - lightMap: any = null; - specularMap: any = null; - envMap: any = null; + map = undefined; + lightMap = null; + specularMap = null; + envMap = null; reflectivity = 1; refractionRatio = 0.98; fog = true; @@ -32,7 +31,7 @@ export class InstancedMaterial extends Material { shaderID = "instanced"; vertexColors = Coloring.NoColors; skinning = false; - sphere: { geometryGroups: any[]; } = null; + sphere = null; constructor(parameters?: any) { super(); this.setValues(parameters); diff --git a/src/WebGL/materials/Material.ts b/src/WebGL/materials/Material.ts index 6df8a8fbd..7c037cf88 100644 --- a/src/WebGL/materials/Material.ts +++ b/src/WebGL/materials/Material.ts @@ -35,7 +35,6 @@ export class Material extends EventDispatcher { visible = true; needsUpdate = true; outline = false; - [key: string]: any; setValues( values: Partial> = {} as any diff --git a/src/WebGL/materials/MeshLambertMaterial.ts b/src/WebGL/materials/MeshLambertMaterial.ts index fec6868a3..d27749deb 100644 --- a/src/WebGL/materials/MeshLambertMaterial.ts +++ b/src/WebGL/materials/MeshLambertMaterial.ts @@ -5,7 +5,6 @@ import { Material } from "./Material"; import { Color } from "../../colors"; import { Vector3 } from "../math"; -import { Texture } from "WebGL/core"; /* @constructor */ export class MeshLambertMaterial extends Material { @@ -17,13 +16,13 @@ export class MeshLambertMaterial extends Material { ambient = new Color(0xfffff); emissive = new Color(0x000000); - // TODO: Which of these instance variables do I really need? + //TODO: Which of these instance variables do I really need? wrapAround = false; wrapRGB = new Vector3(1, 1, 1); - map: Texture = undefined; - lightMap: any = null; - specularMap: any = null; - envMap: any = null; + map = undefined; + lightMap = null; + specularMap = null; + envMap = null; reflectivity = 1; refractionRatio = 0.98; fog = true; diff --git a/src/WebGL/materials/VolumetricMaterial.ts b/src/WebGL/materials/VolumetricMaterial.ts index 52e2a7baa..6049b13ce 100644 --- a/src/WebGL/materials/VolumetricMaterial.ts +++ b/src/WebGL/materials/VolumetricMaterial.ts @@ -3,19 +3,18 @@ import { FrontSide } from "../constants/Sides"; import { Color } from "../../colors"; import { Material } from "./Material"; -import { Texture } from "WebGL/core"; /* @constructor */ export class VolumetricMaterial extends Material { transparent = false; volumetric = true; color = new Color(0xffffff); - transferfn: any = null; - map: Texture = undefined; - extent: any[] = []; + transferfn = null; + map = undefined; + extent = []; maxdepth = 100.0; unit = 0; - texmatrix: any = null; + texmatrix = null; transfermin = -1.0; transfermax = 1.0; subsamples = 5.0; From 7932787f541a018f5fbaab0250976e5fb9a08b5a Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Mon, 10 Jul 2023 19:09:35 +0000 Subject: [PATCH 8/8] Reverted Chanegs to Material.ts Signed-off-by: Adithya Krishna --- src/WebGL/materials/Material.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/WebGL/materials/Material.ts b/src/WebGL/materials/Material.ts index 7c037cf88..fb566d549 100644 --- a/src/WebGL/materials/Material.ts +++ b/src/WebGL/materials/Material.ts @@ -3,7 +3,6 @@ import { EventDispatcher } from "../core"; import type { Texture } from "../core"; import { Vector2, Vector3 } from "../math"; import { Color } from "../../colors"; -import { Sphere } from "WebGL/shapes"; /* * Line and Mesh material types * @constructor