Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#865-upgrade-three-js #1002

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0f1d1d4
Geometry removed
ppillot Nov 19, 2023
417345b
remove ply parser for now
ppillot Nov 19, 2023
3295839
.getClearColor() requires a Color object
ppillot Nov 19, 2023
e5378d1
.getInverse() removed
ppillot Nov 19, 2023
65f4686
BufferAttribute usage can't be 0
ppillot Nov 19, 2023
24c0886
typings
ppillot Nov 19, 2023
82a77d9
canvas2d performance improvement
ppillot Nov 20, 2023
71d6d4b
encoding depreacted in favor of colorspace
ppillot Nov 20, 2023
f919994
r154 encodings_fragment --> colorspace_fragment
ppillot Nov 20, 2023
baf2422
r155 useLegacyLights
ppillot Nov 20, 2023
26bee39
update three.js to latest
ppillot Nov 20, 2023
dd7507d
upgrade dev dependencies to pass npm audit
ppillot Nov 20, 2023
8219f6c
fragments: geometryNomal --> nonPerturbedNormal
ppillot Nov 21, 2023
1355891
fragments: `filter` is a reserved keyword
ppillot Nov 21, 2023
d24ea77
revert 356d957: delete Volume._position in setData()
ppillot Nov 22, 2023
e173521
r132 ALPHATEST --> USE_ALPHATEST
ppillot Dec 3, 2023
f9802b2
SpotLight --> DirectionalLight
ppillot Dec 7, 2023
f35f574
Adjust default light intensity
ppillot Dec 7, 2023
3843e91
set colorspace to three.js defaults
ppillot Dec 11, 2023
16c7e47
adjust ambient light level
ppillot Dec 11, 2023
4921bab
convert fog color to linear colorspace
ppillot Dec 16, 2023
d67eb50
Remove unused colorspace properties
ppillot Dec 23, 2023
e3ad21a
convert color when appending to uniforms array
ppillot Dec 23, 2023
3772790
Fix banding appearing after antialiasing
ppillot Dec 24, 2023
48c0db6
Fog planes tweaking
ppillot Dec 25, 2023
b5a3523
More color space conversions
ppillot Apr 8, 2024
d018310
update three.js to latest
ppillot Apr 9, 2024
b09d478
r163 drop WebGL1 support
ppillot Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ NGL.Preferences = function (id, defaultParams) {
cameraFov: 40,
cameraType: 'perspective',
lightColor: 0xdddddd,
lightIntensity: 1.0,
lightIntensity: 3.14,
ambientColor: 0xdddddd,
ambientIntensity: 0.2,
ambientIntensity: 0.63,
hoverTimeout: 0
}

Expand Down
6,825 changes: 3,660 additions & 3,165 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"science"
],
"devDependencies": {
"@babel/preset-env": "^7.17.10",
"@babel/preset-env": "^7.23.3",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.1.1",
Expand All @@ -71,13 +71,14 @@
"@types/offscreencanvas": "^2019.6.4",
"@types/signals": "1.0.1",
"@types/sprintf-js": "^1.1.2",
"@types/three": "^0.163.0",
"@yushijinhun/three-minifier-rollup": "^0.3.1",
"babel-plugin-array-includes": "^2.0.3",
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"rollup": "^2.38.5",
"standard": "^11.0.1",
"ts-jest": "^28.0.2",
"ts-jest": "^29.1.1",
"tslib": "^2.3.1",
"typedoc": "^0.22.15",
"typescript": "^4.5.4"
Expand All @@ -86,6 +87,6 @@
"chroma-js": "^1.3.7",
"signals": "^1.0.0",
"sprintf-js": "^1.1.2",
"three": "^0.118.0"
"three": "^0.163.0"
}
}
2 changes: 1 addition & 1 deletion src/align/superposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class Superposition {
//update transformation matrices for each assembly

const invertTrasform = new Matrix4()
invertTrasform.getInverse(transform)
invertTrasform.copy(transform).invert()

const biomolDict = atoms.biomolDict

Expand Down
4 changes: 2 additions & 2 deletions src/buffer/box-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @private
*/

import { BoxBufferGeometry, Vector3, Matrix4 } from 'three'
import { BoxGeometry, Vector3, Matrix4 } from 'three'

import { BufferRegistry } from '../globals'
import GeometryBuffer from './geometry-buffer'
Expand Down Expand Up @@ -41,7 +41,7 @@ class BoxBuffer extends GeometryBuffer {
_size: Float32Array

constructor (data: BoxBufferData, params: Partial<BufferParameters> = {}) {
super(data, params, new BoxBufferGeometry(1, 1, 1))
super(data, params, new BoxGeometry(1, 1, 1))

this.setAttributes(data, true)
}
Expand Down
28 changes: 13 additions & 15 deletions src/buffer/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import {
BufferGeometry, BufferAttribute,
UniformsUtils, UniformsLib, Uniform,
Group, LineSegments, Points, Mesh, Object3D,
ShaderMaterial
ShaderMaterial,
DynamicDrawUsage,
StaticDrawUsage
} from 'three'

import { Log } from '../globals'
import { createParams, getTypedArray, getUintArray } from '../utils'
import { GenericColor, NumberArray } from '../types'
import { GenericColor, TypedArray } from '../types'
import { getShader, ShaderDefines } from '../shader/shader-utils'
import { serialArray } from '../math/array-utils'
import { Picker } from '../utils/picker'
Expand Down Expand Up @@ -51,7 +53,7 @@ export type BufferMaterials = 'material'|'wireframeMaterial'|'pickingMaterial'

export interface _BufferAttribute {
type: 'f'|'v2'|'v3'|'c'
value?: NumberArray
value?: TypedArray
}

export type Uniforms = { [k: string]: Uniform|{ value: any } }
Expand Down Expand Up @@ -179,13 +181,13 @@ class Buffer {
emissive: { value: new Color(0x000000) },
roughness: { value: this.parameters.roughness },
metalness: { value: this.parameters.metalness },
interiorColor: { value: new Color(this.parameters.interiorColor) },
interiorColor: { value: new Color(this.parameters.interiorColor).convertSRGBToLinear() },
interiorDarkening: { value: this.parameters.interiorDarkening },
},
UniformsLib.lights
])

this.uniforms.diffuse.value.set(this.parameters.diffuse)
this.uniforms.diffuse.value.set(new Color(this.parameters.diffuse).convertSRGBToLinear())

this.pickingUniforms = {
clipNear: { value: 0.0 },
Expand Down Expand Up @@ -255,7 +257,7 @@ class Buffer {
)
const nindex = this.geometry.getIndex();
if (!nindex) { Log.error('Index is null'); return; }
nindex.setUsage(this.dynamic ? WebGLRenderingContext.DYNAMIC_DRAW : 0)
nindex.setUsage(this.dynamic ? DynamicDrawUsage : StaticDrawUsage)
}

makeMaterial () {
Expand All @@ -273,8 +275,6 @@ class Buffer {
side: side
})
m.vertexColors = true
m.extensions.derivatives = true
m.extensions.fragDepth = this.isImpostor

const wm = new ShaderMaterial({
uniforms: this.uniforms,
Expand Down Expand Up @@ -302,7 +302,6 @@ class Buffer {
blending: NoBlending
})
pm.vertexColors = true
pm.extensions.fragDepth = this.isImpostor

;(m as any).clipNear = this.parameters.clipNear
;(wm as any).clipNear = this.parameters.clipNear
Expand All @@ -326,7 +325,7 @@ class Buffer {
wireframeGeometry.attributes = geometry.attributes
if (wireframeIndex) {
wireframeGeometry.setIndex(
new BufferAttribute(wireframeIndex, 1).setUsage(this.dynamic ? WebGLRenderingContext.DYNAMIC_DRAW : 0)
new BufferAttribute(wireframeIndex, 1).setUsage(this.dynamic ? DynamicDrawUsage : StaticDrawUsage)
)
wireframeGeometry.setDrawRange(0, this.wireframeIndexCount)
}
Expand Down Expand Up @@ -441,7 +440,7 @@ class Buffer {
if (this.wireframeGeometry.index &&
this.wireframeIndex.length > this.wireframeGeometry.index.array.length) {
this.wireframeGeometry.setIndex(
new BufferAttribute(this.wireframeIndex, 1).setUsage(this.dynamic ? WebGLRenderingContext.DYNAMIC_DRAW : 0)
new BufferAttribute(this.wireframeIndex, 1).setUsage(this.dynamic ? DynamicDrawUsage : StaticDrawUsage)
)
} else {
const index = this.wireframeGeometry.getIndex()
Expand Down Expand Up @@ -593,7 +592,7 @@ class Buffer {

this.geometry.setAttribute(
name,
new BufferAttribute(buf, itemSize[ a.type ]).setUsage(this.dynamic ? WebGLRenderingContext.DYNAMIC_DRAW : 0)
new BufferAttribute(buf, itemSize[ a.type ]).setUsage(this.dynamic ? DynamicDrawUsage : StaticDrawUsage)
)
}
}
Expand Down Expand Up @@ -720,11 +719,10 @@ class Buffer {
if (length > index.array.length) {
geometry.setIndex(
new BufferAttribute(array, 1)
.setUsage(this.dynamic ? WebGLRenderingContext.DYNAMIC_DRAW : 0)
.setUsage(this.dynamic ? DynamicDrawUsage : StaticDrawUsage)
)
} else {
index.set(array)
index.count = length
index.needsUpdate = length > 0
index.updateRange.count = length
geometry.setDrawRange(0, length)
Expand All @@ -739,7 +737,7 @@ class Buffer {
geometry.setAttribute(
name,
new BufferAttribute(array, attribute.itemSize)
.setUsage(this.dynamic ? WebGLRenderingContext.DYNAMIC_DRAW : 0)
.setUsage(this.dynamic ? DynamicDrawUsage : StaticDrawUsage)
)
} else {
attributes[ name ].set(array)
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/cone-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @private
*/

import { Matrix4, Vector3, ConeBufferGeometry } from 'three'
import { Matrix4, Vector3, ConeGeometry } from 'three'

import { BufferRegistry } from '../globals'
import { defaults } from '../utils'
Expand All @@ -18,7 +18,7 @@ const target = new Vector3()
const up = new Vector3(0, 1, 0)

function getGeo (params: Partial<ConeBufferParameters> = {}) {
const geo = new ConeBufferGeometry(
const geo = new ConeGeometry(
1, // radius
1, // height
defaults(params.radialSegments, 60), // radialSegments
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/cylindergeometry-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @private
*/

import { Matrix4, Vector3, CylinderBufferGeometry } from 'three'
import { Matrix4, Vector3, CylinderGeometry } from 'three'

import { defaults } from '../utils'
import { calculateCenterArray, serialBlockArray } from '../math/array-utils'
Expand Down Expand Up @@ -47,7 +47,7 @@ function getGeo (params: Partial<CylinderGeometryBufferParameters> = {}) {
const openEnded = defaults(params.openEnded, true)
const matrix = new Matrix4().makeRotationX(Math.PI / 2)

const geo = new CylinderBufferGeometry(
const geo = new CylinderGeometry(
1, // radiusTop,
1, // radiusBottom,
1, // height,
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/ellipsoid-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @private
*/

import { IcosahedronBufferGeometry, Vector3, Matrix4 } from 'three'
import { IcosahedronGeometry, Vector3, Matrix4 } from 'three'

import { BufferRegistry } from '../globals'
import { defaults } from '../utils'
Expand Down Expand Up @@ -50,7 +50,7 @@ class EllipsoidBuffer extends GeometryBuffer {
_radius: Float32Array

constructor (data: EllipsoidBufferData, params: Partial<EllipsoidBufferParameters> = {}) {
super(data, params, new IcosahedronBufferGeometry(1, defaults(params.sphereDetail, 2)))
super(data, params, new IcosahedronGeometry(1, defaults(params.sphereDetail, 2)))

this.setAttributes(data, true)
}
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/octahedron-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @private
*/

import { OctahedronBufferGeometry, Vector3, Matrix4 } from 'three'
import { OctahedronGeometry, Vector3, Matrix4 } from 'three'
import { BufferRegistry } from '../globals'
import GeometryBuffer from './geometry-buffer'
import { BufferData, BufferParameters } from './buffer'
Expand Down Expand Up @@ -40,7 +40,7 @@ class OctahedronBuffer extends GeometryBuffer {
_size: Float32Array

constructor (data: OctahedronBufferData, params: Partial<BufferParameters> = {}) {
super(data, params, new OctahedronBufferGeometry(1, 0))
super(data, params, new OctahedronGeometry(1, 0))

this.setAttributes(data, true)
}
Expand Down
7 changes: 4 additions & 3 deletions src/buffer/point-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const PointBufferParameterTypes = Object.assign({
pointSize: { uniform: 'size' },
sizeAttenuation: { updateShader: true },
sortParticles: {},
alphaTest: { updateShader: true },
alphaTest: { uniform: true },
useTexture: { updateShader: true },
forceTransparent: {},
edgeBleach: { uniform: true }
Expand Down Expand Up @@ -123,7 +123,8 @@ class PointBuffer extends Buffer {
'size': { value: this.parameters.pointSize },
'canvasHeight': { value: 1.0 },
'pixelRatio': { value: 1.0 },
'map': { value: null }
'map': { value: null },
'alphaTest': {value: this.parameters.alphaTest}
})
}

Expand Down Expand Up @@ -163,7 +164,7 @@ class PointBuffer extends Buffer {
}

if (this.parameters.alphaTest > 0 && this.parameters.alphaTest <= 1) {
defines.ALPHATEST = this.parameters.alphaTest.toPrecision(2)
defines.USE_ALPHATEST = 1
}

return defines
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/spheregeometry-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @private
*/

import { IcosahedronBufferGeometry, Vector3, Matrix4 } from 'three'
import { IcosahedronGeometry, Vector3, Matrix4 } from 'three'
import { defaults } from '../utils'
import GeometryBuffer from './geometry-buffer'
import { SphereBufferData } from './sphere-buffer'
Expand Down Expand Up @@ -42,7 +42,7 @@ class SphereGeometryBuffer extends GeometryBuffer {
* @param {BufferParameters} params - parameter object
*/
constructor (data: SphereBufferData, params: Partial<SphereGeometryBufferParameters> = {}) {
super(data, params, new IcosahedronBufferGeometry(1, defaults(params.sphereDetail, 1)))
super(data, params, new IcosahedronGeometry(1, defaults(params.sphereDetail, 1)))

this.setAttributes(data, true)
}
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/tetrahedron-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @private
*/

import { TetrahedronBufferGeometry, Vector3, Matrix4 } from 'three'
import { TetrahedronGeometry, Vector3, Matrix4 } from 'three'
import { BufferRegistry } from '../globals'
import GeometryBuffer from './geometry-buffer'
import { BufferData, BufferParameters } from './buffer'
Expand Down Expand Up @@ -40,7 +40,7 @@ class TetrahedronBuffer extends GeometryBuffer {
_size: Float32Array

constructor (data: TetrahedronBufferData, params: Partial<BufferParameters> = {}) {
super(data, params, new TetrahedronBufferGeometry(1, 0))
super(data, params, new TetrahedronGeometry(1, 0))

this.setAttributes(data, true)
}
Expand Down
5 changes: 1 addition & 4 deletions src/buffer/text-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class TextAtlas {
canvas.width = maxWidth
canvas.height = lineHeight

const ctx = this.context = this.canvas.getContext('2d')!
const ctx = this.context = this.canvas.getContext('2d', { willReadFrequently: true})!
ctx.font = `${p.style} ${p.variant} ${p.weight} ${p.size}px ${p.font}`
ctx.fillStyle = 'black'
ctx.textAlign = 'left'
Expand Down Expand Up @@ -431,20 +431,17 @@ class TextBuffer extends MappedQuadBuffer {

const m = this.material
m.transparent = true
m.extensions.derivatives = true
m.lights = false
m.uniforms.fontTexture.value = tex
m.needsUpdate = true

const wm = this.wireframeMaterial
wm.transparent = true
wm.extensions.derivatives = true
wm.lights = false
wm.uniforms.fontTexture.value = tex
wm.needsUpdate = true

const pm = this.pickingMaterial
pm.extensions.derivatives = true
pm.lights = false
pm.uniforms.fontTexture.value = tex
pm.needsUpdate = true
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/torus-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @private
*/

import { TorusBufferGeometry, Vector3, Matrix4 } from 'three'
import { TorusGeometry, Vector3, Matrix4 } from 'three'

import { BufferRegistry } from '../globals'
import { defaults } from '../utils'
Expand Down Expand Up @@ -52,7 +52,7 @@ class TorusBuffer extends GeometryBuffer {
_radius: Float32Array

constructor (data: TorusBufferData, params: Partial<TorusBufferParameters> = {}) {
super(data, params, new TorusBufferGeometry(
super(data, params, new TorusGeometry(
1,
defaults(params.radiusRatio, 0.2),
defaults(params.radialSegments, 16),
Expand Down
3 changes: 1 addition & 2 deletions src/color/atomindex-colormaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { ColormakerRegistry } from '../globals'
import { defaults } from '../utils'
import Colormaker, { StuctureColormakerParams, ColormakerScale, manageColor } from './colormaker'
import Colormaker, { StuctureColormakerParams, ColormakerScale } from './colormaker'
import AtomProxy from '../proxy/atom-proxy'
import ModelProxy from '../proxy/model-proxy'

Expand Down Expand Up @@ -47,7 +47,6 @@ class AtomindexColormaker extends Colormaker {
* @param {AtomProxy} atom - atom to get color for
* @return {Integer} hex atom color
*/
@manageColor
atomColor (atom: AtomProxy) {
return this.scalePerModel[ atom.modelIndex ](atom.index)
}
Expand Down
Loading
Loading