Comments (11)
Sure, if could your code with me I can try and find a way to make it work then explain how I did it and make some changes to this repo to make it work better in multi page contexts.
from react-webgl-fluid.
You can try call gl.getExtension('WEBGL_lose_context').loseContext();
on page change, that will stop the sim from running, otherwise removing the canvas from the DOM and adding it again will reset the sim too. I'd like to try make the script a function that you can call whenever at some point, but I hope that helps.
from react-webgl-fluid.
Thanks for the response!
So put gl.getExtension('WEBGL_lose_context').loseContext();
under a ComponentWillUnMount()
?
from react-webgl-fluid.
If it helps, this is the error I get in console when I navigate back to the page with the canvas element:
from react-webgl-fluid.
You can also try:
componentDidMount() {
const script = document.createElement("script");
script.src = "./assets/js/fluid-init.js";
script.id = "fluid-src"; // give the script tag an ID
script.async = true;
script.onload = () => this.fluidLoaded();
document.body.appendChild(script);
}
componentDidUnMount () {
gl.getExtension('WEBGL_lose_context').loseContext();
document.querySelector("#fluid-src").remove();
}
So when the component unmounts it removes the script and removes the GL context, then when it mounts again it will re-add the script and re-execute the script.
gl.getExtension('WEBGL_lose_context').loseContext();
might not be needed with this approach but give it a shot.
from react-webgl-fluid.
Thanks! And Happy New Year!
Unfortunately, I've already tried that approach by that doesn't seem to work. gl
is undefined in that context so that doesn't work from the component. If I copy the declarations from the script, then getWebGLContext()
is returned as undefined. At that point, so get that to work, I'd have to copy the entire script and create it into a function, like you mentioned earlier. I don't have much experience in this unfortunately. Would you be able to help out?
from react-webgl-fluid.
Sure thing, here you go: https://github.com/MrUltimate/portfolio-2020
The Fluid Component is here: https://github.com/MrUltimate/portfolio-2020/blob/master/src/components/fluid.jsx
And the fluid.js
script is stored here: https://github.com/MrUltimate/portfolio-2020/blob/master/static/assets/scripts/fluid-init.js
Thanks for all your help!
from react-webgl-fluid.
I couldn't get your site to run with gatsby develop
because your datoCMS API key is missing from .env and it just seems to break further if I try remove the datoCMS packages. I don't really want to reverse it into a standalone react site so If you're okay with sending me your .env file you can email to me.
from react-webgl-fluid.
Just sent it to you!
from react-webgl-fluid.
Thanks, I changed the script so that the fluid sim can be called and started with fluid()
and stopped by calling fluidStop()
. But even with those functions working just fine the weird stacking problem still happens. I think it's something to do with React's pagination that keeps the sim running in the background regardless of the page change. I guess I'll have to look deeper into webGL garbage collection so the stop script will properly kill the process on navigating away from the page it's on.
The only short term solution I can think of is just setting your home page link to an absolute URL like
<Link className="link home" to={"https://helloshivam.com/"}>
That way the entire page reloads fully and the script will run properly without overlapping.
Or you could try make a basic HTML with the sim running in it and embed that in an iframe then replace the canvas with that.
I made a PR here with the changes to the script https://github.com/MrUltimate/portfolio-2020/pull/1
Sorry I couldn't get it working perfectly but I'll try and make this implementation work correctly with page changes soon.
from react-webgl-fluid.
Thanks for all the help, looks like with this update, the WebGL canvas fails to render completely, with lots of errors that I don't understand.
from react-webgl-fluid.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ī¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-webgl-fluid.