Просмотр исходного кода

Some type fixes, add uniforms in constructor for material extension plugins.

master
Palash Bansal 2 лет назад
Родитель
Сommit
3b31fd284e
Аккаунт пользователя с таким Email не найден

+ 1
- 1
src/core/object/RootScene.ts Просмотреть файл



updateShaderProperties(material: {defines: Record<string, string|number|undefined>, uniforms: {[name: string]: IUniform}}): this { updateShaderProperties(material: {defines: Record<string, string|number|undefined>, uniforms: {[name: string]: IUniform}}): this {
if (material.uniforms.sceneBoundingRadius) material.uniforms.sceneBoundingRadius.value = this._sceneBoundingRadius if (material.uniforms.sceneBoundingRadius) material.uniforms.sceneBoundingRadius.value = this._sceneBoundingRadius
else console.warn('BaseRenderer: no uniform: sceneBoundingRadius')
else console.warn('RootScene: no uniform: sceneBoundingRadius')
return this return this
} }



+ 3
- 3
src/materials/MaterialExtender.ts Просмотреть файл

import {IMaterial, IMaterialUserData} from '../core'
import {IMaterial, IMaterialUserData, IWebGLRenderer} from '../core'
import {getOrCall, objectMap} from 'ts-browser-helpers' import {getOrCall, objectMap} from 'ts-browser-helpers'
import {shaderReplaceString, shaderUtils} from '../utils' import {shaderReplaceString, shaderUtils} from '../utils'
import {Object3D, Shader, ShaderChunk, WebGLRenderer} from 'three' import {Object3D, Shader, ShaderChunk, WebGLRenderer} from 'three'
if (flag) material.needsUpdate = true if (flag) material.needsUpdate = true
} }


function materialBeforeRender({target, object, renderer}:{object?: Object3D, renderer?: WebGLRenderer, target: IMaterial}) {
function materialBeforeRender({target, object, renderer}:{object?: Object3D, renderer?: IWebGLRenderer, target: IMaterial}) {
const material = target const material = target
if (!material || !object || !renderer) throw new Error('Invalid material, object or renderer') if (!material || !object || !renderer) throw new Error('Invalid material, object or renderer')
if (!material.materialExtensions) return if (!material.materialExtensions) return
} }
} }


function materialAfterRender({target, object, renderer}:{object?: Object3D, renderer?: WebGLRenderer, target: IMaterial}) {
function materialAfterRender({target, object, renderer}:{object?: Object3D, renderer?: IWebGLRenderer, target: IMaterial}) {
const material = target const material = target
if (!material || !object || !renderer) throw new Error('Invalid material, object or renderer') if (!material || !object || !renderer) throw new Error('Invalid material, object or renderer')
if (!material.materialExtensions) return if (!material.materialExtensions) return

+ 3
- 3
src/materials/MaterialExtension.ts Просмотреть файл

import {IUniform, Object3D, Shader, WebGLRenderer} from 'three' import {IUniform, Object3D, Shader, WebGLRenderer} from 'three'
import {IMaterial} from '../core'
import {IMaterial, IWebGLRenderer} from '../core'
import {UiObjectConfig} from 'uiconfig.js' import {UiObjectConfig} from 'uiconfig.js'
import {ValOrFunc} from 'ts-browser-helpers' import {ValOrFunc} from 'ts-browser-helpers'


* @param material * @param material
* @param renderer * @param renderer
*/ */
onObjectRender?: (object: Object3D, material: IMaterial, renderer: WebGLRenderer) => void
onObjectRender?: (object: Object3D, material: IMaterial, renderer: IWebGLRenderer) => void




/** /**
* @param material * @param material
* @param renderer * @param renderer
*/ */
onAfterRender?: (object: Object3D, material: IMaterial, renderer: WebGLRenderer) => void
onAfterRender?: (object: Object3D, material: IMaterial, renderer: IWebGLRenderer) => void


/** /**
* Function to check if this material extension is compatible with the given material. * Function to check if this material extension is compatible with the given material.

+ 2
- 2
src/plugins/base/BaseGroundPlugin.ts Просмотреть файл

if (this._material.userData.gBufferData.tonemapEnabled !== this.tonemapGround) { if (this._material.userData.gBufferData.tonemapEnabled !== this.tonemapGround) {
this._material.userData.gBufferData.tonemapEnabled = this.tonemapGround this._material.userData.gBufferData.tonemapEnabled = this.tonemapGround
} }
this._material.userData.ssaoDisabled = true
this._material.userData.sscsDisabled = true
// this._material.userData.ssaoDisabled = true //todo should be in BakedGroundPlugin
// this._material.userData.sscsDisabled = true //todo should be in BakedGroundPlugin


// if (this._material.userData.__postTonemap === undefined) { // if (this._material.userData.__postTonemap === undefined) {
// this._material.userData.__postTonemap = this._material.userData.postTonemap // this._material.userData.__postTonemap = this._material.userData.postTonemap

+ 3
- 2
src/plugins/material/ClearcoatTintPlugin.ts Просмотреть файл

}, material) }, material)
}, },
extraUniforms: { extraUniforms: {
...this._uniforms,
// ...this._uniforms, // done in constructor
}, },
computeCacheKey: (material1: PhysicalMaterial) => { computeCacheKey: (material1: PhysicalMaterial) => {
return (this.isDisabled() ? '0' : '1') + (material1.userData._clearcoatTint?.enableTint ? '1' : '0') + (material1.clearcoat > 0 ? '1' : '0') return (this.isDisabled() ? '0' : '1') + (material1.userData._clearcoatTint?.enableTint ? '1' : '0') + (material1.clearcoat > 0 ? '1' : '0')
isCompatible: (material1: PhysicalMaterial) => { isCompatible: (material1: PhysicalMaterial) => {
return material1.isPhysicalMaterial return material1.isPhysicalMaterial
}, },
getUiConfig: (material: PhysicalMaterial) => {
getUiConfig: (material: PhysicalMaterial) => { // todo use uiConfigMaterialExtension
const viewer = this._viewer! const viewer = this._viewer!
if (material.userData._clearcoatTint === undefined) material.userData._clearcoatTint = {} if (material.userData._clearcoatTint === undefined) material.userData._clearcoatTint = {}
const state = material.userData._clearcoatTint const state = material.userData._clearcoatTint
constructor() { constructor() {
super() super()
this._loaderCreate = this._loaderCreate.bind(this) this._loaderCreate = this._loaderCreate.bind(this)
Object.assign(this.materialExtension.extraUniforms!, this._uniforms)
} }


onAdded(v: ThreeViewer) { onAdded(v: ThreeViewer) {

+ 3
- 2
src/plugins/material/CustomBumpMapPlugin.ts Просмотреть файл

}, material) }, material)
}, },
extraUniforms: { extraUniforms: {
...this._uniforms,
// ...this._uniforms, // done in constructor
}, },
computeCacheKey: (material1: PhysicalMaterial) => { computeCacheKey: (material1: PhysicalMaterial) => {
return (this.enabled ? '1' : '0') + (material1.userData._hasCustomBump ? '1' : '0') + material1.userData?._customBumpMap?.uuid return (this.enabled ? '1' : '0') + (material1.userData._hasCustomBump ? '1' : '0') + material1.userData?._customBumpMap?.uuid
}, },
isCompatible: (material1: PhysicalMaterial) => material1.isPhysicalMaterial, isCompatible: (material1: PhysicalMaterial) => material1.isPhysicalMaterial,
getUiConfig: material => {
getUiConfig: material => { // todo use uiConfigMaterialExtension
const viewer = this._viewer! const viewer = this._viewer!
const enableCustomBump = this.enableCustomBump.bind(this) const enableCustomBump = this.enableCustomBump.bind(this)
const state = material.userData const state = material.userData
constructor() { constructor() {
super() super()
this._loaderCreate = this._loaderCreate.bind(this) this._loaderCreate = this._loaderCreate.bind(this)
Object.assign(this.materialExtension.extraUniforms!, this._uniforms)
} }


onAdded(v: ThreeViewer) { onAdded(v: ThreeViewer) {

+ 3
- 2
src/plugins/material/FragmentClippingExtensionPlugin.ts Просмотреть файл

}, material) }, material)
}, },
extraUniforms: { extraUniforms: {
...this._uniforms,
// ...this._uniforms, // done in constructor
}, },
computeCacheKey: (material1: PhysicalMaterial) => { computeCacheKey: (material1: PhysicalMaterial) => {
return (this.enabled ? '1' : '0') + (material1.userData._fragmentClippingExt?.clipEnabled ? '1' : '0') return (this.enabled ? '1' : '0') + (material1.userData._fragmentClippingExt?.clipEnabled ? '1' : '0')
isCompatible: (material1: PhysicalMaterial) => { isCompatible: (material1: PhysicalMaterial) => {
return material1.isPhysicalMaterial || material1.userData.isGBufferMaterial // todo isGBufferMaterial return material1.isPhysicalMaterial || material1.userData.isGBufferMaterial // todo isGBufferMaterial
}, },
getUiConfig: material => {
getUiConfig: material => { // todo use uiConfigMaterialExtension
const viewer = this._viewer! const viewer = this._viewer!
if (material.userData._fragmentClippingExt === undefined) material.userData._fragmentClippingExt = {} if (material.userData._fragmentClippingExt === undefined) material.userData._fragmentClippingExt = {}
const state = material.userData._fragmentClippingExt const state = material.userData._fragmentClippingExt
constructor() { constructor() {
super() super()
this._loaderCreate = this._loaderCreate.bind(this) this._loaderCreate = this._loaderCreate.bind(this)
Object.assign(this.materialExtension.extraUniforms!, this._uniforms)
} }


onAdded(v: ThreeViewer) { onAdded(v: ThreeViewer) {

+ 3
- 2
src/plugins/material/NoiseBumpMaterialPlugin.ts Просмотреть файл

}, material) }, material)
}, },
extraUniforms: { extraUniforms: {
...this._uniforms,
// ...this._uniforms, // done in constructor
}, },
computeCacheKey: (material1: PhysicalMaterial) => { computeCacheKey: (material1: PhysicalMaterial) => {
return (this.isDisabled() ? '0' : '1') + (material1.userData._noiseBumpMat?.hasBump ? '1' : '0') return (this.isDisabled() ? '0' : '1') + (material1.userData._noiseBumpMat?.hasBump ? '1' : '0')
}, },
isCompatible: (material1: PhysicalMaterial) => material1.isPhysicalMaterial, isCompatible: (material1: PhysicalMaterial) => material1.isPhysicalMaterial,
getUiConfig: material => {
getUiConfig: material => { // todo use uiConfigMaterialExtension
const viewer = this._viewer! const viewer = this._viewer!
if (material.userData._noiseBumpMat === undefined) material.userData._noiseBumpMat = {} if (material.userData._noiseBumpMat === undefined) material.userData._noiseBumpMat = {}
const state = material.userData._noiseBumpMat const state = material.userData._noiseBumpMat
constructor() { constructor() {
super() super()
this._loaderCreate = this._loaderCreate.bind(this) this._loaderCreate = this._loaderCreate.bind(this)
Object.assign(this.materialExtension.extraUniforms!, this._uniforms)
} }


onAdded(v: ThreeViewer) { onAdded(v: ThreeViewer) {

Загрузка…
Отмена
Сохранить