-
-
Notifications
You must be signed in to change notification settings - Fork 457
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
Canvas works, SVG works, WebGL renders nothing #736
Comments
I should add: leafing through that same browser console, it does appear that our application's content is in the |
Hmmm, that is sufficiently vague. Couple things stand out as potential next steps:
Generally, if you're not using the const two = new Two({ type: Two.Types.webgl, autostart: true }).appendTo(document.body);
// If you haven't autostarted you need
// to call two.update();
const rectangle = new Two.Rectangle(x, y, width, height);
two.add(rectangle); With groups as intermediaries it is possible that all the nested elements in a group could get missed on the update invocation. But, without an example it's hard to know for sure. |
What do ya mean there? Is there anything we could dig into? Or something about the conditions which might make that happen? Thanks again! |
Could you export one scene in SVG? Then I could import it into Two.js using WebGL and it should produce the same error. What I mean regarding groups, is if you can tell me the exact order that elements are added then maybe I can reproduce the issue. To confirm, this only happens with simple paths? Or also with text and images? This could give a hint because Text and Images are not based on Two.Path. All other primitive shapes are. |
OK that makes sense, I'll export some SVGs. |
OK attaching an example SVG. svgString = (): Result<string> => {
this.two.update();
const { innerHTML } = this.twoParentDiv;
// Stick that `xmlns` attribute in there, so most readers will accept it.
const s = innerHTML.replace(
"<svg",
'<svg xmlns="http://www.w3.org/2000/svg"'
);
return Result.Ok(s);
}; Just double-checked that swapping to the webgl renderer renders this blank. |
An unrelated note: if at all possible I would highly recommend making the grid a single path. |
Very interesting indeed! And one big path sounds like a pretty good idea. |
Yep, it would reduce the draw calls |
FWIW passing that SVG content to |
Hmm, that would indicate that there's something you're doing (or not doing) that This is all the method does once the content is loaded and available in the DOM for (i = 0; i < dom.temp.children.length; i++) {
elem = dom.temp.children[i];
child = this.interpret(elem, false, false);
if (child !== null) {
group.add(child);
}
} |
Is it possible that transforming (scaling & positioning) a group works differently in the webgl renderer than in the others? // Apply to a `Two.Shape`.
// Notably `Two.Group` is a `Shape`, and is the most common use-case.
apply: (t: CoordTransform, shape: Shape) => {
const { scale, offset } = t;
// Note y-axis inversion is applied right here!
shape.scale = new Vector(scale, -scale);
shape.position = new Vector(offset.x, offset.y);
}, Usually the |
I'll try to make a minimal demo case. |
OK yeah that's it, or something to do with it. import Two from 'https://cdn.skypack.dev/two.js@latest';
const two = new Two({
type: Two.Types.svg,
fullscreen: true,
autostart: true
}).appendTo(document.body);
// Create a single child group
const g = new Two.Group();
g.addTo(two);
// Add a rectangle to it
const r = new Two.Rectangle(100,-100,100,100);
r.fill = "red";
r.addTo(g);
// Now scale and shift the parent group
g.scale = new Two.Vector(1, -1);
g.position = new Two.Vector(100, 100);
two.render(); Looks like: Change to: type: Two.Types.webgl, And it looks like this: |
Ah, hah! Thank you! I'll look into this. |
Thanks! FWIW after toying with it some more, it seems to come up in the cases where the scale has opposite signs in x vs y. Eg in the example code scale is (1,-1) (where we are essentially converting "positive y is up" coordinates into "web browser coordinates"). Something similar goes wrong when setting it to (-1,1). |
Ohhhhh, yes this makes sense. In WebGL you can define which "side" you want to render textures to (aka paths, images, text). In Two.js I believe I only have front facing enabled. By enabling both front and back this should fix the issue. I'll work on this right now. |
The above PR addresses your issue. Thanks for reporting! |
This is probably gonna be a pretty crappy bug report, but I'm not really sure what to report.
In our application SVG and Canvas have always worked. WebGL has never worked. It just renders a blank canvas.
It's a big complicated application; I'm not sure how to peel off a minimal repro case.
Currently using Two v0.8.14. Mostly in current Chrome, but also tried in Firefox & Safari, all on current MacOS.
And I did notice something today: calling functions like
makeRectangle
andmakeCircle
on ourTwo
instance in the browser developer console does get them to show up:And noting, our application generally does not use those
makeXyz
functions. We do something more like:I guess the question is: does anything come to mind as to why that combination wouldn't work?
The text was updated successfully, but these errors were encountered: