Recently, I have been extensively exploring the source code for this Three.js example: gpgpu / water.
I think that this example is super cool, and I was hoping to use the values of the water to affect certain things in other parts of my script (perhaps mapping one of the values to an oscillator's frequency). However, I have not been able to find what is actually changing in the data. Anyone can plainly see that some kind of data is changing. If you show the wireframe, then you can see vertices and lines moving in 3D space. Something is changing! But I can't find what it is.
I'm pretty sure that the custom shader has a lot to do with me being unable to find anything. Perhaps the values are hidden somewhere in GPU Land where I can't access them, but I have no idea. I've even looked at values within the GPUComputationRenderer.js script that's used to help with this example, but EVERYTHING seems to be static.
Granted, I'm pretty new to 3D graphics in general, so all of my findings and assumptions may be wrong. Either way, I just want someone to tell me where some kind of data is changing.
A huge thanks to anyone that can help me out with this! At this point, I just want to regain my sanity.
I'm fairly new at D3 and recently saw this piece of code while someone was creating a transition: d3.select({}) in d3.select({}).transition() etc. This seems to be doing the same thing as d3.select([]). In the console, it showed up as an array, but I'm still unsure what it does. Any help would be appreciated, thank you!
The only place I've seen this is here. Now usually you would d3.select the object you want to run the transition on. But in the linked example, Bostock is not operating on svg composed of different DOM objects to manipulate but instead on a canvas that has to be wiped and redrawn for each step in the transition. So, d3.select({}).transition(), simply becomes an easy way to fire up a generic transition he can work with. You should note that something has to be selected to create a transition, just doing d3.select().transition() won't work and an empty object (or an empty array) allows it to work.
From looking at the code, it seems that three does not give much control over the depthFunc. I would like to confirm that it's only set once as the default GL state, and not available say, in the material?
I'm not familiar with all examples, and was wondering if this is happening somewhere?
If not, what would be the best approach to set the depthFunc to gl.EQUAL for example, when a specific draw call is being made i.e. a mesh with a material?
Is something like toggling between scenes i.e. use one to render stuff, then use another one to render stuff on top of the first one a good solution for this? That's the only example that i've seen of tweaking the otherwise sorted objects.
It's currently in the dev branch of three.js: the pull request.
I do have a Paper.path() in Raphael that is filled with a simple texture:
var fill = screen.path(Iso.topFacePath(top)).attr({
fill: 'url(http://www.example.com/mytexture.jpg)',
});
The path can be altered by the user via drag and drop. For this I use Element.drag() to bind the handlers.
The problem that I encouter now is that while the onmove-handler function is called the element in question will be recalculated and has to be drawn again. Apparently this is "too much" for raphael and the fill pattern will disappear randomly (flicker) and appear again some time later (at latest onend).
The actual code I use is a little too much to post here but I built a fiddle where you can see what's going on (you can drag the upper sides of the quadrangle).
Is there a simple fix to this?
I am used to canvas much more than raphael (actually this is the first time I really use raphael) so maybe my approach of redrawing everything everytime sth changes is plain wrong?
EDIT: I just found out that seems to be somehow browser-related as well. Chrome and Firefox will produce the flicker where Safari seems to do everything just fine.
This seems to be caching issue (raphael.js does not cache the bitmap fill and will reload it on every change) and is fixed (for me) by this pull request on GitHub that is (as of 08/14/2012) still pending.
Raphael is pretty hard / impossible to build oneself as the make file points to local and/or inexistent files, but you can either concatenate everything by hand, modify the build script or use the modified build that is used in the example to get hold of the fix.
Let's hope it will find its way into a future release of Raphael.
How can I determine the current transform that's being applied by an html5 canvas.
It seems that it only supports two methods for dealing with transforms "transform", "setTransform" but I can't seem to discover the results of applying the transforms.
Short of tracking them all myself and duplicating the the matrix mathematics that it must be doing natively, how can I figure out the current transform?
I've made a wrapper which adds this method to Canvas.
http://proceduralgraphics.blogspot.com/2010/03/canvas-wrapper-with-gettransform.html
Firefox's Canvas 2D contexts have (non-standard) mozCurrentTransform and mozCurrentTransformInverse properties.
The WhatWG have now defined currentTransform and currentTransformInverse properties (the former even being writable). Here's the relevant part of the spec:
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#transformations
However these probably won't be universally implemented in browsers for some time yet, so if you want portability you will have to fall back to tracking the matrix manually as #Dave and #James say.
Every man and his dog seems to have written such a Canvas-transform-matrix-tracker. I just had a look at #Dave Lawrence's one; I think mine is better in a few ways, even though I'm sure it's also inferior in other ways.
Mine doesn't require any changes to user JS code - it modifies the Canvas and context prototypes, so you just add a
script
tag and you're good to go.
It intercepts setting of the currentTransform property.
It tries hard only to do what it needs to do.
It works in latest Chrome and Firefox, but I haven't tested it in IE yet.
I put mine in a jsfiddle, with a simple demonstration:
http://jsfiddle.net/XmYqL/1/
Here is a code block to placate stackoverflow so it lets me link to jsfiddle (??):
code, code, wonderful code
I finally got around to uploading my polyfill to GitHub:
https://github.com/supermattydomain/canvas.currentTransform.js
I know it's not perfect, but I'd really like to see us all work together on implementing One True Solution to this problem. I don't care if it's mine or someone else's. This corner of JavaScript/HTML5/Canvas is too much like the Balkans: a sea of partial solutions.
Please, everybody, fork mine, add your changes and send me pull requests, or send me your URL so I can merge your code in, or replace mine wholesale with yours, or whatever.
This is a stupid problem that I just want to nail. If we work together we can do it.
You can look here for the functions that affect transformation:
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#transformations
If you use the setTransform function, then the current transform matrix is set to the identity matrix, then it uses what was set.
At that point you have the current transform matrix.
Now, if you are going to reset it, then start to call the other transformation methods, if you need to know what it is, it is easy to do the math to calculate the transformation matrix, so just do the operations, using your own transformation functions, then you can set the transform, as you have calculated it.
If you can't do that, then you are currently out of luck, but this post also has the same problem, so you may want to petition to have a new function added, getTransform.
http://forums.whatwg.org/viewtopic.php?t=4164
Although not a solution for how to get the current transform, it may be an useful fact that contexts include a save() and a restore() function that can be used to push and pop context state, including the current transformation matrix.
(At least it may benefit those, who, similarly to me, were looking for getTransform in order to implement a stack using it...)