-
Notifications
You must be signed in to change notification settings - Fork 106
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
[discussion and proposal]: InstancesMesh #61
Comments
Hi Hooke! I really like this idea. I was thinking an instance would work something like this:
I think InstanceData is missing:
Your proposal looks like a really good way to instantiate a lot of objects easily, but doesn't allow extra control (like instance3 above) - this would also allow access to manually updating vertex data. It also seems less intuitive about how to update position. Do you intend to be able to update positions with your API? I think both ways could be supported. Let me know how I can help - I'll make a I think also it would be good to support loaded models - maybe with hooks. |
So, this is something like the hook I was thinking of. It would force the re-render with some kind of trick and publish the ref for re-use. This kind of hook could be re-used if generic to clean up even some current stories like the PixiJS one for tetures. Anyway: export const useMesh = <T extends AbstractMesh>(): [MutableRefObject<T>, T] => {
const [unused, swapState] = useState(false)
const ref = useRef<T>(undefined as any)
useLayoutEffect(
() => void swapState((value: boolean) => !value),
[ref.current]
)
return [ref, ref.current]
} Then I made a story like this: const Instance = (props) => {
console.log('creating')
const createdInstance = props.mesh.hostInstance.createInstance(props.name);
createdInstance.position = props.position;
return null;
}
const InstancedMeshes = () => {
const [boxRef, box] = useMesh()
return (
<>
<box ref={boxRef} name='box1' position={new Vector3(2, 0, 0)} />
{box &&
<>
{Array.from(new Array(50), (_, index) => index).map(number => (
<Instance name={`box${number}`} mesh={box} position={new Vector3((number * 2) - 50, 2, 0)} />
))
}
</>
}
</>
)
} I just added the above to a story. Need to think about how it would handle all of the lifecycle methods and updates to properties. ie: we should be able to have something like:
Anyway, that's just an idea. Would really like to see what direction you were headed, because this looks really useful :) |
|
Thank you for writing a demo so quickly. |
@brianzinn
Hi, brianzinn. I'm busy with my works these days. But we can start to design
InstancesMesh
API.Why use InstancesMesh
(Have you ever compared the performance of the MergedMesh and InstancesMesh?)
Features
API suggestion
The text was updated successfully, but these errors were encountered: