-
Notifications
You must be signed in to change notification settings - Fork 140
BatchedText: billboard material #341
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
Comments
Hmm, that's a tricky one. I'll try to see if I can make the batched matrix transforms work with other custom shader transforms. But you may be right about this being a common option that would belong in the base shader. |
I am looking to use |
For anyone needed this, I wrote typescript version of this shader: import { Camera, Vector3 } from 'three'
import { BatchedText } from 'troika-three-text'
const _position = new Vector3()
const _scale = new Vector3()
const _cameraPosition = new Vector3()
// usage: add Text with `billboardBatchedText.addText(text)`,
// and then add it to three's parent with `group.add(text)`
class BillboardBatchedText extends BatchedText {
constructor(public scaleFactor: number = 1) {
super()
}
update(camera: Camera) {
const texts = this._members.keys()
camera.getWorldPosition(_cameraPosition)
texts.forEach((text) => {
const parent = text.parent
parent.updateMatrix()
parent.updateWorldMatrix(false, false)
parent.getWorldPosition(_position)
text.position.copy(_position)
camera.getWorldQuaternion(text.quaternion)
// size attenuation
const scale =
_scale.subVectors(text.position, _cameraPosition).length() * this.scaleFactor
text.scale.set(scale, scale, scale)
})
}
}
export default BillboardBatchedText |
Thanks @upisfree for your code! Unfortunately in the loop on the texts inside the BatchText, the Sorry for my ignorance, but I cannot decipher the entire content of the loop. Anyway, leaving only the Thanks! |
I assumed that it would take one instance of const group = new Group();
// position, scale or rotate the group somehow. it will be used to position our text as a parent
const batchedText = new BillboardBatchedText();
const text = new Text();
batchedText.addText(text);
group.add(text); |
Thanks @upisfree !
What I cannot evaluate is if this setup will speedup label rendering. Hopefully the documentation for batchedText will be ready someday... |
The |
@lojjic This means my way to use BatchedText (Adding it to the scene) is the correct one. Correct? |
@crystalfp Yes, it makes sense to me. The billboarding should be achievable by just setting the Text's quaternion, it doesn't need to be added to any external group to do so. |
The reason I did put |
Hello again :)
I'm trying to combine
BatchedText
and yourcreateBillboardMaterial
, but I'm not good at shaders so I don't know why it doesn't work. Maybe I need to do some magic matrix stuff, but I can't figure it out which matrix to use :)Could you please suggest what I'm doing wrong? Thanks again :D
createBillboardMaterial
source (it works with usual Text class just fine):#101 (comment)
https://codesandbox.io/s/createbillboardmaterial-xl6mt?file=/src/createBillboardMaterial.js:0-580
BatchedText
+createBillboardMaterial
— all texts are fixed in camera viewBatchedText
+ material without modifications — all texts are in right places, but they don't look at the cameraP. S. It might make sense to add the
createBillboardMaterial
implementation to the repository, since Text looking always at the camera is a very common request among developers?The text was updated successfully, but these errors were encountered: