Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated line endings

  • Loading branch information...
commit 4d11bafee40e19503f728f8e0c50984a750bab8a 1 parent ccd7567
@paullewis paullewis authored
View
22 frameless-window/background.js
@@ -1,11 +1,11 @@
-chrome.app.runtime.onLaunched.addListener(function() {
- chrome.app.window.create("frameless_window.html",
- { frame: "none", width: 360,
- height: 300,
- minWidth: 220,
- minHeight: 220,
- left: 600
- }
- );
-});
-
+chrome.app.runtime.onLaunched.addListener(function() {
+ chrome.app.window.create("frameless_window.html",
+ { frame: "none", width: 360,
+ height: 300,
+ minWidth: 220,
+ minHeight: 220,
+ left: 600
+ }
+ );
+});
+
View
74 frameless-window/frameless_window.html
@@ -1,37 +1,37 @@
-<html>
-
-<head>
-
-<title>Frameless Window</title>
-
-<link rel="stylesheet" type="text/css" href="style.css" />
-<script src="titlebar.js"></script>
-<script src="frameless_window.js"></script>
-
-</head>
-
-<body>
-
-<div id="content">
-
-<div id="inner-content">
-
-Select the titlebar to enable:<br/>
-<input type="checkbox" id="top-box">Top Titlebar
-<br/>
-<input type="checkbox" id="bottom-box">Bottom Titlebar
-<br/>
-<input type="checkbox" id="left-box">Left Titlebar
-<br/>
-<input type="checkbox" id="right-box">Right Titlebar
-<br/>
-<br/>
-<button id="close-window-button">Close Window</button>
-
-</div>
-
-</div>
-
-</body>
-
-</html>
+<html>
+
+<head>
+
+<title>Frameless Window</title>
+
+<link rel="stylesheet" type="text/css" href="style.css" />
+<script src="titlebar.js"></script>
+<script src="frameless_window.js"></script>
+
+</head>
+
+<body>
+
+<div id="content">
+
+<div id="inner-content">
+
+Select the titlebar to enable:<br/>
+<input type="checkbox" id="top-box">Top Titlebar
+<br/>
+<input type="checkbox" id="bottom-box">Bottom Titlebar
+<br/>
+<input type="checkbox" id="left-box">Left Titlebar
+<br/>
+<input type="checkbox" id="right-box">Right Titlebar
+<br/>
+<br/>
+<button id="close-window-button">Close Window</button>
+
+</div>
+
+</div>
+
+</body>
+
+</html>
View
122 frameless-window/frameless_window.js
@@ -1,61 +1,61 @@
-function updateCheckbox() {
- var top_checkbox = document.getElementById("top-box");
- var bottom_checkbox = document.getElementById("bottom-box");
- var left_checkbox = document.getElementById("left-box");
- var right_checkbox = document.getElementById("right-box");
- if (top_checkbox.checked || bottom_checkbox.checked) {
- left_checkbox.disabled = true;
- right_checkbox.disabled = true;
- } else if (left_checkbox.checked || right_checkbox.checked) {
- top_checkbox.disabled = true;
- bottom_checkbox.disabled = true;
- } else {
- left_checkbox.disabled = false;
- right_checkbox.disabled = false;
- top_checkbox.disabled = false;
- bottom_checkbox.disabled = false;
- }
-}
-
-function initCheckbox(checkboxId, titlebar_name, titlebar_icon_url, titlebar_text) {
- var elem = document.getElementById(checkboxId);
- if (!elem)
- return;
- elem.onclick = function() {
- if (document.getElementById(checkboxId).checked)
- addTitlebar(titlebar_name, titlebar_icon_url, titlebar_text);
- else
- removeTitlebar(titlebar_name);
- focusTitlebars(true);
-
- updateContentStyle();
- updateCheckbox();
- }
-}
-
-window.onfocus = function() {
- console.log("focus");
- focusTitlebars(true);
-}
-
-window.onblur = function() {
- console.log("blur");
- focusTitlebars(false);
-}
-
-window.onresize = function() {
- updateContentStyle();
-}
-
-window.onload = function() {
- initCheckbox("top-box", "top-titlebar", "top-titlebar.png", "Top Titlebar");
- initCheckbox("bottom-box", "bottom-titlebar", "bottom-titlebar.png", "Bottom Titlebar");
- initCheckbox("left-box", "left-titlebar", "left-titlebar.png", "Left Titlebar");
- initCheckbox("right-box", "right-titlebar", "right-titlebar.png", "Right Titlebar");
-
- document.getElementById("close-window-button").onclick = function() {
- window.close();
- }
-
- updateContentStyle();
-}
+function updateCheckbox() {
+ var top_checkbox = document.getElementById("top-box");
+ var bottom_checkbox = document.getElementById("bottom-box");
+ var left_checkbox = document.getElementById("left-box");
+ var right_checkbox = document.getElementById("right-box");
+ if (top_checkbox.checked || bottom_checkbox.checked) {
+ left_checkbox.disabled = true;
+ right_checkbox.disabled = true;
+ } else if (left_checkbox.checked || right_checkbox.checked) {
+ top_checkbox.disabled = true;
+ bottom_checkbox.disabled = true;
+ } else {
+ left_checkbox.disabled = false;
+ right_checkbox.disabled = false;
+ top_checkbox.disabled = false;
+ bottom_checkbox.disabled = false;
+ }
+}
+
+function initCheckbox(checkboxId, titlebar_name, titlebar_icon_url, titlebar_text) {
+ var elem = document.getElementById(checkboxId);
+ if (!elem)
+ return;
+ elem.onclick = function() {
+ if (document.getElementById(checkboxId).checked)
+ addTitlebar(titlebar_name, titlebar_icon_url, titlebar_text);
+ else
+ removeTitlebar(titlebar_name);
+ focusTitlebars(true);
+
+ updateContentStyle();
+ updateCheckbox();
+ }
+}
+
+window.onfocus = function() {
+ console.log("focus");
+ focusTitlebars(true);
+}
+
+window.onblur = function() {
+ console.log("blur");
+ focusTitlebars(false);
+}
+
+window.onresize = function() {
+ updateContentStyle();
+}
+
+window.onload = function() {
+ initCheckbox("top-box", "top-titlebar", "top-titlebar.png", "Top Titlebar");
+ initCheckbox("bottom-box", "bottom-titlebar", "bottom-titlebar.png", "Bottom Titlebar");
+ initCheckbox("left-box", "left-titlebar", "left-titlebar.png", "Left Titlebar");
+ initCheckbox("right-box", "right-titlebar", "right-titlebar.png", "Right Titlebar");
+
+ document.getElementById("close-window-button").onclick = function() {
+ window.close();
+ }
+
+ updateContentStyle();
+}
View
26 frameless-window/manifest.json
@@ -1,13 +1,13 @@
-{
- "name": "Frameless Window",
- "description": "Chrome platform app.",
- "manifest_version": 2,
- "version": "0.1",
- "app": {
- "background": {
- "scripts": ["background.js"]
- }
- },
- "permissions": ["experimental"],
- "icons": { "128": "icon_128.png" }
-}
+{
+ "name": "Frameless Window",
+ "description": "Chrome platform app.",
+ "manifest_version": 2,
+ "version": "0.1",
+ "app": {
+ "background": {
+ "scripts": ["background.js"]
+ }
+ },
+ "permissions": ["experimental"],
+ "icons": { "128": "icon_128.png" }
+}
View
390 frameless-window/style.css
@@ -1,195 +1,195 @@
-html {
- margin: 0px;
- padding: 0px;
- overflow: hidden;
-}
-
-body {
- margin: 0px;
- padding: 0px;
-}
-
-::-webkit-scrollbar-thumb {
- display: none;
-}
-
-input[type="checkbox"]:disabled
-{
- opacity: .3;
-}
-
-div#content {
- background-color: #dddddd;
- margin: 0px;
- padding: 0px;
-}
-
-div#inner-content {
- background-color: #dddddd;
- margin: 10px;
- width: 100%;
- height: 100%;
-}
-
-.top-titlebar {
- position: absolute;
- left: 0px;
- top: 0px;
- width: 100%;
- height: 32px;
- background-color: #7a7c7c;
-}
-
-.bottom-titlebar {
- position: absolute;
- left: 0px;
- bottom: 0px;
- width: 100%;
- height: 32px;
- background-color: #7a7c7c;
-}
-
-.left-titlebar {
- position: absolute;
- left: 0px;
- top: 0px;
- width: 32px;
- height: 100%;
- background-color: #7a7c7c;
-}
-
-.right-titlebar {
- position: absolute;
- right: 0px;
- top: 0px;
- width: 32px;
- height: 100%;
- background-color: #7a7c7c;
-}
-
-.top-titlebar-icon,
-.bottom-titlebar-icon {
- position: absolute;
- left: 6px;
- margin-top: 6px;
- margin-bottom: 6px;
-}
-
-.left-titlebar-icon {
- position: absolute;
- bottom: 6px;
- margin-left: 6px;
- margin-right: 6px;
-}
-
-.right-titlebar-icon {
- position: absolute;
- top: 6px;
- margin-left: 6px;
- margin-right: 6px;
-}
-
-.top-titlebar-text,
-.bottom-titlebar-text {
- position: absolute;
- left: 32px;
- width: 80%;
- margin-top: 6px;
- margin-bottom: 6px;
- font-style: Arial;
- font-size: 11pt;
- color: #ffffff;
-}
-
-.left-titlebar-text {
- position: absolute;
- bottom: 32px;
- width: 100px;
- margin-left: 6px;
- margin-right: 6px;
- font-style: Arial;
- font-size: 12pt;
- color: #ffffff;
- -webkit-transform: rotate(-90deg) translate(0, 100%);
- -webkit-transform-origin: 0% 100%;
-}
-
-.right-titlebar-text {
- position: absolute;
- top: 0px;
- width: 100px;
- margin-left: 6px;
- margin-right: 6px;
- font-style: Arial;
- font-size: 12pt;
- color: #ffffff;
- -webkit-transform: rotate(90deg) translate(0, 100%);
- -webkit-transform-origin: 0% 200%;
-}
-
-.top-titlebar-close-button,
-.bottom-titlebar-close-button {
- position: absolute;
- right: 11px;
- width: 17px;
- height: 17px;
- margin-top: 6px;
- margin-bottom: 6px;
- -webkit-widget-region: region(control rectangle);
-}
-
-.left-titlebar-close-button {
- position: absolute;
- top: 11px;
- width: 17px;
- height: 17px;
- margin-left: 6px;
- margin-right: 6px;
- -webkit-widget-region: region(control rectangle);
-}
-
-.right-titlebar-close-button {
- position: absolute;
- bottom: 11px;
- width: 17px;
- height: 17px;
- margin-left: 6px;
- margin-right: 6px;
- -webkit-widget-region: region(control rectangle);
-}
-
-.top-titlebar-divider {
- position: absolute;
- left: 0px;
- top: 31px;
- width: 100%;
- height: 1px;
- background-color: #2a2c2c;
-}
-
-.bottom-titlebar-divider {
- position: absolute;
- left: 0px;
- bottom: 31px;
- width: 100%;
- height: 1px;
- background-color: #2a2c2c;
-}
-
-.left-titlebar-divider {
- position: absolute;
- left: 31px;
- top: 0px;
- width: 1px;
- height: 100%;
- background-color: #2a2c2c;
-}
-
-.right-titlebar-divider {
- position: absolute;
- right: 31px;
- top: 0px;
- width: 1px;
- height: 100%;
- background-color: #2a2c2c;
-}
+html {
+ margin: 0px;
+ padding: 0px;
+ overflow: hidden;
+}
+
+body {
+ margin: 0px;
+ padding: 0px;
+}
+
+::-webkit-scrollbar-thumb {
+ display: none;
+}
+
+input[type="checkbox"]:disabled
+{
+ opacity: .3;
+}
+
+div#content {
+ background-color: #dddddd;
+ margin: 0px;
+ padding: 0px;
+}
+
+div#inner-content {
+ background-color: #dddddd;
+ margin: 10px;
+ width: 100%;
+ height: 100%;
+}
+
+.top-titlebar {
+ position: absolute;
+ left: 0px;
+ top: 0px;
+ width: 100%;
+ height: 32px;
+ background-color: #7a7c7c;
+}
+
+.bottom-titlebar {
+ position: absolute;
+ left: 0px;
+ bottom: 0px;
+ width: 100%;
+ height: 32px;
+ background-color: #7a7c7c;
+}
+
+.left-titlebar {
+ position: absolute;
+ left: 0px;
+ top: 0px;
+ width: 32px;
+ height: 100%;
+ background-color: #7a7c7c;
+}
+
+.right-titlebar {
+ position: absolute;
+ right: 0px;
+ top: 0px;
+ width: 32px;
+ height: 100%;
+ background-color: #7a7c7c;
+}
+
+.top-titlebar-icon,
+.bottom-titlebar-icon {
+ position: absolute;
+ left: 6px;
+ margin-top: 6px;
+ margin-bottom: 6px;
+}
+
+.left-titlebar-icon {
+ position: absolute;
+ bottom: 6px;
+ margin-left: 6px;
+ margin-right: 6px;
+}
+
+.right-titlebar-icon {
+ position: absolute;
+ top: 6px;
+ margin-left: 6px;
+ margin-right: 6px;
+}
+
+.top-titlebar-text,
+.bottom-titlebar-text {
+ position: absolute;
+ left: 32px;
+ width: 80%;
+ margin-top: 6px;
+ margin-bottom: 6px;
+ font-style: Arial;
+ font-size: 11pt;
+ color: #ffffff;
+}
+
+.left-titlebar-text {
+ position: absolute;
+ bottom: 32px;
+ width: 100px;
+ margin-left: 6px;
+ margin-right: 6px;
+ font-style: Arial;
+ font-size: 12pt;
+ color: #ffffff;
+ -webkit-transform: rotate(-90deg) translate(0, 100%);
+ -webkit-transform-origin: 0% 100%;
+}
+
+.right-titlebar-text {
+ position: absolute;
+ top: 0px;
+ width: 100px;
+ margin-left: 6px;
+ margin-right: 6px;
+ font-style: Arial;
+ font-size: 12pt;
+ color: #ffffff;
+ -webkit-transform: rotate(90deg) translate(0, 100%);
+ -webkit-transform-origin: 0% 200%;
+}
+
+.top-titlebar-close-button,
+.bottom-titlebar-close-button {
+ position: absolute;
+ right: 11px;
+ width: 17px;
+ height: 17px;
+ margin-top: 6px;
+ margin-bottom: 6px;
+ -webkit-widget-region: region(control rectangle);
+}
+
+.left-titlebar-close-button {
+ position: absolute;
+ top: 11px;
+ width: 17px;
+ height: 17px;
+ margin-left: 6px;
+ margin-right: 6px;
+ -webkit-widget-region: region(control rectangle);
+}
+
+.right-titlebar-close-button {
+ position: absolute;
+ bottom: 11px;
+ width: 17px;
+ height: 17px;
+ margin-left: 6px;
+ margin-right: 6px;
+ -webkit-widget-region: region(control rectangle);
+}
+
+.top-titlebar-divider {
+ position: absolute;
+ left: 0px;
+ top: 31px;
+ width: 100%;
+ height: 1px;
+ background-color: #2a2c2c;
+}
+
+.bottom-titlebar-divider {
+ position: absolute;
+ left: 0px;
+ bottom: 31px;
+ width: 100%;
+ height: 1px;
+ background-color: #2a2c2c;
+}
+
+.left-titlebar-divider {
+ position: absolute;
+ left: 31px;
+ top: 0px;
+ width: 1px;
+ height: 100%;
+ background-color: #2a2c2c;
+}
+
+.right-titlebar-divider {
+ position: absolute;
+ right: 31px;
+ top: 0px;
+ width: 1px;
+ height: 100%;
+ background-color: #2a2c2c;
+}
View
242 frameless-window/titlebar.js
@@ -1,121 +1,121 @@
-function closeWindow() {
- window.close();
-}
-
-function updateImageUrl(image_id, new_image_url) {
- var image = document.getElementById(image_id);
- if (image)
- image.src = new_image_url;
-}
-
-function createImage(image_id, image_url) {
- var image = document.createElement("img");
- image.setAttribute("id", image_id);
- image.src = image_url;
- return image;
-}
-
-function createButton(button_id, button_name, normal_image_url,
- hover_image_url, click_func) {
- var button = document.createElement("div");
- button.setAttribute("class", button_name);
- var button_img = createImage(button_id, normal_image_url);
- button.appendChild(button_img);
- button.onmouseover = function() {
- updateImageUrl(button_id, hover_image_url);
- }
- button.onmouseout = function() {
- updateImageUrl(button_id, normal_image_url);
- }
- button.onclick = click_func;
- return button;
-}
-
-function focusTitlebars(focus) {
- var bg_color = focus ? "#3a3d3d" : "#7a7c7c";
-
- var titlebar = document.getElementById("top-titlebar");
- if (titlebar)
- titlebar.style.backgroundColor = bg_color;
- titlebar = document.getElementById("bottom-titlebar");
- if (titlebar)
- titlebar.style.backgroundColor = bg_color;
- titlebar = document.getElementById("left-titlebar");
- if (titlebar)
- titlebar.style.backgroundColor = bg_color;
- titlebar = document.getElementById("right-titlebar");
- if (titlebar)
- titlebar.style.backgroundColor = bg_color;
-}
-
-function addTitlebar(titlebar_name, titlebar_icon_url, titlebar_text) {
- var titlebar = document.createElement("div");
- titlebar.setAttribute("id", titlebar_name);
- titlebar.setAttribute("class", titlebar_name);
-
- var icon = document.createElement("div");
- icon.setAttribute("class", titlebar_name + "-icon");
- icon.appendChild(createImage(titlebar_name + "icon", titlebar_icon_url));
- titlebar.appendChild(icon);
-
- var title = document.createElement("div");
- title.setAttribute("class", titlebar_name + "-text");
- title.innerText = titlebar_text;
- titlebar.appendChild(title);
-
- var closeButton = createButton(titlebar_name + "-close-button",
- titlebar_name + "-close-button",
- "button_close.png",
- "button_close_hover.png",
- closeWindow);
- titlebar.appendChild(closeButton);
-
- var divider = document.createElement("div");
- divider.setAttribute("class", titlebar_name + "-divider");
- titlebar.appendChild(divider);
-
- document.body.appendChild(titlebar);
-}
-
-function removeTitlebar(titlebar_name) {
- var titlebar = document.getElementById(titlebar_name);
- if (titlebar)
- document.body.removeChild(titlebar);
-}
-
-function updateContentStyle() {
- var content = document.getElementById("content");
- if (!content)
- return;
-
- var left = 0;
- var top = 0;
- var width = window.outerWidth;
- var height = window.outerHeight;
-
- var titlebar = document.getElementById("top-titlebar");
- if (titlebar) {
- height -= titlebar.offsetHeight;
- top += titlebar.offsetHeight;
- }
- titlebar = document.getElementById("bottom-titlebar");
- if (titlebar) {
- height -= titlebar.offsetHeight;
- }
- titlebar = document.getElementById("left-titlebar");
- if (titlebar) {
- width -= titlebar.offsetWidth;
- left += titlebar.offsetWidth;
- }
- titlebar = document.getElementById("right-titlebar");
- if (titlebar) {
- width -= titlebar.offsetWidth;
- }
-
- var contentStyle = "position: absolute; -webkit-widget-region: region(control rectangle); ";
- contentStyle += "left: " + left + "px; ";
- contentStyle += "top: " + top + "px; ";
- contentStyle += "width: " + width + "px; ";
- contentStyle += "height: " + height + "px; ";
- content.setAttribute("style", contentStyle);
-}
+function closeWindow() {
+ window.close();
+}
+
+function updateImageUrl(image_id, new_image_url) {
+ var image = document.getElementById(image_id);
+ if (image)
+ image.src = new_image_url;
+}
+
+function createImage(image_id, image_url) {
+ var image = document.createElement("img");
+ image.setAttribute("id", image_id);
+ image.src = image_url;
+ return image;
+}
+
+function createButton(button_id, button_name, normal_image_url,
+ hover_image_url, click_func) {
+ var button = document.createElement("div");
+ button.setAttribute("class", button_name);
+ var button_img = createImage(button_id, normal_image_url);
+ button.appendChild(button_img);
+ button.onmouseover = function() {
+ updateImageUrl(button_id, hover_image_url);
+ }
+ button.onmouseout = function() {
+ updateImageUrl(button_id, normal_image_url);
+ }
+ button.onclick = click_func;
+ return button;
+}
+
+function focusTitlebars(focus) {
+ var bg_color = focus ? "#3a3d3d" : "#7a7c7c";
+
+ var titlebar = document.getElementById("top-titlebar");
+ if (titlebar)
+ titlebar.style.backgroundColor = bg_color;
+ titlebar = document.getElementById("bottom-titlebar");
+ if (titlebar)
+ titlebar.style.backgroundColor = bg_color;
+ titlebar = document.getElementById("left-titlebar");
+ if (titlebar)
+ titlebar.style.backgroundColor = bg_color;
+ titlebar = document.getElementById("right-titlebar");
+ if (titlebar)
+ titlebar.style.backgroundColor = bg_color;
+}
+
+function addTitlebar(titlebar_name, titlebar_icon_url, titlebar_text) {
+ var titlebar = document.createElement("div");
+ titlebar.setAttribute("id", titlebar_name);
+ titlebar.setAttribute("class", titlebar_name);
+
+ var icon = document.createElement("div");
+ icon.setAttribute("class", titlebar_name + "-icon");
+ icon.appendChild(createImage(titlebar_name + "icon", titlebar_icon_url));
+ titlebar.appendChild(icon);
+
+ var title = document.createElement("div");
+ title.setAttribute("class", titlebar_name + "-text");
+ title.innerText = titlebar_text;
+ titlebar.appendChild(title);
+
+ var closeButton = createButton(titlebar_name + "-close-button",
+ titlebar_name + "-close-button",
+ "button_close.png",
+ "button_close_hover.png",
+ closeWindow);
+ titlebar.appendChild(closeButton);
+
+ var divider = document.createElement("div");
+ divider.setAttribute("class", titlebar_name + "-divider");
+ titlebar.appendChild(divider);
+
+ document.body.appendChild(titlebar);
+}
+
+function removeTitlebar(titlebar_name) {
+ var titlebar = document.getElementById(titlebar_name);
+ if (titlebar)
+ document.body.removeChild(titlebar);
+}
+
+function updateContentStyle() {
+ var content = document.getElementById("content");
+ if (!content)
+ return;
+
+ var left = 0;
+ var top = 0;
+ var width = window.outerWidth;
+ var height = window.outerHeight;
+
+ var titlebar = document.getElementById("top-titlebar");
+ if (titlebar) {
+ height -= titlebar.offsetHeight;
+ top += titlebar.offsetHeight;
+ }
+ titlebar = document.getElementById("bottom-titlebar");
+ if (titlebar) {
+ height -= titlebar.offsetHeight;
+ }
+ titlebar = document.getElementById("left-titlebar");
+ if (titlebar) {
+ width -= titlebar.offsetWidth;
+ left += titlebar.offsetWidth;
+ }
+ titlebar = document.getElementById("right-titlebar");
+ if (titlebar) {
+ width -= titlebar.offsetWidth;
+ }
+
+ var contentStyle = "position: absolute; -webkit-widget-region: region(control rectangle); ";
+ contentStyle += "left: " + left + "px; ";
+ contentStyle += "top: " + top + "px; ";
+ contentStyle += "width: " + width + "px; ";
+ contentStyle += "height: " + height + "px; ";
+ content.setAttribute("style", contentStyle);
+}
View
3,790 webgl/js/three.min.js
@@ -6336,409 +6336,409 @@ THREE.SpotLight = function ( hex, intensity, distance, angle, exponent ) {
};
THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
-/**
- * @author alteredq / http://alteredqualia.com/
- */
-
-THREE.Loader = function ( showStatus ) {
-
- this.showStatus = showStatus;
- this.statusDomElement = showStatus ? THREE.Loader.prototype.addStatusElement() : null;
-
- this.onLoadStart = function () {};
- this.onLoadProgress = function () {};
- this.onLoadComplete = function () {};
-
-};
-
-THREE.Loader.prototype = {
-
- constructor: THREE.Loader,
-
- crossOrigin: 'anonymous',
-
- addStatusElement: function () {
-
- var e = document.createElement( "div" );
-
- e.style.position = "absolute";
- e.style.right = "0px";
- e.style.top = "0px";
- e.style.fontSize = "0.8em";
- e.style.textAlign = "left";
- e.style.background = "rgba(0,0,0,0.25)";
- e.style.color = "#fff";
- e.style.width = "120px";
- e.style.padding = "0.5em 0.5em 0.5em 0.5em";
- e.style.zIndex = 1000;
-
- e.innerHTML = "Loading ...";
-
- return e;
-
- },
-
- updateProgress: function ( progress ) {
-
- var message = "Loaded ";
-
- if ( progress.total ) {
-
- message += ( 100 * progress.loaded / progress.total ).toFixed(0) + "%";
-
-
- } else {
-
- message += ( progress.loaded / 1000 ).toFixed(2) + " KB";
-
- }
-
- this.statusDomElement.innerHTML = message;
-
- },
-
- extractUrlBase: function ( url ) {
-
- var parts = url.split( '/' );
- parts.pop();
- return ( parts.length < 1 ? '.' : parts.join( '/' ) ) + '/';
-
- },
-
- initMaterials: function ( scope, materials, texturePath ) {
-
- scope.materials = [];
-
- for ( var i = 0; i < materials.length; ++ i ) {
-
- scope.materials[ i ] = THREE.Loader.prototype.createMaterial( materials[ i ], texturePath );
-
- }
-
- },
-
- hasNormals: function ( scope ) {
-
- var m, i, il = scope.materials.length;
-
- for( i = 0; i < il; i ++ ) {
-
- m = scope.materials[ i ];
-
- if ( m instanceof THREE.ShaderMaterial ) return true;
-
- }
-
- return false;
-
- },
-
- createMaterial: function ( m, texturePath ) {
-
- var _this = this;
-
- function is_pow2( n ) {
-
- var l = Math.log( n ) / Math.LN2;
- return Math.floor( l ) == l;
-
- }
-
- function nearest_pow2( n ) {
-
- var l = Math.log( n ) / Math.LN2;
- return Math.pow( 2, Math.round( l ) );
-
- }
-
- function load_image( where, url ) {
-
- var image = new Image();
-
- image.onload = function () {
-
- if ( !is_pow2( this.width ) || !is_pow2( this.height ) ) {
-
- var width = nearest_pow2( this.width );
- var height = nearest_pow2( this.height );
-
- where.image.width = width;
- where.image.height = height;
- where.image.getContext( '2d' ).drawImage( this, 0, 0, width, height );
-
- } else {
-
- where.image = this;
-
- }
-
- where.needsUpdate = true;
-
- };
-
- image.crossOrigin = _this.crossOrigin;
- image.src = url;
-
- }
-
- function create_texture( where, name, sourceFile, repeat, offset, wrap ) {
-
- var texture = document.createElement( 'canvas' );
-
- where[ name ] = new THREE.Texture( texture );
- where[ name ].sourceFile = sourceFile;
-
- if( repeat ) {
-
- where[ name ].repeat.set( repeat[ 0 ], repeat[ 1 ] );
-
- if ( repeat[ 0 ] !== 1 ) where[ name ].wrapS = THREE.RepeatWrapping;
- if ( repeat[ 1 ] !== 1 ) where[ name ].wrapT = THREE.RepeatWrapping;
-
- }
-
- if ( offset ) {
-
- where[ name ].offset.set( offset[ 0 ], offset[ 1 ] );
-
- }
-
- if ( wrap ) {
-
- var wrapMap = {
- "repeat": THREE.RepeatWrapping,
- "mirror": THREE.MirroredRepeatWrapping
- }
-
- if ( wrapMap[ wrap[ 0 ] ] !== undefined ) where[ name ].wrapS = wrapMap[ wrap[ 0 ] ];
- if ( wrapMap[ wrap[ 1 ] ] !== undefined ) where[ name ].wrapT = wrapMap[ wrap[ 1 ] ];
-
- }
-
- load_image( where[ name ], texturePath + "/" + sourceFile );
-
- }
-
- function rgb2hex( rgb ) {
-
- return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
-
- }
-
- // defaults
-
- var mtype = "MeshLambertMaterial";
- var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
-
- // parameters from model file
-
- if ( m.shading ) {
-
- var shading = m.shading.toLowerCase();
-
- if ( shading === "phong" ) mtype = "MeshPhongMaterial";
- else if ( shading === "basic" ) mtype = "MeshBasicMaterial";
-
- }
-
- if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
-
- mpars.blending = THREE[ m.blending ];
-
- }
-
- if ( m.transparent !== undefined || m.opacity < 1.0 ) {
-
- mpars.transparent = m.transparent;
-
- }
-
- if ( m.depthTest !== undefined ) {
-
- mpars.depthTest = m.depthTest;
-
- }
-
- if ( m.depthWrite !== undefined ) {
-
- mpars.depthWrite = m.depthWrite;
-
- }
-
- if ( m.visible !== undefined ) {
-
- mpars.visible = m.visible;
-
- }
-
- if ( m.flipSided !== undefined ) {
-
- mpars.side = THREE.BackSide;
-
- }
-
- if ( m.doubleSided !== undefined ) {
-
- mpars.side = THREE.DoubleSide;
-
- }
-
- if ( m.wireframe !== undefined ) {
-
- mpars.wireframe = m.wireframe;
-
- }
-
- if ( m.vertexColors !== undefined ) {
-
- if ( m.vertexColors == "face" ) {
-
- mpars.vertexColors = THREE.FaceColors;
-
- } else if ( m.vertexColors ) {
-
- mpars.vertexColors = THREE.VertexColors;
-
- }
-
- }
-
- // colors
-
- if ( m.colorDiffuse ) {
-
- mpars.color = rgb2hex( m.colorDiffuse );
-
- } else if ( m.DbgColor ) {
-
- mpars.color = m.DbgColor;
-
- }
-
- if ( m.colorSpecular ) {
-
- mpars.specular = rgb2hex( m.colorSpecular );
-
- }
-
- if ( m.colorAmbient ) {
-
- mpars.ambient = rgb2hex( m.colorAmbient );
-
- }
-
- // modifiers
-
- if ( m.transparency ) {
-
- mpars.opacity = m.transparency;
-
- }
-
- if ( m.specularCoef ) {
-
- mpars.shininess = m.specularCoef;
-
- }
-
- // textures
-
- if ( m.mapDiffuse && texturePath ) {
-
- create_texture( mpars, "map", m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap );
-
- }
-
- if ( m.mapLight && texturePath ) {
-
- create_texture( mpars, "lightMap", m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap );
-
- }
-
- if ( m.mapBump && texturePath ) {
-
- create_texture( mpars, "bumpMap", m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap );
-
- }
-
- if ( m.mapNormal && texturePath ) {
-
- create_texture( mpars, "normalMap", m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap );
-
- }
-
- if ( m.mapSpecular && texturePath ) {
-
- create_texture( mpars, "specularMap", m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap );
-
- }
-
- // special case for normal mapped material
-
- if ( m.mapNormal ) {
-
- var shader = THREE.ShaderUtils.lib[ "normal" ];
- var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
-
- uniforms[ "tNormal" ].texture = mpars.normalMap;
-
- if ( m.mapNormalFactor ) {
-
- uniforms[ "uNormalScale" ].value = m.mapNormalFactor;
-
- }
-
- if ( mpars.map ) {
-
- uniforms[ "tDiffuse" ].texture = mpars.map;
- uniforms[ "enableDiffuse" ].value = true;
-
- }
-
- if ( mpars.specularMap ) {
-
- uniforms[ "tSpecular" ].texture = mpars.specularMap;
- uniforms[ "enableSpecular" ].value = true;
-
- }
-
- if ( mpars.lightMap ) {
-
- uniforms[ "tAO" ].texture = mpars.lightMap;
- uniforms[ "enableAO" ].value = true;
-
- }
-
- // for the moment don't handle displacement texture
-
- uniforms[ "uDiffuseColor" ].value.setHex( mpars.color );
- uniforms[ "uSpecularColor" ].value.setHex( mpars.specular );
- uniforms[ "uAmbientColor" ].value.setHex( mpars.ambient );
-
- uniforms[ "uShininess" ].value = mpars.shininess;
-
- if ( mpars.opacity !== undefined ) {
-
- uniforms[ "uOpacity" ].value = mpars.opacity;
-
- }
-
- var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
- var material = new THREE.ShaderMaterial( parameters );
-
- } else {
-
- var material = new THREE[ mtype ]( mpars );
-
- }
-
- if ( m.DbgName !== undefined ) material.name = m.DbgName;
-
- return material;
-
- }
-
-};
+/**
+ * @author alteredq / http://alteredqualia.com/
+ */
+
+THREE.Loader = function ( showStatus ) {
+
+ this.showStatus = showStatus;
+ this.statusDomElement = showStatus ? THREE.Loader.prototype.addStatusElement() : null;
+
+ this.onLoadStart = function () {};
+ this.onLoadProgress = function () {};
+ this.onLoadComplete = function () {};
+
+};
+
+THREE.Loader.prototype = {
+
+ constructor: THREE.Loader,
+
+ crossOrigin: 'anonymous',
+
+ addStatusElement: function () {
+
+ var e = document.createElement( "div" );
+
+ e.style.position = "absolute";
+ e.style.right = "0px";
+ e.style.top = "0px";
+ e.style.fontSize = "0.8em";
+ e.style.textAlign = "left";
+ e.style.background = "rgba(0,0,0,0.25)";
+ e.style.color = "#fff";
+ e.style.width = "120px";
+ e.style.padding = "0.5em 0.5em 0.5em 0.5em";
+ e.style.zIndex = 1000;
+
+ e.innerHTML = "Loading ...";
+
+ return e;
+
+ },
+
+ updateProgress: function ( progress ) {
+
+ var message = "Loaded ";
+
+ if ( progress.total ) {
+
+ message += ( 100 * progress.loaded / progress.total ).toFixed(0) + "%";
+
+
+ } else {
+
+ message += ( progress.loaded / 1000 ).toFixed(2) + " KB";
+
+ }
+
+ this.statusDomElement.innerHTML = message;
+
+ },
+
+ extractUrlBase: function ( url ) {
+
+ var parts = url.split( '/' );
+ parts.pop();
+ return ( parts.length < 1 ? '.' : parts.join( '/' ) ) + '/';
+
+ },
+
+ initMaterials: function ( scope, materials, texturePath ) {
+
+ scope.materials = [];
+
+ for ( var i = 0; i < materials.length; ++ i ) {
+
+ scope.materials[ i ] = THREE.Loader.prototype.createMaterial( materials[ i ], texturePath );
+
+ }
+
+ },
+
+ hasNormals: function ( scope ) {
+
+ var m, i, il = scope.materials.length;
+
+ for( i = 0; i < il; i ++ ) {
+
+ m = scope.materials[ i ];
+
+ if ( m instanceof THREE.ShaderMaterial ) return true;
+
+ }
+
+ return false;
+
+ },
+
+ createMaterial: function ( m, texturePath ) {
+
+ var _this = this;
+
+ function is_pow2( n ) {
+
+ var l = Math.log( n ) / Math.LN2;
+ return Math.floor( l ) == l;
+
+ }
+
+ function nearest_pow2( n ) {
+
+ var l = Math.log( n ) / Math.LN2;
+ return Math.pow( 2, Math.round( l ) );
+
+ }
+
+ function load_image( where, url ) {
+
+ var image = new Image();
+
+ image.onload = function () {
+
+ if ( !is_pow2( this.width ) || !is_pow2( this.height ) ) {
+
+ var width = nearest_pow2( this.width );
+ var height = nearest_pow2( this.height );
+
+ where.image.width = width;
+ where.image.height = height;
+ where.image.getContext( '2d' ).drawImage( this, 0, 0, width, height );
+
+ } else {
+
+ where.image = this;
+
+ }
+
+ where.needsUpdate = true;
+
+ };
+
+ image.crossOrigin = _this.crossOrigin;
+ image.src = url;
+
+ }
+
+ function create_texture( where, name, sourceFile, repeat, offset, wrap ) {
+
+ var texture = document.createElement( 'canvas' );
+
+ where[ name ] = new THREE.Texture( texture );
+ where[ name ].sourceFile = sourceFile;
+
+ if( repeat ) {
+
+ where[ name ].repeat.set( repeat[ 0 ], repeat[ 1 ] );
+
+ if ( repeat[ 0 ] !== 1 ) where[ name ].wrapS = THREE.RepeatWrapping;
+ if ( repeat[ 1 ] !== 1 ) where[ name ].wrapT = THREE.RepeatWrapping;
+
+ }
+
+ if ( offset ) {
+
+ where[ name ].offset.set( offset[ 0 ], offset[ 1 ] );
+
+ }
+
+ if ( wrap ) {
+
+ var wrapMap = {
+ "repeat": THREE.RepeatWrapping,
+ "mirror": THREE.MirroredRepeatWrapping
+ }
+
+ if ( wrapMap[ wrap[ 0 ] ] !== undefined ) where[ name ].wrapS = wrapMap[ wrap[ 0 ] ];
+ if ( wrapMap[ wrap[ 1 ] ] !== undefined ) where[ name ].wrapT = wrapMap[ wrap[ 1 ] ];
+
+ }
+
+ load_image( where[ name ], texturePath + "/" + sourceFile );
+
+ }
+
+ function rgb2hex( rgb ) {
+
+ return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
+
+ }
+
+ // defaults
+
+ var mtype = "MeshLambertMaterial";
+ var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
+
+ // parameters from model file
+
+ if ( m.shading ) {
+
+ var shading = m.shading.toLowerCase();
+
+ if ( shading === "phong" ) mtype = "MeshPhongMaterial";
+ else if ( shading === "basic" ) mtype = "MeshBasicMaterial";
+
+ }
+
+ if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
+
+ mpars.blending = THREE[ m.blending ];
+
+ }
+
+ if ( m.transparent !== undefined || m.opacity < 1.0 ) {
+
+ mpars.transparent = m.transparent;
+
+ }
+
+ if ( m.depthTest !== undefined ) {
+
+ mpars.depthTest = m.depthTest;
+
+ }
+
+ if ( m.depthWrite !== undefined ) {
+
+ mpars.depthWrite = m.depthWrite;
+
+ }
+
+ if ( m.visible !== undefined ) {
+
+ mpars.visible = m.visible;
+
+ }
+
+ if ( m.flipSided !== undefined ) {
+
+ mpars.side = THREE.BackSide;
+
+ }
+
+ if ( m.doubleSided !== undefined ) {
+
+ mpars.side = THREE.DoubleSide;
+
+ }
+
+ if ( m.wireframe !== undefined ) {
+
+ mpars.wireframe = m.wireframe;
+
+ }
+
+ if ( m.vertexColors !== undefined ) {
+
+ if ( m.vertexColors == "face" ) {
+
+ mpars.vertexColors = THREE.FaceColors;
+
+ } else if ( m.vertexColors ) {
+
+ mpars.vertexColors = THREE.VertexColors;
+
+ }
+
+ }
+
+ // colors
+
+ if ( m.colorDiffuse ) {
+
+ mpars.color = rgb2hex( m.colorDiffuse );
+
+ } else if ( m.DbgColor ) {
+
+ mpars.color = m.DbgColor;
+
+ }
+
+ if ( m.colorSpecular ) {
+
+ mpars.specular = rgb2hex( m.colorSpecular );
+
+ }
+
+ if ( m.colorAmbient ) {
+
+ mpars.ambient = rgb2hex( m.colorAmbient );
+
+ }
+
+ // modifiers
+
+ if ( m.transparency ) {
+
+ mpars.opacity = m.transparency;
+
+ }
+
+ if ( m.specularCoef ) {
+
+ mpars.shininess = m.specularCoef;
+
+ }
+
+ // textures
+
+ if ( m.mapDiffuse && texturePath ) {
+
+ create_texture( mpars, "map", m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap );
+
+ }
+
+ if ( m.mapLight && texturePath ) {
+
+ create_texture( mpars, "lightMap", m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap );
+
+ }
+
+ if ( m.mapBump && texturePath ) {
+
+ create_texture( mpars, "bumpMap", m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap );
+
+ }
+
+ if ( m.mapNormal && texturePath ) {
+
+ create_texture( mpars, "normalMap", m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap );
+
+ }
+
+ if ( m.mapSpecular && texturePath ) {
+
+ create_texture( mpars, "specularMap", m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap );
+
+ }
+
+ // special case for normal mapped material
+
+ if ( m.mapNormal ) {
+
+ var shader = THREE.ShaderUtils.lib[ "normal" ];
+ var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
+
+ uniforms[ "tNormal" ].texture = mpars.normalMap;
+
+ if ( m.mapNormalFactor ) {
+
+ uniforms[ "uNormalScale" ].value = m.mapNormalFactor;
+
+ }
+
+ if ( mpars.map ) {
+
+ uniforms[ "tDiffuse" ].texture = mpars.map;
+ uniforms[ "enableDiffuse" ].value = true;
+
+ }
+
+ if ( mpars.specularMap ) {
+
+ uniforms[ "tSpecular" ].texture = mpars.specularMap;
+ uniforms[ "enableSpecular" ].value = true;
+
+ }
+
+ if ( mpars.lightMap ) {
+
+ uniforms[ "tAO" ].texture = mpars.lightMap;
+ uniforms[ "enableAO" ].value = true;
+
+ }
+
+ // for the moment don't handle displacement texture
+
+ uniforms[ "uDiffuseColor" ].value.setHex( mpars.color );
+ uniforms[ "uSpecularColor" ].value.setHex( mpars.specular );
+ uniforms[ "uAmbientColor" ].value.setHex( mpars.ambient );
+
+ uniforms[ "uShininess" ].value = mpars.shininess;
+
+ if ( mpars.opacity !== undefined ) {
+
+ uniforms[ "uOpacity" ].value = mpars.opacity;
+
+ }
+
+ var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
+ var material = new THREE.ShaderMaterial( parameters );
+
+ } else {
+
+ var material = new THREE[ mtype ]( mpars );
+
+ }
+
+ if ( m.DbgName !== undefined ) material.name = m.DbgName;
+
+ return material;
+
+ }
+
+};
/**
* @author alteredq / http://alteredqualia.com/
*/
@@ -7528,1141 +7528,1141 @@ THREE.ImageLoader.prototype = {
if ( image === undefined ) image = new Image();
- image.addEventListener( 'load', function () {
+ image.addEventListener( 'load', function () {
+
+ scope.dispatchEvent( { type: 'load', content: image } );
+
+ }, false );
+
+ image.addEventListener( 'error', function () {
+
+ scope.dispatchEvent( { type: 'error', message: 'Couldn\'t load URL [' + url + ']' } );
+
+ }, false );
+
+ if ( scope.crossOrigin ) image.crossOrigin = scope.crossOrigin;
+
+ image.src = url;
+
+ }
+
+}
+/**
+ * @author mrdoob / http://mrdoob.com/
+ * @author alteredq / http://alteredqualia.com/
+ */
+
+THREE.JSONLoader = function ( showStatus ) {
+
+ THREE.Loader.call( this, showStatus );
+
+};
+
+THREE.JSONLoader.prototype = Object.create( THREE.Loader.prototype );
+
+THREE.JSONLoader.prototype.load = function ( url, callback, texturePath ) {
+
+ var scope = this;
+
+ texturePath = texturePath ? texturePath : this.extractUrlBase( url );
+
+ this.onLoadStart();
+ this.loadAjaxJSON( this, url, callback, texturePath );
+
+};
+
+THREE.JSONLoader.prototype.loadAjaxJSON = function ( context, url, callback, texturePath, callbackProgress ) {
+
+ var xhr = new XMLHttpRequest();
+
+ var length = 0;
+
+ xhr.onreadystatechange = function () {
+
+ if ( xhr.readyState === xhr.DONE ) {
+
+ if ( xhr.status === 200 || xhr.status === 0 ) {
+
+ if ( xhr.responseText ) {
+
+ var json = JSON.parse( xhr.responseText );
+ context.createModel( json, callback, texturePath );
+
+ } else {
+
+ console.warn( "THREE.JSONLoader: [" + url + "] seems to be unreachable or file there is empty" );
+
+ }
+
+ // in context of more complex asset initialization
+ // do not block on single failed file
+ // maybe should go even one more level up
+
+ context.onLoadComplete();
+
+ } else {
+
+ console.error( "THREE.JSONLoader: Couldn't load [" + url + "] [" + xhr.status + "]" );
+
+ }
+
+ } else if ( xhr.readyState === xhr.LOADING ) {
+
+ if ( callbackProgress ) {
+
+ if ( length === 0 ) {
+
+ length = xhr.getResponseHeader( "Content-Length" );
+
+ }
+
+ callbackProgress( { total: length, loaded: xhr.responseText.length } );
+
+ }
+
+ } else if ( xhr.readyState === xhr.HEADERS_RECEIVED ) {
+
+ length = xhr.getResponseHeader( "Content-Length" );
+
+ }
+
+ };
+
+ xhr.open( "GET", url, true );
+ if ( xhr.overrideMimeType ) xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
+ xhr.setRequestHeader( "Content-Type", "text/plain" );
+ xhr.send( null );
+
+};
+
+THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath ) {
+
+ var scope = this,
+ geometry = new THREE.Geometry(),
+ scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
+
+ this.initMaterials( geometry, json.materials, texturePath );
+
+ parseModel( scale );
+
+ parseSkin();
+ parseMorphing( scale );
+
+ geometry.computeCentroids();
+ geometry.computeFaceNormals();
+
+ if ( this.hasNormals( geometry ) ) geometry.computeTangents();
+
+
+ function parseModel( scale ) {
+
+ function isBitSet( value, position ) {
+
+ return value & ( 1 << position );
+
+ }
+
+ var i, j, fi,
+
+ offset, zLength, nVertices,
+
+ colorIndex, normalIndex, uvIndex, materialIndex,
+
+ type,
+ isQuad,
+ hasMaterial,
+ hasFaceUv, hasFaceVertexUv,
+ hasFaceNormal, hasFaceVertexNormal,
+ hasFaceColor, hasFaceVertexColor,
+
+ vertex, face, color, normal,
+
+ uvLayer, uvs, u, v,
+
+ faces = json.faces,
+ vertices = json.vertices,
+ normals = json.normals,
+ colors = json.colors,
+
+ nUvLayers = 0;
+
+ // disregard empty arrays
+
+ for ( i = 0; i < json.uvs.length; i++ ) {
+
+ if ( json.uvs[ i ].length ) nUvLayers ++;
+
+ }
+
+ for ( i = 0; i < nUvLayers; i++ ) {
+
+ geometry.faceUvs[ i ] = [];
+ geometry.faceVertexUvs[ i ] = [];
+
+ }
+
+ offset = 0;
+ zLength = vertices.length;
+
+ while ( offset < zLength ) {
+
+ vertex = new THREE.Vector3();
+
+ vertex.x = vertices[ offset ++ ] * scale;
+ vertex.y = vertices[ offset ++ ] * scale;
+ vertex.z = vertices[ offset ++ ] * scale;
+
+ geometry.vertices.push( vertex );
+
+ }
+
+ offset = 0;
+ zLength = faces.length;
+
+ while ( offset < zLength ) {
+
+ type = faces[ offset ++ ];
+
+
+ isQuad = isBitSet( type, 0 );
+ hasMaterial = isBitSet( type, 1 );
+ hasFaceUv = isBitSet( type, 2 );
+ hasFaceVertexUv = isBitSet( type, 3 );
+ hasFaceNormal = isBitSet( type, 4 );
+ hasFaceVertexNormal = isBitSet( type, 5 );
+ hasFaceColor = isBitSet( type, 6 );
+ hasFaceVertexColor = isBitSet( type, 7 );
+
+ //console.log("type", type, "bits", isQuad, hasMaterial, hasFaceUv, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
+
+ if ( isQuad ) {
+
+ face = new THREE.Face4();
+
+ face.a = faces[ offset ++ ];
+ face.b = faces[ offset ++ ];
+ face.c = faces[ offset ++ ];
+ face.d = faces[ offset ++ ];
+
+ nVertices = 4;
+
+ } else {
+
+ face = new THREE.Face3();
+
+ face.a = faces[ offset ++ ];
+ face.b = faces[ offset ++ ];
+ face.c = faces[ offset ++ ];
+
+ nVertices = 3;
+
+ }
+
+ if ( hasMaterial ) {
+
+ materialIndex = faces[ offset ++ ];
+ face.materialIndex = materialIndex;
+
+ }
+
+ // to get face <=> uv index correspondence
+
+ fi = geometry.faces.length;
+
+ if ( hasFaceUv ) {
+
+ for ( i = 0; i < nUvLayers; i++ ) {
+
+ uvLayer = json.uvs[ i ];
+
+ uvIndex = faces[ offset ++ ];
+
+ u = uvLayer[ uvIndex * 2 ];
+ v = uvLayer[ uvIndex * 2 + 1 ];
+
+ geometry.faceUvs[ i ][ fi ] = new THREE.UV( u, v );
+
+ }
+
+ }
+
+ if ( hasFaceVertexUv ) {
+
+ for ( i = 0; i < nUvLayers; i++ ) {
+
+ uvLayer = json.uvs[ i ];
+
+ uvs = [];
+
+ for ( j = 0; j < nVertices; j ++ ) {
+
+ uvIndex = faces[ offset ++ ];
+
+ u = uvLayer[ uvIndex * 2 ];
+ v = uvLayer[ uvIndex * 2 + 1 ];
+
+ uvs[ j ] = new THREE.UV( u, v );
+
+ }
+
+ geometry.faceVertexUvs[ i ][ fi ] = uvs;
+
+ }
+
+ }
+
+ if ( hasFaceNormal ) {
+
+ normalIndex = faces[ offset ++ ] * 3;
+
+ normal = new THREE.Vector3();
+
+ normal.x = normals[ normalIndex ++ ];
+ normal.y = normals[ normalIndex ++ ];
+ normal.z = normals[ normalIndex ];
+
+ face.normal = normal;
+
+ }
+
+ if ( hasFaceVertexNormal ) {
+
+ for ( i = 0; i < nVertices; i++ ) {
+
+ normalIndex = faces[ offset ++ ] * 3;
+
+ normal = new THREE.Vector3();
+
+ normal.x = normals[ normalIndex ++ ];
+ normal.y = normals[ normalIndex ++ ];
+ normal.z = normals[ normalIndex ];
+
+ face.vertexNormals.push( normal );
+
+ }
+
+ }
+
+
+ if ( hasFaceColor ) {
+
+ colorIndex = faces[ offset ++ ];
+
+ color = new THREE.Color( colors[ colorIndex ] );
+ face.color = color;
+
+ }
+
+
+ if ( hasFaceVertexColor ) {
+
+ for ( i = 0; i < nVertices; i++ ) {
+
+ colorIndex = faces[ offset ++ ];
+
+ color = new THREE.Color( colors[ colorIndex ] );
+ face.vertexColors.push( color );
+
+ }
+
+ }
+
+ geometry.faces.push( face );
+
+ }
+
+ };
+
+ function parseSkin() {
+
+ var i, l, x, y, z, w, a, b, c, d;
+
+ if ( json.skinWeights ) {
+
+ for ( i = 0, l = json.skinWeights.length; i < l; i += 2 ) {
+
+ x = json.skinWeights[ i ];
+ y = json.skinWeights[ i + 1 ];
+ z = 0;
+ w = 0;
+
+ geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
+
+ }
+
+ }
+
+ if ( json.skinIndices ) {
+
+ for ( i = 0, l = json.skinIndices.length; i < l; i += 2 ) {
+
+ a = json.skinIndices[ i ];
+ b = json.skinIndices[ i + 1 ];
+ c = 0;
+ d = 0;
+
+ geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
+
+ }
+
+ }
+
+ geometry.bones = json.bones;
+ geometry.animation = json.animation;
+
+ };
+
+ function parseMorphing( scale ) {
+
+ if ( json.morphTargets !== undefined ) {
+
+ var i, l, v, vl, dstVertices, srcVertices;
+
+ for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
+
+ geometry.morphTargets[ i ] = {};
+ geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
+ geometry.morphTargets[ i ].vertices = [];
+
+ dstVertices = geometry.morphTargets[ i ].vertices;
+ srcVertices = json.morphTargets [ i ].vertices;
+
+ for( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
+
+ var vertex = new THREE.Vector3();
+ vertex.x = srcVertices[ v ] * scale;
+ vertex.y = srcVertices[ v + 1 ] * scale;
+ vertex.z = srcVertices[ v + 2 ] * scale;
+
+ dstVertices.push( vertex );
+
+ }
+
+ }
+
+ }
+
+ if ( json.morphColors !== undefined ) {
+
+ var i, l, c, cl, dstColors, srcColors, color;
+
+ for ( i = 0, l = json.morphColors.length; i < l; i++ ) {
+
+ geometry.morphColors[ i ] = {};
+ geometry.morphColors[ i ].name = json.morphColors[ i ].name;
+ geometry.morphColors[ i ].colors = [];
+
+ dstColors = geometry.morphColors[ i ].colors;
+ srcColors = json.morphColors [ i ].colors;
+
+ for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
+
+ color = new THREE.Color( 0xffaa00 );
+ color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
+ dstColors.push( color );
+
+ }
+
+ }
+
+ }
+
+ };
+
+ callback( geometry );
+
+};
+/**
+ * @author mrdoob / http://mrdoob.com/
+ * @author alteredq / http://alteredqualia.com/
+ */
+
+THREE.GeometryLoader = function () {
+
+ THREE.EventTarget.call( this );
+
+ this.crossOrigin = null;
+ this.path = null;
+
+
+};
+
+THREE.GeometryLoader.prototype = {
+
+ constructor: THREE.GeometryLoader,
+
+ load: function ( url ) {
+
+ var scope = this;
+ var geometry = null;
+
+ if ( scope.path === null ) {
+
+ var parts = url.split( '/' ); parts.pop();
+ scope.path = ( parts.length < 1 ? '.' : parts.join( '/' ) );
+
+ }
+
+ //
+
+ var xhr = new XMLHttpRequest();
+
+ xhr.addEventListener( 'load', function ( event ) {
+
+ if ( event.target.responseText ) {
+
+ geometry = scope.parse( JSON.parse( event.target.responseText ), monitor );
+
+ } else {
+
+ scope.dispatchEvent( { type: 'error', message: 'Invalid file [' + url + ']' } );
+
+ }
+
+ }, false );
+
+ xhr.addEventListener( 'error', function () {
+
+ scope.dispatchEvent( { type: 'error', message: 'Couldn\'t load URL [' + url + ']' } );
+
+ }, false );
+
+ xhr.open( 'GET', url, true );
+ xhr.send( null );
+
+ //
+
+ var monitor = new THREE.LoadingMonitor();
+
+ monitor.addEventListener( 'load', function ( event ) {
+
+ scope.dispatchEvent( { type: 'load', content: geometry } );
+
+ } );
+
+ monitor.add( xhr );
+
+ },
+
+ parse: function ( data, monitor ) {
+
+ var scope = this;
+ var geometry = new THREE.Geometry();
+
+ var scale = ( data.scale !== undefined ) ? 1 / data.scale : 1;
+
+ // materials
+
+ if ( data.materials ) {
+
+ geometry.materials = [];
+
+ for ( var i = 0; i < data.materials.length; ++ i ) {
+
+ var m = data.materials[ i ];
+
+ function isPow2( n ) {
+
+ var l = Math.log( n ) / Math.LN2;
+ return Math.floor( l ) == l;
+
+ }
+
+ function nearestPow2( n ) {
+
+ var l = Math.log( n ) / Math.LN2;
+ return Math.pow( 2, Math.round( l ) );
+
+ }
+
+ function createTexture( where, name, sourceFile, repeat, offset, wrap ) {
+
+ where[ name ] = new THREE.Texture();
+ where[ name ].sourceFile = sourceFile;
+
+ if ( repeat ) {
+
+ where[ name ].repeat.set( repeat[ 0 ], repeat[ 1 ] );
+
+ if ( repeat[ 0 ] !== 1 ) where[ name ].wrapS = THREE.RepeatWrapping;
+ if ( repeat[ 1 ] !== 1 ) where[ name ].wrapT = THREE.RepeatWrapping;
+
+ }
+
+ if ( offset ) {
+
+ where[ name ].offset.set( offset[ 0 ], offset[ 1 ] );
+
+ }
+
+ if ( wrap ) {
+
+ var wrapMap = {
+
+ "repeat": THREE.RepeatWrapping,
+ "mirror": THREE.MirroredRepeatWrapping
+
+ }
+
+ if ( wrapMap[ wrap[ 0 ] ] !== undefined ) where[ name ].wrapS = wrapMap[ wrap[ 0 ] ];
+ if ( wrapMap[ wrap[ 1 ] ] !== undefined ) where[ name ].wrapT = wrapMap[ wrap[ 1 ] ];
+
+ }
+
+ // load image
+
+ var texture = where[ name ];
+
+ var loader = new THREE.ImageLoader();
+ loader.addEventListener( 'load', function ( event ) {
+
+ var image = event.content;
+
+ if ( !isPow2( image.width ) || !isPow2( image.height ) ) {
+
+ var width = nearestPow2( image.width );
+ var height = nearestPow2( image.height );
+
+ texture.image = document.createElement( 'canvas' );
+ texture.image.width = width;
+ texture.image.height = height;
+ texture.image.getContext( '2d' ).drawImage( image, 0, 0, width, height );
+
+ } else {
+
+ texture.image = image;
+
+ }
+
+ texture.needsUpdate = true;
+
+ } );
+ loader.crossOrigin = scope.crossOrigin;
+ loader.load( scope.path + '/' + sourceFile );
+
+ if ( monitor ) monitor.add( loader );
+
+ }
+
+ function rgb2hex( rgb ) {
+
+ return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
+
+ }
+
+ // defaults
+
+ var mtype = "MeshLambertMaterial";
+ var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
+
+ // parameters from model file
+
+ if ( m.shading ) {
+
+ var shading = m.shading.toLowerCase();
+
+ if ( shading === "phong" ) mtype = "MeshPhongMaterial";
+ else if ( shading === "basic" ) mtype = "MeshBasicMaterial";
+
+ }
+
+ if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
+
+ mpars.blending = THREE[ m.blending ];
+
+ }
+
+ if ( m.transparent !== undefined || m.opacity < 1.0 ) {
+
+ mpars.transparent = m.transparent;
+
+ }
+
+ if ( m.depthTest !== undefined ) {
+
+ mpars.depthTest = m.depthTest;
+
+ }
+
+ if ( m.depthWrite !== undefined ) {
+
+ mpars.depthWrite = m.depthWrite;
+
+ }
+
+ if ( m.vertexColors !== undefined ) {
+
+ if ( m.vertexColors == "face" ) {
+
+ mpars.vertexColors = THREE.FaceColors;
+
+ } else if ( m.vertexColors ) {
+
+ mpars.vertexColors = THREE.VertexColors;
+
+ }
+
+ }
+
+ // colors
+
+ if ( m.colorDiffuse ) {
+
+ mpars.color = rgb2hex( m.colorDiffuse );
+
+ } else if ( m.DbgColor ) {
+
+ mpars.color = m.DbgColor;
+
+ }
+
+ if ( m.colorSpecular ) {
+
+ mpars.specular = rgb2hex( m.colorSpecular );
+
+ }
+
+ if ( m.colorAmbient ) {
+
+ mpars.ambient = rgb2hex( m.colorAmbient );
+
+ }
+
+ // modifiers
+
+ if ( m.transparency ) {
+
+ mpars.opacity = m.transparency;
+
+ }
+
+ if ( m.specularCoef ) {
+
+ mpars.shininess = m.specularCoef;
+
+ }
+
+ if ( m.visible !== undefined ) {
+
+ mpars.visible = m.visible;
+
+ }
+
+ if ( m.flipSided !== undefined ) {
+
+ mpars.side = THREE.BackSide;
+
+ }
+
+ if ( m.doubleSided !== undefined ) {
+
+ mpars.side = THREE.DoubleSide;
+
+ }
+
+ if ( m.wireframe !== undefined ) {
+
+ mpars.wireframe = m.wireframe;
+
+ }
+
+ // textures
+
+ if ( m.mapDiffuse ) {
+
+ createTexture( mpars, "map", m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap );
+
+ }
+
+ if ( m.mapLight ) {
+
+ createTexture( mpars, "lightMap", m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap );
+
+ }
+
+ if ( m.mapBump ) {
+
+ createTexture( mpars, "bumpMap", m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap );
+
+ }
+
+ if ( m.mapNormal ) {
+
+ createTexture( mpars, "normalMap", m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap );
+
+ }
+
+ if ( m.mapSpecular ) {
+
+ createTexture( mpars, "specularMap", m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap );
+
+ }
+
+ // special case for normal mapped material
+
+ if ( m.mapNormal ) {
+
+ var shader = THREE.ShaderUtils.lib[ "normal" ];
+ var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
+
+ uniforms[ "tNormal" ].texture = mpars.normalMap;
+
+ if ( m.mapNormalFactor ) {
+
+ uniforms[ "uNormalScale" ].value = m.mapNormalFactor;
+
+ }
+
+ if ( mpars.map ) {
+
+ uniforms[ "tDiffuse" ].texture = mpars.map;
+ uniforms[ "enableDiffuse" ].value = true;
+
+ }
+
+ if ( mpars.specularMap ) {
+
+ uniforms[ "tSpecular" ].texture = mpars.specularMap;
+ uniforms[ "enableSpecular" ].value = true;
+
+ }
+
+ if ( mpars.lightMap ) {
+
+ uniforms[ "tAO" ].texture = mpars.lightMap;
+ uniforms[ "enableAO" ].value = true;
+
+ }
+
+ // for the moment don't handle displacement texture
+
+ uniforms[ "uDiffuseColor" ].value.setHex( mpars.color );
+ uniforms[ "uSpecularColor" ].value.setHex( mpars.specular );
+ uniforms[ "uAmbientColor" ].value.setHex( mpars.ambient );
+
+ uniforms[ "uShininess" ].value = mpars.shininess;
+
+ if ( mpars.opacity !== undefined ) {
+
+ uniforms[ "uOpacity" ].value = mpars.opacity;
+
+ }
+
+ var parameters = { fragmentShader: shader.fragmentShader, vertexShade