@threepipe/webgi-plugins 0.6.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +99 -0
- package/LICENSE +133 -16
- package/README.md +29 -26
- package/THIRD_PARTY_NOTICES.md +243 -0
- package/dist/dependencies.txt +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3907 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3824 -18
- package/dist/index.mjs.map +1 -1
- package/dist/passes/BilateralFilterPass.d.ts +1 -1
- package/dist/passes/BilateralFilterPass.d.ts.map +1 -1
- package/dist/plugins/buffer/VelocityBufferPlugin.d.ts.map +1 -1
- package/dist/plugins/extras/AdvancedGroundPlugin.d.ts +4 -3
- package/dist/plugins/extras/AdvancedGroundPlugin.d.ts.map +1 -1
- package/dist/plugins/extras/AnisotropyPlugin.d.ts +5 -4
- package/dist/plugins/extras/AnisotropyPlugin.d.ts.map +1 -1
- package/dist/plugins/extras/WatchHandsPlugin.d.ts +1 -1
- package/dist/plugins/extras/WatchHandsPlugin.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +23 -23
- package/dist/plugins/postprocessing/BloomPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/DepthOfFieldPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/OutlinePlugin.d.ts +1 -1
- package/dist/plugins/postprocessing/OutlinePlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/SSContactShadowsPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/SSGIPlugin.d.ts +3 -2
- package/dist/plugins/postprocessing/SSGIPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/SSReflectionPlugin.d.ts +1 -1
- package/dist/plugins/postprocessing/SSReflectionPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/TemporalAAPlugin.d.ts.map +1 -1
- package/dist/utils/FSShadowMaterial.d.ts.map +1 -1
- package/dist/utils/RandomizedDirectionalLight.d.ts.map +1 -1
- package/dist/utils/Reflector2.d.ts +4 -4
- package/dist/utils/Reflector2.d.ts.map +1 -1
- package/dist/utils/ShadowMapBaker.d.ts +1 -1
- package/dist/utils/ShadowMapBaker.d.ts.map +1 -1
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +22 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1648 -0
- package/docs/classes/AdvancedGroundPlugin.html +736 -0
- package/docs/classes/AnisotropyPlugin.html +432 -0
- package/docs/classes/BloomPlugin.html +466 -0
- package/docs/classes/BloomPluginPass.html +323 -0
- package/docs/classes/DepthOfFieldPlugin.html +493 -0
- package/docs/classes/DepthOfFieldPluginPass.html +340 -0
- package/docs/classes/OutlinePlugin.html +696 -0
- package/docs/classes/OutlineRenderPass.html +252 -0
- package/docs/classes/SSContactShadowsPlugin.html +421 -0
- package/docs/classes/SSGIPlugin.html +488 -0
- package/docs/classes/SSGIPluginPass.html +404 -0
- package/docs/classes/SSReflectionPlugin.html +495 -0
- package/docs/classes/SSReflectionPluginPass.html +410 -0
- package/docs/classes/SSVelocityMaterial.html +110 -0
- package/docs/classes/TemporalAAPlugin.html +447 -0
- package/docs/classes/TemporalAAPluginPass.html +337 -0
- package/docs/classes/VelocityBufferPlugin.html +480 -0
- package/docs/classes/WatchHandsPlugin.html +443 -0
- package/docs/hierarchy.html +28 -0
- package/docs/index.html +38 -0
- package/docs/types/OutlinePluginPass.html +32 -0
- package/docs/types/OutlinePluginTarget.html +32 -0
- package/docs/types/SSGIPluginTarget.html +32 -0
- package/docs/types/SSReflectionPluginTarget.html +32 -0
- package/docs/types/VelocityBufferPluginPass.html +32 -0
- package/docs/types/VelocityBufferPluginTarget.html +32 -0
- package/docs/variables/anisotropyGLTFExtension.html +43 -0
- package/docs/variables/webgiPlugins.html +32 -0
- package/package.json +23 -22
- package/src/global.d.ts +27 -0
- package/src/index.ts +1 -0
- package/src/passes/BilateralFilterPass.ts +62 -0
- package/src/passes/shaders/ssaoBilateral.glsl +89 -0
- package/src/plugins/buffer/VelocityBufferPlugin.ts +270 -0
- package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.frag.glsl +46 -0
- package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.vert.glsl +51 -0
- package/src/plugins/buffer/shaders/VelocityBufferPlugin.unpack.glsl +8 -0
- package/src/plugins/extras/AdvancedGroundPlugin.ts +385 -0
- package/src/plugins/extras/AnisotropyPlugin.ts +519 -0
- package/src/plugins/extras/WatchHandsPlugin.ts +156 -0
- package/src/plugins/extras/shaders/anisotropyBsdf.glsl +64 -0
- package/src/plugins/extras/shaders/anisotropyTBN.glsl +35 -0
- package/src/plugins/index.ts +38 -0
- package/src/plugins/postprocessing/BloomPlugin.ts +377 -0
- package/src/plugins/postprocessing/DepthOfFieldPlugin.ts +470 -0
- package/src/plugins/postprocessing/OutlinePlugin.ts +476 -0
- package/src/plugins/postprocessing/SSContactShadowsPlugin.ts +374 -0
- package/src/plugins/postprocessing/SSGIPlugin.ts +597 -0
- package/src/plugins/postprocessing/SSReflectionPlugin.ts +563 -0
- package/src/plugins/postprocessing/TemporalAAPlugin.ts +301 -0
- package/src/plugins/postprocessing/shaders/dofBlurBox.glsl +46 -0
- package/src/plugins/postprocessing/shaders/dofCombine.glsl +68 -0
- package/src/plugins/postprocessing/shaders/dofComputeCoC.glsl +21 -0
- package/src/plugins/postprocessing/shaders/dofExpandCoC.glsl +56 -0
- package/src/plugins/postprocessing/shaders/dofPoissonBox.glsl +90 -0
- package/src/plugins/postprocessing/shaders/giPatch.glsl +53 -0
- package/src/plugins/postprocessing/shaders/hdrBloom.glsl +101 -0
- package/src/plugins/postprocessing/shaders/outline.glsl +60 -0
- package/src/plugins/postprocessing/shaders/outlineDepthFrag.glsl +22 -0
- package/src/plugins/postprocessing/shaders/outlineDepthVert.glsl +26 -0
- package/src/plugins/postprocessing/shaders/poissonDiskSamples.glsl +19 -0
- package/src/plugins/postprocessing/shaders/samplePointHelpers.glsl +3 -0
- package/src/plugins/postprocessing/shaders/ssrPatch.glsl +145 -0
- package/src/plugins/postprocessing/shaders/ssreflectionMain.glsl +69 -0
- package/src/plugins/postprocessing/shaders/ssrt.glsl +118 -0
- package/src/utils/FSShadowMaterial.ts +65 -0
- package/src/utils/RandomizedDirectionalLight.ts +288 -0
- package/src/utils/Reflector2.ts +309 -0
- package/src/utils/ShadowMapBaker.ts +527 -0
- package/src/utils/shaders/computeScreenSpaceVelocity.glsl +16 -0
- package/src/utils/shaders/getWorldPositionFromViewZ.glsl +9 -0
- package/src/utils/shaders/poissonDiskSamples.glsl +19 -0
- package/src/utils/shaders/reflectorSample.glsl +54 -0
- package/src/utils/shaders/seperableBlurShaderMasked.glsl +28 -0
- package/src/utils/shaders/seperableShadowBlur.glsl +21 -0
- package/src/utils/shaders/ssreflection.glsl +141 -0
- package/src/utils/shaders/ssrtao.glsl +275 -0
- package/src/utils/shaders/temporalaa.glsl +233 -0
- package/src/utils/shaders.ts +24 -0
- package/tsconfig.json +40 -44
- package/dist/version.d.ts +0 -2
- package/dist/version.d.ts.map +0 -1
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import {
|
|
2
|
+
animateTarget,
|
|
3
|
+
AScreenPassExtensionPlugin,
|
|
4
|
+
Color,
|
|
5
|
+
DoubleSide,
|
|
6
|
+
GBufferPlugin,
|
|
7
|
+
getOrCall,
|
|
8
|
+
glsl,
|
|
9
|
+
ICamera, IGeometry,
|
|
10
|
+
IMaterial,
|
|
11
|
+
IObject3D,
|
|
12
|
+
IPassID,
|
|
13
|
+
IPipelinePass,
|
|
14
|
+
IRenderManager,
|
|
15
|
+
IScene, ITexture,
|
|
16
|
+
IUniform,
|
|
17
|
+
IWebGLRenderer,
|
|
18
|
+
matDefineBool,
|
|
19
|
+
onChange,
|
|
20
|
+
PickingPlugin,
|
|
21
|
+
RenderPass, SelectionObject, SelectionObjectArr,
|
|
22
|
+
serialize,
|
|
23
|
+
ShaderMaterial,
|
|
24
|
+
Texture,
|
|
25
|
+
TextureDataType,
|
|
26
|
+
ThreeViewer,
|
|
27
|
+
uiColor,
|
|
28
|
+
uiFolderContainer,
|
|
29
|
+
uiImage,
|
|
30
|
+
UiObjectConfig,
|
|
31
|
+
uiSlider,
|
|
32
|
+
uiToggle,
|
|
33
|
+
uniform,
|
|
34
|
+
UnsignedByteType,
|
|
35
|
+
ValOrFunc,
|
|
36
|
+
Vector2,
|
|
37
|
+
WebGLRenderTarget,
|
|
38
|
+
} from 'threepipe'
|
|
39
|
+
import outlineShader from './shaders/outline.glsl'
|
|
40
|
+
import outlineDepthVertex from './shaders/outlineDepthVert.glsl'
|
|
41
|
+
import outlineDepthFrag from './shaders/outlineDepthFrag.glsl'
|
|
42
|
+
|
|
43
|
+
export type OutlinePluginTarget = WebGLRenderTarget
|
|
44
|
+
export type OutlinePluginPass = OutlineRenderPass<'outline', OutlinePluginTarget | undefined >
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Outline Plugin
|
|
48
|
+
* Adds an extension to {@link ScreenPass} material and a RenderPass to render the outlines and highlights of the selected objects.
|
|
49
|
+
* It interfaces with the {@link PickingPlugin} to render the outlines of the selected objects.
|
|
50
|
+
* The intensity, thickness, etc of the effect can be controlled with the `intensity`(previously outlineIntensity), `thickness` etc properties.
|
|
51
|
+
*
|
|
52
|
+
* @category Plugins
|
|
53
|
+
*/
|
|
54
|
+
@uiFolderContainer('Selection Outline')
|
|
55
|
+
export class OutlinePlugin extends AScreenPassExtensionPlugin {
|
|
56
|
+
readonly passId = 'outline'
|
|
57
|
+
static readonly PluginType = 'OutlinePlugin'
|
|
58
|
+
static readonly OldPluginType = 'Outline'
|
|
59
|
+
|
|
60
|
+
readonly extraUniforms = {
|
|
61
|
+
outlineIntensity: {value: 1},
|
|
62
|
+
outlineThickness: {value: 2},
|
|
63
|
+
highlightTransparency: {value: 1},
|
|
64
|
+
outlineColor: {value: new Color(0xe98a65)},
|
|
65
|
+
enableHighlight: {value: true},
|
|
66
|
+
dpr: {value: 1} as IUniform<number>,
|
|
67
|
+
|
|
68
|
+
outlineBuffer: {value: null},
|
|
69
|
+
tDiffuseSize: {value: new Vector2(1024, 1024)},
|
|
70
|
+
} as const
|
|
71
|
+
extraDefines = {
|
|
72
|
+
['DEBUG_OUTLINE']: '0',
|
|
73
|
+
} as const
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The priority of the material extension when applied to the material in ScreenPass
|
|
77
|
+
* set to very low priority, so applied at the end.
|
|
78
|
+
*/
|
|
79
|
+
priority = -101
|
|
80
|
+
|
|
81
|
+
@onChange(OutlinePlugin.prototype.setDirty)
|
|
82
|
+
@uiToggle('Enable')
|
|
83
|
+
@serialize() enabled: boolean
|
|
84
|
+
|
|
85
|
+
@uiToggle('Highlight')
|
|
86
|
+
@uniform({propKey: 'enableHighlight'})
|
|
87
|
+
@serialize() enableHighlight = false
|
|
88
|
+
|
|
89
|
+
@onChange(OutlinePlugin.prototype.setDirty)
|
|
90
|
+
@uiToggle('DynamicSelection')
|
|
91
|
+
@serialize() enableDynamicSelection = true
|
|
92
|
+
|
|
93
|
+
@uiSlider('Intensity', [0., 4], 0.001)
|
|
94
|
+
@uniform({propKey: 'outlineIntensity'})
|
|
95
|
+
@serialize('outlineIntensity') intensity = 2
|
|
96
|
+
|
|
97
|
+
@onChange(OutlinePlugin.prototype.setDirty)
|
|
98
|
+
@uiSlider('Transparency', [0., 1], 0.01)
|
|
99
|
+
@serialize() highlightTransparency = 0.84
|
|
100
|
+
|
|
101
|
+
@uiColor('Color')
|
|
102
|
+
@uniform({propKey: 'outlineColor'})
|
|
103
|
+
@serialize('outlineColor') color = new Color(0xe98a65)
|
|
104
|
+
|
|
105
|
+
@uiSlider('Thickness', [0, 10], 0.01)
|
|
106
|
+
@uniform({propKey: 'outlineThickness'})
|
|
107
|
+
@serialize('outlineThickness') thickness = 2
|
|
108
|
+
|
|
109
|
+
@uiToggle('Debug')
|
|
110
|
+
// todo onchange
|
|
111
|
+
@matDefineBool('DEBUG_OUTLINE', undefined, true)
|
|
112
|
+
debugOutline = false
|
|
113
|
+
|
|
114
|
+
@onChange(OutlinePlugin.prototype.setDirty)
|
|
115
|
+
@uiToggle('Highlight Selected Materials')
|
|
116
|
+
highlightSelectedMaterials = false
|
|
117
|
+
|
|
118
|
+
@onChange(OutlinePlugin.prototype.setDirty)
|
|
119
|
+
@uiToggle('Highlight Materials (same name)')
|
|
120
|
+
highlightMaterialSameNames = false
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Highlight Transparency.
|
|
124
|
+
*
|
|
125
|
+
* For internal use, don't change. use {@link highlightTransparency} instead.
|
|
126
|
+
*/
|
|
127
|
+
@uniform({propKey: 'highlightTransparency'})
|
|
128
|
+
transparency = 0
|
|
129
|
+
|
|
130
|
+
parsFragmentSnippet = () => {
|
|
131
|
+
if (this.isDisabled()) return ''
|
|
132
|
+
|
|
133
|
+
return glsl`
|
|
134
|
+
${outlineShader}
|
|
135
|
+
`
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
protected _shaderPatch = 'diffuseColor = outline(diffuseColor);'
|
|
139
|
+
|
|
140
|
+
constructor(enabled = true, bufferType: TextureDataType = UnsignedByteType) {
|
|
141
|
+
super()
|
|
142
|
+
this.enabled = enabled
|
|
143
|
+
this.bufferType = bufferType
|
|
144
|
+
}
|
|
145
|
+
dependencies = [PickingPlugin, GBufferPlugin]
|
|
146
|
+
|
|
147
|
+
private _pickingWidgetDisabled = false
|
|
148
|
+
setDirty() {
|
|
149
|
+
super.setDirty()
|
|
150
|
+
if (!this._viewer) return
|
|
151
|
+
const picking = this._viewer.getPlugin(PickingPlugin)
|
|
152
|
+
let enabled = !this.isDisabled()
|
|
153
|
+
if (enabled) {
|
|
154
|
+
// special check for lines, as they look bad with the outline
|
|
155
|
+
const selected = picking?.getSelectedObject<IObject3D>() // primary object for line check
|
|
156
|
+
if (typeof selected?.type === 'string' && selected?.type?.includes('Line')) {
|
|
157
|
+
enabled = false
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (picking) {
|
|
161
|
+
if (enabled && picking.widgetEnabled) {
|
|
162
|
+
picking.widgetEnabled = false
|
|
163
|
+
this._pickingWidgetDisabled = true
|
|
164
|
+
} else if (!enabled && this._pickingWidgetDisabled) {
|
|
165
|
+
picking.widgetEnabled = true
|
|
166
|
+
this._pickingWidgetDisabled = false
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
this._viewer.setDirty()
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// @serialize('pass')
|
|
173
|
+
protected _pass?: OutlinePluginPass
|
|
174
|
+
|
|
175
|
+
onAdded(viewer: ThreeViewer) {
|
|
176
|
+
super.onAdded(viewer)
|
|
177
|
+
this.setDirty() // for picking widget
|
|
178
|
+
|
|
179
|
+
this._pass = this._createPass()
|
|
180
|
+
this._pass.onDirty?.push(viewer.setDirty)
|
|
181
|
+
// this._pass.beforeRender = wrapThisFunction2(this._beforeRender, this._pass.beforeRender) // not needed at the moment
|
|
182
|
+
viewer.renderManager.registerPass(this._pass)
|
|
183
|
+
|
|
184
|
+
// todo use forPlugin and remove listener
|
|
185
|
+
const pickingPlugin = viewer.getPlugin(PickingPlugin)
|
|
186
|
+
pickingPlugin?.addEventListener('selectedObjectChanged', ()=> {
|
|
187
|
+
if (!this._animationCallBack && this) {
|
|
188
|
+
if (pickingPlugin?.getSelectedObject()) {
|
|
189
|
+
if (this.enableDynamicSelection) {
|
|
190
|
+
this.transparency = 1
|
|
191
|
+
this._animationCallBack = this._startTransparencyAnimation(1, this.highlightTransparency, 400)
|
|
192
|
+
} else {
|
|
193
|
+
this.transparency = this.highlightTransparency
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
this.transparency = 1
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
// todo remove listener
|
|
202
|
+
document.addEventListener('mousemove', (e: MouseEvent)=> {
|
|
203
|
+
if (!this) return
|
|
204
|
+
if (!this.mouseInOutAnimationEnabled) return
|
|
205
|
+
if (!this.enableHighlight) return
|
|
206
|
+
const selectedObject = pickingPlugin?.getSelectedObject()
|
|
207
|
+
if (selectedObject && this.enableDynamicSelection) {
|
|
208
|
+
if (e.target !== viewer.canvas) {
|
|
209
|
+
if (!this._animationCallBack && this._state === 'in') {
|
|
210
|
+
this._animationCallBack = this._startTransparencyAnimation(this.highlightTransparency, 1, 600)
|
|
211
|
+
this._state = 'out'
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
if (!this._animationCallBack && this._state === 'out') {
|
|
215
|
+
this._animationCallBack = this._startTransparencyAnimation(1, this.highlightTransparency, 600)
|
|
216
|
+
this._state = 'in'
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
this.transparency = selectedObject ? this.highlightTransparency : 1
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
onRemove(viewer: ThreeViewer): void {
|
|
225
|
+
this._disposeTarget()
|
|
226
|
+
if (this._pass) {
|
|
227
|
+
viewer.renderManager.unregisterPass(this._pass)
|
|
228
|
+
if (this._pass.dispose) this._pass.dispose()
|
|
229
|
+
}
|
|
230
|
+
this._pass = undefined
|
|
231
|
+
return super.onRemove(viewer)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
target?: OutlinePluginTarget
|
|
235
|
+
|
|
236
|
+
@uniform({propKey: 'outlineBuffer'})
|
|
237
|
+
@uiImage('Outline Buffer', {readOnly: true}) texture?: Texture
|
|
238
|
+
|
|
239
|
+
readonly material: ShaderMaterial = new ShaderMaterial({
|
|
240
|
+
uniforms: {
|
|
241
|
+
'cameraNearFar': {value: new Vector2(0.1, 100)},
|
|
242
|
+
},
|
|
243
|
+
vertexShader: outlineDepthVertex,
|
|
244
|
+
fragmentShader: outlineDepthFrag,
|
|
245
|
+
side: DoubleSide,
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
// @onChange2(OutlinePlugin.prototype._createTarget)
|
|
249
|
+
// @uiDropdown('Buffer Type', threeConstMappings.TextureDataType.uiConfig)
|
|
250
|
+
readonly bufferType: TextureDataType // cannot be changed after creation (for now)
|
|
251
|
+
|
|
252
|
+
protected _createTarget(recreate = true) {
|
|
253
|
+
if (!this._viewer) return
|
|
254
|
+
if (recreate) this._disposeTarget()
|
|
255
|
+
|
|
256
|
+
if (!this.target) this.target = this._viewer.renderManager.createTarget<OutlinePluginTarget>(
|
|
257
|
+
{
|
|
258
|
+
// depthBuffer: true,
|
|
259
|
+
sizeMultiplier: 1,
|
|
260
|
+
type: this.bufferType,
|
|
261
|
+
// magFilter: NearestFilter,
|
|
262
|
+
// minFilter: NearestFilter,
|
|
263
|
+
// generateMipmaps: false,
|
|
264
|
+
// colorSpace: LinearSRGBColorSpace,
|
|
265
|
+
})
|
|
266
|
+
this.texture = this.target.texture
|
|
267
|
+
this.texture.name = 'normalBuffer'
|
|
268
|
+
}
|
|
269
|
+
protected _disposeTarget() {
|
|
270
|
+
if (!this._viewer) return
|
|
271
|
+
if (this.target) {
|
|
272
|
+
this._viewer.renderManager.disposeTarget(this.target)
|
|
273
|
+
this.target = undefined
|
|
274
|
+
}
|
|
275
|
+
this.texture = undefined
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private _getSelectedObject = () => {
|
|
279
|
+
if (!this._viewer) return null
|
|
280
|
+
// getSelectedObjects exists since threepipe 0.5.0, older versions only have getSelectedObject
|
|
281
|
+
const picking: (PickingPlugin & {getSelectedObjects?: () => SelectionObject[]}) | undefined = this._viewer.getPlugin(PickingPlugin)
|
|
282
|
+
if (this.highlightSelectedMaterials) {
|
|
283
|
+
const mat = picking?.getSelectedObject<IObject3D>()?.material || null
|
|
284
|
+
if (this.highlightMaterialSameNames && mat) {
|
|
285
|
+
const names = Array.isArray(mat) ? mat.map(m => m.name) : [mat.name]
|
|
286
|
+
const mats = new Set<IMaterial>()
|
|
287
|
+
for (const name of names) {
|
|
288
|
+
const mats1 = this._viewer?.assetManager?.materials?.findMaterialsByName(name)
|
|
289
|
+
mats1?.forEach(m => mats.add(m))
|
|
290
|
+
}
|
|
291
|
+
return [...mats]
|
|
292
|
+
}
|
|
293
|
+
return mat
|
|
294
|
+
}
|
|
295
|
+
const objects = picking ? picking.getSelectedObjects ? picking.getSelectedObjects() : [picking.getSelectedObject() || null] : null
|
|
296
|
+
return objects && objects.length > 0 ? objects.length === 1 ? objects[0] : objects as SelectionObjectArr : null
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
protected _createPass() {
|
|
300
|
+
this._createTarget(true)
|
|
301
|
+
if (!this.target) throw new Error('OutlinePlugin: target not created')
|
|
302
|
+
|
|
303
|
+
this.material.userData.isOutlinePluginMaterial = true
|
|
304
|
+
const pass = new OutlineRenderPass<'outline', OutlinePluginTarget|undefined>(this.passId, this._getSelectedObject, ()=>this.target, this.material)
|
|
305
|
+
return pass
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
protected _viewerListeners = {
|
|
309
|
+
preRender: ()=>{
|
|
310
|
+
if (this.isDisabled() || !this._viewer) return
|
|
311
|
+
// todo directly bind to value
|
|
312
|
+
this.extraUniforms.dpr.value = this._viewer.renderManager.renderScale * 2
|
|
313
|
+
},
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// region animation
|
|
317
|
+
|
|
318
|
+
mouseInOutAnimationEnabled = true
|
|
319
|
+
|
|
320
|
+
private _state = 'in'
|
|
321
|
+
|
|
322
|
+
private _animationCallBack?: Promise<void>
|
|
323
|
+
|
|
324
|
+
private async _startTransparencyAnimation(from: number, to: number, duration: number) {
|
|
325
|
+
return animateTarget(this, 'transparency', {
|
|
326
|
+
from: from,
|
|
327
|
+
to: to,
|
|
328
|
+
duration: duration,
|
|
329
|
+
onComplete: () => {
|
|
330
|
+
this._animationCallBack = undefined
|
|
331
|
+
},
|
|
332
|
+
})
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// endregion animation
|
|
336
|
+
|
|
337
|
+
// region deprecated
|
|
338
|
+
|
|
339
|
+
get outlineIntensity() {
|
|
340
|
+
console.warn('OutlinePlugin.outlineIntensity is deprecated, use OutlinePlugin.intensity instead')
|
|
341
|
+
return this.intensity
|
|
342
|
+
}
|
|
343
|
+
set outlineIntensity(v) {
|
|
344
|
+
console.warn('OutlinePlugin.outlineIntensity is deprecated, use OutlinePlugin.intensity instead')
|
|
345
|
+
this.intensity = v
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
get outlineColor() {
|
|
349
|
+
console.warn('OutlinePlugin.outlineColor is deprecated, use OutlinePlugin.intensity instead')
|
|
350
|
+
return this.intensity
|
|
351
|
+
}
|
|
352
|
+
set outlineColor(v) {
|
|
353
|
+
console.warn('OutlinePlugin.outlineColor is deprecated, use OutlinePlugin.intensity instead')
|
|
354
|
+
this.intensity = v
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// endregion deprecated
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
@uiFolderContainer<OutlineRenderPass>((c: OutlineRenderPass)=>c.passId + ' Render Pass')
|
|
361
|
+
export class OutlineRenderPass<TP extends IPassID=IPassID, T extends WebGLRenderTarget | undefined = WebGLRenderTarget | undefined > extends RenderPass implements IPipelinePass<TP> { // todo: extend from jittered?
|
|
362
|
+
readonly isOutlineRenderPass = true
|
|
363
|
+
declare uiConfig: UiObjectConfig
|
|
364
|
+
|
|
365
|
+
@uiToggle('Enabled') enabled = true
|
|
366
|
+
|
|
367
|
+
declare scene?: IScene
|
|
368
|
+
before = ['render']
|
|
369
|
+
after = ['gbuffer']
|
|
370
|
+
required = ['render', 'gbuffer']
|
|
371
|
+
|
|
372
|
+
declare overrideMaterial: ShaderMaterial
|
|
373
|
+
|
|
374
|
+
constructor(public readonly passId: TP, private _getSelectedObjectOrMaterial: ()=>SelectionObject|SelectionObjectArr, public target: ValOrFunc<T>, overrideMaterial: ShaderMaterial) {
|
|
375
|
+
super(undefined, undefined, overrideMaterial, new Color(1, 1, 1), 1)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// constructor(private _getSelectedObjectOrMaterial: ()=>SelType, public target: WebGLRenderTarget, material: Material, clearColor: Color = new Color(1, 1, 1), clearAlpha = 1) {
|
|
379
|
+
// super(undefined as any, undefined as any, material, clearColor, clearAlpha)
|
|
380
|
+
// }
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Renders to {@link target}
|
|
384
|
+
* @param renderer
|
|
385
|
+
* @param writeBuffer - this is ignored? or used as transmissionRenderTarget?
|
|
386
|
+
* @param _1 - this is ignored
|
|
387
|
+
* @param deltaTime
|
|
388
|
+
* @param maskActive
|
|
389
|
+
*/
|
|
390
|
+
render(renderer: IWebGLRenderer, writeBuffer?: WebGLRenderTarget|null, _1?: WebGLRenderTarget, deltaTime?: number, maskActive?: boolean) {
|
|
391
|
+
if (!this.scene || !this.camera || !this.enabled) return
|
|
392
|
+
|
|
393
|
+
const t = renderer.getRenderTarget()
|
|
394
|
+
const activeCubeFace = renderer.getActiveCubeFace()
|
|
395
|
+
const activeMipLevel = renderer.getActiveMipmapLevel()
|
|
396
|
+
|
|
397
|
+
const selectedObject = this._getSelectedObjectOrMaterial()
|
|
398
|
+
if (selectedObject) {
|
|
399
|
+
this._renderSelectedObject(renderer, selectedObject, writeBuffer || null, deltaTime, maskActive)
|
|
400
|
+
} else {
|
|
401
|
+
renderer.setRenderTarget(getOrCall(this.target) || null)
|
|
402
|
+
const color = new Color()
|
|
403
|
+
renderer.getClearColor(color)
|
|
404
|
+
renderer.setClearColor(new Color(0xffffff))
|
|
405
|
+
renderer.clear(true, true)
|
|
406
|
+
renderer.setClearColor(color)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
renderer.setRenderTarget(t, activeCubeFace, activeMipLevel)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
private _renderSelectedObject(renderer: IWebGLRenderer, selectedObject: SelectionObject|SelectionObjectArr, writeBuffer: WebGLRenderTarget | null, deltaTime: any, maskActive: any) {
|
|
413
|
+
if (!this.camera || !selectedObject) return
|
|
414
|
+
const selectionLayer = 6
|
|
415
|
+
|
|
416
|
+
// flatten array and get applied meshes from materials
|
|
417
|
+
const objs = (Array.isArray(selectedObject) ? selectedObject : [selectedObject])
|
|
418
|
+
.flatMap(o =>
|
|
419
|
+
(o as ITexture)?.isTexture ? [...(o as ITexture).appliedObjects?.values() || []] : o)
|
|
420
|
+
.flatMap(o =>
|
|
421
|
+
(o as IMaterial)?.isMaterial ? [...(o as IMaterial).appliedMeshes?.values() || []] :
|
|
422
|
+
(o as IGeometry)?.isBufferGeometry ? [...(o as IGeometry).appliedMeshes?.values() || []] :
|
|
423
|
+
o as IObject3D)
|
|
424
|
+
|
|
425
|
+
for (const o1 of objs) {
|
|
426
|
+
o1 && o1.traverse((o) => {
|
|
427
|
+
o.layers.enable(selectionLayer)
|
|
428
|
+
})
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const mask = this.camera.layers.mask
|
|
432
|
+
this.camera.layers.set(selectionLayer)
|
|
433
|
+
|
|
434
|
+
const ud = (renderer as any).userData
|
|
435
|
+
if (!ud) console.error('threejs is not patched?')
|
|
436
|
+
|
|
437
|
+
ud.transmissionRenderTarget = writeBuffer
|
|
438
|
+
|
|
439
|
+
renderer.renderWithModes({
|
|
440
|
+
shadowMapRender: false,
|
|
441
|
+
backgroundRender: false,
|
|
442
|
+
opaqueRender: true,
|
|
443
|
+
transparentRender: true,
|
|
444
|
+
transmissionRender: true,
|
|
445
|
+
mainRenderPass: false,
|
|
446
|
+
}, ()=> super.render(renderer, writeBuffer as any, getOrCall(this.target), deltaTime as any, maskActive as any)) // here this.target is the write-buffer, variable writeBuffer is ignored
|
|
447
|
+
|
|
448
|
+
ud.transmissionRenderTarget = undefined
|
|
449
|
+
|
|
450
|
+
objs.forEach(o1=>o1.traverse(o => {
|
|
451
|
+
o.layers.disable(selectionLayer)
|
|
452
|
+
}))
|
|
453
|
+
|
|
454
|
+
this.camera.layers.mask = mask
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
public onDirty: (()=>void)[] = []
|
|
458
|
+
|
|
459
|
+
dispose() {
|
|
460
|
+
this.onDirty = []
|
|
461
|
+
this.scene = undefined
|
|
462
|
+
this.camera = undefined
|
|
463
|
+
super.dispose?.()
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
setDirty() {
|
|
467
|
+
this.onDirty.forEach(v=>v())
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
beforeRender(scene: IScene, camera: ICamera, _: IRenderManager): void {
|
|
471
|
+
this.scene = scene
|
|
472
|
+
this.camera = camera
|
|
473
|
+
camera.updateShaderProperties(this.overrideMaterial)
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
}
|