pax_global_header 0000666 0000000 0000000 00000000064 14163525002 0014510 g ustar 00root root 0000000 0000000 52 comment=05644f2b40d32bd8d8e9e8f786ff8cf959804fe1
3p-cubemap_to_eqr_js-master/ 0000775 0000000 0000000 00000000000 14163525002 0016346 5 ustar 00root root 0000000 0000000 3p-cubemap_to_eqr_js-master/.gitignore 0000664 0000000 0000000 00000000027 14163525002 0020335 0 ustar 00root root 0000000 0000000 .DS_Store
stage/
*.bz2
3p-cubemap_to_eqr_js-master/.gitlab-ci.yml 0000664 0000000 0000000 00000000305 14163525002 0021000 0 ustar 00root root 0000000 0000000 include:
- project: 'alchemy/infrastructure/gitlab-ci-config'
file: '3p-library.yml'
variables:
BUILD_COMMON: 1
BUILD_WINDOWS: 0
BUILD_WINDOWS64: 0
BUILD_LINUX64: 0
BUILD_MACOS: 0
3p-cubemap_to_eqr_js-master/THREE.CubemapToEquirectangular/ 0000775 0000000 0000000 00000000000 14163525002 0024147 5 ustar 00root root 0000000 0000000 3p-cubemap_to_eqr_js-master/THREE.CubemapToEquirectangular/LICENSE 0000664 0000000 0000000 00000002123 14163525002 0025152 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2017 Jaume Sanchez Elias, http://www.clicktorelease.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3p-cubemap_to_eqr_js-master/THREE.CubemapToEquirectangular/README.md 0000664 0000000 0000000 00000006433 14163525002 0025434 0 ustar 00root root 0000000 0000000 # THREE.CubemapToEquirectangular
Helper to extract an equirectangular panorama PNG from any three.js scene.
Here's a demo with some cubes: [Demo](http://clicktorelease.com/tools/CubemapToEquirectangular/index-managed.html)
![](https://raw.githubusercontent.com/spite/THREE.CubemapToEquirectangular/master/about/pano-cru%C2%B7ci%C2%B7form-1471040116139.jpg)
![](https://raw.githubusercontent.com/spite/THREE.CubemapToEquirectangular/master/about/pano-The%20Polygon%20Shredder-1471041904038.jpg)
#### How to use ####
Include script after THREE is included
```js
```
or use npm to install it
```
npm i three.cubemap-to-equirectangular
```
and include it in your code with (remember to require three.js)
```js
var THREE = require('three');
var CubemapToEquirectangular = require('three.cubemap-to-equirectangular');
```
Define a new instance of THREE.CubemapToEquirectangular.
```js
// create renderer, scene, camera, etc.
var renderer = new THREE.WebGLRenderer();
var scene = new THREE.Scene();
var camera = new THREE.Camera( /* ... */ );
// Create a managed CubemapToEquirectangular
var equiManaged = new CubemapToEquirectangular( renderer, true );
// or create an unmanaged CubemapToEquirectangular
var equiUnmanaged = new CubemapToEquirectangular( renderer, false );
```
#### Managed CubemapToEquirectangular ####
With Managed mode, the THREE.CubeCamera creation, update, render, etc. is all taken care of. You only have to call:
```js
equiManaged.update( camera, scene );
```
at any point in your code that you want to extract a panorama.
The cube map created will be 2048x2048 and the exported panorama will be 4096x2048.
*Note: The cubemap can easily be 4096x4096, but that seems to work on most mobiles, too*
Demo of Managed mode: [Demo](http://clicktorelease.com/tools/CubemapToEquirectangular/index-managed.html)
#### Unmanaged CubemapToEquirectangular ####
If you want to use a different CubeMap camera, or do something custom with the render, you will have to set the Unmanaged mode.
You will have to create and manage your THREE.CubeCamera:
```js
var cubeCamera = new THREE.CubeCamera( .1, 1000, 4096 );
```
and manage all your scene update and rendering. When you want to export a panorama, call:
```js
// this is where the developer updates the scene and creates a cubemap of the scene
cubeCamera.position.copy( camera.position );
cubeCamera.updateCubeMap( renderer, scene );
// call this to convert the cubemap rendertarget to a panorama
equiUnmanaged.convert( cubeCamera );
```
Demo of Unmanaged mode: [Demo](http://clicktorelease.com/tools/CubemapToEquirectangular/index-unmanaged.html)
#### Changing output size ####
To export a different size, call ```setSize( width, height )```:
```js
equi.setSize( 2048, 1024 );
```
#### Notes ###
Built using ES6 template strings.
Needs canvas.toBlob, polyfill in the examples folder
#### TODO ####
- ~~Fix for Android (if it's a relevant use case)~~ (seems to work with 2048x2048)
- Check for mobile (if it's a relevant use case)
- Add importance sampling (improves quality of output)
- Handle postprocessing
- Handle Safari not supporting download attribute
- Let users have more control over file name, callbacks, progress
#### License ####
MIT licensed
Copyright (C) 2016 Jaume Sanchez Elias, http://www.clicktorelease.com
3p-cubemap_to_eqr_js-master/THREE.CubemapToEquirectangular/src/ 0000775 0000000 0000000 00000000000 14163525002 0024736 5 ustar 00root root 0000000 0000000 3p-cubemap_to_eqr_js-master/THREE.CubemapToEquirectangular/src/CubemapToEquirectangular.js 0000664 0000000 0000000 00000015101 14163525002 0032225 0 ustar 00root root 0000000 0000000 // Copyright (C) 2016 Jaume Sanchez Elias, http://www.clicktorelease.com
// https://github.com/spite/THREE.CubemapToEquirectangular
//
// Modified by Callum Prentice (callum@lindenlab.com) 2021-07-28 to use
// external jpeg encoder and write XMP metadata
(function () {
"use strict";
var root = this;
var has_require = typeof require !== "undefined";
var THREE = root.THREE || (has_require && require("three"));
if (!THREE) throw new Error("CubemapToEquirectangular requires three.js");
var vertexShader = `
attribute vec3 position;
attribute vec2 uv;
uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;
varying vec2 vUv;
void main() {
vUv = vec2( 1.- uv.x, uv.y );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
`;
var fragmentShader = `
precision mediump float;
uniform samplerCube map;
varying vec2 vUv;
#define M_PI 3.1415926535897932384626433832795
void main() {
vec2 uv = vUv;
float longitude = uv.x * 2. * M_PI - M_PI + M_PI / 2.;
float latitude = uv.y * M_PI;
vec3 dir = vec3(
- sin( longitude ) * sin( latitude ),
cos( latitude ),
- cos( longitude ) * sin( latitude )
);
normalize( dir );
gl_FragColor = vec4( textureCube( map, dir ).rgb, 1. );
}
`;
function CubemapToEquirectangular(renderer, provideCubeCamera, eqr_width, eqr_height) {
this.width = 1;
this.height = 1;
this.renderer = renderer;
this.material = new THREE.RawShaderMaterial({
uniforms: {
map: { type: "t", value: null },
},
vertexShader: vertexShader,
fragmentShader: fragmentShader,
side: THREE.DoubleSide,
});
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(1, 1), this.material);
this.scene.add(this.quad);
this.camera = new THREE.OrthographicCamera(1 / -2, 1 / 2, 1 / 2, 1 / -2, -10000, 10000);
this.canvas = document.createElement("canvas");
this.ctx = this.canvas.getContext("2d");
this.cubeCamera = null;
this.attachedCamera = null;
this.setSize(eqr_width, eqr_height);
var gl = this.renderer.getContext();
this.cubeMapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
if (provideCubeCamera) {
this.getCubeCamera(eqr_height);
}
}
CubemapToEquirectangular.prototype.setSize = function (width, height) {
this.width = width;
this.height = height;
this.quad.scale.set(this.width, this.height, 1);
this.camera.left = this.width / -2;
this.camera.right = this.width / 2;
this.camera.top = this.height / 2;
this.camera.bottom = this.height / -2;
this.camera.updateProjectionMatrix();
this.output = new THREE.WebGLRenderTarget(this.width, this.height, {
minFilter: THREE.LinearFilter,
magFilter: THREE.LinearFilter,
wrapS: THREE.ClampToEdgeWrapping,
wrapT: THREE.ClampToEdgeWrapping,
format: THREE.RGBAFormat,
type: THREE.UnsignedByteType,
});
this.canvas.width = this.width;
this.canvas.height = this.height;
};
CubemapToEquirectangular.prototype.getCubeCamera = function (size) {
var options = {
format: THREE.RGBAFormat,
magFilter: THREE.LinearFilter,
minFilter: THREE.LinearFilter,
};
const renderTarget = new THREE.WebGLCubeRenderTarget(size, options);
this.cubeCamera = new THREE.CubeCamera(0.1, 1000, renderTarget);
return this.cubeCamera;
};
CubemapToEquirectangular.prototype.attachCubeCamera = function (camera) {
this.getCubeCamera();
this.attachedCamera = camera;
};
// http://stackoverflow.com/a/5100158/603983
CubemapToEquirectangular.prototype.dataURItoBlob = function (dataURI) {
// convert base64/URLEncoded data component to raw binary data held in a string
var byteString;
if (dataURI.split(",")[0].indexOf("base64") >= 0) byteString = atob(dataURI.split(",")[1]);
else byteString = unescape(dataURI.split(",")[1]);
// separate out the mime component
var mimeString = dataURI.split(",")[0].split(":")[1].split(";")[0];
// write the bytes of the string to a typed array
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ia], { type: mimeString });
};
CubemapToEquirectangular.prototype.convert = function (cubeCamera, suggested_filename, xmp_details) {
this.quad.material.uniforms.map.value = cubeCamera.renderTarget.texture;
this.renderer.setRenderTarget(this.output);
this.renderer.render(this.scene, this.camera);
var pixels = new Uint8Array(4 * this.width * this.height);
this.renderer.readRenderTargetPixels(this.output, 0, 0, this.width, this.height, pixels);
var imageData = new ImageData(new Uint8ClampedArray(pixels), this.width, this.height);
var encoder = new JPEGEncoder(90);
var jpegURI = encoder.encode(imageData, 100, xmp_details);
var blob = this.dataURItoBlob(jpegURI);
var url = URL.createObjectURL(blob);
var anchor = document.createElement("a");
anchor.href = url;
anchor.setAttribute("download", suggested_filename);
anchor.className = "download-js-link";
anchor.innerHTML = "downloading...";
anchor.style.display = "none";
document.body.appendChild(anchor);
setTimeout(function () {
anchor.click();
document.body.removeChild(anchor);
}, 1);
this.renderer.setRenderTarget(null);
};
CubemapToEquirectangular.prototype.update = function (camera, scene, suggested_filename, xmp_details) {
var autoClear = this.renderer.autoClear;
this.renderer.autoClear = true;
this.cubeCamera.position.copy(camera.position);
this.cubeCamera.update(this.renderer, scene);
this.renderer.autoClear = autoClear;
this.convert(this.cubeCamera, suggested_filename, xmp_details);
};
if (typeof exports !== "undefined") {
if (typeof module !== "undefined" && module.exports) {
exports = module.exports = CubemapToEquirectangular;
}
exports.CubemapToEquirectangular = CubemapToEquirectangular;
} else {
root.CubemapToEquirectangular = CubemapToEquirectangular;
}
}.call(this));
3p-cubemap_to_eqr_js-master/autobuild.xml 0000664 0000000 0000000 00000003147 14163525002 0021065 0 ustar 00root root 0000000 0000000
3p-cubemap_to_eqr_js-master/build-cmd.sh 0000664 0000000 0000000 00000001716 14163525002 0020547 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
cd "$(dirname "$0")"
# turn on verbose debugging output
exec 4>&1; export BASH_XTRACEFD=4; set -x
# make errors fatal
set -e
# bleat on references to undefined shell variables
set -u
if [ -z "$AUTOBUILD" ] ; then
exit 1
fi
if [ "$OSTYPE" = "cygwin" ] ; then
export AUTOBUILD="$(cygpath -u $AUTOBUILD)"
fi
top="$(pwd)"
stage="$(pwd)/stage"
source_environment_tempfile="$stage/source_environment.sh"
"$AUTOBUILD" source_environment > "$source_environment_tempfile"
. "$source_environment_tempfile"
SOURCE_DIR="THREE.CubemapToEquirectangular"
build=${AUTOBUILD_BUILD_ID:=0}
echo "1.1.0" > "$stage/VERSION.txt"
case "$AUTOBUILD_PLATFORM" in
common)
mkdir -p "$stage/js"
mkdir -p "$stage/LICENSES"
cp "${SOURCE_DIR}/src/CubemapToEquirectangular.js" "$stage/js/"
cp "${SOURCE_DIR}/LICENSE" "$stage/LICENSES/CUBEMAPTOEQUIRECTANGULAR_LICENSE.txt"
;;
"linux")
;;
"linux64")
;;
esac