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

BatchedMesh edge case: wrong frustum when perObjectFrustumCulled = false #29603

Closed
Makio64 opened this issue Oct 9, 2024 · 1 comment · Fixed by #29687
Closed

BatchedMesh edge case: wrong frustum when perObjectFrustumCulled = false #29603

Makio64 opened this issue Oct 9, 2024 · 1 comment · Fixed by #29687
Labels
Milestone

Comments

@Makio64
Copy link
Contributor

Makio64 commented Oct 9, 2024

Description

Add an Instance after the BatchedMesh creation + perObjectFrustumCulled = false, result in BatchedMesh not showing at all.

Expected result : the new added instance show up in both case perObjectFrustumCulled = false or perObjectFrustumCulled = true

Reproduction steps

  1. Create a BatchedMesh, set perObjectFrustumCulled = false
  2. addInstance after some time
  3. Nothing show up

Code

import * as THREE from 'three'
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
let mesh, renderer, scene, camera, controls

init()

function init() {
	// renderer
	renderer = new THREE.WebGPURenderer({ alpha: false })
	renderer.setSize(window.innerWidth, window.innerHeight)
	renderer.setPixelRatio(window.devicePixelRatio)
	renderer.setAnimationLoop(animate)
	document.body.appendChild(renderer.domElement)

	// scene
	scene = new THREE.Scene()

	// camera
	camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 1, 100)
	camera.position.set(15, 0, 0)

	// controls
	controls = new OrbitControls(camera, renderer.domElement)


	const box = new THREE.BoxGeometry(1, 1, 1)
	const sphere = new THREE.SphereGeometry(1)
	const material = new THREE.MeshStandardNodeMaterial()

	const batchedMesh = new THREE.BatchedMesh(10, 5000, 10000, material)
	batchedMesh.perObjectFrustumCulled = false // WORK IF TRUE
	batchedMesh.sortObjects = false
	
	const boxGeometryId = batchedMesh.addGeometry(box)
	const sphereGeometryId = batchedMesh.addGeometry(sphere)

	scene.add(batchedMesh)
  
	scene.add(new THREE.DirectionalLight(0xDDDDDff, 2))

	animate()
	
	setTimeout(()=>{
		const dummy = new THREE.Object3D()
		let rand = ()=> THREE.MathUtils.randFloat ( -5,5)

		for(let i=0; i<5; i++){
			let instance = batchedMesh.addInstance(Math.random()>.5?boxGeometryId:sphereGeometryId)
			dummy.position.set(rand(), rand(), rand())
			dummy.rotation.set(rand(), rand(), rand())
			dummy.updateMatrix()
			batchedMesh.setMatrixAt(instance, dummy.matrix)
		}
	},1000)

}

function animate(now = 0) {
	renderer.renderAsync(scene, camera)
}

Live example

https://jsfiddle.net/Makio64/8ewqcsf1/10/

Screenshots

No response

Version

r169 dev

Device

Desktop, Mobile

Browser

Chrome

OS

MacOS

@gkjohnson gkjohnson added the Bug label Oct 10, 2024
@gkjohnson gkjohnson added this to the r170 milestone Oct 10, 2024
@gkjohnson
Copy link
Collaborator

This is likely because the _visibilityChanged isn't set to true in the addInstance function, which tells the class that the render ranges need to be updated even if the the sort and frustum flags are disabled.

It should probably be set in the "optimize" function, as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants