I'm sharing a bunch of images between a React layer and an AFRAME VR layer.
I've preloaded the images into in an assets entity (not using the aframe asset manager as these assets are loaded dynamically at run time)
i.e.
const asset = getAsset(state, assetId, thumbnail)
const image = new Image()
image.id = assetId
image.src= asset.url
document.getElementById('assets').appendChild(image)
When switching too VR, I'm trying to use the same assets to load the thumbnails
i.e.
const thumb = document.getElementById(assetId)
this.el.setAttribute('src', thumb.src)
However the browser is reloading the assets.
In this comment https://stackoverflow.com/a/44868733/2884250
Loading images as img in AFrame doesn't store them in THREE.Cache
therefore the image was loaded twice. But if you load the image as
a-asset-item it does.
So I've attempted to add the files to the THREE.Cache (I'm assuming as a src)
window.THREE.Cache.add(assetId, asset.url)
How then in AFRAME do I get this image into the AFRAME A-IMAGE Entity as a src?
Figured it out..
Add the image to the cache with the ID
image.onload = () => window.THREE.Cache.add(assetId, image)
And use the ID as the SRC
this.el.setAttribute('src', '#'+assetId)
Related
I'm building a web app which has 360 degree images loaded into an a-sky primitive. I'm using aframe-react. There are total of 20+ 360 degree images and only one img asset inside a-assets. once user switches scene react will change src of asset img and scene will re render. Everything works fine but it's using lot of memory because of caching. One time it used 4GB+ memory. In mobile the web page crashes after switching through ~8+ images. How do I handle this situation?
I tried looking into THREE.Cache but images are not cached there.
Is this memory usage has anything to do with using React?
There's an issue for A-Frame to automatically manage it, but right now have to hack around to clear textures.
AFRAME.scenes[0].systems.material.textureCache[url].then(function (texture) {
texture.dispose();
});
I'm grabbing photos from FB's API and I'd like to merge a transparent filter on top and then save it as a new image to then post is a new picture to FB. I've looked into using Canvas however toDataURL() only works when the photos are on the same server. I've also tried using the filter as the src for an image and setting the fb pic as the background image but you can't save it off as this as it's editing through CSS. Any suggestion on how to actually blend the photos together and actually be able to save as a new image?
How to debug canvas?
It's loading bunch of rotating images in canvas. I want to check what images they are. But firebug shows nothing but the canvas tag.
Is there any way to find out what these canvas pre-loaded images are so I can download them?
You can check the new Firebug feature of 3D view of the page (canvas, div, ...).
You can place debugger; in your javascript code, so the debugger will automatically stop there.
Images drawn to canvas elements are loaded by javascript e.g.
var img = new Image();
image.onload = function(){ draw on canvas };
img.src = "image url";
You could try searching the JS source for .jpg or .png references, etc.
I need to load images within my Flash project
I don't want to use the Loader class cause the images are from a different domain.
I load images with a TextField
Here is my code:
var ti:TextField = new TextField();
ti.border=1
ti.htmlText += " <img id='movieInTxt' align='center' src='"+pic+"' />";
allMC[counter].img.addChild(ti);
I am loading the images to movieClip in a shape of a box.
I want to position the image in the center.
How can I make it ?
I tried ti.autoSize = TextFieldAutoSize.CENTER but it doesn't work...
Any suggestions how to load an image and position it in the center ?
You can use <p align='center'><img /></p> I guess.
You can totally use a Loader on domain you don't own since you don't access any advanced properties on the image (like pixel-level manipulations). You can then access the size of the image, and center it in your container.
AS3 doc says :
You can load content from any accessible source.
If the loaded content is an image, its data cannot be accessed by a SWF file outside of the security sandbox, unless the domain of that SWF file was included in a cross-domain policy file at the origin domain of the image.
You can force flashplayer to not check crossdomain.xml file by passing false in the LoaderContext constructor :
myLoader.load(urlReq, new LoaderContext(false));
I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code, I used the "Image Scale / Resize" code and I found something that I cannot explain. I mean, instead of using :
final Image img = new Image("/img/test.jpg");
I have used the client bundle and so the following code:
final Image img = new Image(NormalResources.NORMAL_RES_INSTANCE.axl1());
And I do not have any error, but the image did not appears. Finally I found the solution with :
final Image img = new Image(NormalResources.NORMAL_RES_INSTANCE.axl1().getSafeUri());
Do you know the reason why ".getSafeUri()" solves the problem ?
See ImageResource in ClientBundle as real <img> element
An Image created with an ImageResource will unconditionally use a clipped image, where the image is set as a CSS background image (and the <img>'s src is a 1×1px transparent GIF). Because the image actually is a blank GIF, painting it to the canvas does nothing noticeable; canvas does not take CSS styles into account.
Using getSafeUri() you'll have the data: URL of the image, which will be used as the src of the <img>. No blank.gif here, so the image is correctly painted on the canvas.
Note however that getSafeUri() won't work in IE6 and IE7 by default. If you need to support them, you'll have to annotate your ImageResources with either #ImageOptions(preventInlining = true) or #ImageOptions(repeatStyle = RepeatStyle.Both). Alternately, you could use DataResources instead of ImageResources.