If I check a radio button for the first time I'm getting a short freezing. Checking them a second time everything runs super smooth. I think because they are now in the browser-cache. Any chance of a preload here?
var insideMap1 = THREE.ImageUtils.loadTexture( 'insideMap1.jpg' );
var insideMap2 = THREE.ImageUtils.loadTexture( 'insideMap2.jpg' );
var insideMap3 = THREE.ImageUtils.loadTexture( 'insideMap3.jpg' );
$("input[name='opt1']").change(function() {
if ($("#radio1").is(":checked")) {
material[ "inside" ].map = insideMap1;
}
if ($("#radio2").is(":checked")) {
material[ "inside" ].map = insideMap2;
}
if ($("#radio3").is(":checked")) {
material[ "inside" ].map = insideMap3;
}
});
Called directly before setup(), the preload() function is used to handle asynchronous loading of external files in a blocking way. If a preload function is defined, setup() will wait until any load calls within have finished.
The rel="preload" attribute value is used to preload assets. It can be applied to several file formats, including CSS, JS, fonts, images, and more. Depending on the type of file you would like to preload, the corresponding as attribute may also need to be included along with rel="preload" .
Preloading JavaScript files #Because browsers don't execute preloaded files, preloading is useful to separate fetching from execution which can improve metrics such as Time to Interactive. Preloading works best if you split your JavaScript bundles and only preload critical chunks.
You can have javascript "preloaded", it loads inline with the rest of the page, and due to it usually being larger than the rest of the page takes longer to download. You can't make javascript load first, that's not the way it works.
Use THREE.Cache:
<script>
$(document).ready(function() {
THREE.Cache.enabled = true;
var url = '/img/DSC03537.JPG';
var newImg = document.createElement('img');
newImg.src = url;
THREE.Cache.add(url, newImg);
// main program part
var insideMap2 = THREE.ImageUtils.loadTexture(url);
$("#testBox").change(function () {
$("#tstImg").map = insideMap2;
});
});
</script>
Notice: THREE.ImageUtils.loadTexture is being deprecated. Use THREE.TextureLoader() instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With