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

Instances Shadows Fix #3681

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ export class ExtendedSelection extends SelectionExtension {
)
}
this.lastGizmoTranslation.copy(this.dummyAnchor.position)
this.viewer.requestRender(UpdateFlags.RENDER | UpdateFlags.SHADOWS)
this.viewer.requestRender(UpdateFlags.RENDER_RESET | UpdateFlags.SHADOWS)
}
}
7 changes: 5 additions & 2 deletions packages/viewer-sandbox/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SectionTool } from '@speckle/viewer'
import { SectionOutlines } from '@speckle/viewer'
import { ViewModesKeys } from './Extensions/ViewModesKeys'
import { BoxSelection } from './Extensions/BoxSelection'
import { ExtendedSelection } from './Extensions/ExtendedSelection'

const createViewer = async (containerName: string, stream: string) => {
const container = document.querySelector<HTMLElement>(containerName)
Expand All @@ -45,7 +46,8 @@ const createViewer = async (containerName: string, stream: string) => {
await viewer.init()

const cameraController = viewer.createExtension(CameraController)
const selection = viewer.createExtension(SelectionExtension)
const selection = viewer.createExtension(ExtendedSelection)
selection.init()
const sections = viewer.createExtension(SectionTool)
viewer.createExtension(SectionOutlines)
const measurements = viewer.createExtension(MeasurementsExtension)
Expand Down Expand Up @@ -115,7 +117,7 @@ const getStream = () => {
// 'https://app.speckle.systems/streams/da9e320dad/commits/5388ef24b8'
// 'https://latest.speckle.systems/streams/58b5648c4d/commits/60371ecb2d'
// 'Super' heavy revit shit
'https://app.speckle.systems/streams/e6f9156405/commits/0694d53bb5'
// 'https://app.speckle.systems/streams/e6f9156405/commits/0694d53bb5'
// IFC building (good for a tree based structure)
// 'https://latest.speckle.systems/streams/92b620fb17/commits/2ebd336223'
// IFC story, a subtree of the above
Expand Down Expand Up @@ -454,6 +456,7 @@ const getStream = () => {
// 'https://app.speckle.systems/projects/344f803f81/models/5582ab673e'

// 'https://speckle.xyz/streams/27e89d0ad6/commits/5ed4b74252'
'https://app.speckle.systems/projects/e89b61b65c/models/2a0995f124'
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ void main() {
vec4 rtePivotShadow = computeRelativePositionSeparate(tPivotLow.xyz, tPivotHigh.xyz, uShadowViewer_low, uShadowViewer_high);
shadowPosition.xyz = rotate_vertex_position((shadowPosition - rtePivotShadow).xyz, tQuaternion) * tScale.xyz + rtePivotShadow.xyz + tTranslation.xyz;
#endif
#ifdef USE_INSTANCING
vec4 rtePivotShadow = computeRelativePositionSeparate(ZERO3, ZERO3, uShadowViewer_low, uShadowViewer_high);
shadowPosition.xyz = (mat3(instanceMatrix) * (shadowPosition - rtePivotShadow).xyz) + rtePivotShadow.xyz + instanceMatrix[3].xyz;
#endif
shadowWorldPosition = modelMatrix * shadowPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
vDirectionalShadowCoord[ i ] = shadowMatrix * shadowWorldPosition;
Expand Down
11 changes: 11 additions & 0 deletions packages/viewer/src/modules/objects/SpeckleInstancedMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Object3D,
Ray,
Raycaster,
RGBADepthPacking,
SkinnedMesh,
Sphere,
Triangle,
Expand All @@ -29,6 +30,7 @@ import {
} from '../batching/Batch.js'
import { SpeckleRaycaster } from './SpeckleRaycaster.js'
import Logger from '../utils/Logger.js'
import SpeckleDepthMaterial from '../materials/SpeckleDepthMaterial.js'

const _inverseMatrix = new Matrix4()
const _ray = new Ray()
Expand Down Expand Up @@ -183,6 +185,7 @@ export default class SpeckleInstancedMesh extends Group {
public updateDrawGroups(transformBuffer: Float32Array, gradientBuffer: Float32Array) {
this.instances.forEach((value: InstancedMesh) => {
this.remove(value)
value.customDepthMaterial?.dispose()
value.dispose()
})
this.instances.length = 0
Expand Down Expand Up @@ -218,6 +221,14 @@ export default class SpeckleInstancedMesh extends Group {
group.instanceMatrix.needsUpdate = true
group.layers.set(ObjectLayers.STREAM_CONTENT_MESH)
group.frustumCulled = false
group.customDepthMaterial = new SpeckleDepthMaterial(
{
depthPacking: RGBADepthPacking
},
['USE_RTE', 'ALPHATEST_REJECTION']
)
group.castShadow = !material.transparent
group.receiveShadow = !material.transparent

this.instances.push(group)
this.add(group)
Expand Down
Loading