jsc3d-rails 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +33 -0
- data/jsc3d-rails.gemspec +23 -0
- data/lib/generators/jquery/install/install_generator.rb +59 -0
- data/lib/jsc3d-rails.rb +1 -0
- data/lib/jsc3d/rails.rb +8 -0
- data/lib/jsc3d/rails/engine.rb +6 -0
- data/lib/jsc3d/rails/version.rb +6 -0
- data/vendor/assets/javascripts/bin/jsc3d.min.js +139 -0
- data/vendor/assets/javascripts/bin/jsc3d_ie.min.js +133 -0
- data/vendor/assets/javascripts/build/compile.bat +1 -0
- data/vendor/assets/javascripts/build/compile.sh +2 -0
- data/vendor/assets/javascripts/build/gendoc.bat +2 -0
- data/vendor/assets/javascripts/build/gendoc.sh +2 -0
- data/vendor/assets/javascripts/docs/files.html +247 -0
- data/vendor/assets/javascripts/docs/index.html +349 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.AABB.html +436 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.BinaryStream.html +1051 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.LoaderSelector.html +455 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.Material.html +430 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.Math3D.html +468 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.Matrix3x4.html +682 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.Mesh.html +628 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.ObjLoader.html +428 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.PickInfo.html +332 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.Scene.html +571 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.StlLoader.html +473 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.Texture.html +589 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.Viewer.html +1156 -0
- data/vendor/assets/javascripts/docs/symbols/JSC3D.html +329 -0
- data/vendor/assets/javascripts/docs/symbols/_global_.html +279 -0
- data/vendor/assets/javascripts/docs/symbols/src/jsc3d.js.html +4804 -0
- data/vendor/assets/javascripts/jsc3d.console.js +146 -0
- data/vendor/assets/javascripts/jsc3d.js +4796 -0
- data/vendor/assets/javascripts/jsc3d_ie.js +4487 -0
- data/vendor/assets/javascripts/tools/closure/COPYING +202 -0
- data/vendor/assets/javascripts/tools/closure/README +261 -0
- data/vendor/assets/javascripts/tools/closure/USAGE +87 -0
- data/vendor/assets/javascripts/tools/closure/compiler.jar +0 -0
- data/vendor/assets/javascripts/tools/doc_generator/README.txt +146 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/frame.js +33 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/frame/Chain.js +102 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/frame/Dumper.js +144 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/frame/Hash.js +84 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/frame/Link.js +148 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/frame/Namespace.js +10 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/frame/Opt.js +134 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/frame/Reflection.js +26 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/frame/String.js +93 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/frame/Testrun.js +129 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/handlers/FOODOC.js +26 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/handlers/XMLDOC.js +26 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/handlers/XMLDOC/DomReader.js +159 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/handlers/XMLDOC/XMLDoc.js +16 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/handlers/XMLDOC/XMLParse.js +292 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC.js +101 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/DocComment.js +200 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/DocTag.js +294 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/JsDoc.js +126 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/JsPlate.js +109 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/Lang.js +144 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/Parser.js +107 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/PluginManager.js +33 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/Symbol.js +643 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/SymbolSet.js +229 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/TextStream.js +41 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/Token.js +18 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/TokenReader.js +332 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/TokenStream.js +133 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/Util.js +32 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/lib/JSDOC/Walker.js +459 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/main.js +111 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/plugins/commentSrcJson.js +20 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/plugins/frameworkPrototype.js +16 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/plugins/functionCall.js +10 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/plugins/publishSrcHilite.js +62 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/plugins/symbolLink.js +9 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/plugins/tagParamConfig.js +31 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/plugins/tagSynonyms.js +43 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/run.js +348 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/t/TestDoc.js +144 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/t/runner.js +13 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test.js +307 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/addon.js +24 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/anon_inner.js +14 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/augments.js +31 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/augments2.js +26 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/borrows.js +41 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/borrows2.js +23 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/config.js +22 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/constructs.js +18 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/encoding.js +10 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/encoding_other.js +12 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/event.js +54 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/functions_anon.js +39 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/functions_nested.js +33 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/global.js +13 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/globals.js +25 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/ignore.js +10 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/inner.js +16 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/jsdoc_test.js +477 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/lend.js +33 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/memberof.js +19 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/memberof_constructor.js +17 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/name.js +19 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/namespace_nested.js +23 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/nocode.js +13 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/oblit_anon.js +20 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/overview.js +20 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/param_inline.js +37 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/params_optional.js +8 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/prototype.js +17 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/prototype_nested.js +9 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/prototype_oblit.js +13 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/prototype_oblit_constructor.js +24 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/public.js +10 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/shared.js +42 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/shared2.js +2 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/shortcuts.js +22 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/static_this.js +13 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/synonyms.js +31 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/tosource.js +23 -0
- data/vendor/assets/javascripts/tools/doc_generator/app/test/variable_redefine.js +14 -0
- data/vendor/assets/javascripts/tools/doc_generator/changes.txt +75 -0
- data/vendor/assets/javascripts/tools/doc_generator/conf/sample.conf +31 -0
- data/vendor/assets/javascripts/tools/doc_generator/java/build.xml +36 -0
- data/vendor/assets/javascripts/tools/doc_generator/java/build_1.4.xml +36 -0
- data/vendor/assets/javascripts/tools/doc_generator/java/classes/js.jar +0 -0
- data/vendor/assets/javascripts/tools/doc_generator/java/src/JsDebugRun.java +21 -0
- data/vendor/assets/javascripts/tools/doc_generator/java/src/JsRun.java +21 -0
- data/vendor/assets/javascripts/tools/doc_generator/jsdebug.jar +0 -0
- data/vendor/assets/javascripts/tools/doc_generator/jsrun.jar +0 -0
- data/vendor/assets/javascripts/tools/doc_generator/templates/jsdoc/allclasses.tmpl +17 -0
- data/vendor/assets/javascripts/tools/doc_generator/templates/jsdoc/allfiles.tmpl +56 -0
- data/vendor/assets/javascripts/tools/doc_generator/templates/jsdoc/class.tmpl +646 -0
- data/vendor/assets/javascripts/tools/doc_generator/templates/jsdoc/index.tmpl +39 -0
- data/vendor/assets/javascripts/tools/doc_generator/templates/jsdoc/publish.js +184 -0
- data/vendor/assets/javascripts/tools/doc_generator/templates/jsdoc/static/default.css +165 -0
- data/vendor/assets/javascripts/tools/doc_generator/templates/jsdoc/static/header.html +2 -0
- data/vendor/assets/javascripts/tools/doc_generator/templates/jsdoc/static/index.html +19 -0
- data/vendor/assets/javascripts/tools/doc_generator/templates/jsdoc/symbol.tmpl +35 -0
- metadata +234 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Andre Arko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# jquery-rails
|
2
|
+
|
3
|
+
jsc3d! For Rails! So great.
|
4
|
+
|
5
|
+
This gem provides:
|
6
|
+
|
7
|
+
* jsc3d 0.9.8
|
8
|
+
|
9
|
+
## Versions
|
10
|
+
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add jsc3d-rails to your Gemfile
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem "jsc3d-rails"
|
18
|
+
```
|
19
|
+
|
20
|
+
And run `bundle install`. The rest of the installation depends on
|
21
|
+
whether the asset pipeline is being used.
|
22
|
+
|
23
|
+
### Rails 3.1 or greater (with asset pipeline *enabled*)
|
24
|
+
|
25
|
+
The jsc3d files will be added to the asset pipeline and available for you to use. If they're not already in `app/assets/javascripts/application.js` by default, add these lines
|
26
|
+
|
27
|
+
```js
|
28
|
+
//= require jsc3d.console
|
29
|
+
//= require jsc3d_ie
|
30
|
+
//= require jsc3d
|
31
|
+
```
|
32
|
+
|
33
|
+
You're done!
|
data/jsc3d-rails.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/jsc3d/rails/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "jsc3d-rails"
|
6
|
+
s.version = Jsc3d::Rails::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Eugene Howe"]
|
9
|
+
s.email = ["eugene@xtreme-computers.net"]
|
10
|
+
s.homepage = "http://github.com/ehowe/jsc3d-rails.git"
|
11
|
+
s.summary = "Use JSC3D with Rails 3"
|
12
|
+
s.description = "This gem provides access to the client side rendering application JSC3D"
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.required_rubygems_version = ">= 1.3.6"
|
16
|
+
|
17
|
+
s.add_dependency "railties", ">= 3.0", "< 5.0"
|
18
|
+
s.add_dependency "thor", ">= 0.14", "< 2.0"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
22
|
+
s.require_path = 'lib'
|
23
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
# Supply generator for Rails 3.0.x or if asset pipeline is not enabled
|
4
|
+
if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
|
5
|
+
module Jquery
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < ::Rails::Generators::Base
|
8
|
+
|
9
|
+
desc "This generator installs jQuery #{Jquery::Rails::JQUERY_VERSION}, jQuery-ujs, and (optionally) jQuery UI #{Jquery::Rails::JQUERY_UI_VERSION}"
|
10
|
+
class_option :ui, :type => :boolean, :default => false, :desc => "Include jQueryUI"
|
11
|
+
source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
|
12
|
+
|
13
|
+
def remove_prototype
|
14
|
+
Rails::PROTOTYPE_JS.each do |name|
|
15
|
+
remove_file "public/javascripts/#{name}.js"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_jquery
|
20
|
+
say_status("copying", "jQuery (#{Jquery::Rails::JQUERY_VERSION})", :green)
|
21
|
+
copy_file "jquery.js", "public/javascripts/jquery.js"
|
22
|
+
copy_file "jquery.min.js", "public/javascripts/jquery.min.js"
|
23
|
+
end
|
24
|
+
|
25
|
+
def copy_jquery_ui
|
26
|
+
if options.ui?
|
27
|
+
say_status("copying", "jQuery UI (#{Jquery::Rails::JQUERY_UI_VERSION})", :green)
|
28
|
+
copy_file "jquery-ui.js", "public/javascripts/jquery-ui.js"
|
29
|
+
copy_file "jquery-ui.min.js", "public/javascripts/jquery-ui.min.js"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def copy_ujs_driver
|
34
|
+
say_status("copying", "jQuery UJS adapter (#{Jquery::Rails::JQUERY_UJS_VERSION[0..5]})", :green)
|
35
|
+
remove_file "public/javascripts/rails.js"
|
36
|
+
copy_file "jquery_ujs.js", "public/javascripts/jquery_ujs.js"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
else
|
43
|
+
module Jquery
|
44
|
+
module Generators
|
45
|
+
class InstallGenerator < ::Rails::Generators::Base
|
46
|
+
desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
|
47
|
+
|
48
|
+
def do_nothing
|
49
|
+
say_status("deprecated", "You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.")
|
50
|
+
say_status("", "The necessary files are already in your asset pipeline.")
|
51
|
+
say_status("", "Just add `//= require jquery` and `//= require jquery_ujs` to your app/assets/javascripts/application.js")
|
52
|
+
say_status("", "If you upgraded your app from Rails 3.0 and still have jquery.js, rails.js, or jquery_ujs.js in your javascripts, be sure to remove them.")
|
53
|
+
say_status("", "If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.")
|
54
|
+
# ok, nothing
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/jsc3d-rails.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'jsc3d/rails'
|
data/lib/jsc3d/rails.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2012 Humu humu2009@gmail.com
|
3
|
+
jsc3d is freely distributable under the terms of the MIT license.
|
4
|
+
*/
|
5
|
+
var a,JSC3D=JSC3D||{};
|
6
|
+
JSC3D.Viewer=function(b,c){this.params=c?{SceneUrl:c.SceneUrl||"",InitRotationX:c.InitRotationX||0,InitRotationY:c.InitRotationY||0,InitRotationZ:c.InitRotationZ||0,ModelColor:c.ModelColor||"#caa618",BackgroundColor1:c.BackgroundColor1||"#ffffff",BackgroundColor2:c.BackgroundColor2||"#383840",BackgroundImageUrl:c.BackgroundImageUrl||"",RenderMode:c.RenderMode||"flat",Definition:c.Definition||"standard",MipMapping:c.MipMapping||"off",SphereMapUrl:c.SphereMapUrl||""}:{SceneUrl:"",InitRotationX:0,InitRotationY:0,
|
7
|
+
InitRotationZ:0,ModelColor:"#caa618",BackgroundColor1:"#ffffff",BackgroundColor2:"#383840",BackgroundImageUrl:"",RenderMode:"flat",Definition:"standard",MipMapping:"off",SphereMapUrl:""};this.canvas=b;this.selectionBuffer=this.zBuffer=this.colorBuffer=this.bkgColorBuffer=this.canvasData=this.ctx=null;this.frameWidth=b.width;this.frameHeight=b.height;this.sphereMap=this.defaultMaterial=this.scene=null;this.isFailed=this.isLoaded=false;this.errorMsg="";this.needRepaint=this.needUpdate=false;this.initRotZ=
|
8
|
+
this.initRotY=this.initRotX=0;this.zoomFactor=1;this.rotMatrix=new JSC3D.Matrix3x4;this.transformMatrix=new JSC3D.Matrix3x4;this.sceneUrl="";this.modelColor=13280792;this.bkgColor1=16777215;this.bkgColor2=3684416;this.bkgImageUrl="";this.bkgImage=null;this.renderMode="flat";this.definition="standard";this.isMipMappingOn=false;this.sphereMapUrl="";this.buttonStates={};this.keyStates={};this.mouseY=this.mouseX=0;this.afterupdate=this.beforeupdate=this.onmousemove=this.onmouseup=this.onmousedown=null;
|
9
|
+
this.mouseUsage="default";this.isDefaultInputHandlerEnabled=true;var d=this;if(document.createTouch!=undefined){this.canvas.addEventListener("touchstart",function(e){d.touchStartHandler(e)},false);this.canvas.addEventListener("touchend",function(e){d.touchEndHandler(e)},false);this.canvas.addEventListener("touchmove",function(e){d.touchMoveHandler(e)},false)}else{this.canvas.addEventListener("mousedown",function(e){d.mouseDownHandler(e)},false);this.canvas.addEventListener("mouseup",function(e){d.mouseUpHandler(e)},
|
10
|
+
false);this.canvas.addEventListener("mousemove",function(e){d.mouseMoveHandler(e)},false);document.addEventListener("keydown",function(e){d.keyDownHandler(e)},false);document.addEventListener("keyup",function(e){d.keyUpHandler(e)},false)}};a=JSC3D.Viewer.prototype;a.setParameter=function(b,c){this.params[b]=c};
|
11
|
+
a.init=function(){this.sceneUrl=this.params.SceneUrl;this.initRotX=parseFloat(this.params.InitRotationX);this.initRotY=parseFloat(this.params.InitRotationY);this.initRotZ=parseFloat(this.params.InitRotationZ);this.modelColor=parseInt("0x"+this.params.ModelColor.substring(1));this.bkgColor1=parseInt("0x"+this.params.BackgroundColor1.substring(1));this.bkgColor2=parseInt("0x"+this.params.BackgroundColor2.substring(1));this.bkgImageUrl=this.params.BackgroundImageUrl;this.renderMode=this.params.RenderMode.toLowerCase();
|
12
|
+
this.definition=this.params.Definition.toLowerCase();this.isMipMappingOn=this.params.MipMapping.toLowerCase()=="on";this.sphereMapUrl=this.params.SphereMapUrl;try{this.ctx=this.canvas.getContext("2d");this.canvasData=this.ctx.getImageData(0,0,this.canvas.width,this.canvas.height)}catch(b){this.canvasData=this.ctx=null}if(this.canvas.width<=2||this.canvas.height<=2)this.definition="standard";switch(this.definition){case "low":this.frameWidth=~~((this.canvas.width+1)/2);this.frameHeight=~~((this.canvas.height+
|
13
|
+
1)/2);break;case "high":this.frameWidth=this.canvas.width*2;this.frameHeight=this.canvas.height*2;break;case "standard":default:this.frameWidth=this.canvas.width;this.frameHeight=this.canvas.height;break}this.zoomFactor=1;this.rotMatrix.identity();this.transformMatrix.identity();this.isFailed=this.isLoaded=false;this.errorMsg="";this.needRepaint=this.needUpdate=false;this.scene=null;this.colorBuffer=new Array(this.frameWidth*this.frameHeight);this.zBuffer=new Array(this.frameWidth*this.frameHeight);
|
14
|
+
this.selectionBuffer=new Array(this.frameWidth*this.frameHeight);this.bkgColorBuffer=new Array(this.frameWidth*this.frameHeight);this.generateBackground();this.defaultMaterial=new JSC3D.Material;this.defaultMaterial.ambientColor=0;this.defaultMaterial.diffuseColor=this.modelColor;this.defaultMaterial.transparency=0;this.defaultMaterial.simulateSpecular=true;this.drawBackground();var c=this;setInterval(function(){c.doUpdate()},30);this.setBackgroudImageFromUrl(this.bkgImageUrl);this.loadScene();this.setSphereMapFromUrl(this.sphereMapUrl)};
|
15
|
+
a.update=function(b){if(this.isFailed)this.reportError(this.errorMsg);else if(b)this.needRepaint=true;else this.needUpdate=true};a.rotate=function(b,c,d){this.rotMatrix.rotateAboutXAxis(b);this.rotMatrix.rotateAboutYAxis(c);this.rotMatrix.rotateAboutZAxis(d)};a.setRenderMode=function(b){this.renderMode=this.params.RenderMode=b};
|
16
|
+
a.setDefinition=function(b){if(this.canvas.width<=2||this.canvas.height<=2)b="standard";if(b!=this.definition){this.definition=this.params.Definition=b;b=this.frameWidth;switch(this.definition){case "low":this.frameWidth=~~((this.canvas.width+1)/2);this.frameHeight=~~((this.canvas.height+1)/2);break;case "high":this.frameWidth=this.canvas.width*2;this.frameHeight=this.canvas.height*2;break;case "standard":default:this.frameWidth=this.canvas.width;this.frameHeight=this.canvas.height;break}var c=this.frameWidth*
|
17
|
+
this.frameHeight;if(this.colorBuffer.length<c)this.colorBuffer=new Array(c);if(this.zBuffer.length<c)this.zBuffer=new Array(c);if(this.selectionBuffer.length<c)this.selectionBuffer=new Array(c);if(this.bkgColorBuffer.length<c)this.bkgColorBuffer=new Array(c);this.generateBackground();this.zoomFactor*=this.frameWidth/b}};
|
18
|
+
a.setBackgroudImageFromUrl=function(b){this.bkgImageUrl=this.params.BackgroundImageUrl=b;if(b=="")this.bkgImage=null;else{var c=this,d=new Image;d.onload=function(){c.bkgImage=this;c.generateBackground()};d.src=b}};a.setSphereMapFromUrl=function(b){this.sphereMapUrl=this.params.SphereMapUrl=b;if(b=="")this.sphereMap=null;else{var c=this,d=new JSC3D.Texture;d.onready=function(){c.sphereMap=d;c.update()};d.createFromUrl(this.sphereMapUrl)}};
|
19
|
+
a.enableDefaultInputHandler=function(b){this.isDefaultInputHandlerEnabled=b};a.setMouseUsage=function(b){this.mouseUsage=b};a.replaceSceneFromUrl=function(b){this.sceneUrl=this.params.SceneUrl=b;this.isFailed=this.isLoaded=false;this.loadScene()};a.replaceScene=function(b){this.sceneUrl=this.params.SceneUrl="";this.isFailed=false;this.isLoaded=true;this.errorMsg="";this.setupScene(b)};a.getScene=function(){return this.scene};
|
20
|
+
a.pick=function(b,c){var d=new JSC3D.PickInfo,e=this.canvas.getBoundingClientRect();b=b-e.left;c=c-e.top;e=b;var f=c;if(this.selectionBuffer!=null&&b>=0&&b<this.canvas.width&&c>=0&&c<this.canvas.height){switch(this.definition){case "low":e=~~(e/2);f=~~(f/2);break;case "high":e*=2;f*=2;break;case "standard":default:break}var g=this.selectionBuffer[f*this.frameWidth+e];if(g>0)for(var h=this.scene.getChildren(),i=0;i<h.length;i++)if(h[i].internalId==g){d.mesh=h[i];break}}d.canvasX=b;d.canvasY=c;if(d.mesh)d.depth=
|
21
|
+
this.zBuffer[f*this.frameWidth+e];return d};a.doUpdate=function(){if(this.needUpdate||this.needRepaint){this.beforeupdate!=null&&typeof this.beforeupdate=="function"&&this.beforeupdate();if(this.scene){if(this.needUpdate&&this.colorBuffer!=null){this.beginScene();this.render();this.endScene()}this.paint()}else this.drawBackground();this.needUpdate=this.needRepaint=false;this.afterupdate!=null&&typeof this.afterupdate=="function"&&this.afterupdate()}};
|
22
|
+
a.paint=function(){this.canvasData&&this.ctx.putImageData(this.canvasData,0,0)};a.mouseDownHandler=function(b){if(this.onmousedown){var c=this.pick(b.clientX,b.clientY);this.onmousedown(c.canvasX,c.canvasY,b.button,c.depth,c.mesh)}b.preventDefault();if(this.isDefaultInputHandlerEnabled){this.buttonStates[b.button]=true;this.mouseX=b.clientX;this.mouseY=b.clientY}};
|
23
|
+
a.mouseUpHandler=function(b){if(this.onmouseup){var c=this.pick(b.clientX,b.clientY);this.onmouseup(c.canvasX,c.canvasY,b.button,c.depth,c.mesh)}b.preventDefault();if(this.isDefaultInputHandlerEnabled)this.buttonStates[b.button]=false};
|
24
|
+
a.mouseMoveHandler=function(b){if(this.onmousemove){var c=this.pick(b.clientX,b.clientY);this.onmousemove(c.canvasX,c.canvasY,b.button,c.depth,c.mesh)}b.preventDefault();if(this.isDefaultInputHandlerEnabled){c=this.keyStates[16]==true;if(this.buttonStates[0]==true){if(c&&this.mouseUsage=="default"||this.mouseUsage=="zoom")this.zoomFactor*=this.mouseY<=b.clientY?1.11:0.9;else if(this.mouseUsage=="default"||this.mouseUsage=="rotate"){c=(b.clientX-this.mouseX)*360/this.canvas.height;this.rotMatrix.rotateAboutXAxis((b.clientY-
|
25
|
+
this.mouseY)*360/this.canvas.width);this.rotMatrix.rotateAboutYAxis(c)}this.mouseX=b.clientX;this.mouseY=b.clientY;this.update()}}};a.touchStartHandler=function(b){if(b.touches.length>0){var c=b.touches[0].clientX,d=b.touches[0].clientY;if(this.onmousedown){var e=this.pick(c,d);this.onmousedown(e.canvasX,e.canvasY,0,e.depth,e.mesh)}b.preventDefault();if(this.isDefaultInputHandlerEnabled){this.buttonStates[0]=true;this.mouseX=c;this.mouseY=d}}};
|
26
|
+
a.touchEndHandler=function(b){if(this.onmouseup){var c=this.pick(this.mouseX,this.mouseY);this.onmouseup(c.canvasX,c.canvasY,0,c.depth,c.mesh)}b.preventDefault();if(this.isDefaultInputHandlerEnabled)this.buttonStates[0]=false};
|
27
|
+
a.touchMoveHandler=function(b){if(b.touches.length>0){var c=b.touches[0].clientX,d=b.touches[0].clientY;if(this.onmousemove){var e=this.pick(c,d);this.onmousemove(e.canvasX,e.canvasY,0,e.depth,e.mesh)}b.preventDefault();if(this.isDefaultInputHandlerEnabled){if(this.mouseUsage=="zoom")this.zoomFactor*=this.mouseY<=d?1.11:0.9;else if(this.mouseUsage=="default"||this.mouseUsage=="rotate"){b=(c-this.mouseX)*360/this.canvas.height;this.rotMatrix.rotateAboutXAxis((d-this.mouseY)*360/this.canvas.width);
|
28
|
+
this.rotMatrix.rotateAboutYAxis(b)}this.mouseX=c;this.mouseY=d;this.update()}}};a.keyDownHandler=function(b){if(this.isDefaultInputHandlerEnabled)this.keyStates[b.keyCode]=true};a.keyUpHandler=function(b){if(this.isDefaultInputHandlerEnabled)this.keyStates[b.keyCode]=false};
|
29
|
+
a.loadScene=function(){this.scene=null;this.isLoaded=false;if(this.sceneUrl=="")return false;var b=this.sceneUrl.lastIndexOf("/");if(b==-1)b=this.sceneUrl.lastIndexOf("\\");b=this.sceneUrl.substring(b+1);var c=b.lastIndexOf(".");if(c==-1)return false;b=b.substring(c+1);b=JSC3D.LoaderSelector.getLoader(b);if(!b)return false;var d=this;b.onload=function(e){d.setupScene(e)};b.onerror=function(e){d.scene=null;d.isLoaded=false;d.isFailed=true;d.errorMsg=e;d.update()};b.onprogress=function(e,f){d.reportProgress(e,
|
30
|
+
f)};b.onresource=function(e){e instanceof JSC3D.Texture&&d.isMipMappingOn&&!e.hasMipmap()&&e.generateMipmaps();d.update()};b.loadFromUrl(this.sceneUrl);return true};
|
31
|
+
a.setupScene=function(b){b.init();if(!b.isEmpty()){var c=b.aabb.lengthOfDiagonal(),d=this.frameWidth,e=this.frameHeight;this.zoomFactor=c==0?1:(d<e?d:e)/c}this.rotMatrix.identity();this.rotMatrix.rotateAboutXAxis(this.initRotX);this.rotMatrix.rotateAboutYAxis(this.initRotY);this.rotMatrix.rotateAboutZAxis(this.initRotZ);this.scene=b;this.isLoaded=true;this.isFailed=false;this.errorMsg="";this.needRepaint=this.needUpdate=false;this.update()};
|
32
|
+
a.reportProgress=function(b,c){if(this.ctx){this.drawBackground();this.ctx.save();var d=255-((this.bkgColor1&65280)>>8),e=255-(this.bkgColor1&255);d="#"+(255-((this.bkgColor1&16711680)>>16)).toString(16)+d.toString(16)+e.toString(16);this.ctx.strokeStyle=d;this.ctx.fillStyle=d;d=this.canvas.height*0.38;e=this.canvas.width-80;this.ctx.strokeRect(40,d,e,20);this.ctx.fillRect(42,d+2,(e-4)*c,16);this.ctx.font="12px Courier New";this.ctx.textAlign="left";this.ctx.fillText(b,40,d-4,e);this.ctx.restore()}};
|
33
|
+
a.reportError=function(b){if(this.ctx){this.drawBackground();this.ctx.save();var c=this.canvas.height*0.38-4,d=255-((this.bkgColor1&65280)>>8),e=255-(this.bkgColor1&255);this.ctx.fillStyle="#"+(255-((this.bkgColor1&16711680)>>16)).toString(16)+d.toString(16)+e.toString(16);this.ctx.font="16px Courier New";this.ctx.textAlign="left";this.ctx.fillText(b,40,c);this.ctx.restore()}};a.generateBackground=function(){this.bkgImage?this.fillBackgroundWithImage():this.fillGradientBackground()};
|
34
|
+
a.fillGradientBackground=function(){for(var b=this.frameWidth,c=this.frameHeight,d=this.bkgColorBuffer,e=(this.bkgColor1&16711680)>>16,f=(this.bkgColor1&65280)>>8,g=this.bkgColor1&255,h=(this.bkgColor2&16711680)>>16,i=(this.bkgColor2&65280)>>8,m=this.bkgColor2&255,o=0,r=0;r<c;r++)for(var j=e+r*(h-e)/c&255,B=f+r*(i-f)/c&255,k=g+r*(m-g)/c&255,M=0;M<b;M++)d[o++]=j<<16|B<<8|k};
|
35
|
+
a.fillBackgroundWithImage=function(){var b=this.frameWidth,c=this.frameHeight;if(!(this.bkgImage.width<=0||this.bkgImage.height<=0)){var d=false,e=JSC3D.Texture.cv;if(!e)try{e=document.createElement("canvas");JSC3D.Texture.cv=e;d=true}catch(f){return}if(e.width!=b||e.height!=c){e.width=b;e.height=c;d=true}var g=null;try{var h=e.getContext("2d");d||h.clearRect(0,0,b,c);h.drawImage(this.bkgImage,0,0,b,c);g=h.getImageData(0,0,b,c).data}catch(i){return}d=this.bkgColorBuffer;b=b*c;for(e=c=0;c<b;c++,e+=
|
36
|
+
4)d[c]=g[e]<<16|g[e+1]<<8|g[e+2]}};a.drawBackground=function(){if(this.canvasData){this.beginScene();this.endScene();this.paint()}};a.beginScene=function(){for(var b=this.colorBuffer,c=this.zBuffer,d=this.selectionBuffer,e=this.bkgColorBuffer,f=this.frameWidth*this.frameHeight,g=-Number.MAX_VALUE,h=0;h<f;h++){b[h]=e[h];c[h]=g;d[h]=0}};
|
37
|
+
a.endScene=function(){var b=this.canvasData.data,c=this.canvas.width,d=this.canvas.height,e=this.colorBuffer,f=this.frameWidth,g=f*this.frameHeight;switch(this.definition){case "low":var h=c>>1,i=f-h,m=0,o=0;for(g=0;g<d;g++){for(var r=0;r<c;r++){f=e[m];b[o]=(f&16711680)>>16;b[o+1]=(f&65280)>>8;b[o+2]=f&255;b[o+3]=255;m+=r&1;o+=4}m+=g&1?i:-h}break;case "high":for(g=o=m=0;g<d;g++){for(r=0;r<c;r++){h=e[m];i=e[m+1];var j=e[m+f],B=e[m+f+1];b[o]=(h&16711680)+(i&16711680)+(j&16711680)+(B&16711680)>>18;b[o+
|
38
|
+
1]=(h&65280)+(i&65280)+(j&65280)+(B&65280)>>10;b[o+2]=(h&255)+(i&255)+(j&255)+(B&255)>>2;b[o+3]=255;m+=2;o+=4}m+=f}break;case "standard":default:for(o=m=0;m<g;m++,o+=4){f=e[m];b[o]=(f&16711680)>>16;b[o+1]=(f&65280)>>8;b[o+2]=f&255;b[o+3]=255}break}};
|
39
|
+
a.render=function(){if(!this.scene.isEmpty()){var b=this.scene.aabb;this.transformMatrix.identity();this.transformMatrix.translate(-(b.minX+b.maxX)/2,-(b.minY+b.maxY)/2,-(b.minZ+b.maxZ)/2);this.transformMatrix.multiply(this.rotMatrix);this.transformMatrix.scale(this.zoomFactor,-this.zoomFactor,this.zoomFactor);this.transformMatrix.translate(this.frameWidth/2,this.frameHeight/2,0);b=this.sortScene(this.transformMatrix);for(var c=0;c<b.length;c++){var d=b[c];if(!d.isTrivial()){JSC3D.Math3D.transformVectors(this.transformMatrix,
|
40
|
+
d.vertexBuffer,d.transformedVertexBuffer);if(d.visible)switch(this.renderMode){case "point":this.renderPoint(d);break;case "wireframe":this.renderWireframe(d);break;case "flat":this.renderSolidFlat(d);break;case "smooth":this.renderSolidSmooth(d);break;case "texture":d.hasTexture()?this.renderSolidTexture(d):this.renderSolidFlat(d);break;case "textureflat":d.hasTexture()?this.renderTextureFlat(d):this.renderSolidFlat(d);break;case "texturesmooth":if(d.isEnvironmentCast&&this.sphereMap!=null&&this.sphereMap.hasData())this.renderSolidSphereMapped(d);
|
41
|
+
else d.hasTexture()?this.renderTextureSmooth(d):this.renderSolidSmooth(d);break;default:this.renderSolidFlat(d);break}}}}};
|
42
|
+
a.sortScene=function(b){for(var c=[],d=this.scene.getChildren(),e=0;e<d.length;e++){var f=d[e];if(!f.isTrivial()){c.push(f);var g=f.aabb.center();JSC3D.Math3D.transformVectors(b,g,g);f.sortKey={depth:g[2],isTransparnt:(f.material?f.material:this.defaultMaterial).transparency>0||(f.hasTexture()?f.texture.hasTransparency:false)}}}c.sort(function(h,i){if(!h.sortKey.isTransparnt&&i.sortKey.isTransparnt)return-1;if(h.sortKey.isTransparnt&&!i.sortKey.isTransparnt)return 1;if(h.sortKey.isTransparnt)return h.sortKey.depth-
|
43
|
+
i.sortKey.depth;return i.sortKey.depth-h.sortKey.depth});return c};
|
44
|
+
a.renderPoint=function(b){var c=this.frameWidth,d=c-1,e=this.frameHeight-1,f=b.transformedVertexBuffer,g=b.transformedVertexNormalZBuffer,h=this.colorBuffer,i=this.zBuffer,m=this.selectionBuffer,o=f.length/3,r=b.internalId,j=b.material?b.material.diffuseColor:this.defaultMaterial.diffuseColor;if(!g||g.length<o){b.transformedVertexNormalZBuffer=new Array(o);g=b.transformedVertexNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.vertexNormalBuffer,g);for(var B=0,k=0;B<o;B++,k+=3){var M=g[B];
|
45
|
+
if(b.isDoubleSided)M=M>0?M:-M;if(M>0){var v=~~(f[k]+0.5),y=~~(f[k+1]+0.5);M=f[k+2];if(v>=0&&v<d&&y>=0&&y<e){v=y*c+v;if(M>i[v]){i[v]=M;h[v]=j;m[v]=r}v++;if(M>i[v]){i[v]=M;h[v]=j;m[v]=r}v+=d;if(M>i[v]){i[v]=M;h[v]=j;m[v]=r}v++;if(M>i[v]){i[v]=M;h[v]=j;m[v]=r}}}}};
|
46
|
+
a.renderWireframe=function(b){var c=this.frameWidth,d=c-1,e=this.frameHeight-1,f=b.indexBuffer,g=b.transformedVertexBuffer,h=b.transformedFaceNormalZBuffer,i=this.colorBuffer,m=this.zBuffer,o=this.selectionBuffer,r=b.faceCount,j=b.internalId,B=b.material?b.material.diffuseColor:this.defaultMaterial.diffuseColor;if(!h||h.length<r){b.transformedFaceNormalZBuffer=new Array(r);h=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,h);for(var k=0,M=0;k<r;){var v=
|
47
|
+
h[k++];if(b.isDoubleSided)v=v>0?v:-v;if(v<0){do;while(f[M++]!=-1)}else{var y,D;y=f[M++]*3;D=f[M++]*3;v=y;for(var I=false;!I;){var z=~~(g[y]+0.5),w=~~(g[y+1]+0.5),s=g[y+2],u=~~(g[D]+0.5),n=~~(g[D+1]+0.5),q=g[D+2],A=u-z,p=n-w,E=q-s,l,N,x;if(Math.abs(A)>Math.abs(p)){l=A;N=A>0?1:-1;x=A!=0?N*p/A:0;A=A!=0?N*E/A:0}else{l=p;x=p>0?1:-1;N=p!=0?x*A/p:0;A=p!=0?x*E/p:0}z=z;w=w;s=s;if(l<0){z=u;w=n;s=q;l=-l;N=-N;x=-x;A=-A}for(u=0;u<l;u++){if(z>=0&&z<d&&w>=0&&w<e){n=~~w*c+~~z;if(s>m[n]){m[n]=s;i[n]=B;o[n]=j}}z+=
|
48
|
+
N;w+=x;s+=A}if(D==v)I=true;else{y=D;D=f[M]!=-1?f[M++]*3:v}}M++}}};
|
49
|
+
a.renderSolidFlat=function(b){var c=this.frameWidth,d=this.frameHeight,e=b.indexBuffer,f=b.transformedVertexBuffer,g=b.transformedFaceNormalZBuffer,h=this.colorBuffer,i=this.zBuffer,m=this.selectionBuffer,o=b.faceCount,r=b.internalId,j=b.material?b.material:this.defaultMaterial,B=j.getPalette(),k=j.transparency==0,M=j.transparency*255,v=255-M;if(j.transparency!=1){if(!g||g.length<o){b.transformedFaceNormalZBuffer=new Array(o);g=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,
|
50
|
+
g);j=new Array(3);for(var y=new Array(3),D=new Array(3),I=0,z=0;I<o;){var w=g[I++];if(b.isDoubleSided)w=w>0?w:-w;if(w<0){do;while(e[z++]!=-1)}else{w=B[~~(w*255)];var s,u,n;s=e[z++]*3;u=e[z++]*3;do{n=e[z++]*3;j[0]=~~(f[s]+0.5);y[0]=~~(f[s+1]+0.5);D[0]=f[s+2];j[1]=~~(f[u]+0.5);y[1]=~~(f[u+1]+0.5);D[1]=f[u+2];j[2]=~~(f[n]+0.5);y[2]=~~(f[n+1]+0.5);D[2]=f[n+2];u=y[0]<y[1]?0:1;u=y[u]<y[2]?u:2;var q=y[0]>y[1]?0:1;q=y[q]>y[2]?q:2;var A=3-q-u;if(u!=q){var p=j[q],E=D[q],l=y[q]-y[u];l=l!=0?l:1;var N=(j[q]-j[u])/
|
51
|
+
l;l=(D[q]-D[u])/l;var x=j[q],t=D[q],C=y[q]-y[A];C=C!=0?C:1;var J=(j[q]-j[A])/C;C=(D[q]-D[A])/C;var R=j[A],O=D[A],F=y[A]-y[u];F=F!=0?F:1;var ha=(j[A]-j[u])/F;F=(D[A]-D[u])/F;var X=y[q]*c;for(q=y[q];q>y[u];q--){if(q>=0&&q<d){var $=~~p,G=E,aa,oa;if(q>y[A]){aa=~~x;oa=t}else{aa=~~R;oa=O}if($>aa){var ca;ca=$;$=aa;aa=ca;ca=G;G=oa;oa=ca}if($<0)$=0;if(aa>=c)aa=c-1;oa=$!=aa?(oa-G)/(aa-$):1;ca=X+$;if(k){$=$;for(G=G;$<=aa;$++,G+=oa){if(G>i[ca]){i[ca]=G;h[ca]=w;m[ca]=r}ca++}}else{$=$;for(G=G;$<aa;$++,G+=oa){if(G>
|
52
|
+
i[ca]){var ma=h[ca];h[ca]=(ma&16711680)*M+(w&16711680)*v>>8&16711680|(ma&65280)*M+(w&65280)*v>>8&65280|(ma&255)*M+(w&255)*v>>8&255;m[ca]=r}ca++}}}p-=N;E-=l;if(q>y[A]){x-=J;t-=C}else{R-=ha;O-=F}X-=c}}u=n}while(e[z]!=-1);z++}}}};
|
53
|
+
a.renderSolidSmooth=function(b){var c=this.frameWidth,d=this.frameHeight,e=b.indexBuffer,f=b.transformedVertexBuffer,g=b.transformedVertexNormalZBuffer,h=b.transformedFaceNormalZBuffer,i=this.colorBuffer,m=this.zBuffer,o=this.selectionBuffer,r=b.faceCount,j=f.length/3,B=b.internalId,k=b.material?b.material:this.defaultMaterial,M=k.getPalette(),v=k.transparency==0,y=k.transparency*255,D=255-y;if(k.transparency!=1){if(!g||g.length<j){b.transformedVertexNormalZBuffer=new Array(j);g=b.transformedVertexNormalZBuffer}if(!h||
|
54
|
+
h.length<r){b.transformedFaceNormalZBuffer=new Array(r);h=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.vertexNormalBuffer,g);JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,h);b=b.isDoubleSided;j=new Array(3);k=new Array(3);for(var I=new Array(3),z=new Array(3),w=0,s=0;w<r;){var u=h[w++];if(b)u=u>0?u:-u;if(u<0){do;while(e[s++]!=-1)}else{var n,q,A,p,E;u=e[s++];A=u*3;n=e[s++];p=n*3;do{q=e[s++];E=q*3;j[0]=~~(f[A]+0.5);k[0]=~~(f[A+1]+0.5);I[0]=f[A+2];
|
55
|
+
j[1]=~~(f[p]+0.5);k[1]=~~(f[p+1]+0.5);I[1]=f[p+2];j[2]=~~(f[E]+0.5);k[2]=~~(f[E+1]+0.5);I[2]=f[E+2];z[0]=g[u];z[1]=g[n];z[2]=g[q];if(b){if(z[0]<0)z[0]=-z[0];if(z[1]<0)z[1]=-z[1];if(z[2]<0)z[2]=-z[2]}n=k[0]<k[1]?0:1;n=k[n]<k[2]?n:2;var l=k[0]>k[1]?0:1;l=k[l]>k[2]?l:2;p=3-l-n;if(n!=l){var N=j[l],x=I[l],t=z[l]*255,C=k[l]-k[n];C=C!=0?C:1;var J=(j[l]-j[n])/C,R=(I[l]-I[n])/C;C=(z[l]-z[n])*255/C;var O=j[l],F=I[l],ha=z[l]*255,X=k[l]-k[p];X=X!=0?X:1;var $=(j[l]-j[p])/X,G=(I[l]-I[p])/X;X=(z[l]-z[p])*255/X;
|
56
|
+
var aa=j[p],oa=I[p],ca=z[p]*255,ma=k[p]-k[n];ma=ma!=0?ma:1;var ra=(j[p]-j[n])/ma,xa=(I[p]-I[n])/ma;ma=(z[p]-z[n])*255/ma;var ta=k[l]*c;for(l=k[l];l>k[n];l--){if(l>=0&&l<d){var da=~~N,ea=x,ka=t,na,ua,sa;if(l>k[p]){na=~~O;ua=F;sa=ha}else{na=~~aa;ua=oa;sa=ca}if(da>na){var Y;Y=da;da=na;na=Y;Y=ea;ea=ua;ua=Y;Y=ka;ka=sa;sa=Y}ua=da!=na?(ua-ea)/(na-da):1;sa=da!=na?(sa-ka)/(na-da):1;if(da<0){ea-=da*ua;ka-=da*sa;da=0}if(na>=c)na=c-1;Y=ta+da;if(v){da=da;ea=ea;for(ka=ka;da<=na;da++,ea+=ua,ka+=sa){if(ea>m[Y]){m[Y]=
|
57
|
+
ea;i[Y]=M[ka>0?~~ka:0];o[Y]=B}Y++}}else{da=da;ea=ea;for(ka=ka;da<na;da++,ea+=ua,ka+=sa){if(ea>m[Y]){var pa=M[ka>0?~~ka:0],za=i[Y];i[Y]=(za&16711680)*y+(pa&16711680)*D>>8&16711680|(za&65280)*y+(pa&65280)*D>>8&65280|(za&255)*y+(pa&255)*D>>8&255;o[Y]=B}Y++}}}N-=J;x-=R;t-=C;if(l>k[p]){O-=$;F-=G;ha-=X}else{aa-=ra;oa-=xa;ca-=ma}ta-=c}}p=E;n=q}while(e[s]!=-1);s++}}}};
|
58
|
+
a.renderSolidTexture=function(b){var c=this.frameWidth,d=this.frameHeight,e=b.indexBuffer,f=b.transformedVertexBuffer,g=b.transformedFaceNormalZBuffer,h=this.colorBuffer,i=this.zBuffer,m=this.selectionBuffer,o=b.faceCount,r=b.internalId,j=b.texture,B=!j.hasTransparency,k=b.texCoordBuffer,M=b.texCoordIndexBuffer,v=j.data,y=j.width,D=y-1,I=j.hasMipmap()?j.mipmaps:null,z=I?j.mipentries:null;if(!g||g.length<o){b.transformedFaceNormalZBuffer=new Array(o);g=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,
|
59
|
+
b.faceNormalBuffer,g);for(var w=new Array(3),s=new Array(3),u=new Array(3),n=new Array(3),q=new Array(3),A=0,p=0;A<o;){var E=g[A++];if(b.isDoubleSided)E=E>0?E:-E;if(E<0){do;while(e[p++]!=-1)}else{var l,N,x,t,C;E=e[p]*3;x=M[p]*2;p++;l=e[p]*3;t=M[p]*2;p++;if(I){N=e[p]*3;C=M[p]*2;y=j.width;w[0]=f[E];s[0]=f[E+1];w[1]=f[l];s[1]=f[l+1];w[2]=f[N];s[2]=f[N+1];n[0]=k[x]*y;q[0]=k[x+1]*y;n[1]=k[t]*y;q[1]=k[t+1]*y;n[2]=k[C]*y;q[2]=k[C+1]*y;v=(w[1]-w[0])*(s[2]-s[0])-(s[1]-s[0])*(w[2]-w[0]);if(v<0)v=-v;v+=1;D=
|
60
|
+
(n[1]-n[0])*(q[2]-q[0])-(q[1]-q[0])*(n[2]-n[0]);if(D<0)D=-D;v=D/v;D=0;if(v<z[1])D=0;else if(v>=z[z.length-1]){D=z.length-1;y=1}else for(;v>=z[D+1];){D++;y/=2}v=I[D];D=y-1}do{N=e[p]*3;C=M[p]*2;p++;w[0]=~~(f[E]+0.5);s[0]=~~(f[E+1]+0.5);u[0]=f[E+2];w[1]=~~(f[l]+0.5);s[1]=~~(f[l+1]+0.5);u[1]=f[l+2];w[2]=~~(f[N]+0.5);s[2]=~~(f[N+1]+0.5);u[2]=f[N+2];n[0]=k[x]*y;q[0]=k[x+1]*y;n[1]=k[t]*y;q[1]=k[t+1]*y;n[2]=k[C]*y;q[2]=k[C+1]*y;l=s[0]<s[1]?0:1;l=s[l]<s[2]?l:2;var J=s[0]>s[1]?0:1;J=s[J]>s[2]?J:2;t=3-J-l;if(l!=
|
61
|
+
J){var R=w[J],O=u[J],F=n[J],ha=q[J],X=s[J]-s[l];X=X!=0?X:1;var $=(w[J]-w[l])/X,G=(u[J]-u[l])/X,aa=(n[J]-n[l])/X;X=(q[J]-q[l])/X;var oa=w[J],ca=u[J],ma=n[J],ra=q[J],xa=s[J]-s[t];xa=xa!=0?xa:1;var ta=(w[J]-w[t])/xa,da=(u[J]-u[t])/xa,ea=(n[J]-n[t])/xa;xa=(q[J]-q[t])/xa;var ka=w[t],na=u[t],ua=n[t],sa=q[t],Y=s[t]-s[l];Y=Y!=0?Y:1;var pa=(w[t]-w[l])/Y,za=(u[t]-u[l])/Y,la=(n[t]-n[l])/Y;Y=(q[t]-q[l])/Y;var Ea=s[J]*c;for(J=s[J];J>s[l];J--){if(J>=0&&J<d){var fa=~~R,va=O,wa=F,Q=ha,H,U,K,S;if(J>s[t]){H=~~oa;U=
|
62
|
+
ca;K=ma;S=ra}else{H=~~ka;U=na;K=ua;S=sa}if(fa>H){var P;P=fa;fa=H;H=P;P=va;va=U;U=P;P=wa;wa=K;K=P;P=Q;Q=S;S=P}U=fa!=H?(U-va)/(H-fa):1;K=fa!=H?(K-wa)/(H-fa):1;S=fa!=H?(S-Q)/(H-fa):1;if(fa<0){va-=fa*U;wa-=fa*K;Q-=fa*S;fa=0}if(H>=c)H=c-1;P=Ea+fa;if(B){fa=fa;va=va;wa=wa;for(Q=Q;fa<=H;fa++,va+=U,wa+=K,Q+=S){if(va>i[P]){i[P]=va;h[P]=v[(Q&D)*y+(wa&D)];m[P]=r}P++}}else{fa=fa;va=va;wa=wa;for(Q=Q;fa<H;fa++,va+=U,wa+=K,Q+=S){if(va>i[P]){var Z=v[(Q&D)*y+(wa&D)],ja=h[P],V=Z>>24&255,L=255-V;h[P]=(ja&16711680)*L+
|
63
|
+
(Z&16711680)*V>>8&16711680|(ja&65280)*L+(Z&65280)*V>>8&65280|(ja&255)*L+(Z&255)*V>>8&255;m[P]=r}P++}}}R-=$;O-=G;F-=aa;ha-=X;if(J>s[t]){oa-=ta;ca-=da;ma-=ea;ra-=xa}else{ka-=pa;na-=za;ua-=la;sa-=Y}Ea-=c}}l=N;t=C}while(e[p]!=-1);p++}}};
|
64
|
+
a.renderTextureFlat=function(b){var c=this.frameWidth,d=this.frameHeight,e=b.indexBuffer,f=b.transformedVertexBuffer,g=b.transformedFaceNormalZBuffer,h=this.colorBuffer,i=this.zBuffer,m=this.selectionBuffer,o=b.faceCount,r=b.internalId,j=b.material?b.material:this.defaultMaterial,B=j.getPalette(),k=b.texture,M=j.transparency==0&&!k.hasTransparency,v=~~((1-j.transparency)*255),y=b.texCoordBuffer,D=b.texCoordIndexBuffer,I=k.data,z=k.width,w=z-1,s=k.hasMipmap()?k.mipmaps:null,u=s?k.mipentries:null;if(j.transparency!=
|
65
|
+
1){if(!g||g.length<o){b.transformedFaceNormalZBuffer=new Array(o);g=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,g);j=new Array(3);for(var n=new Array(3),q=new Array(3),A=new Array(3),p=new Array(3),E=0,l=0;E<o;){var N=g[E++];if(b.isDoubleSided)N=N>0?N:-N;if(N<0){do;while(e[l++]!=-1)}else{N=B[~~(N*255)];var x,t,C,J,R,O;x=e[l]*3;J=D[l]*2;l++;t=e[l]*3;R=D[l]*2;l++;if(s){C=e[l]*3;O=D[l]*2;z=k.width;j[0]=f[x];n[0]=f[x+1];j[1]=f[t];n[1]=f[t+1];j[2]=f[C];
|
66
|
+
n[2]=f[C+1];A[0]=y[J]*z;p[0]=y[J+1]*z;A[1]=y[R]*z;p[1]=y[R+1]*z;A[2]=y[O]*z;p[2]=y[O+1]*z;I=(j[1]-j[0])*(n[2]-n[0])-(n[1]-n[0])*(j[2]-j[0]);if(I<0)I=-I;I+=1;w=(A[1]-A[0])*(p[2]-p[0])-(p[1]-p[0])*(A[2]-A[0]);if(w<0)w=-w;I=w/I;w=0;if(I<u[1])w=0;else if(I>=u[u.length-1]){w=u.length-1;z=1}else for(;I>=u[w+1];){w++;z/=2}I=s[w];w=z-1}do{C=e[l]*3;O=D[l]*2;l++;j[0]=~~(f[x]+0.5);n[0]=~~(f[x+1]+0.5);q[0]=f[x+2];j[1]=~~(f[t]+0.5);n[1]=~~(f[t+1]+0.5);q[1]=f[t+2];j[2]=~~(f[C]+0.5);n[2]=~~(f[C+1]+0.5);q[2]=f[C+
|
67
|
+
2];A[0]=y[J]*z;p[0]=y[J+1]*z;A[1]=y[R]*z;p[1]=y[R+1]*z;A[2]=y[O]*z;p[2]=y[O+1]*z;t=n[0]<n[1]?0:1;t=n[t]<n[2]?t:2;var F=n[0]>n[1]?0:1;F=n[F]>n[2]?F:2;R=3-F-t;if(t!=F){var ha=j[F],X=q[F],$=A[F],G=p[F],aa=n[F]-n[t];aa=aa!=0?aa:1;var oa=(j[F]-j[t])/aa,ca=(q[F]-q[t])/aa,ma=(A[F]-A[t])/aa;aa=(p[F]-p[t])/aa;var ra=j[F],xa=q[F],ta=A[F],da=p[F],ea=n[F]-n[R];ea=ea!=0?ea:1;var ka=(j[F]-j[R])/ea,na=(q[F]-q[R])/ea,ua=(A[F]-A[R])/ea;ea=(p[F]-p[R])/ea;var sa=j[R],Y=q[R],pa=A[R],za=p[R],la=n[R]-n[t];la=la!=0?la:
|
68
|
+
1;var Ea=(j[R]-j[t])/la,fa=(q[R]-q[t])/la,va=(A[R]-A[t])/la;la=(p[R]-p[t])/la;var wa=n[F]*c;for(F=n[F];F>n[t];F--){if(F>=0&&F<d){var Q=~~ha,H=X,U=$,K=G,S,P,Z,ja;if(F>n[R]){S=~~ra;P=xa;Z=ta;ja=da}else{S=~~sa;P=Y;Z=pa;ja=za}if(Q>S){var V;V=Q;Q=S;S=V;V=H;H=P;P=V;V=U;U=Z;Z=V;V=K;K=ja;ja=V}P=Q!=S?(P-H)/(S-Q):1;Z=Q!=S?(Z-U)/(S-Q):1;ja=Q!=S?(ja-K)/(S-Q):1;if(Q<0){H-=Q*P;U-=Q*Z;K-=Q*ja;Q=0}if(S>=c)S=c-1;V=wa+Q;if(M){Q=Q;H=H;U=U;for(K=K;Q<=S;Q++,H+=P,U+=Z,K+=ja){if(H>i[V]){i[V]=H;var L=I[(K&w)*z+(U&w)],ba=
|
69
|
+
((N&16711680)>>16)*((L&16711680)>>8),T=((N&65280)>>8)*((L&65280)>>8),W=(N&255)*(L&255)>>8;h[V]=ba&16711680|T&65280|W&255;m[V]=r}V++}}else{Q=Q;H=H;U=U;for(K=K;Q<S;Q++,H+=P,U+=Z,K+=ja){if(H>i[V]){W=I[(K&w)*z+(U&w)];L=h[V];var ga=(W>>24&255)*(v&255)>>8;ba=((N&16711680)>>16)*((W&16711680)>>8);T=((N&65280)>>8)*((W&65280)>>8);W=(N&255)*(W&255)>>8;if(ga>250)i[V]=H;else{var ia=255-ga;ba=ba*ga+(L&16711680)*ia>>8;T=T*ga+(L&65280)*ia>>8;W=W*ga+(L&255)*ia>>8}h[V]=ba&16711680|T&65280|W&255;m[V]=r}V++}}}ha-=oa;
|
70
|
+
X-=ca;$-=ma;G-=aa;if(F>n[R]){ra-=ka;xa-=na;ta-=ua;da-=ea}else{sa-=Ea;Y-=fa;pa-=va;za-=la}wa-=c}}t=C;R=O}while(e[l]!=-1);l++}}}};
|
71
|
+
a.renderTextureSmooth=function(b){var c=this.frameWidth,d=this.frameHeight,e=b.indexBuffer,f=b.transformedVertexBuffer,g=b.transformedVertexNormalZBuffer,h=b.transformedFaceNormalZBuffer,i=this.colorBuffer,m=this.zBuffer,o=this.selectionBuffer,r=b.faceCount,j=b.internalId,B=f.length/3,k=b.material?b.material:this.defaultMaterial,M=k.getPalette(),v=b.texture,y=k.transparency==0&&!v.hasTransparency,D=~~((1-k.transparency)*255),I=b.texCoordBuffer,z=b.texCoordIndexBuffer,w=v.data,s=v.width,u=s-1,n=v.hasMipmap()?
|
72
|
+
v.mipmaps:null,q=n?v.mipentries:null;if(k.transparency!=1){if(!g||g.length<B){b.transformedVertexNormalZBuffer=new Array(B);g=b.transformedVertexNormalZBuffer}if(!h||h.length<r){b.transformedFaceNormalZBuffer=new Array(r);h=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.vertexNormalBuffer,g);JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,h);b=b.isDoubleSided;B=new Array(3);k=new Array(3);for(var A=new Array(3),p=new Array(3),E=new Array(3),l=new Array(3),
|
73
|
+
N=0,x=0;N<r;){var t=h[N++];if(b)t=t>0?t:-t;if(t<0){do;while(e[x++]!=-1)}else{var C,J,R,O,F,ha,X,$;t=e[x];R=t*3;ha=z[x]*2;x++;C=e[x];O=C*3;X=z[x]*2;x++;if(n){F=e[x]*3;$=z[x]*2;s=v.width;B[0]=f[R];k[0]=f[R+1];B[1]=f[O];k[1]=f[O+1];B[2]=f[F];k[2]=f[F+1];E[0]=I[ha]*s;l[0]=I[ha+1]*s;E[1]=I[X]*s;l[1]=I[X+1]*s;E[2]=I[$]*s;l[2]=I[$+1]*s;w=(B[1]-B[0])*(k[2]-k[0])-(k[1]-k[0])*(B[2]-B[0]);if(w<0)w=-w;w+=1;u=(E[1]-E[0])*(l[2]-l[0])-(l[1]-l[0])*(E[2]-E[0]);if(u<0)u=-u;w=u/w;u=0;if(w<q[1])u=0;else if(w>=q[q.length-
|
74
|
+
1]){u=q.length-1;s=1}else for(;w>=q[u+1];){u++;s/=2}w=n[u];u=s-1}do{J=e[x];F=J*3;$=z[x]*2;x++;B[0]=~~(f[R]+0.5);k[0]=~~(f[R+1]+0.5);A[0]=f[R+2];B[1]=~~(f[O]+0.5);k[1]=~~(f[O+1]+0.5);A[1]=f[O+2];B[2]=~~(f[F]+0.5);k[2]=~~(f[F+1]+0.5);A[2]=f[F+2];E[0]=I[ha]*s;l[0]=I[ha+1]*s;E[1]=I[X]*s;l[1]=I[X+1]*s;E[2]=I[$]*s;l[2]=I[$+1]*s;p[0]=g[t];p[1]=g[C];p[2]=g[J];if(b){if(p[0]<0)p[0]=-p[0];if(p[1]<0)p[1]=-p[1];if(p[2]<0)p[2]=-p[2]}C=k[0]<k[1]?0:1;C=k[C]<k[2]?C:2;var G=k[0]>k[1]?0:1;G=k[G]>k[2]?G:2;O=3-G-C;if(C!=
|
75
|
+
G){X=B[G];var aa=A[G],oa=E[G],ca=l[G],ma=p[G]*255,ra=k[G]-k[C];ra=ra!=0?ra:1;var xa=(B[G]-B[C])/ra,ta=(A[G]-A[C])/ra,da=(E[G]-E[C])/ra,ea=(l[G]-l[C])/ra;ra=(p[G]-p[C])*255/ra;var ka=B[G],na=A[G],ua=E[G],sa=l[G],Y=p[G]*255,pa=k[G]-k[O];pa=pa!=0?pa:1;var za=(B[G]-B[O])/pa,la=(A[G]-A[O])/pa,Ea=(E[G]-E[O])/pa,fa=(l[G]-l[O])/pa;pa=(p[G]-p[O])*255/pa;var va=B[O],wa=A[O],Q=E[O],H=l[O],U=p[O]*255,K=k[O]-k[C];K=K!=0?K:1;var S=(B[O]-B[C])/K,P=(A[O]-A[C])/K,Z=(E[O]-E[C])/K,ja=(l[O]-l[C])/K;K=(p[O]-p[C])*255/
|
76
|
+
K;var V=k[G]*c;for(G=k[G];G>k[C];G--){if(G>=0&&G<d){var L=~~X,ba=aa,T=oa,W=ca,ga=ma,ia,ya,Aa,Ca,Da;if(G>k[O]){ia=~~ka;ya=na;Aa=ua;Ca=sa;Da=Y}else{ia=~~va;ya=wa;Aa=Q;Ca=H;Da=U}if(L>ia){var qa;qa=L;L=ia;ia=qa;qa=ba;ba=ya;ya=qa;qa=T;T=Aa;Aa=qa;qa=W;W=Ca;Ca=qa;qa=ga;ga=Da;Da=qa}ya=L!=ia?(ya-ba)/(ia-L):1;Aa=L!=ia?(Aa-T)/(ia-L):1;Ca=L!=ia?(Ca-W)/(ia-L):1;Da=L!=ia?(Da-ga)/(ia-L):0;if(L<0){ba-=L*ya;T-=L*Aa;W-=L*Ca;ga-=L*Da;L=0}if(ia>=c)ia=c-1;qa=V+L;if(y){L=L;ba=ba;ga=ga;T=T;for(W=W;L<=ia;L++,ba+=ya,ga+=
|
77
|
+
Da,T+=Aa,W+=Ca){if(ba>m[qa]){m[qa]=ba;var Ba=M[ga>0?~~ga:0],Ga=w[(W&u)*s+(T&u)],Ha=((Ba&16711680)>>16)*((Ga&16711680)>>8),Ia=((Ba&65280)>>8)*((Ga&65280)>>8);Ba=(Ba&255)*(Ga&255)>>8;i[qa]=Ha&16711680|Ia&65280|Ba&255;o[qa]=j}qa++}}else{L=L;ba=ba;ga=ga;T=T;for(W=W;L<ia;L++,ba+=ya,ga+=Da,T+=Aa,W+=Ca){if(ba>m[qa]){Ba=M[ga>0?~~ga:0];var Fa=w[(W&u)*s+(T&u)];Ga=i[qa];var Ja=(Fa>>24&255)*(D&255)>>8;Ha=((Ba&16711680)>>16)*((Fa&16711680)>>8);Ia=((Ba&65280)>>8)*((Fa&65280)>>8);Ba=(Ba&255)*(Fa&255)>>8;if(Ja>250)m[qa]=
|
78
|
+
ba;else{Fa=255-Ja;Ha=Ha*Ja+(Ga&16711680)*Fa>>8;Ia=Ia*Ja+(Ga&65280)*Fa>>8;Ba=Ba*Ja+(Ga&255)*Fa>>8}i[qa]=Ha&16711680|Ia&65280|Ba&255;o[qa]=j}qa++}}}X-=xa;aa-=ta;oa-=da;ca-=ea;ma-=ra;if(G>k[O]){ka-=za;na-=la;ua-=Ea;sa-=fa;Y-=pa}else{va-=S;wa-=P;Q-=Z;H-=ja;U-=K}V-=c}}C=J;O=F;X=$}while(e[x]!=-1);x++}}}};
|
79
|
+
a.renderSolidSphereMapped=function(b){var c=this.frameWidth,d=this.frameHeight,e=b.indexBuffer,f=b.transformedVertexBuffer,g=b.transformedVertexNormalBuffer,h=b.transformedFaceNormalZBuffer,i=this.colorBuffer,m=this.zBuffer,o=this.selectionBuffer,r=b.faceCount,j=f.length/3,B=b.internalId,k=b.material?b.material:this.defaultMaterial,M=k.getPalette(),v=this.sphereMap,y=v.data;v=v.width;var D=v-1,I=k.transparency==0,z=k.transparency*255,w=255-z;if(k.transparency!=1){if(!g||g.length<j*3){b.transformedVertexNormalBuffer=
|
80
|
+
new Array(j*3);g=b.transformedVertexNormalBuffer}if(!h||h.length<r){b.transformedFaceNormalZBuffer=new Array(r);h=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectors(this.rotMatrix,b.vertexNormalBuffer,g);JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,h);b=b.isDoubleSided;j=new Array(3);k=new Array(3);for(var s=new Array(3),u=new Array(3),n=new Array(3),q=new Array(3),A=0,p=0;A<r;){var E=h[A++];if(b)E=E>0?E:-E;if(E<0){do;while(e[p++]!=-1)}else{var l,N;E=e[p++]*3;l=e[p++]*
|
81
|
+
3;do{N=e[p++]*3;j[0]=~~(f[E]+0.5);k[0]=~~(f[E+1]+0.5);s[0]=f[E+2];j[1]=~~(f[l]+0.5);k[1]=~~(f[l+1]+0.5);s[1]=f[l+2];j[2]=~~(f[N]+0.5);k[2]=~~(f[N+1]+0.5);s[2]=f[N+2];u[0]=g[E];n[0]=g[E+1];q[0]=g[E+2];u[1]=g[l];n[1]=g[l+1];q[1]=g[l+2];u[2]=g[N];n[2]=g[N+1];q[2]=g[N+2];if(b){if(q[0]<0)q[0]=-q[0];if(q[1]<0)q[1]=-q[1];if(q[2]<0)q[2]=-q[2]}l=k[0]<k[1]?0:1;l=k[l]<k[2]?l:2;var x=k[0]>k[1]?0:1;x=k[x]>k[2]?x:2;var t=3-x-l;if(l!=x){var C=j[x],J=s[x],R=q[x]*255,O=(u[x]/2+0.5)*v&D,F=(0.5-n[x]/2)*v&D,ha=k[x]-
|
82
|
+
k[l];ha=ha!=0?ha:1;var X=(j[x]-j[l])/ha,$=(s[x]-s[l])/ha,G=(q[x]-q[l])*255/ha,aa=(u[x]-u[l])/2*v/ha;ha=(n[l]-n[x])/2*v/ha;var oa=j[x],ca=s[x],ma=q[x]*255,ra=(u[x]/2+0.5)*v&D,xa=(0.5-n[x]/2)*v&D,ta=k[x]-k[t];ta=ta!=0?ta:1;var da=(j[x]-j[t])/ta,ea=(s[x]-s[t])/ta,ka=(q[x]-q[t])*255/ta,na=(u[x]-u[t])/2*v/ta;ta=(n[t]-n[x])/2*v/ta;var ua=j[t],sa=s[t],Y=q[t]*255,pa=(u[t]/2+0.5)*v&D,za=(0.5-n[t]/2)*v&D,la=k[t]-k[l];la=la!=0?la:1;var Ea=(j[t]-j[l])/la,fa=(s[t]-s[l])/la,va=(q[t]-q[l])*255/la,wa=(u[t]-u[l])/
|
83
|
+
2*v/la;la=(n[l]-n[t])/2*v/la;var Q=k[x]*c;for(x=k[x];x>k[l];x--){if(x>=0&&x<d){var H=~~C,U=J,K=R,S=O,P=F,Z,ja,V,L,ba;if(x>k[t]){Z=~~oa;ja=ca;V=ma;L=ra;ba=xa}else{Z=~~ua;ja=sa;V=Y;L=pa;ba=za}if(H>Z){var T;T=H;H=Z;Z=T;T=U;U=ja;ja=T;T=K;K=V;V=T;T=S;S=L;L=T;T=P;P=ba;ba=T}ja=H!=Z?(ja-U)/(Z-H):1;V=H!=Z?(V-K)/(Z-H):1;L=H!=Z?(L-S)/(Z-H):1;ba=H!=Z?(ba-P)/(Z-H):1;if(H<0){U-=H*ja;K-=H*V;S-=S*L;P-=P*ba;H=0}if(Z>=c)Z=c-1;T=Q+H;if(I){H=H;U=U;K=K;S=S;for(P=P;H<=Z;H++,U+=ja,K+=V,S+=L,P+=ba){if(U>m[T]){m[T]=U;var W=
|
84
|
+
M[K>0?~~K:0],ga=y[(P&D)*v+(S&D)],ia=((W&16711680)>>16)*((ga&16711680)>>8),ya=((W&65280)>>8)*((ga&65280)>>8);W=(W&255)*(ga&255)>>8;i[T]=ia&16711680|ya&65280|W&255;o[T]=B}T++}}else{H=H;U=U;K=K;S=S;for(P=P;H<Z;H++,U+=ja,K+=V,S+=L,P+=ba){if(U>m[T]){W=M[K>0?~~K:0];var Aa=y[(P&D)*v+(S&D)];ga=i[T];ia=((W&16711680)>>16)*((Aa&16711680)>>8);ya=((W&65280)>>8)*((Aa&65280)>>8);W=(W&255)*(Aa&255)>>8;ia=ia*w+(ga&16711680)*z>>8;ya=ya*w+(ga&65280)*z>>8;W=W*w+(ga&255)*z>>8;i[T]=ia&16711680|ya&65280|W&255;o[T]=B}T++}}}C-=
|
85
|
+
X;J-=$;R-=G;O-=aa;F-=ha;if(x>k[t]){oa-=da;ca-=ea;ma-=ka;ra-=na;xa-=ta}else{ua-=Ea;sa-=fa;Y-=va;pa-=wa;za-=la}Q-=c}}l=N}while(e[p]!=-1);p++}}}};a.params=null;a.canvas=null;a.ctx=null;a.canvasData=null;a.bkgColorBuffer=null;a.colorBuffer=null;a.zBuffer=null;a.selectionBuffer=null;a.frameWidth=0;a.frameHeight=0;a.scene=null;a.defaultMaterial=null;a.sphereMap=null;a.isLoaded=false;a.isFailed=false;a.errorMsg="";a.needUpdate=false;a.needRepaint=false;a.initRotX=0;a.initRotY=0;a.initRotZ=0;
|
86
|
+
a.zoomFactor=1;a.rotMatrix=null;a.transformMatrix=null;a.sceneUrl="";a.modelColor=13280792;a.bkgColor1=16777215;a.bkgColor2=16777088;a.renderMode="flat";a.definition="standard";a.isMipMappingOn=false;a.sphereMapUrl="";a.buttonStates=null;a.keyStates=null;a.mouseX=0;a.mouseY=0;a.onmousedown=null;a.onmouseup=null;a.onmousemove=null;a.beforeupdate=null;a.afterupdate=null;a.mouseUsage="default";a.isDefaultInputHandlerEnabled=false;
|
87
|
+
JSC3D.PickInfo=function(){this.canvasY=this.canvasX=0;this.depth=-Infinity;this.mesh=null};JSC3D.Scene=function(b){this.name=b||"";this.aabb=null;this.children=[];this.maxChildId=1};a=JSC3D.Scene.prototype;a.init=function(){if(!this.isEmpty()){for(var b=0;b<this.children.length;b++)this.children[b].init();if(!this.aabb){this.aabb=new JSC3D.AABB;this.calcAABB()}}};a.isEmpty=function(){return this.children.length==0};a.addChild=function(b){b.internalId=this.maxChildId++;this.children.push(b)};
|
88
|
+
a.removeChild=function(b){for(var c=0;c<this.children.length;c++)if(this.children[c]==b){this.children.splice(c,1);break}};a.getChildren=function(){return this.children};
|
89
|
+
a.calcAABB=function(){this.aabb.minX=this.aabb.minY=this.aabb.minZ=Number.MAX_VALUE;this.aabb.maxX=this.aabb.maxY=this.aabb.maxZ=-Number.MAX_VALUE;for(var b=0;b<this.children.length;b++){var c=this.children[b];if(!c.isTrivial()){var d=c.aabb.minX,e=c.aabb.minY,f=c.aabb.minZ,g=c.aabb.maxX,h=c.aabb.maxY;c=c.aabb.maxZ;if(this.aabb.minX>d)this.aabb.minX=d;if(this.aabb.minY>e)this.aabb.minY=e;if(this.aabb.minZ>f)this.aabb.minZ=f;if(this.aabb.maxX<g)this.aabb.maxX=g;if(this.aabb.maxY<h)this.aabb.maxY=h;
|
90
|
+
if(this.aabb.maxZ<c)this.aabb.maxZ=c}}};a.name="";a.aabb=null;a.children=null;a.maxChildId=1;
|
91
|
+
JSC3D.Mesh=function(b,c,d,e,f,g,h,i,m,o){this.name=b||"";this.metadata="";this.visible=c!=undefined?c:true;this.aabb=null;this.vertexBuffer=h||null;this.indexBuffer=i||null;this.faceNormalBuffer=this.vertexNormalBuffer=null;this.material=d||null;this.texture=e||null;this.faceCount=0;this.isDoubleSided=f||false;this.isEnvironmentCast=g||false;this.internalId=0;this.texCoordBuffer=m||null;this.texCoordIndexBuffer=o||null;this.transformedVertexNormalBuffer=this.transformedFaceNormalZBuffer=this.transformedVertexNormalZBuffer=
|
92
|
+
this.transformedVertexBuffer=null};a=JSC3D.Mesh.prototype;a.init=function(){if(!this.isTrivial()){if(this.faceCount==0){this.calcFaceCount();if(this.faceCount==0)return}if(!this.aabb){this.aabb=new JSC3D.AABB;this.calcAABB()}if(!this.faceNormalBuffer){this.faceNormalBuffer=new Array(this.faceCount*3);this.calcFaceNormals()}if(!this.vertexNormalBuffer){this.vertexNormalBuffer=new Array(this.vertexBuffer.length);this.calcVertexNormals()}this.normalizeFaceNormals();this.transformedVertexBuffer=new Array(this.vertexBuffer.length)}};
|
93
|
+
a.isTrivial=function(){return!this.vertexBuffer||this.vertexBuffer.length<3||!this.indexBuffer||this.indexBuffer.length<3};a.setMaterial=function(b){this.material=b};a.setTexture=function(b){this.texture=b};a.hasTexture=function(){return this.texCoordBuffer!=null&&this.texCoordBuffer.length>=2&&this.texCoordIndexBuffer!=null&&this.texCoordIndexBuffer.length>=3&&this.texCoordIndexBuffer.length>=this.indexBuffer.length&&this.texture!=null&&this.texture.hasData()};
|
94
|
+
a.calcFaceCount=function(){this.faceCount=0;var b=this.indexBuffer;b[b.length-1]!=-1&&b.push(-1);for(var c=0;c<b.length;c++)b[c]==-1&&this.faceCount++};
|
95
|
+
a.calcAABB=function(){for(var b=minY=minZ=Number.MAX_VALUE,c=maxY=maxZ=-Number.MAX_VALUE,d=this.vertexBuffer,e=0;e<d.length;e+=3){var f=d[e],g=d[e+1],h=d[e+2];if(f<b)b=f;if(f>c)c=f;if(g<minY)minY=g;if(g>maxY)maxY=g;if(h<minZ)minZ=h;if(h>maxZ)maxZ=h}this.aabb.minX=b;this.aabb.minY=minY;this.aabb.minZ=minZ;this.aabb.maxX=c;this.aabb.maxY=maxY;this.aabb.maxZ=maxZ};
|
96
|
+
a.calcFaceNormals=function(){for(var b=this.vertexBuffer,c=this.indexBuffer,d=this.faceNormalBuffer,e=0,f=0;e<c.length;){var g=c[e++]*3,h=b[g],i=b[g+1],m=b[g+2];g=c[e++]*3;var o=b[g],r=b[g+1],j=b[g+2];g=c[e++]*3;o=o-h;r=r-i;j=j-m;h=b[g]-h;i=b[g+1]-i;m=b[g+2]-m;g=r*m-j*i;m=j*h-o*m;o=o*i-r*h;d[f++]=g;d[f++]=m;d[f++]=o;do;while(c[e++]!=-1)}};
|
97
|
+
a.calcVertexNormals=function(){if(!this.faceNormalBuffer){this.faceNormalBuffer=new Array(this.faceCount*3);this.calcFaceNormals()}for(var b=this.indexBuffer,c=this.faceNormalBuffer,d=this.vertexNormalBuffer,e=0;e<d.length;e++)d[e]=0;for(var f=e=0,g=0;e<b.length;){g=b[e++];if(g==-1)f+=3;else{g=g*3;d[g]+=c[f];d[g+1]+=c[f+1];d[g+2]+=c[f+2]}}for(f=e=0;e<d.length;e+=3,f++){b=d[e];c=d[e+1];g=d[e+2];var h=Math.sqrt(b*b+c*c+g*g);if(h>0){b/=h;c/=h;g/=h}d[e]=b;d[e+1]=c;d[e+2]=g}};
|
98
|
+
a.normalizeFaceNormals=function(){for(var b=this.faceNormalBuffer,c=0;c<b.length;c+=3){var d=b[c],e=b[c+1],f=b[c+2],g=Math.sqrt(d*d+e*e+f*f);if(g>0){d/=g;e/=g;f/=g}b[c]=d;b[c+1]=e;b[c+2]=f}};a.checkValid=function(){};a.name="";a.metadata="";a.visible=false;a.aabb=null;a.vertexBuffer=null;a.indexBuffer=null;a.vertexNormalBuffer=null;a.faceNormalBuffer=null;a.texCoordBuffer=null;a.texCoordIndexBuffer=null;a.material=null;a.texture=null;a.faceCount=0;a.isDoubleSided=false;a.isEnvironmentCast=false;
|
99
|
+
a.internalId=0;a.transformedVertexBuffer=null;a.transformedVertexNormalZBuffer=null;a.transformedFaceNormalZBuffer=null;a.transformedVertexNormalBuffer=null;JSC3D.Material=function(b,c,d,e,f){this.name=b||"";this.ambientColor=c||0;this.diffuseColor=d||8355711;this.transparency=e||0;this.simulateSpecular=f||false;this.palette=null};a=JSC3D.Material.prototype;a.getPalette=function(){if(!this.palette){this.palette=new Array(256);this.generatePalette()}return this.palette};
|
100
|
+
a.generatePalette=function(){var b=(this.ambientColor&16711680)>>16,c=(this.ambientColor&65280)>>8,d=this.ambientColor&255,e=(this.diffuseColor&16711680)>>16,f=(this.diffuseColor&65280)>>8,g=this.diffuseColor&255;if(this.simulateSpecular){for(var h=0;h<204;){var i=b+h*e/204,m=c+h*f/204,o=d+h*g/204;if(i>255)i=255;if(m>255)m=255;if(o>255)o=255;this.palette[h++]=i<<16|m<<8|o}for(;h<256;){i=b+e+(h-204)*(255-e)/82;m=c+f+(h-204)*(255-f)/82;o=d+g+(h-204)*(255-g)/82;if(i>255)i=255;if(m>255)m=255;if(o>255)o=
|
101
|
+
255;this.palette[h++]=i<<16|m<<8|o}}else for(h=0;h<256;){i=b+h*e/256;m=c+h*f/256;o=d+h*g/256;if(i>255)i=255;if(m>255)m=255;if(o>255)o=255;this.palette[h++]=i<<16|m<<8|o}};a.name="";a.ambientColor=0;a.diffuseColor=8355711;a.transparency=0;a.simulateSpecular=false;a.palette=null;JSC3D.Texture=function(b,c){this.name=b||"";this.height=this.width=0;this.mipentries=this.mipmaps=this.data=null;this.hasTransparency=false;this.srcUrl="";this.onready=c&&typeof c=="function"?c:null};a=JSC3D.Texture.prototype;
|
102
|
+
a.createFromUrl=function(b,c){var d=this,e=new Image;e.onload=function(){d.data=null;d.mipmaps=null;d.mipentries=null;d.width=0;d.height=0;d.hasTransparency=false;d.srcUrl="";d.createFromImage(this,c);JSC3D.console&&JSC3D.console.logInfo('Finished loading texture image file "'+this.src+'".')};e.onerror=function(){d.data=null;d.mipmaps=null;d.mipentries=null;d.width=0;d.height=0;d.hasTransparency=false;d.srcUrl="";JSC3D.console&&JSC3D.console.logWarning('Failed to load texture image file "'+this.src+
|
103
|
+
'". This texture will be discarded.')};e.src=b};
|
104
|
+
a.createFromImage=function(b,c){if(!(b.width<=0||b.height<=0)){var d=false,e=JSC3D.Texture.cv;if(!e)try{e=document.createElement("canvas");JSC3D.Texture.cv=e;d=true}catch(f){return}var g=b.width>b.height?b.width:b.height;g=g<=32?32:g<=64?64:g<=128?128:g<=256?256:512;if(e.width!=g||e.height!=g){e.width=e.height=g;d=true}var h;try{var i=e.getContext("2d");d||i.clearRect(0,0,g,g);i.drawImage(b,0,0,g,g);h=i.getImageData(0,0,g,g).data}catch(m){return}d=h.length/4;this.data=new Array(d);for(var o=i=0;i<
|
105
|
+
d;i++,o+=4){e=h[o+3];this.data[i]=e<<24|h[o]<<16|h[o+1]<<8|h[o+2];if(e<255)this.hasTransparency=true}this.height=this.width=g;this.mipmaps=null;c&&this.generateMipmaps();this.srcUrl=b.src;this.onready!=null&&typeof this.onready=="function"&&this.onready()}};a.hasData=function(){return this.data!=null};
|
106
|
+
a.generateMipmaps=function(){if(!(this.width<=1||this.data==null||this.mipmaps!=null)){this.mipmaps=[this.data];this.mipentries=[1];for(var b=1+~~(0.1+Math.log(this.width)*Math.LOG2E),c=this.width>>1,d=1;d<b;d++){for(var e=new Array(c*c),f=this.mipmaps[d-1],g=c<<1,h=0,i=0,m=0;m<c;m++){for(var o=0;o<c;o++){var r=f[h],j=f[h+1],B=f[h+g],k=f[h+g+1];e[i]=(((r&4278190080)>>>2)+((j&4278190080)>>>2)+((B&4278190080)>>>2)+((k&4278190080)>>>2)&4278190080)+((r&16711680)+(j&16711680)+(B&16711680)+(k&16711680)>>
|
107
|
+
2&16711680)+((r&65280)+(j&65280)+(B&65280)+(k&65280)>>2&65280)+((r&255)+(j&255)+(B&255)+(k&255)>>2&255);h+=2;i++}h+=g}this.mipmaps.push(e);this.mipentries.push(Math.pow(4,d));c>>=1}}};a.hasMipmap=function(){return this.mipmaps!=null};a.name="";a.data=null;a.mipmaps=null;a.mipentries=null;a.width=0;a.height=0;a.hasTransparency=false;a.srcUrl="";a.onready=null;JSC3D.Texture.cv=null;JSC3D.AABB=function(){this.minZ=this.maxZ=this.minY=this.maxY=this.minX=this.maxX=0};
|
108
|
+
JSC3D.AABB.prototype.center=function(){return[(this.minX+this.maxX)/2,(this.minY+this.maxY)/2,(this.minZ+this.maxZ)/2]};JSC3D.AABB.prototype.lengthOfDiagonal=function(){var b=this.maxX-this.minX,c=this.maxY-this.minY,d=this.maxZ-this.minZ;return Math.sqrt(b*b+c*c+d*d)};JSC3D.Matrix3x4=function(){this.m00=1;this.m10=this.m03=this.m02=this.m01=0;this.m11=1;this.m21=this.m20=this.m13=this.m12=0;this.m22=1;this.m23=0};a=JSC3D.Matrix3x4.prototype;
|
109
|
+
a.identity=function(){this.m00=1;this.m10=this.m03=this.m02=this.m01=0;this.m11=1;this.m21=this.m20=this.m13=this.m12=0;this.m22=1;this.m23=0};a.scale=function(b,c,d){this.m00*=b;this.m01*=b;this.m02*=b;this.m03*=b;this.m10*=c;this.m11*=c;this.m12*=c;this.m13*=c;this.m20*=d;this.m21*=d;this.m22*=d;this.m23*=d};a.translate=function(b,c,d){this.m03+=b;this.m13+=c;this.m23+=d};
|
110
|
+
a.rotateAboutXAxis=function(b){if(b!=0){b*=Math.PI/180;var c=Math.cos(b);b=Math.sin(b);var d=c*this.m11-b*this.m21,e=c*this.m12-b*this.m22,f=c*this.m13-b*this.m23,g=c*this.m20+b*this.m10,h=c*this.m21+b*this.m11,i=c*this.m22+b*this.m12,m=c*this.m23+b*this.m13;this.m10=c*this.m10-b*this.m20;this.m11=d;this.m12=e;this.m13=f;this.m20=g;this.m21=h;this.m22=i;this.m23=m}};
|
111
|
+
a.rotateAboutYAxis=function(b){if(b!=0){b*=Math.PI/180;var c=Math.cos(b);b=Math.sin(b);var d=c*this.m01+b*this.m21,e=c*this.m02+b*this.m22,f=c*this.m03+b*this.m23,g=c*this.m20-b*this.m00,h=c*this.m21-b*this.m01,i=c*this.m22-b*this.m02,m=c*this.m23-b*this.m03;this.m00=c*this.m00+b*this.m20;this.m01=d;this.m02=e;this.m03=f;this.m20=g;this.m21=h;this.m22=i;this.m23=m}};
|
112
|
+
a.rotateAboutZAxis=function(b){if(b!=0){b*=Math.PI/180;var c=Math.cos(b);b=Math.sin(b);var d=c*this.m10+b*this.m00,e=c*this.m11+b*this.m01,f=c*this.m12+b*this.m02,g=c*this.m13+b*this.m03,h=c*this.m01-b*this.m11,i=c*this.m02-b*this.m12,m=c*this.m03-b*this.m13;this.m00=c*this.m00-b*this.m10;this.m01=h;this.m02=i;this.m03=m;this.m10=d;this.m11=e;this.m12=f;this.m13=g}};
|
113
|
+
a.multiply=function(b){var c=b.m00*this.m01+b.m01*this.m11+b.m02*this.m21,d=b.m00*this.m02+b.m01*this.m12+b.m02*this.m22,e=b.m00*this.m03+b.m01*this.m13+b.m02*this.m23+b.m03,f=b.m10*this.m00+b.m11*this.m10+b.m12*this.m20,g=b.m10*this.m01+b.m11*this.m11+b.m12*this.m21,h=b.m10*this.m02+b.m11*this.m12+b.m12*this.m22,i=b.m10*this.m03+b.m11*this.m13+b.m12*this.m23+b.m13,m=b.m20*this.m00+b.m21*this.m10+b.m22*this.m20,o=b.m20*this.m01+b.m21*this.m11+b.m22*this.m21,r=b.m20*this.m02+b.m21*this.m12+b.m22*this.m22,
|
114
|
+
j=b.m20*this.m03+b.m21*this.m13+b.m22*this.m23+b.m23;this.m00=b.m00*this.m00+b.m01*this.m10+b.m02*this.m20;this.m01=c;this.m02=d;this.m03=e;this.m10=f;this.m11=g;this.m12=h;this.m13=i;this.m20=m;this.m21=o;this.m22=r;this.m23=j};
|
115
|
+
JSC3D.Math3D={transformVectors:function(b,c,d){for(var e=0;e<c.length;e+=3){var f=c[e],g=c[e+1],h=c[e+2];d[e]=b.m00*f+b.m01*g+b.m02*h+b.m03;d[e+1]=b.m10*f+b.m11*g+b.m12*h+b.m13;d[e+2]=b.m20*f+b.m21*g+b.m22*h+b.m23}},transformVectorZs:function(b,c,d){for(var e=c.length/3,f=0,g=0;f<e;){d[f]=b.m20*c[g]+b.m21*c[g+1]+b.m22*c[g+2]+b.m23;f++;g+=3}}};JSC3D.BinaryStream=function(b,c){if(c)throw"JSC3D.BinaryStream constructor failed: Big endian is not supported yet!";this.data=b;this.offset=0};a=JSC3D.BinaryStream.prototype;
|
116
|
+
a.size=function(){return this.data.length};a.tell=function(){return this.offset};a.seek=function(b){if(b<0||b>=this.data.length)return false;this.offset=b;return true};a.reset=function(){this.offset=0};a.skip=function(b){if(this.offset+b>this.data.length)this.offset=this.data.length;else this.offset+=b};a.available=function(){return this.data.length-this.offset};a.eof=function(){return!(this.offset<this.data.length)};a.readUInt8=function(){return this.decodeInt(1,false)};
|
117
|
+
a.readInt8=function(){return this.decodeInt(1,true)};a.readUInt16=function(){return this.decodeInt(2,false)};a.readInt16=function(){return this.decodeInt(2,true)};a.readUInt32=function(){return this.decodeInt(4,false)};a.readInt32=function(){return this.decodeInt(4,true)};a.readFloat32=function(){return this.decodeFloat(4,23)};a.readFloat64=function(){return this.decodeFloat(8,52)};
|
118
|
+
a.readBytes=function(b,c){var d=c;if(this.offset+c>this.data.length)d=this.data.length-this.offset;for(c=0;c<d;c++)b[c]=this.data[this.offset++].charCodeAt(0)&255;return d};a.decodeInt=function(b,c){if(this.offset+b>this.data.length){this.offset=this.data.length;return NaN}for(var d=0,e=1,f=0;f<b;f++){d+=(this.data[this.offset++].charCodeAt(0)&255)*e;e*=256}if(c&&d&Math.pow(2,b*8-1))d-=Math.pow(2,b*8);return d};
|
119
|
+
a.decodeFloat=function(b,c){if(this.offset+b>this.data.length){this.offset=this.data.length;return NaN}var d=b*8-c-1,e=(1<<d)-1,f=e>>1,g=b-1,h=this.data[this.offset+g].charCodeAt(0)&255;g+=-1;var i=-7,m=h&(1<<-i)-1;h>>=-i;for(i+=d;i>0;){m=m*256+(this.data[this.offset+g].charCodeAt(0)&255);g+=-1;i-=8}d=m&(1<<-i)-1;m>>=-i;for(i+=c;i>0;){d=d*256+(this.data[this.offset+g].charCodeAt(0)&255);g+=-1;i-=8}this.offset+=b;switch(m){case 0:m=1-f;break;case e:return d?NaN:(h?-1:1)*Infinity;default:d+=Math.pow(2,
|
120
|
+
c);m-=f;break}return(h?-1:1)*d*Math.pow(2,m-c)};JSC3D.LoaderSelector={registerLoader:function(b,c){if(typeof c=="function")JSC3D.LoaderSelector.loaderTable[b]=c},getLoader:function(b){b=JSC3D.LoaderSelector.loaderTable[b.toLowerCase()];if(!b)return null;var c;try{c=new b}catch(d){c=null}return c},loaderTable:{}};
|
121
|
+
JSC3D.ObjLoader=function(b,c,d,e){this.onload=b&&typeof b=="function"?b:null;this.onerror=c&&typeof c=="function"?c:null;this.onprogress=d&&typeof d=="function"?d:null;this.onresource=e&&typeof e=="function"?e:null;this.requestCount=0};a=JSC3D.ObjLoader.prototype;a.loadFromUrl=function(b){var c="",d=b,e=b.lastIndexOf("/");if(e==-1)e=b.lastIndexOf("\\");if(e!=-1){c=b.substring(0,e+1);d=b.substring(e+1)}this.requestCount=0;this.loadObjFile(c,d)};
|
122
|
+
a.loadObjFile=function(b,c){var d=b+c,e=this;c=new XMLHttpRequest;c.open("GET",d,true);c.onreadystatechange=function(){if(this.readyState==4)if(this.status==200||this.status==0){if(e.onload){e.onprogress&&e.onprogress("Loading obj file ...",1);JSC3D.console&&JSC3D.console.logInfo('Finished loading obj file "'+d+'".');var f=new JSC3D.Scene,g=e.parseObj(f,this.responseText);if(g.length>0)for(var h=0;h<g.length;h++)e.loadMtlFile(f,b,g[h]);--e.requestCount==0&&e.onload(f)}}else{JSC3D.console&&JSC3D.console.logError('Failed to load obj file "'+
|
123
|
+
d+'".');if(e.onerror){e.requestCount--;e.onerror('Failed to load obj file "'+d+'".')}}};if(this.onprogress){this.onprogress("Loading obj file ...",0);c.onprogress=function(f){e.onprogress("Loading obj file ...",f.position/f.totalSize)}}this.requestCount++;c.send()};
|
124
|
+
a.loadMtlFile=function(b,c,d){var e=c+d,f=this,g=new XMLHttpRequest;g.open("GET",e,true);g.onreadystatechange=function(){if(this.readyState==4){if(this.status==200||this.status==0){f.onprogress&&f.onprogress("Loading mtl file ...",1);JSC3D.console&&JSC3D.console.logInfo('Finished loading mtl file "'+e+'".');for(var h=f.parseMtl(this.responseText),i={},m=b.getChildren(),o=0;o<m.length;o++){var r=m[o];if(r.mtl!=null&&r.mtllib!=null&&r.mtllib==d){var j=h[r.mtl];if(j!=null){j.material!=null&&r.setMaterial(j.material);
|
125
|
+
if(j.textureFileName!="")if(i[j.textureFileName])i[j.textureFileName].push(r);else i[j.textureFileName]=[r]}}}for(var B in i)f.setupTexture(i[B],c+B)}else JSC3D.console&&JSC3D.console.logWarning('Failed to load mtl file "'+e+'". A default material will be applied.');--f.requestCount==0&&f.onload(b)}};if(this.onprogress){this.onprogress("Loading mtl file ...",0);g.onprogress=function(h){f.onprogress("Loading mtl file ...",h.position/h.totalSize)}}this.requestCount++;g.send()};
|
126
|
+
a.parseObj=function(b,c){var d={},e=[],f=0,g=null,h="",i="",m=[],o=[];g="obj-"+f++;var r=new JSC3D.Mesh;r.name=g;r.indexBuffer=[];g=d.nomtl=r;var j=c.split("\n");for(c=0;c<j.length;c++){i=j[c].split(/[ \t]+/);if(i.length>0)switch(i[0]){case "v":if(i.length>3)for(var B=1;B<4;B++)m.push(parseFloat(i[B]));break;case "vn":break;case "vt":if(i.length>2){o.push(parseFloat(i[1]));o.push(1-parseFloat(i[2]))}break;case "f":if(i.length>3){for(B=1;B<i.length;B++){var k=i[B].split("/");g.indexBuffer.push(parseInt(k[0])-
|
127
|
+
1);if(k.length>1&&k[1]!=""){if(!g.texCoordIndexBuffer)g.texCoordIndexBuffer=[];g.texCoordIndexBuffer.push(parseInt(k[1])-1)}}g.indexBuffer.push(-1);g.texCoordIndexBuffer&&g.texCoordIndexBuffer.push(-1)}break;case "mtllib":if(i.length>1){h=i[1];e.push(h)}else h="";break;case "usemtl":if(i.length>1&&i[1]!=""&&h!=""){i=i[1];B=h+"-"+i;g=d[B];if(!g){g=new JSC3D.Mesh;g.name="obj-"+f++;g.indexBuffer=[];g.mtllib=h;g.mtl=i;d[B]=g}g=g}else g=r;break;case "#":default:break}}f=m.length>=3?new Array(m.length/
|
128
|
+
3):null;h=o.length>=2?new Array(o.length/2):null;for(var M in d){g=d[M];if(m.length>=3&&g.indexBuffer.length>0){for(c=0;c<f.length;c++)f[c]=-1;g.vertexBuffer=[];for(c=j=r=0;c<g.indexBuffer.length;c++){r=g.indexBuffer[c];if(r!=-1)if(f[r]==-1){i=r*3;g.vertexBuffer.push(m[i]);g.vertexBuffer.push(m[i+1]);g.vertexBuffer.push(m[i+2]);g.indexBuffer[c]=j;f[r]=j;j++}else g.indexBuffer[c]=f[r]}}if(o.length>=2&&g.texCoordIndexBuffer!=null&&g.texCoordIndexBuffer.length>0){for(c=0;c<h.length;c++)h[c]=-1;g.texCoordBuffer=
|
129
|
+
[];for(c=j=r=0;c<g.texCoordIndexBuffer.length;c++){r=g.texCoordIndexBuffer[c];if(r!=-1)if(h[r]==-1){i=r*2;g.texCoordBuffer.push(o[i]);g.texCoordBuffer.push(o[i+1]);g.texCoordIndexBuffer[c]=j;h[r]=j;j++}else g.texCoordIndexBuffer[c]=h[r]}}g.isTrivial()||b.addChild(g)}return e};
|
130
|
+
a.parseMtl=function(b){var c={},d="";b=b.split("\n");for(var e=0;e<b.length;e++){var f=b[e].split(/[ \t]+/);if(f.length>0)switch(f[0]){case "newmtl":d=f[1];f={};f.material=new JSC3D.Material;f.textureFileName="";c[d]=f;break;case "Ka":break;case "Kd":if(f.length==4&&!isNaN(f[1])){var g=parseFloat(f[1])*255&255,h=parseFloat(f[2])*255&255,i=parseFloat(f[3])*255&255;f=c[d];if(f!=null)f.material.diffuseColor=g<<16|h<<8|i}break;case "Ks":break;case "d":if(f.length==2&&!isNaN(f[1])){g=parseFloat(f[1]);
|
131
|
+
f=c[d];if(f!=null)f.material.transparency=1-g}break;case "illum":break;case "map_Kd":if(f.length==2){g=f[1];f=c[d];if(f!=null)f.textureFileName=g}break;case "#":default:break}}return c};a.setupTexture=function(b,c){var d=this,e=new JSC3D.Texture;e.onready=function(){for(var f=0;f<b.length;f++)b[f].setTexture(this);d.onresource&&d.onresource(this)};e.createFromUrl(c)};a.onload=null;a.onerror=null;a.onprogress=null;a.onresource=null;a.requestCount=0;JSC3D.LoaderSelector.registerLoader("obj",JSC3D.ObjLoader);
|
132
|
+
JSC3D.StlLoader=function(b,c,d,e){this.onload=b&&typeof b=="function"?b:null;this.onerror=c&&typeof c=="function"?c:null;this.onprogress=d&&typeof d=="function"?d:null;this.onresource=e&&typeof e=="function"?e:null;this.decimalPrecision=3};a=JSC3D.StlLoader.prototype;
|
133
|
+
a.loadFromUrl=function(b){var c=this,d=new XMLHttpRequest;d.open("GET",b,true);d.overrideMimeType("text/plain; charset=x-user-defined");d.onreadystatechange=function(){if(this.readyState==4)if(this.status==200||this.status==0){JSC3D.console&&JSC3D.console.logInfo('Finished loading STL file "'+b+'".');if(c.onload){c.onprogress&&c.onprogress("Loading STL file ...",1);var e=new JSC3D.Scene;c.parseStl(e,this.responseText);c.onload(e)}}else{JSC3D.console&&JSC3D.console.logError('Failed to load STL file "'+
|
134
|
+
b+'".');c.onerror&&c.onerror('Failed to load STL file "'+b+'".')}};if(this.onprogress){this.onprogress("Loading STL file ...",0);d.onprogress=function(e){c.onprogress("Loading STL file ...",e.position/e.totalSize)}}d.send()};a.setDecimalPrecision=function(b){this.decimalPrecision=b};
|
135
|
+
a.parseStl=function(b,c){var d=new JSC3D.Mesh;d.vertexBuffer=[];d.indexBuffer=[];d.faceNormalBuffer=[];var e=false,f=new JSC3D.BinaryStream(c);f.skip(84);for(var g=0;g<256&&!f.eof();g++)if(f.readUInt8()>127){e=true;break}if(JSC3D.console)JSC3D.console.logInfo("This is recognised as "+(e?"a binary":"an ASCII")+" STL file.");if(e){f.reset();f.skip(80);e=f.readUInt32();c=84+50*e;if(f.size()<c){JSC3D.console&&JSC3D.console.logError("Failed to parse contents of the file. It seems not complete.");return}d.faceCount=
|
136
|
+
e;h={};for(g=0;g<e;g++){d.faceNormalBuffer.push(f.readFloat32());d.faceNormalBuffer.push(f.readFloat32());d.faceNormalBuffer.push(f.readFloat32());for(c=0;c<3;c++){i=f.readFloat32();m=f.readFloat32();o=f.readFloat32();r=i.toFixed(this.decimalPrecision)+"-"+m.toFixed(this.decimalPrecision)+"-"+o.toFixed(this.decimalPrecision);j=h[r];if(j==undefined){j=d.vertexBuffer.length/3;h[r]=j;d.vertexBuffer.push(i);d.vertexBuffer.push(m);d.vertexBuffer.push(o)}d.indexBuffer.push(j)}d.indexBuffer.push(-1);f.skip(2)}}else{f=
|
137
|
+
new RegExp("facet\\s+normal\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+outer\\s+loop\\s+vertex\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+vertex\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+vertex\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+endloop\\s+endfacet",
|
138
|
+
"ig");if(g=c.match(f)){e=g.length;d.faceCount=e;var h={};f.lastIndex=0;f.global=false;for(e=f.exec(c);e!=null;e=f.exec(c)){d.faceNormalBuffer.push(parseFloat(e[1]),parseFloat(e[2]),parseFloat(e[3]));for(g=0;g<3;g++){var i=parseFloat(e[4+g*3]),m=parseFloat(e[5+g*3]),o=parseFloat(e[6+g*3]),r=i.toFixed(this.decimalPrecision)+"-"+m.toFixed(this.decimalPrecision)+"-"+o.toFixed(this.decimalPrecision),j=h[r];if(j===undefined){j=d.vertexBuffer.length/3;h[r]=j;d.vertexBuffer.push(i);d.vertexBuffer.push(m);
|
139
|
+
d.vertexBuffer.push(o)}d.indexBuffer.push(j)}d.indexBuffer.push(-1)}}}d.isTrivial()||b.addChild(d)};a.onload=null;a.onerror=null;a.onprogress=null;a.onresource=null;a.decimalPrecision=3;JSC3D.LoaderSelector.registerLoader("stl",JSC3D.StlLoader);
|
@@ -0,0 +1,133 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2012 Humu humu2009@gmail.com
|
3
|
+
jsc3d is freely distributable under the terms of the MIT license.
|
4
|
+
*/
|
5
|
+
var a,JSC3D=JSC3D||{};
|
6
|
+
JSC3D.Viewer=function(b,c){this.params=c?{SceneUrl:c.SceneUrl||"",InitRotationX:c.InitRotationX||0,InitRotationY:c.InitRotationY||0,InitRotationZ:c.InitRotationZ||0,ModelColor:c.ModelColor||"#caa618",BackgroundColor1:c.BackgroundColor1||"#ffffff",BackgroundColor2:c.BackgroundColor2||"#383840",RenderMode:c.RenderMode||"flat",Definition:c.Definition||"standard",MipMapping:c.MipMapping||"off",SphereMapUrl:c.SphereMapUrl||""}:{SceneUrl:"",InitRotationX:0,InitRotationY:0,InitRotationZ:0,ModelColor:"#caa618",
|
7
|
+
BackgroundColor1:"#ffffff",BackgroundColor2:"#383840",RenderMode:"flat",Definition:"standard",MipMapping:"off",SphereMapUrl:""};this.canvas=b;this.selectionBuffer=this.zBuffer=this.colorBuffer=this.bkgColorBuffer=this.canvasData=this.ctx=null;this.frameWidth=b.width;this.frameHeight=b.height;this.sphereMap=this.defaultMaterial=this.scene=null;this.isFailed=this.isLoaded=false;this.errorMsg="";this.initRotZ=this.initRotY=this.initRotX=0;this.zoomFactor=1;this.rotMatrix=new JSC3D.Matrix3x4;this.transformMatrix=
|
8
|
+
new JSC3D.Matrix3x4;this.sceneUrl="";this.modelColor=13280792;this.bkgColor1=16777215;this.bkgColor2=3684416;this.renderMode="flat";this.definition="standard";this.isMipMappingOn=false;this.sphereMapUrl="";this.buttonStates={};this.keyStates={};this.mouseY=this.mouseX=0;this.afterupdate=this.beforeupdate=this.onmousemove=this.onmouseup=this.onmousedown=null;this.mouseUsage="default";this.isDefaultInputHandlerEnabled=true;var e=this;b.attachEvent("onmousedown",function(f){e.mouseDownHandler(f)});b.attachEvent("onmouseup",
|
9
|
+
function(f){e.mouseUpHandler(f)});b.attachEvent("onmousemove",function(f){e.mouseMoveHandler(f)});document.attachEvent("onkeydown",function(f){e.keyDownHandler(f)});document.attachEvent("onkeyup",function(f){e.keyUpHandler(f)})};a=JSC3D.Viewer.prototype;a.setParameter=function(b,c){this.params[b]=c};
|
10
|
+
a.init=function(){this.sceneUrl=this.params.SceneUrl;this.initRotX=parseFloat(this.params.InitRotationX);this.initRotY=parseFloat(this.params.InitRotationY);this.initRotZ=parseFloat(this.params.InitRotationZ);this.modelColor=parseInt("0x"+this.params.ModelColor.substring(1));this.bkgColor1=parseInt("0x"+this.params.BackgroundColor1.substring(1));this.bkgColor2=parseInt("0x"+this.params.BackgroundColor2.substring(1));this.renderMode=this.params.RenderMode.toLowerCase();this.definition=this.params.Definition.toLowerCase();
|
11
|
+
this.isMipMappingOn=this.params.MipMapping.toLowerCase()=="on";this.sphereMapUrl=this.params.SphereMapUrl;try{this.ctx=this.canvas.getContext("2d");this.canvasData=this.ctx.getImageData(0,0,this.canvas.width,this.canvas.height)}catch(b){this.canvasData=this.ctx=null}if(this.canvas.width<=2||this.canvas.height<=2)this.definition="standard";switch(this.definition){case "low":this.frameWidth=~~((this.canvas.width+1)/2);this.frameHeight=~~((this.canvas.height+1)/2);break;case "high":this.frameWidth=this.canvas.width*
|
12
|
+
2;this.frameHeight=this.canvas.height*2;break;case "standard":default:this.frameWidth=this.canvas.width;this.frameHeight=this.canvas.height;break}this.zoomFactor=1;this.rotMatrix.identity();this.transformMatrix.identity();this.isFailed=this.isLoaded=false;this.errorMsg="";this.scene=null;this.colorBuffer=new Array(this.frameWidth*this.frameHeight);this.zBuffer=new Array(this.frameWidth*this.frameHeight);this.selectionBuffer=new Array(this.frameWidth*this.frameHeight);this.bkgColorBuffer=new Array(this.frameWidth*
|
13
|
+
this.frameHeight);this.generateBackground();this.defaultMaterial=new JSC3D.Material;this.defaultMaterial.ambientColor=0;this.defaultMaterial.diffuseColor=this.modelColor;this.defaultMaterial.transparency=0;this.defaultMaterial.simulateSpecular=true;this.drawBackground();this.loadScene();this.setSphereMapFromUrl(this.sphereMapUrl)};
|
14
|
+
a.update=function(b){if(this.isFailed)this.reportError(this.errorMsg);else{this.beforeupdate!=null&&typeof this.beforeupdate=="function"&&this.beforeupdate();if(this.scene){if(!b&&this.colorBuffer!=null){this.beginScene();this.render();this.endScene()}this.paint()}else this.drawBackground();this.afterupdate!=null&&typeof this.afterupdate=="function"&&this.afterupdate()}};a.rotate=function(b,c,e){this.rotMatrix.rotateAboutXAxis(b);this.rotMatrix.rotateAboutYAxis(c);this.rotMatrix.rotateAboutZAxis(e)};
|
15
|
+
a.setRenderMode=function(b){this.renderMode=this.params.RenderMode=b};
|
16
|
+
a.setDefinition=function(b){if(this.canvas.width<=2||this.canvas.height<=2)b="standard";if(b!=this.definition){this.definition=this.params.Definition=b;b=this.frameWidth;switch(this.definition){case "low":this.frameWidth=~~((this.canvas.width+1)/2);this.frameHeight=~~((this.canvas.height+1)/2);break;case "high":this.frameWidth=this.canvas.width*2;this.frameHeight=this.canvas.height*2;break;case "standard":default:this.frameWidth=this.canvas.width;this.frameHeight=this.canvas.height;break}var c=this.frameWidth*
|
17
|
+
this.frameHeight;if(this.colorBuffer.length<c)this.colorBuffer=new Array(c);if(this.zBuffer.length<c)this.zBuffer=new Array(c);if(this.selectionBuffer.length<c)this.selectionBuffer=new Array(c);if(this.bkgColorBuffer.length<c)this.bkgColorBuffer=new Array(c);this.generateBackground();this.zoomFactor*=this.frameWidth/b}};
|
18
|
+
a.setSphereMapFromUrl=function(b){if(b=="")this.sphereMap=null;else{this.sphereMapUrl=this.params.SphereMapUrl=b;var c=this,e=new JSC3D.Texture;e.onready=function(){c.sphereMap=e;c.update()};e.createFromUrl(this.sphereMapUrl)}};a.enableDefaultInputHandler=function(b){this.isDefaultInputHandlerEnabled=b};a.setMouseUsage=function(b){this.mouseUsage=b};a.replaceSceneFromUrl=function(b){this.sceneUrl=this.params.SceneUrl=b;this.isFailed=this.isLoaded=false;this.loadScene()};
|
19
|
+
a.replaceScene=function(b){this.sceneUrl=this.params.SceneUrl="";this.isFailed=false;this.isLoaded=true;this.errorMsg="";this.setupScene(b)};a.getScene=function(){return this.scene};
|
20
|
+
a.pick=function(b,c){var e=new JSC3D.PickInfo,f=this.canvas.getBoundingClientRect();b=b-f.left;c=c-f.top;f=b;var d=c;if(this.selectionBuffer!=null&&b>=0&&b<this.canvas.width&&c>=0&&c<this.canvas.height){switch(this.definition){case "low":f=~~(f/2);d=~~(d/2);break;case "high":f*=2;d*=2;break;case "standard":default:break}var g=this.selectionBuffer[d*this.frameWidth+f];if(g>0)for(var h=this.scene.getChildren(),l=0;l<h.length;l++)if(h[l].internalId==g){e.mesh=h[l];break}}e.canvasX=b;e.canvasY=c;if(e.mesh)e.depth=
|
21
|
+
this.zBuffer[d*this.frameWidth+f];return e};a.paint=function(){this.canvasData&&this.ctx.putImageData(this.canvasData,0,0)};a.mouseDownHandler=function(b){if(this.onmousedown){var c=this.pick(b.clientX,b.clientY);this.onmousedown(c.canvasX,c.canvasY,b.button,c.depth,c.mesh)}if(this.isDefaultInputHandlerEnabled){this.buttonStates[b.button]=true;this.mouseX=b.clientX;this.mouseY=b.clientY}};
|
22
|
+
a.mouseUpHandler=function(b){if(this.onmouseup){var c=this.pick(b.clientX,b.clientY);this.onmouseup(c.canvasX,c.canvasY,b.button,c.depth,c.mesh)}if(this.isDefaultInputHandlerEnabled){c=this.keyStates[16]==true;if(this.buttonStates[1]==true){if((c&&this.mouseUsage=="default"||this.mouseUsage=="zoom")&&b.clientY!=this.mouseY)this.zoomFactor*=this.mouseY<b.clientY?Math.pow(1.11,~~(1+(b.clientY-this.mouseY)*8/this.canvas.height)):Math.pow(0.9,~~(1+(this.mouseY-b.clientY)*8/this.canvas.height));else if(this.mouseUsage==
|
23
|
+
"default"||this.mouseUsage=="rotate"){c=(b.clientX-this.mouseX)*180/this.canvas.height;this.rotMatrix.rotateAboutXAxis((b.clientY-this.mouseY)*180/this.canvas.width);this.rotMatrix.rotateAboutYAxis(c)}this.mouseX=b.clientX;this.mouseY=b.clientY;this.update()}this.buttonStates[b.button]=false}};a.mouseMoveHandler=function(b){if(this.onmousemove){var c=this.pick(b.clientX,b.clientY);this.onmousemove(c.canvasX,c.canvasY,b.button,c.depth,c.mesh)}};
|
24
|
+
a.keyDownHandler=function(b){this.keyStates[b.keyCode]=true};a.keyUpHandler=function(b){this.keyStates[b.keyCode]=false};
|
25
|
+
a.loadScene=function(){this.scene=null;this.isLoaded=false;if(this.sceneUrl=="")return false;var b=this.sceneUrl.lastIndexOf("/");if(b==-1)b=this.sceneUrl.lastIndexOf("\\");b=this.sceneUrl.substring(b+1);var c=b.lastIndexOf(".");if(c==-1)return false;b=b.substring(c+1);b=JSC3D.LoaderSelector.getLoader(b);if(!b)return false;var e=this;b.onload=function(f){e.setupScene(f)};b.onerror=function(f){e.scene=null;e.isLoaded=false;e.isFailed=true;e.errorMsg=f;e.update()};b.onprogress=function(f,d){e.reportProgress(f,
|
26
|
+
d)};b.onresource=function(f){f instanceof JSC3D.Texture&&e.isMipMappingOn&&!f.hasMipmap()&&f.generateMipmaps();e.update()};b.loadFromUrl(this.sceneUrl);return true};
|
27
|
+
a.setupScene=function(b){b.init();if(!b.isEmpty()){var c=b.aabb.lengthOfDiagonal(),e=this.frameWidth,f=this.frameHeight;this.zoomFactor=c==0?1:(e<f?e:f)/c}this.rotMatrix.identity();this.rotMatrix.rotateAboutXAxis(this.initRotX);this.rotMatrix.rotateAboutYAxis(this.initRotY);this.rotMatrix.rotateAboutZAxis(this.initRotZ);this.scene=b;this.isLoaded=true;this.isFailed=false;this.errorMsg="";this.update()};
|
28
|
+
a.reportProgress=function(b,c){if(this.ctx){this.drawBackground();this.ctx.save();var e=255-((this.bkgColor1&65280)>>8),f=255-(this.bkgColor1&255);e="#"+(255-((this.bkgColor1&16711680)>>16)).toString(16)+e.toString(16)+f.toString(16);this.ctx.strokeStyle=e;this.ctx.fillStyle=e;e=this.canvas.height*0.38;f=this.canvas.width-80;this.ctx.strokeRect(40,e,f,20);this.ctx.fillRect(42,e+2,(f-4)*c,16);this.ctx.font="12px Courier New";this.ctx.textAlign="left";this.ctx.fillText(b,40,e-4,f);this.ctx.restore()}};
|
29
|
+
a.reportError=function(b){if(this.ctx){this.drawBackground();this.ctx.save();var c=this.canvas.height*0.38-4,e=255-((this.bkgColor1&65280)>>8),f=255-(this.bkgColor1&255);this.ctx.fillStyle="#"+(255-((this.bkgColor1&16711680)>>16)).toString(16)+e.toString(16)+f.toString(16);this.ctx.font="16px Courier New";this.ctx.textAlign="left";this.ctx.fillText(b,40,c);this.ctx.restore()}};
|
30
|
+
a.generateBackground=function(){for(var b=this.frameWidth,c=this.frameHeight,e=this.bkgColorBuffer,f=(this.bkgColor1&16711680)>>16,d=(this.bkgColor1&65280)>>8,g=this.bkgColor1&255,h=(this.bkgColor2&16711680)>>16,l=(this.bkgColor2&65280)>>8,m=this.bkgColor2&255,p=0,r=0;r<c;r++)for(var i=f+r*(h-f)/c&255,y=d+r*(l-d)/c&255,j=g+r*(m-g)/c&255,M=0;M<b;M++)e[p++]=i<<16|y<<8|j};a.drawBackground=function(){if(this.canvasData){this.beginScene();this.endScene();this.paint()}};
|
31
|
+
a.beginScene=function(){for(var b=this.colorBuffer,c=this.zBuffer,e=this.selectionBuffer,f=this.bkgColorBuffer,d=this.frameWidth*this.frameHeight,g=-Number.MAX_VALUE,h=0;h<d;h++){b[h]=f[h];c[h]=g;e[h]=0}};
|
32
|
+
a.endScene=function(){var b=this.canvasData.data,c=this.canvas.width,e=this.canvas.height,f=this.colorBuffer,d=this.frameWidth,g=d*this.frameHeight;switch(this.definition){case "low":var h=c>>1,l=d-h,m=0,p=0;for(g=0;g<e;g++){for(var r=0;r<c;r++){d=f[m];b[p]=(d&16711680)>>16;b[p+1]=(d&65280)>>8;b[p+2]=d&255;b[p+3]=255;m+=r&1;p+=4}m+=g&1?l:-h}break;case "high":for(g=p=m=0;g<e;g++){for(r=0;r<c;r++){h=f[m];l=f[m+1];var i=f[m+d],y=f[m+d+1];b[p]=(h&16711680)+(l&16711680)+(i&16711680)+(y&16711680)>>18;b[p+
|
33
|
+
1]=(h&65280)+(l&65280)+(i&65280)+(y&65280)>>10;b[p+2]=(h&255)+(l&255)+(i&255)+(y&255)>>2;b[p+3]=255;m+=2;p+=4}m+=d}break;case "standard":default:for(p=m=0;m<g;m++,p+=4){d=f[m];b[p]=(d&16711680)>>16;b[p+1]=(d&65280)>>8;b[p+2]=d&255;b[p+3]=255}break}};
|
34
|
+
a.render=function(){if(!this.scene.isEmpty()){var b=this.scene.aabb;this.transformMatrix.identity();this.transformMatrix.translate(-(b.minX+b.maxX)/2,-(b.minY+b.maxY)/2,-(b.minZ+b.maxZ)/2);this.transformMatrix.multiply(this.rotMatrix);this.transformMatrix.scale(this.zoomFactor,-this.zoomFactor,this.zoomFactor);this.transformMatrix.translate(this.frameWidth/2,this.frameHeight/2,0);b=this.sortScene(this.transformMatrix);for(var c=0;c<b.length;c++){var e=b[c];if(!e.isTrivial()){JSC3D.Math3D.transformVectors(this.transformMatrix,
|
35
|
+
e.vertexBuffer,e.transformedVertexBuffer);if(e.visible)switch(this.renderMode){case "point":this.renderPoint(e);break;case "wireframe":this.renderWireframe(e);break;case "flat":this.renderSolidFlat(e);break;case "smooth":this.renderSolidSmooth(e);break;case "texture":e.hasTexture()?this.renderSolidTexture(e):this.renderSolidFlat(e);break;case "textureflat":e.hasTexture()?this.renderTextureFlat(e):this.renderSolidFlat(e);break;case "texturesmooth":if(e.isEnvironmentCast&&this.sphereMap!=null&&this.sphereMap.hasData())this.renderSolidSphereMapped(e);
|
36
|
+
else e.hasTexture()?this.renderTextureSmooth(e):this.renderSolidSmooth(e);break;default:this.renderSolidFlat(e);break}}}}};
|
37
|
+
a.sortScene=function(b){for(var c=[],e=this.scene.getChildren(),f=0;f<e.length;f++){var d=e[f];if(!d.isTrivial()){c.push(d);var g=d.aabb.center();JSC3D.Math3D.transformVectors(b,g,g);d.sortKey={depth:g[2],isTransparnt:(d.material?d.material:this.defaultMaterial).transparency>0||(d.hasTexture()?d.texture.hasTransparency:false)}}}c.sort(function(h,l){if(!h.sortKey.isTransparnt&&l.sortKey.isTransparnt)return-1;if(h.sortKey.isTransparnt&&!l.sortKey.isTransparnt)return 1;if(h.sortKey.isTransparnt)return h.sortKey.depth-
|
38
|
+
l.sortKey.depth;return l.sortKey.depth-h.sortKey.depth});return c};
|
39
|
+
a.renderPoint=function(b){var c=this.frameWidth,e=c-1,f=this.frameHeight-1,d=b.transformedVertexBuffer,g=b.transformedVertexNormalZBuffer,h=this.colorBuffer,l=this.zBuffer,m=this.selectionBuffer,p=d.length/3,r=b.internalId,i=b.material?b.material.diffuseColor:this.defaultMaterial.diffuseColor;if(!g||g.length<p){b.transformedVertexNormalZBuffer=new Array(p);g=b.transformedVertexNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.vertexNormalBuffer,g);for(var y=0,j=0;y<p;y++,j+=3){var M=g[y];
|
40
|
+
if(b.isDoubleSided)M=M>0?M:-M;if(M>0){var v=~~(d[j]+0.5),z=~~(d[j+1]+0.5);M=d[j+2];if(v>=0&&v<e&&z>=0&&z<f){v=z*c+v;if(M>l[v]){l[v]=M;h[v]=i;m[v]=r}v++;if(M>l[v]){l[v]=M;h[v]=i;m[v]=r}v+=e;if(M>l[v]){l[v]=M;h[v]=i;m[v]=r}v++;if(M>l[v]){l[v]=M;h[v]=i;m[v]=r}}}}};
|
41
|
+
a.renderWireframe=function(b){var c=this.frameWidth,e=c-1,f=this.frameHeight-1,d=b.indexBuffer,g=b.transformedVertexBuffer,h=b.transformedFaceNormalZBuffer,l=this.colorBuffer,m=this.zBuffer,p=this.selectionBuffer,r=b.faceCount,i=b.internalId,y=b.material?b.material.diffuseColor:this.defaultMaterial.diffuseColor;if(!h||h.length<r){b.transformedFaceNormalZBuffer=new Array(r);h=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,h);for(var j=0,M=0;j<r;){var v=
|
42
|
+
h[j++];if(b.isDoubleSided)v=v>0?v:-v;if(v<0){do;while(d[M++]!=-1)}else{var z,D;z=d[M++]*3;D=d[M++]*3;v=z;for(var I=false;!I;){var A=~~(g[z]+0.5),w=~~(g[z+1]+0.5),s=g[z+2],u=~~(g[D]+0.5),n=~~(g[D+1]+0.5),q=g[D+2],B=u-A,o=n-w,E=q-s,k,N,x;if(Math.abs(B)>Math.abs(o)){k=B;N=B>0?1:-1;x=B!=0?N*o/B:0;B=B!=0?N*E/B:0}else{k=o;x=o>0?1:-1;N=o!=0?x*B/o:0;B=o!=0?x*E/o:0}A=A;w=w;s=s;if(k<0){A=u;w=n;s=q;k=-k;N=-N;x=-x;B=-B}for(u=0;u<k;u++){if(A>=0&&A<e&&w>=0&&w<f){n=~~w*c+~~A;if(s>m[n]){m[n]=s;l[n]=y;p[n]=i}}A+=
|
43
|
+
N;w+=x;s+=B}if(D==v)I=true;else{z=D;D=d[M]!=-1?d[M++]*3:v}}M++}}};
|
44
|
+
a.renderSolidFlat=function(b){var c=this.frameWidth,e=this.frameHeight,f=b.indexBuffer,d=b.transformedVertexBuffer,g=b.transformedFaceNormalZBuffer,h=this.colorBuffer,l=this.zBuffer,m=this.selectionBuffer,p=b.faceCount,r=b.internalId,i=b.material?b.material:this.defaultMaterial,y=i.getPalette(),j=i.transparency==0,M=i.transparency*255,v=255-M;if(i.transparency!=1){if(!g||g.length<p){b.transformedFaceNormalZBuffer=new Array(p);g=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,
|
45
|
+
g);i=new Array(3);for(var z=new Array(3),D=new Array(3),I=0,A=0;I<p;){var w=g[I++];if(b.isDoubleSided)w=w>0?w:-w;if(w<0){do;while(f[A++]!=-1)}else{w=y[~~(w*255)];var s,u,n;s=f[A++]*3;u=f[A++]*3;do{n=f[A++]*3;i[0]=~~(d[s]+0.5);z[0]=~~(d[s+1]+0.5);D[0]=d[s+2];i[1]=~~(d[u]+0.5);z[1]=~~(d[u+1]+0.5);D[1]=d[u+2];i[2]=~~(d[n]+0.5);z[2]=~~(d[n+1]+0.5);D[2]=d[n+2];u=z[0]<z[1]?0:1;u=z[u]<z[2]?u:2;var q=z[0]>z[1]?0:1;q=z[q]>z[2]?q:2;var B=3-q-u;if(u!=q){var o=i[q],E=D[q],k=z[q]-z[u];k=k!=0?k:1;var N=(i[q]-i[u])/
|
46
|
+
k;k=(D[q]-D[u])/k;var x=i[q],t=D[q],C=z[q]-z[B];C=C!=0?C:1;var J=(i[q]-i[B])/C;C=(D[q]-D[B])/C;var R=i[B],O=D[B],F=z[B]-z[u];F=F!=0?F:1;var ha=(i[B]-i[u])/F;F=(D[B]-D[u])/F;var X=z[q]*c;for(q=z[q];q>z[u];q--){if(q>=0&&q<e){var $=~~o,G=E,aa,oa;if(q>z[B]){aa=~~x;oa=t}else{aa=~~R;oa=O}if($>aa){var ca;ca=$;$=aa;aa=ca;ca=G;G=oa;oa=ca}if($<0)$=0;if(aa>=c)aa=c-1;oa=$!=aa?(oa-G)/(aa-$):1;ca=X+$;if(j){$=$;for(G=G;$<=aa;$++,G+=oa){if(G>l[ca]){l[ca]=G;h[ca]=w;m[ca]=r}ca++}}else{$=$;for(G=G;$<aa;$++,G+=oa){if(G>
|
47
|
+
l[ca]){var ma=h[ca];h[ca]=(ma&16711680)*M+(w&16711680)*v>>8&16711680|(ma&65280)*M+(w&65280)*v>>8&65280|(ma&255)*M+(w&255)*v>>8&255;m[ca]=r}ca++}}}o-=N;E-=k;if(q>z[B]){x-=J;t-=C}else{R-=ha;O-=F}X-=c}}u=n}while(f[A]!=-1);A++}}}};
|
48
|
+
a.renderSolidSmooth=function(b){var c=this.frameWidth,e=this.frameHeight,f=b.indexBuffer,d=b.transformedVertexBuffer,g=b.transformedVertexNormalZBuffer,h=b.transformedFaceNormalZBuffer,l=this.colorBuffer,m=this.zBuffer,p=this.selectionBuffer,r=b.faceCount,i=d.length/3,y=b.internalId,j=b.material?b.material:this.defaultMaterial,M=j.getPalette(),v=j.transparency==0,z=j.transparency*255,D=255-z;if(j.transparency!=1){if(!g||g.length<i){b.transformedVertexNormalZBuffer=new Array(i);g=b.transformedVertexNormalZBuffer}if(!h||
|
49
|
+
h.length<r){b.transformedFaceNormalZBuffer=new Array(r);h=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.vertexNormalBuffer,g);JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,h);b=b.isDoubleSided;i=new Array(3);j=new Array(3);for(var I=new Array(3),A=new Array(3),w=0,s=0;w<r;){var u=h[w++];if(b)u=u>0?u:-u;if(u<0){do;while(f[s++]!=-1)}else{var n,q,B,o,E;u=f[s++];B=u*3;n=f[s++];o=n*3;do{q=f[s++];E=q*3;i[0]=~~(d[B]+0.5);j[0]=~~(d[B+1]+0.5);I[0]=d[B+2];
|
50
|
+
i[1]=~~(d[o]+0.5);j[1]=~~(d[o+1]+0.5);I[1]=d[o+2];i[2]=~~(d[E]+0.5);j[2]=~~(d[E+1]+0.5);I[2]=d[E+2];A[0]=g[u];A[1]=g[n];A[2]=g[q];if(b){if(A[0]<0)A[0]=-A[0];if(A[1]<0)A[1]=-A[1];if(A[2]<0)A[2]=-A[2]}n=j[0]<j[1]?0:1;n=j[n]<j[2]?n:2;var k=j[0]>j[1]?0:1;k=j[k]>j[2]?k:2;o=3-k-n;if(n!=k){var N=i[k],x=I[k],t=A[k]*255,C=j[k]-j[n];C=C!=0?C:1;var J=(i[k]-i[n])/C,R=(I[k]-I[n])/C;C=(A[k]-A[n])*255/C;var O=i[k],F=I[k],ha=A[k]*255,X=j[k]-j[o];X=X!=0?X:1;var $=(i[k]-i[o])/X,G=(I[k]-I[o])/X;X=(A[k]-A[o])*255/X;
|
51
|
+
var aa=i[o],oa=I[o],ca=A[o]*255,ma=j[o]-j[n];ma=ma!=0?ma:1;var ra=(i[o]-i[n])/ma,xa=(I[o]-I[n])/ma;ma=(A[o]-A[n])*255/ma;var ta=j[k]*c;for(k=j[k];k>j[n];k--){if(k>=0&&k<e){var da=~~N,ea=x,ka=t,na,ua,sa;if(k>j[o]){na=~~O;ua=F;sa=ha}else{na=~~aa;ua=oa;sa=ca}if(da>na){var Y;Y=da;da=na;na=Y;Y=ea;ea=ua;ua=Y;Y=ka;ka=sa;sa=Y}ua=da!=na?(ua-ea)/(na-da):1;sa=da!=na?(sa-ka)/(na-da):1;if(da<0){ea-=da*ua;ka-=da*sa;da=0}if(na>=c)na=c-1;Y=ta+da;if(v){da=da;ea=ea;for(ka=ka;da<=na;da++,ea+=ua,ka+=sa){if(ea>m[Y]){m[Y]=
|
52
|
+
ea;l[Y]=M[ka>0?~~ka:0];p[Y]=y}Y++}}else{da=da;ea=ea;for(ka=ka;da<na;da++,ea+=ua,ka+=sa){if(ea>m[Y]){var pa=M[ka>0?~~ka:0],za=l[Y];l[Y]=(za&16711680)*z+(pa&16711680)*D>>8&16711680|(za&65280)*z+(pa&65280)*D>>8&65280|(za&255)*z+(pa&255)*D>>8&255;p[Y]=y}Y++}}}N-=J;x-=R;t-=C;if(k>j[o]){O-=$;F-=G;ha-=X}else{aa-=ra;oa-=xa;ca-=ma}ta-=c}}o=E;n=q}while(f[s]!=-1);s++}}}};
|
53
|
+
a.renderSolidTexture=function(b){var c=this.frameWidth,e=this.frameHeight,f=b.indexBuffer,d=b.transformedVertexBuffer,g=b.transformedFaceNormalZBuffer,h=this.colorBuffer,l=this.zBuffer,m=this.selectionBuffer,p=b.faceCount,r=b.internalId,i=b.texture,y=!i.hasTransparency,j=b.texCoordBuffer,M=b.texCoordIndexBuffer,v=i.data,z=i.width,D=z-1,I=i.hasMipmap()?i.mipmaps:null,A=I?i.mipentries:null;if(!g||g.length<p){b.transformedFaceNormalZBuffer=new Array(p);g=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,
|
54
|
+
b.faceNormalBuffer,g);for(var w=new Array(3),s=new Array(3),u=new Array(3),n=new Array(3),q=new Array(3),B=0,o=0;B<p;){var E=g[B++];if(b.isDoubleSided)E=E>0?E:-E;if(E<0){do;while(f[o++]!=-1)}else{var k,N,x,t,C;E=f[o]*3;x=M[o]*2;o++;k=f[o]*3;t=M[o]*2;o++;if(I){N=f[o]*3;C=M[o]*2;z=i.width;w[0]=d[E];s[0]=d[E+1];w[1]=d[k];s[1]=d[k+1];w[2]=d[N];s[2]=d[N+1];n[0]=j[x]*z;q[0]=j[x+1]*z;n[1]=j[t]*z;q[1]=j[t+1]*z;n[2]=j[C]*z;q[2]=j[C+1]*z;v=(w[1]-w[0])*(s[2]-s[0])-(s[1]-s[0])*(w[2]-w[0]);if(v<0)v=-v;v+=1;D=
|
55
|
+
(n[1]-n[0])*(q[2]-q[0])-(q[1]-q[0])*(n[2]-n[0]);if(D<0)D=-D;v=D/v;D=0;if(v<A[1])D=0;else if(v>=A[A.length-1]){D=A.length-1;z=1}else for(;v>=A[D+1];){D++;z/=2}v=I[D];D=z-1}do{N=f[o]*3;C=M[o]*2;o++;w[0]=~~(d[E]+0.5);s[0]=~~(d[E+1]+0.5);u[0]=d[E+2];w[1]=~~(d[k]+0.5);s[1]=~~(d[k+1]+0.5);u[1]=d[k+2];w[2]=~~(d[N]+0.5);s[2]=~~(d[N+1]+0.5);u[2]=d[N+2];n[0]=j[x]*z;q[0]=j[x+1]*z;n[1]=j[t]*z;q[1]=j[t+1]*z;n[2]=j[C]*z;q[2]=j[C+1]*z;k=s[0]<s[1]?0:1;k=s[k]<s[2]?k:2;var J=s[0]>s[1]?0:1;J=s[J]>s[2]?J:2;t=3-J-k;if(k!=
|
56
|
+
J){var R=w[J],O=u[J],F=n[J],ha=q[J],X=s[J]-s[k];X=X!=0?X:1;var $=(w[J]-w[k])/X,G=(u[J]-u[k])/X,aa=(n[J]-n[k])/X;X=(q[J]-q[k])/X;var oa=w[J],ca=u[J],ma=n[J],ra=q[J],xa=s[J]-s[t];xa=xa!=0?xa:1;var ta=(w[J]-w[t])/xa,da=(u[J]-u[t])/xa,ea=(n[J]-n[t])/xa;xa=(q[J]-q[t])/xa;var ka=w[t],na=u[t],ua=n[t],sa=q[t],Y=s[t]-s[k];Y=Y!=0?Y:1;var pa=(w[t]-w[k])/Y,za=(u[t]-u[k])/Y,la=(n[t]-n[k])/Y;Y=(q[t]-q[k])/Y;var Ea=s[J]*c;for(J=s[J];J>s[k];J--){if(J>=0&&J<e){var fa=~~R,va=O,wa=F,Q=ha,H,U,K,S;if(J>s[t]){H=~~oa;U=
|
57
|
+
ca;K=ma;S=ra}else{H=~~ka;U=na;K=ua;S=sa}if(fa>H){var P;P=fa;fa=H;H=P;P=va;va=U;U=P;P=wa;wa=K;K=P;P=Q;Q=S;S=P}U=fa!=H?(U-va)/(H-fa):1;K=fa!=H?(K-wa)/(H-fa):1;S=fa!=H?(S-Q)/(H-fa):1;if(fa<0){va-=fa*U;wa-=fa*K;Q-=fa*S;fa=0}if(H>=c)H=c-1;P=Ea+fa;if(y){fa=fa;va=va;wa=wa;for(Q=Q;fa<=H;fa++,va+=U,wa+=K,Q+=S){if(va>l[P]){l[P]=va;h[P]=v[(Q&D)*z+(wa&D)];m[P]=r}P++}}else{fa=fa;va=va;wa=wa;for(Q=Q;fa<H;fa++,va+=U,wa+=K,Q+=S){if(va>l[P]){var Z=v[(Q&D)*z+(wa&D)],ja=h[P],V=Z>>24&255,L=255-V;h[P]=(ja&16711680)*L+
|
58
|
+
(Z&16711680)*V>>8&16711680|(ja&65280)*L+(Z&65280)*V>>8&65280|(ja&255)*L+(Z&255)*V>>8&255;m[P]=r}P++}}}R-=$;O-=G;F-=aa;ha-=X;if(J>s[t]){oa-=ta;ca-=da;ma-=ea;ra-=xa}else{ka-=pa;na-=za;ua-=la;sa-=Y}Ea-=c}}k=N;t=C}while(f[o]!=-1);o++}}};
|
59
|
+
a.renderTextureFlat=function(b){var c=this.frameWidth,e=this.frameHeight,f=b.indexBuffer,d=b.transformedVertexBuffer,g=b.transformedFaceNormalZBuffer,h=this.colorBuffer,l=this.zBuffer,m=this.selectionBuffer,p=b.faceCount,r=b.internalId,i=b.material?b.material:this.defaultMaterial,y=i.getPalette(),j=b.texture,M=i.transparency==0&&!j.hasTransparency,v=~~((1-i.transparency)*255),z=b.texCoordBuffer,D=b.texCoordIndexBuffer,I=j.data,A=j.width,w=A-1,s=j.hasMipmap()?j.mipmaps:null,u=s?j.mipentries:null;if(i.transparency!=
|
60
|
+
1){if(!g||g.length<p){b.transformedFaceNormalZBuffer=new Array(p);g=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,g);i=new Array(3);for(var n=new Array(3),q=new Array(3),B=new Array(3),o=new Array(3),E=0,k=0;E<p;){var N=g[E++];if(b.isDoubleSided)N=N>0?N:-N;if(N<0){do;while(f[k++]!=-1)}else{N=y[~~(N*255)];var x,t,C,J,R,O;x=f[k]*3;J=D[k]*2;k++;t=f[k]*3;R=D[k]*2;k++;if(s){C=f[k]*3;O=D[k]*2;A=j.width;i[0]=d[x];n[0]=d[x+1];i[1]=d[t];n[1]=d[t+1];i[2]=d[C];
|
61
|
+
n[2]=d[C+1];B[0]=z[J]*A;o[0]=z[J+1]*A;B[1]=z[R]*A;o[1]=z[R+1]*A;B[2]=z[O]*A;o[2]=z[O+1]*A;I=(i[1]-i[0])*(n[2]-n[0])-(n[1]-n[0])*(i[2]-i[0]);if(I<0)I=-I;I+=1;w=(B[1]-B[0])*(o[2]-o[0])-(o[1]-o[0])*(B[2]-B[0]);if(w<0)w=-w;I=w/I;w=0;if(I<u[1])w=0;else if(I>=u[u.length-1]){w=u.length-1;A=1}else for(;I>=u[w+1];){w++;A/=2}I=s[w];w=A-1}do{C=f[k]*3;O=D[k]*2;k++;i[0]=~~(d[x]+0.5);n[0]=~~(d[x+1]+0.5);q[0]=d[x+2];i[1]=~~(d[t]+0.5);n[1]=~~(d[t+1]+0.5);q[1]=d[t+2];i[2]=~~(d[C]+0.5);n[2]=~~(d[C+1]+0.5);q[2]=d[C+
|
62
|
+
2];B[0]=z[J]*A;o[0]=z[J+1]*A;B[1]=z[R]*A;o[1]=z[R+1]*A;B[2]=z[O]*A;o[2]=z[O+1]*A;t=n[0]<n[1]?0:1;t=n[t]<n[2]?t:2;var F=n[0]>n[1]?0:1;F=n[F]>n[2]?F:2;R=3-F-t;if(t!=F){var ha=i[F],X=q[F],$=B[F],G=o[F],aa=n[F]-n[t];aa=aa!=0?aa:1;var oa=(i[F]-i[t])/aa,ca=(q[F]-q[t])/aa,ma=(B[F]-B[t])/aa;aa=(o[F]-o[t])/aa;var ra=i[F],xa=q[F],ta=B[F],da=o[F],ea=n[F]-n[R];ea=ea!=0?ea:1;var ka=(i[F]-i[R])/ea,na=(q[F]-q[R])/ea,ua=(B[F]-B[R])/ea;ea=(o[F]-o[R])/ea;var sa=i[R],Y=q[R],pa=B[R],za=o[R],la=n[R]-n[t];la=la!=0?la:
|
63
|
+
1;var Ea=(i[R]-i[t])/la,fa=(q[R]-q[t])/la,va=(B[R]-B[t])/la;la=(o[R]-o[t])/la;var wa=n[F]*c;for(F=n[F];F>n[t];F--){if(F>=0&&F<e){var Q=~~ha,H=X,U=$,K=G,S,P,Z,ja;if(F>n[R]){S=~~ra;P=xa;Z=ta;ja=da}else{S=~~sa;P=Y;Z=pa;ja=za}if(Q>S){var V;V=Q;Q=S;S=V;V=H;H=P;P=V;V=U;U=Z;Z=V;V=K;K=ja;ja=V}P=Q!=S?(P-H)/(S-Q):1;Z=Q!=S?(Z-U)/(S-Q):1;ja=Q!=S?(ja-K)/(S-Q):1;if(Q<0){H-=Q*P;U-=Q*Z;K-=Q*ja;Q=0}if(S>=c)S=c-1;V=wa+Q;if(M){Q=Q;H=H;U=U;for(K=K;Q<=S;Q++,H+=P,U+=Z,K+=ja){if(H>l[V]){l[V]=H;var L=I[(K&w)*A+(U&w)],ba=
|
64
|
+
((N&16711680)>>16)*((L&16711680)>>8),T=((N&65280)>>8)*((L&65280)>>8),W=(N&255)*(L&255)>>8;h[V]=ba&16711680|T&65280|W&255;m[V]=r}V++}}else{Q=Q;H=H;U=U;for(K=K;Q<S;Q++,H+=P,U+=Z,K+=ja){if(H>l[V]){W=I[(K&w)*A+(U&w)];L=h[V];var ga=(W>>24&255)*(v&255)>>8;ba=((N&16711680)>>16)*((W&16711680)>>8);T=((N&65280)>>8)*((W&65280)>>8);W=(N&255)*(W&255)>>8;if(ga>250)l[V]=H;else{var ia=255-ga;ba=ba*ga+(L&16711680)*ia>>8;T=T*ga+(L&65280)*ia>>8;W=W*ga+(L&255)*ia>>8}h[V]=ba&16711680|T&65280|W&255;m[V]=r}V++}}}ha-=oa;
|
65
|
+
X-=ca;$-=ma;G-=aa;if(F>n[R]){ra-=ka;xa-=na;ta-=ua;da-=ea}else{sa-=Ea;Y-=fa;pa-=va;za-=la}wa-=c}}t=C;R=O}while(f[k]!=-1);k++}}}};
|
66
|
+
a.renderTextureSmooth=function(b){var c=this.frameWidth,e=this.frameHeight,f=b.indexBuffer,d=b.transformedVertexBuffer,g=b.transformedVertexNormalZBuffer,h=b.transformedFaceNormalZBuffer,l=this.colorBuffer,m=this.zBuffer,p=this.selectionBuffer,r=b.faceCount,i=b.internalId,y=d.length/3,j=b.material?b.material:this.defaultMaterial,M=j.getPalette(),v=b.texture,z=j.transparency==0&&!v.hasTransparency,D=~~((1-j.transparency)*255),I=b.texCoordBuffer,A=b.texCoordIndexBuffer,w=v.data,s=v.width,u=s-1,n=v.hasMipmap()?
|
67
|
+
v.mipmaps:null,q=n?v.mipentries:null;if(j.transparency!=1){if(!g||g.length<y){b.transformedVertexNormalZBuffer=new Array(y);g=b.transformedVertexNormalZBuffer}if(!h||h.length<r){b.transformedFaceNormalZBuffer=new Array(r);h=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.vertexNormalBuffer,g);JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,h);b=b.isDoubleSided;y=new Array(3);j=new Array(3);for(var B=new Array(3),o=new Array(3),E=new Array(3),k=new Array(3),
|
68
|
+
N=0,x=0;N<r;){var t=h[N++];if(b)t=t>0?t:-t;if(t<0){do;while(f[x++]!=-1)}else{var C,J,R,O,F,ha,X,$;t=f[x];R=t*3;ha=A[x]*2;x++;C=f[x];O=C*3;X=A[x]*2;x++;if(n){F=f[x]*3;$=A[x]*2;s=v.width;y[0]=d[R];j[0]=d[R+1];y[1]=d[O];j[1]=d[O+1];y[2]=d[F];j[2]=d[F+1];E[0]=I[ha]*s;k[0]=I[ha+1]*s;E[1]=I[X]*s;k[1]=I[X+1]*s;E[2]=I[$]*s;k[2]=I[$+1]*s;w=(y[1]-y[0])*(j[2]-j[0])-(j[1]-j[0])*(y[2]-y[0]);if(w<0)w=-w;w+=1;u=(E[1]-E[0])*(k[2]-k[0])-(k[1]-k[0])*(E[2]-E[0]);if(u<0)u=-u;w=u/w;u=0;if(w<q[1])u=0;else if(w>=q[q.length-
|
69
|
+
1]){u=q.length-1;s=1}else for(;w>=q[u+1];){u++;s/=2}w=n[u];u=s-1}do{J=f[x];F=J*3;$=A[x]*2;x++;y[0]=~~(d[R]+0.5);j[0]=~~(d[R+1]+0.5);B[0]=d[R+2];y[1]=~~(d[O]+0.5);j[1]=~~(d[O+1]+0.5);B[1]=d[O+2];y[2]=~~(d[F]+0.5);j[2]=~~(d[F+1]+0.5);B[2]=d[F+2];E[0]=I[ha]*s;k[0]=I[ha+1]*s;E[1]=I[X]*s;k[1]=I[X+1]*s;E[2]=I[$]*s;k[2]=I[$+1]*s;o[0]=g[t];o[1]=g[C];o[2]=g[J];if(b){if(o[0]<0)o[0]=-o[0];if(o[1]<0)o[1]=-o[1];if(o[2]<0)o[2]=-o[2]}C=j[0]<j[1]?0:1;C=j[C]<j[2]?C:2;var G=j[0]>j[1]?0:1;G=j[G]>j[2]?G:2;O=3-G-C;if(C!=
|
70
|
+
G){X=y[G];var aa=B[G],oa=E[G],ca=k[G],ma=o[G]*255,ra=j[G]-j[C];ra=ra!=0?ra:1;var xa=(y[G]-y[C])/ra,ta=(B[G]-B[C])/ra,da=(E[G]-E[C])/ra,ea=(k[G]-k[C])/ra;ra=(o[G]-o[C])*255/ra;var ka=y[G],na=B[G],ua=E[G],sa=k[G],Y=o[G]*255,pa=j[G]-j[O];pa=pa!=0?pa:1;var za=(y[G]-y[O])/pa,la=(B[G]-B[O])/pa,Ea=(E[G]-E[O])/pa,fa=(k[G]-k[O])/pa;pa=(o[G]-o[O])*255/pa;var va=y[O],wa=B[O],Q=E[O],H=k[O],U=o[O]*255,K=j[O]-j[C];K=K!=0?K:1;var S=(y[O]-y[C])/K,P=(B[O]-B[C])/K,Z=(E[O]-E[C])/K,ja=(k[O]-k[C])/K;K=(o[O]-o[C])*255/
|
71
|
+
K;var V=j[G]*c;for(G=j[G];G>j[C];G--){if(G>=0&&G<e){var L=~~X,ba=aa,T=oa,W=ca,ga=ma,ia,ya,Aa,Ca,Da;if(G>j[O]){ia=~~ka;ya=na;Aa=ua;Ca=sa;Da=Y}else{ia=~~va;ya=wa;Aa=Q;Ca=H;Da=U}if(L>ia){var qa;qa=L;L=ia;ia=qa;qa=ba;ba=ya;ya=qa;qa=T;T=Aa;Aa=qa;qa=W;W=Ca;Ca=qa;qa=ga;ga=Da;Da=qa}ya=L!=ia?(ya-ba)/(ia-L):1;Aa=L!=ia?(Aa-T)/(ia-L):1;Ca=L!=ia?(Ca-W)/(ia-L):1;Da=L!=ia?(Da-ga)/(ia-L):0;if(L<0){ba-=L*ya;T-=L*Aa;W-=L*Ca;ga-=L*Da;L=0}if(ia>=c)ia=c-1;qa=V+L;if(z){L=L;ba=ba;ga=ga;T=T;for(W=W;L<=ia;L++,ba+=ya,ga+=
|
72
|
+
Da,T+=Aa,W+=Ca){if(ba>m[qa]){m[qa]=ba;var Ba=M[ga>0?~~ga:0],Ga=w[(W&u)*s+(T&u)],Ha=((Ba&16711680)>>16)*((Ga&16711680)>>8),Ia=((Ba&65280)>>8)*((Ga&65280)>>8);Ba=(Ba&255)*(Ga&255)>>8;l[qa]=Ha&16711680|Ia&65280|Ba&255;p[qa]=i}qa++}}else{L=L;ba=ba;ga=ga;T=T;for(W=W;L<ia;L++,ba+=ya,ga+=Da,T+=Aa,W+=Ca){if(ba>m[qa]){Ba=M[ga>0?~~ga:0];var Fa=w[(W&u)*s+(T&u)];Ga=l[qa];var Ja=(Fa>>24&255)*(D&255)>>8;Ha=((Ba&16711680)>>16)*((Fa&16711680)>>8);Ia=((Ba&65280)>>8)*((Fa&65280)>>8);Ba=(Ba&255)*(Fa&255)>>8;if(Ja>250)m[qa]=
|
73
|
+
ba;else{Fa=255-Ja;Ha=Ha*Ja+(Ga&16711680)*Fa>>8;Ia=Ia*Ja+(Ga&65280)*Fa>>8;Ba=Ba*Ja+(Ga&255)*Fa>>8}l[qa]=Ha&16711680|Ia&65280|Ba&255;p[qa]=i}qa++}}}X-=xa;aa-=ta;oa-=da;ca-=ea;ma-=ra;if(G>j[O]){ka-=za;na-=la;ua-=Ea;sa-=fa;Y-=pa}else{va-=S;wa-=P;Q-=Z;H-=ja;U-=K}V-=c}}C=J;O=F;X=$}while(f[x]!=-1);x++}}}};
|
74
|
+
a.renderSolidSphereMapped=function(b){var c=this.frameWidth,e=this.frameHeight,f=b.indexBuffer,d=b.transformedVertexBuffer,g=b.transformedVertexNormalBuffer,h=b.transformedFaceNormalZBuffer,l=this.colorBuffer,m=this.zBuffer,p=this.selectionBuffer,r=b.faceCount,i=d.length/3,y=b.internalId,j=b.material?b.material:this.defaultMaterial,M=j.getPalette(),v=this.sphereMap,z=v.data;v=v.width;var D=v-1,I=j.transparency==0,A=j.transparency*255,w=255-A;if(j.transparency!=1){if(!g||g.length<i*3){b.transformedVertexNormalBuffer=
|
75
|
+
new Array(i*3);g=b.transformedVertexNormalBuffer}if(!h||h.length<r){b.transformedFaceNormalZBuffer=new Array(r);h=b.transformedFaceNormalZBuffer}JSC3D.Math3D.transformVectors(this.rotMatrix,b.vertexNormalBuffer,g);JSC3D.Math3D.transformVectorZs(this.rotMatrix,b.faceNormalBuffer,h);b=b.isDoubleSided;i=new Array(3);j=new Array(3);for(var s=new Array(3),u=new Array(3),n=new Array(3),q=new Array(3),B=0,o=0;B<r;){var E=h[B++];if(b)E=E>0?E:-E;if(E<0){do;while(f[o++]!=-1)}else{var k,N;E=f[o++]*3;k=f[o++]*
|
76
|
+
3;do{N=f[o++]*3;i[0]=~~(d[E]+0.5);j[0]=~~(d[E+1]+0.5);s[0]=d[E+2];i[1]=~~(d[k]+0.5);j[1]=~~(d[k+1]+0.5);s[1]=d[k+2];i[2]=~~(d[N]+0.5);j[2]=~~(d[N+1]+0.5);s[2]=d[N+2];u[0]=g[E];n[0]=g[E+1];q[0]=g[E+2];u[1]=g[k];n[1]=g[k+1];q[1]=g[k+2];u[2]=g[N];n[2]=g[N+1];q[2]=g[N+2];if(b){if(q[0]<0)q[0]=-q[0];if(q[1]<0)q[1]=-q[1];if(q[2]<0)q[2]=-q[2]}k=j[0]<j[1]?0:1;k=j[k]<j[2]?k:2;var x=j[0]>j[1]?0:1;x=j[x]>j[2]?x:2;var t=3-x-k;if(k!=x){var C=i[x],J=s[x],R=q[x]*255,O=(u[x]/2+0.5)*v&D,F=(0.5-n[x]/2)*v&D,ha=j[x]-
|
77
|
+
j[k];ha=ha!=0?ha:1;var X=(i[x]-i[k])/ha,$=(s[x]-s[k])/ha,G=(q[x]-q[k])*255/ha,aa=(u[x]-u[k])/2*v/ha;ha=(n[k]-n[x])/2*v/ha;var oa=i[x],ca=s[x],ma=q[x]*255,ra=(u[x]/2+0.5)*v&D,xa=(0.5-n[x]/2)*v&D,ta=j[x]-j[t];ta=ta!=0?ta:1;var da=(i[x]-i[t])/ta,ea=(s[x]-s[t])/ta,ka=(q[x]-q[t])*255/ta,na=(u[x]-u[t])/2*v/ta;ta=(n[t]-n[x])/2*v/ta;var ua=i[t],sa=s[t],Y=q[t]*255,pa=(u[t]/2+0.5)*v&D,za=(0.5-n[t]/2)*v&D,la=j[t]-j[k];la=la!=0?la:1;var Ea=(i[t]-i[k])/la,fa=(s[t]-s[k])/la,va=(q[t]-q[k])*255/la,wa=(u[t]-u[k])/
|
78
|
+
2*v/la;la=(n[k]-n[t])/2*v/la;var Q=j[x]*c;for(x=j[x];x>j[k];x--){if(x>=0&&x<e){var H=~~C,U=J,K=R,S=O,P=F,Z,ja,V,L,ba;if(x>j[t]){Z=~~oa;ja=ca;V=ma;L=ra;ba=xa}else{Z=~~ua;ja=sa;V=Y;L=pa;ba=za}if(H>Z){var T;T=H;H=Z;Z=T;T=U;U=ja;ja=T;T=K;K=V;V=T;T=S;S=L;L=T;T=P;P=ba;ba=T}ja=H!=Z?(ja-U)/(Z-H):1;V=H!=Z?(V-K)/(Z-H):1;L=H!=Z?(L-S)/(Z-H):1;ba=H!=Z?(ba-P)/(Z-H):1;if(H<0){U-=H*ja;K-=H*V;S-=S*L;P-=P*ba;H=0}if(Z>=c)Z=c-1;T=Q+H;if(I){H=H;U=U;K=K;S=S;for(P=P;H<=Z;H++,U+=ja,K+=V,S+=L,P+=ba){if(U>m[T]){m[T]=U;var W=
|
79
|
+
M[K>0?~~K:0],ga=z[(P&D)*v+(S&D)],ia=((W&16711680)>>16)*((ga&16711680)>>8),ya=((W&65280)>>8)*((ga&65280)>>8);W=(W&255)*(ga&255)>>8;l[T]=ia&16711680|ya&65280|W&255;p[T]=y}T++}}else{H=H;U=U;K=K;S=S;for(P=P;H<Z;H++,U+=ja,K+=V,S+=L,P+=ba){if(U>m[T]){W=M[K>0?~~K:0];var Aa=z[(P&D)*v+(S&D)];ga=l[T];ia=((W&16711680)>>16)*((Aa&16711680)>>8);ya=((W&65280)>>8)*((Aa&65280)>>8);W=(W&255)*(Aa&255)>>8;ia=ia*w+(ga&16711680)*A>>8;ya=ya*w+(ga&65280)*A>>8;W=W*w+(ga&255)*A>>8;l[T]=ia&16711680|ya&65280|W&255;p[T]=y}T++}}}C-=
|
80
|
+
X;J-=$;R-=G;O-=aa;F-=ha;if(x>j[t]){oa-=da;ca-=ea;ma-=ka;ra-=na;xa-=ta}else{ua-=Ea;sa-=fa;Y-=va;pa-=wa;za-=la}Q-=c}}k=N}while(f[o]!=-1);o++}}}};a.params=null;a.canvas=null;a.ctx=null;a.canvasData=null;a.bkgColorBuffer=null;a.colorBuffer=null;a.zBuffer=null;a.selectionBuffer=null;a.frameWidth=0;a.frameHeight=0;a.scene=null;a.defaultMaterial=null;a.sphereMap=null;a.isLoaded=false;a.isFailed=false;a.errorMsg="";a.initRotX=0;a.initRotY=0;a.initRotZ=0;a.zoomFactor=1;a.rotMatrix=null;a.transformMatrix=null;
|
81
|
+
a.sceneUrl="";a.modelColor=13280792;a.bkgColor1=16777215;a.bkgColor2=16777088;a.renderMode="flat";a.definition="standard";a.isMipMappingOn=false;a.sphereMapUrl="";a.buttonStates=null;a.keyStates=null;a.mouseX=0;a.mouseY=0;a.onmousedown=null;a.onmouseup=null;a.onmousemove=null;a.beforeupdate=null;a.afterupdate=null;a.mouseUsage="default";a.isDefaultInputHandlerEnabled=false;JSC3D.PickInfo=function(){this.canvasY=this.canvasX=0;this.depth=-Infinity;this.mesh=null};
|
82
|
+
JSC3D.Scene=function(b){this.name=b||"";this.aabb=null;this.children=[];this.maxChildId=1};a=JSC3D.Scene.prototype;a.init=function(){if(!this.isEmpty()){for(var b=0;b<this.children.length;b++)this.children[b].init();if(!this.aabb){this.aabb=new JSC3D.AABB;this.calcAABB()}}};a.isEmpty=function(){return this.children.length==0};a.addChild=function(b){b.internalId=this.maxChildId++;this.children.push(b)};
|
83
|
+
a.removeChild=function(b){for(var c=0;c<this.children.length;c++)if(this.children[c]==b){this.children.splice(c,1);break}};a.getChildren=function(){return this.children};
|
84
|
+
a.calcAABB=function(){this.aabb.minX=this.aabb.minY=this.aabb.minZ=Number.MAX_VALUE;this.aabb.maxX=this.aabb.maxY=this.aabb.maxZ=-Number.MAX_VALUE;for(var b=0;b<this.children.length;b++){var c=this.children[b];if(!c.isTrivial()){var e=c.aabb.minX,f=c.aabb.minY,d=c.aabb.minZ,g=c.aabb.maxX,h=c.aabb.maxY;c=c.aabb.maxZ;if(this.aabb.minX>e)this.aabb.minX=e;if(this.aabb.minY>f)this.aabb.minY=f;if(this.aabb.minZ>d)this.aabb.minZ=d;if(this.aabb.maxX<g)this.aabb.maxX=g;if(this.aabb.maxY<h)this.aabb.maxY=h;
|
85
|
+
if(this.aabb.maxZ<c)this.aabb.maxZ=c}}};a.name="";a.aabb=null;a.children=null;a.maxChildId=1;
|
86
|
+
JSC3D.Mesh=function(b,c,e,f,d,g,h,l,m,p){this.name=b||"";this.metadata="";this.visible=c!=undefined?c:true;this.aabb=null;this.vertexBuffer=h||null;this.indexBuffer=l||null;this.faceNormalBuffer=this.vertexNormalBuffer=null;this.material=e||null;this.texture=f||null;this.faceCount=0;this.isDoubleSided=d||false;this.isEnvironmentCast=g||false;this.internalId=0;this.texCoordBuffer=m||null;this.texCoordIndexBuffer=p||null;this.transformedVertexNormalBuffer=this.transformedFaceNormalZBuffer=this.transformedVertexNormalZBuffer=
|
87
|
+
this.transformedVertexBuffer=null};a=JSC3D.Mesh.prototype;a.init=function(){if(!this.isTrivial()){if(this.faceCount==0){this.calcFaceCount();if(this.faceCount==0)return}if(!this.aabb){this.aabb=new JSC3D.AABB;this.calcAABB()}if(!this.faceNormalBuffer){this.faceNormalBuffer=new Array(this.faceCount*3);this.calcFaceNormals()}if(!this.vertexNormalBuffer){this.vertexNormalBuffer=new Array(this.vertexBuffer.length);this.calcVertexNormals()}this.normalizeFaceNormals();this.transformedVertexBuffer=new Array(this.vertexBuffer.length)}};
|
88
|
+
a.isTrivial=function(){return!this.vertexBuffer||this.vertexBuffer.length<3||!this.indexBuffer||this.indexBuffer.length<3};a.setMaterial=function(b){this.material=b};a.setTexture=function(b){this.texture=b};a.hasTexture=function(){return this.texCoordBuffer!=null&&this.texCoordBuffer.length>=2&&this.texCoordIndexBuffer!=null&&this.texCoordIndexBuffer.length>=3&&this.texCoordIndexBuffer.length>=this.indexBuffer.length&&this.texture!=null&&this.texture.hasData()};
|
89
|
+
a.calcFaceCount=function(){this.faceCount=0;var b=this.indexBuffer;b[b.length-1]!=-1&&b.push(-1);for(var c=0;c<b.length;c++)b[c]==-1&&this.faceCount++};
|
90
|
+
a.calcAABB=function(){for(var b=minY=minZ=Number.MAX_VALUE,c=maxY=maxZ=-Number.MAX_VALUE,e=this.vertexBuffer,f=0;f<e.length;f+=3){var d=e[f],g=e[f+1],h=e[f+2];if(d<b)b=d;if(d>c)c=d;if(g<minY)minY=g;if(g>maxY)maxY=g;if(h<minZ)minZ=h;if(h>maxZ)maxZ=h}this.aabb.minX=b;this.aabb.minY=minY;this.aabb.minZ=minZ;this.aabb.maxX=c;this.aabb.maxY=maxY;this.aabb.maxZ=maxZ};
|
91
|
+
a.calcFaceNormals=function(){for(var b=this.vertexBuffer,c=this.indexBuffer,e=this.faceNormalBuffer,f=0,d=0;f<c.length;){var g=c[f++]*3,h=b[g],l=b[g+1],m=b[g+2];g=c[f++]*3;var p=b[g],r=b[g+1],i=b[g+2];g=c[f++]*3;p=p-h;r=r-l;i=i-m;h=b[g]-h;l=b[g+1]-l;m=b[g+2]-m;g=r*m-i*l;m=i*h-p*m;p=p*l-r*h;e[d++]=g;e[d++]=m;e[d++]=p;do;while(c[f++]!=-1)}};
|
92
|
+
a.calcVertexNormals=function(){if(!this.faceNormalBuffer){this.faceNormalBuffer=new Array(this.faceCount*3);this.calcFaceNormals()}for(var b=this.indexBuffer,c=this.faceNormalBuffer,e=this.vertexNormalBuffer,f=0;f<e.length;f++)e[f]=0;for(var d=f=0,g=0;f<b.length;){g=b[f++];if(g==-1)d+=3;else{g=g*3;e[g]+=c[d];e[g+1]+=c[d+1];e[g+2]+=c[d+2]}}for(d=f=0;f<e.length;f+=3,d++){b=e[f];c=e[f+1];g=e[f+2];var h=Math.sqrt(b*b+c*c+g*g);if(h>0){b/=h;c/=h;g/=h}e[f]=b;e[f+1]=c;e[f+2]=g}};
|
93
|
+
a.normalizeFaceNormals=function(){for(var b=this.faceNormalBuffer,c=0;c<b.length;c+=3){var e=b[c],f=b[c+1],d=b[c+2],g=Math.sqrt(e*e+f*f+d*d);if(g>0){e/=g;f/=g;d/=g}b[c]=e;b[c+1]=f;b[c+2]=d}};a.checkValid=function(){};a.name="";a.metadata="";a.visible=false;a.aabb=null;a.vertexBuffer=null;a.indexBuffer=null;a.vertexNormalBuffer=null;a.faceNormalBuffer=null;a.texCoordBuffer=null;a.texCoordIndexBuffer=null;a.material=null;a.texture=null;a.faceCount=0;a.isDoubleSided=false;a.isEnvironmentCast=false;
|
94
|
+
a.internalId=0;a.transformedVertexBuffer=null;a.transformedVertexNormalZBuffer=null;a.transformedFaceNormalZBuffer=null;a.transformedVertexNormalBuffer=null;JSC3D.Material=function(b,c,e,f,d){this.name=b||"";this.ambientColor=c||0;this.diffuseColor=e||8355711;this.transparency=f||0;this.simulateSpecular=d||false;this.palette=null};a=JSC3D.Material.prototype;a.getPalette=function(){if(!this.palette){this.palette=new Array(256);this.generatePalette()}return this.palette};
|
95
|
+
a.generatePalette=function(){var b=(this.ambientColor&16711680)>>16,c=(this.ambientColor&65280)>>8,e=this.ambientColor&255,f=(this.diffuseColor&16711680)>>16,d=(this.diffuseColor&65280)>>8,g=this.diffuseColor&255;if(this.simulateSpecular){for(var h=0;h<204;){var l=b+h*f/204,m=c+h*d/204,p=e+h*g/204;if(l>255)l=255;if(m>255)m=255;if(p>255)p=255;this.palette[h++]=l<<16|m<<8|p}for(;h<256;){l=b+f+(h-204)*(255-f)/82;m=c+d+(h-204)*(255-d)/82;p=e+g+(h-204)*(255-g)/82;if(l>255)l=255;if(m>255)m=255;if(p>255)p=
|
96
|
+
255;this.palette[h++]=l<<16|m<<8|p}}else for(h=0;h<256;){l=b+h*f/256;m=c+h*d/256;p=e+h*g/256;if(l>255)l=255;if(m>255)m=255;if(p>255)p=255;this.palette[h++]=l<<16|m<<8|p}};a.name="";a.ambientColor=0;a.diffuseColor=8355711;a.transparency=0;a.simulateSpecular=false;a.palette=null;JSC3D.Texture=function(b,c){this.name=b||"";this.height=this.width=0;this.mipentries=this.mipmaps=this.data=null;this.hasTransparency=false;this.srcUrl="";this.onready=c&&typeof c=="function"?c:null};a=JSC3D.Texture.prototype;
|
97
|
+
a.createFromUrl=function(b,c){var e=this,f=new Image;f.onload=function(){e.data=null;e.mipmaps=null;e.mipentries=null;e.width=0;e.height=0;e.hasTransparency=false;e.srcUrl="";e.createFromImage(this,c)};f.onerror=function(){e.data=null;e.mipmaps=null;e.mipentries=null;e.width=0;e.height=0;e.hasTransparency=false;e.srcUrl=""};f.src=b};
|
98
|
+
a.createFromImage=function(b,c){if(!(b.width<=0||b.height<=0))if(JSC3D.Texture.cv_is_locked){var e=this;setTimeout(function(){e.createFromImage(b)},JSC3D.Texture.cv_lock_cycle)}else{var f=JSC3D.Texture.cv;if(!f)try{f=document.createElement("canvas");JSC3D.Texture.cv=f}catch(d){return}var g=b.width>b.height?b.width:b.height;g=g<=32?32:g<=64?64:g<=128?128:256;try{JSC3D.Texture.cv_is_locked=true;e=this;if(f.width!=g||f.height!=g)f.width=f.height=g;setTimeout(function(){var l=f.getContext("2d");l.drawImage(b,
|
99
|
+
0,0,g,g);setTimeout(function(){var m=l.getImageData(0,0,g,g).data,p=m.length/4;e.data=new Array(p);for(var r,i=0,y=0;i<p;i++,y+=4){r=m[y+3];e.data[i]=r<<24|m[y]<<16|m[y+1]<<8|m[y+2];if(r<250)e.hasTransparency=true}e.width=g;e.height=g;f.width=1;f.height=1;JSC3D.Texture.cv_is_locked=false;e.mipmaps=null;c&&e.generateMipmaps();e.srcUrl=b.src;e.onready!=null&&typeof e.onready=="function"&&e.onready()},JSC3D.Texture.cv_lock_cycle)},JSC3D.Texture.cv_lock_cycle)}catch(h){JSC3D.Texture.cv_is_locked=false}}};
|
100
|
+
a.hasData=function(){return this.data!=null};
|
101
|
+
a.generateMipmaps=function(){if(!(this.width<=1||this.data==null||this.mipmaps!=null)){this.mipmaps=[this.data];this.mipentries=[1];for(var b=1+~~(0.1+Math.log(this.width)*Math.LOG2E),c=this.width>>1,e=1;e<b;e++){for(var f=new Array(c*c),d=this.mipmaps[e-1],g=c<<1,h=0,l=0,m=0;m<c;m++){for(var p=0;p<c;p++){var r=d[h],i=d[h+1],y=d[h+g],j=d[h+g+1];f[l]=(((r&4278190080)>>>2)+((i&4278190080)>>>2)+((y&4278190080)>>>2)+((j&4278190080)>>>2)&4278190080)+((r&16711680)+(i&16711680)+(y&16711680)+(j&16711680)>>
|
102
|
+
2&16711680)+((r&65280)+(i&65280)+(y&65280)+(j&65280)>>2&65280)+((r&255)+(i&255)+(y&255)+(j&255)>>2&255);h+=2;l++}h+=g}this.mipmaps.push(f);this.mipentries.push(Math.pow(4,e));c>>=1}}};a.hasMipmap=function(){return this.mipmaps!=null};a.name="";a.data=null;a.mipmaps=null;a.mipentries=null;a.width=0;a.height=0;a.hasTransparency=false;a.srcUrl="";a.onready=null;JSC3D.Texture.cv=null;JSC3D.Texture.cv_is_locked=false;JSC3D.Texture.cv_lock_cycle=100;
|
103
|
+
JSC3D.AABB=function(){this.minZ=this.maxZ=this.minY=this.maxY=this.minX=this.maxX=0};JSC3D.AABB.prototype.center=function(){return[(this.minX+this.maxX)/2,(this.minY+this.maxY)/2,(this.minZ+this.maxZ)/2]};JSC3D.AABB.prototype.lengthOfDiagonal=function(){var b=this.maxX-this.minX,c=this.maxY-this.minY,e=this.maxZ-this.minZ;return Math.sqrt(b*b+c*c+e*e)};JSC3D.Matrix3x4=function(){this.m00=1;this.m10=this.m03=this.m02=this.m01=0;this.m11=1;this.m21=this.m20=this.m13=this.m12=0;this.m22=1;this.m23=0};
|
104
|
+
a=JSC3D.Matrix3x4.prototype;a.identity=function(){this.m00=1;this.m10=this.m03=this.m02=this.m01=0;this.m11=1;this.m21=this.m20=this.m13=this.m12=0;this.m22=1;this.m23=0};a.scale=function(b,c,e){this.m00*=b;this.m01*=b;this.m02*=b;this.m03*=b;this.m10*=c;this.m11*=c;this.m12*=c;this.m13*=c;this.m20*=e;this.m21*=e;this.m22*=e;this.m23*=e};a.translate=function(b,c,e){this.m03+=b;this.m13+=c;this.m23+=e};
|
105
|
+
a.rotateAboutXAxis=function(b){if(b!=0){b*=Math.PI/180;var c=Math.cos(b);b=Math.sin(b);var e=c*this.m11-b*this.m21,f=c*this.m12-b*this.m22,d=c*this.m13-b*this.m23,g=c*this.m20+b*this.m10,h=c*this.m21+b*this.m11,l=c*this.m22+b*this.m12,m=c*this.m23+b*this.m13;this.m10=c*this.m10-b*this.m20;this.m11=e;this.m12=f;this.m13=d;this.m20=g;this.m21=h;this.m22=l;this.m23=m}};
|
106
|
+
a.rotateAboutYAxis=function(b){if(b!=0){b*=Math.PI/180;var c=Math.cos(b);b=Math.sin(b);var e=c*this.m01+b*this.m21,f=c*this.m02+b*this.m22,d=c*this.m03+b*this.m23,g=c*this.m20-b*this.m00,h=c*this.m21-b*this.m01,l=c*this.m22-b*this.m02,m=c*this.m23-b*this.m03;this.m00=c*this.m00+b*this.m20;this.m01=e;this.m02=f;this.m03=d;this.m20=g;this.m21=h;this.m22=l;this.m23=m}};
|
107
|
+
a.rotateAboutZAxis=function(b){if(b!=0){b*=Math.PI/180;var c=Math.cos(b);b=Math.sin(b);var e=c*this.m10+b*this.m00,f=c*this.m11+b*this.m01,d=c*this.m12+b*this.m02,g=c*this.m13+b*this.m03,h=c*this.m01-b*this.m11,l=c*this.m02-b*this.m12,m=c*this.m03-b*this.m13;this.m00=c*this.m00-b*this.m10;this.m01=h;this.m02=l;this.m03=m;this.m10=e;this.m11=f;this.m12=d;this.m13=g}};
|
108
|
+
a.multiply=function(b){var c=b.m00*this.m01+b.m01*this.m11+b.m02*this.m21,e=b.m00*this.m02+b.m01*this.m12+b.m02*this.m22,f=b.m00*this.m03+b.m01*this.m13+b.m02*this.m23+b.m03,d=b.m10*this.m00+b.m11*this.m10+b.m12*this.m20,g=b.m10*this.m01+b.m11*this.m11+b.m12*this.m21,h=b.m10*this.m02+b.m11*this.m12+b.m12*this.m22,l=b.m10*this.m03+b.m11*this.m13+b.m12*this.m23+b.m13,m=b.m20*this.m00+b.m21*this.m10+b.m22*this.m20,p=b.m20*this.m01+b.m21*this.m11+b.m22*this.m21,r=b.m20*this.m02+b.m21*this.m12+b.m22*this.m22,
|
109
|
+
i=b.m20*this.m03+b.m21*this.m13+b.m22*this.m23+b.m23;this.m00=b.m00*this.m00+b.m01*this.m10+b.m02*this.m20;this.m01=c;this.m02=e;this.m03=f;this.m10=d;this.m11=g;this.m12=h;this.m13=l;this.m20=m;this.m21=p;this.m22=r;this.m23=i};
|
110
|
+
JSC3D.Math3D={transformVectors:function(b,c,e){for(var f=0;f<c.length;f+=3){var d=c[f],g=c[f+1],h=c[f+2];e[f]=b.m00*d+b.m01*g+b.m02*h+b.m03;e[f+1]=b.m10*d+b.m11*g+b.m12*h+b.m13;e[f+2]=b.m20*d+b.m21*g+b.m22*h+b.m23}},transformVectorZs:function(b,c,e){for(var f=c.length/3,d=0,g=0;d<f;){e[d]=b.m20*c[g]+b.m21*c[g+1]+b.m22*c[g+2]+b.m23;d++;g+=3}}};
|
111
|
+
JSC3D.LoaderSelector={registerLoader:function(b,c){if(typeof c=="function")JSC3D.LoaderSelector.loaderTable[b]=c},getLoader:function(b){b=JSC3D.LoaderSelector.loaderTable[b.toLowerCase()];if(!b)return null;var c;try{c=new b}catch(e){c=null}return c},loaderTable:{}};JSC3D.ObjLoader=function(b,c,e,f){this.onload=b&&typeof b=="function"?b:null;this.onerror=c&&typeof c=="function"?c:null;this.onprogress=e&&typeof e=="function"?e:null;this.onresource=f&&typeof f=="function"?f:null;this.requestCount=0};
|
112
|
+
a=JSC3D.ObjLoader.prototype;a.loadFromUrl=function(b){var c="",e=b,f=b.lastIndexOf("/");if(f==-1)f=b.lastIndexOf("\\");if(f!=-1){c=b.substring(0,f+1);e=b.substring(f+1)}this.requestCount=0;this.loadObjFile(c,e)};
|
113
|
+
a.loadObjFile=function(b,c){var e=b+c,f=this;c=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0");c.open("GET",e,true);c.onreadystatechange=function(){if(this.readyState==4)if(this.status==200||this.status==0){if(f.onload){f.onprogress&&f.onprogress("Loading obj file ...",1);var d=new JSC3D.Scene,g=f.parseObj(d,this.responseText);if(g.length>0)for(var h=0;h<g.length;h++)f.loadMtlFile(d,b,g[h]);--f.requestCount==0&&f.onload(d)}}else if(f.onerror){f.requestCount--;f.onerror("Failed to load obj file '"+
|
114
|
+
e+"'.")}};if(this.onprogress&&c.onprogress){this.onprogress("Loading obj file ...",0);c.onprogress=function(d){f.onprogress("Loading obj file ...",d.position/d.totalSize)}}this.requestCount++;c.send()};
|
115
|
+
a.loadMtlFile=function(b,c,e){var f=c+e,d=this,g=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0");g.open("GET",f,true);g.onreadystatechange=function(){if(this.readyState==4){if(this.status==200||this.status==0){d.onprogress&&d.onprogress("Loading mtl file ...",1);for(var h=d.parseMtl(this.responseText),l={},m=b.getChildren(),p=0;p<m.length;p++){var r=m[p];if(r.mtl!=null&&r.mtllib!=null&&r.mtllib==e){var i=h[r.mtl];if(i!=null){i.material!=null&&r.setMaterial(i.material);
|
116
|
+
if(i.textureFileName!="")if(l[i.textureFileName])l[i.textureFileName].push(r);else l[i.textureFileName]=[r]}}}for(var y in l)d.setupTexture(l[y],c+y)}--d.requestCount==0&&d.onload(b)}};if(this.onprogress&&g.onprogress){this.onprogress("Loading mtl file ...",0);g.onprogress=function(h){d.onprogress("Loading mtl file ...",h.position/h.totalSize)}}this.requestCount++;g.send()};
|
117
|
+
a.parseObj=function(b,c){var e={},f=[],d=0,g=null,h="",l="",m=[],p=[];g="obj-"+d++;var r=new JSC3D.Mesh;r.name=g;r.indexBuffer=[];g=e.nomtl=r;var i=c.split("\n");for(c=0;c<i.length;c++){l=i[c].split(/[ \t]+/);if(l.length>0)switch(l[0]){case "v":if(l.length>3)for(var y=1;y<4;y++)m.push(parseFloat(l[y]));break;case "vn":break;case "vt":if(l.length>2){p.push(parseFloat(l[1]));p.push(1-parseFloat(l[2]))}break;case "f":if(l.length>3){for(y=1;y<l.length;y++){var j=l[y].split("/");g.indexBuffer.push(parseInt(j[0])-
|
118
|
+
1);if(j.length>1&&j[1]!=""){if(!g.texCoordIndexBuffer)g.texCoordIndexBuffer=[];g.texCoordIndexBuffer.push(parseInt(j[1])-1)}}g.indexBuffer.push(-1);g.texCoordIndexBuffer&&g.texCoordIndexBuffer.push(-1)}break;case "mtllib":if(l.length>1){h=l[1];f.push(h)}else h="";break;case "usemtl":if(l.length>1&&l[1]!=""&&h!=""){l=l[1];y=h+"-"+l;g=e[y];if(!g){g=new JSC3D.Mesh;g.name="obj-"+d++;g.indexBuffer=[];g.mtllib=h;g.mtl=l;e[y]=g}g=g}else g=r;break;case "#":default:break}}d=m.length>=3?new Array(m.length/
|
119
|
+
3):null;h=p.length>=2?new Array(p.length/2):null;for(var M in e){g=e[M];if(m.length>=3&&g.indexBuffer.length>0){for(c=0;c<d.length;c++)d[c]=-1;g.vertexBuffer=[];for(c=i=r=0;c<g.indexBuffer.length;c++){r=g.indexBuffer[c];if(r!=-1)if(d[r]==-1){l=r*3;g.vertexBuffer.push(m[l]);g.vertexBuffer.push(m[l+1]);g.vertexBuffer.push(m[l+2]);g.indexBuffer[c]=i;d[r]=i;i++}else g.indexBuffer[c]=d[r]}}if(p.length>=2&&g.texCoordIndexBuffer!=null&&g.texCoordIndexBuffer.length>0){for(c=0;c<h.length;c++)h[c]=-1;g.texCoordBuffer=
|
120
|
+
[];for(c=i=r=0;c<g.texCoordIndexBuffer.length;c++){r=g.texCoordIndexBuffer[c];if(r!=-1)if(h[r]==-1){l=r*2;g.texCoordBuffer.push(p[l]);g.texCoordBuffer.push(p[l+1]);g.texCoordIndexBuffer[c]=i;h[r]=i;i++}else g.texCoordIndexBuffer[c]=h[r]}}g.isTrivial()||b.addChild(g)}return f};
|
121
|
+
a.parseMtl=function(b){var c={},e="";b=b.split("\n");for(var f=0;f<b.length;f++){var d=b[f].split(/[ \t]+/);if(d.length>0)switch(d[0]){case "newmtl":e=d[1];d={};d.material=new JSC3D.Material;d.textureFileName="";c[e]=d;break;case "Ka":break;case "Kd":if(d.length==4&&!isNaN(d[1])){var g=parseFloat(d[1])*255&255,h=parseFloat(d[2])*255&255,l=parseFloat(d[3])*255&255;d=c[e];if(d!=null)d.material.diffuseColor=g<<16|h<<8|l}break;case "Ks":break;case "d":if(d.length==2&&!isNaN(d[1])){g=parseFloat(d[1]);
|
122
|
+
d=c[e];if(d!=null)d.material.transparency=1-g}break;case "illum":break;case "map_Kd":if(d.length==2){g=d[1];d=c[e];if(d!=null)d.textureFileName=g}break;case "#":default:break}}return c};a.setupTexture=function(b,c){var e=this,f=new JSC3D.Texture;f.onready=function(){for(var d=0;d<b.length;d++)b[d].setTexture(this);e.onresource&&e.onresource(this)};f.createFromUrl(c)};a.onload=null;a.onerror=null;a.onprogress=null;a.onresource=null;a.requestCount=0;JSC3D.LoaderSelector.registerLoader("obj",JSC3D.ObjLoader);
|
123
|
+
JSC3D.StlLoader=function(b,c,e,f){this.onload=b&&typeof b=="function"?b:null;this.onerror=c&&typeof c=="function"?c:null;this.onprogress=e&&typeof e=="function"?e:null;this.onresource=f&&typeof f=="function"?f:null;this.decimalPrecision=3};a=JSC3D.StlLoader.prototype;
|
124
|
+
a.loadFromUrl=function(b){var c=this,e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0");e.open("GET",b,true);e.onreadystatechange=function(){if(this.readyState==4)if(this.status==200||this.status==0){if(c.onload){c.onprogress&&c.onprogress("Loading stl file ...",1);if(this.responseText.substring(0,5).toLowerCase()=="solid"){var f=new JSC3D.Scene;c.parseStlAscii(f,this.responseText);c.onload(f)}else c.loadBinaryFromUrl(b)}}else c.onerror&&c.onerror("Failed to load stl file '"+
|
125
|
+
b+"'.")};if(this.onprogress&&e.onprogress){this.onprogress("Loading stl file ...",0);e.onprogress=function(f){c.onprogress("Loading stl file ...",f.position/f.totalSize)}}e.send()};
|
126
|
+
a.loadBinaryFromUrl=function(b){var c=this,e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0");e.open("GET",b,true);e.setRequestHeader("Accept-Charset","x-user-defined");e.onreadystatechange=function(){if(this.readyState==4)if(this.status==200||this.status==0){if(c.onload){c.onprogress&&c.onprogress("Loading binary stl file ...",1);var f=new JSC3D.Scene;try{execScript("Function BinaryToArray(Binary)\n Dim length\n length = LenB(Binary)\n ReDim byteArray(length)\n Dim i\n For i = 1 To length\n byteArray(i-1) = AscB(MidB(Binary, i, 1))\n Next\n BinaryToArray = byteArray\nEnd Function",
|
127
|
+
"vbscript");c.parseStlBinary(f,BinaryToArray(this.responseBody).toArray())}catch(d){}c.onload(f)}}else c.onerror&&c.onerror("Failed to load binary stl file '"+b+"'.")};if(this.onprogress&&e.onprogress){this.onprogress("Loading binary stl file ...",0);e.onprogress=function(f){c.onprogress("Loading binary stl file ...",f.position/f.totalSize)}}e.send()};a.setDecimalPrecision=function(b){this.decimalPrecision=b};
|
128
|
+
a.parseStlAscii=function(b,c){var e=new JSC3D.Mesh;e.vertexBuffer=[];e.indexBuffer=[];e.faceNormalBuffer=[];var f=new RegExp("facet\\s+normal\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+outer\\s+loop\\s+vertex\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+vertex\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+vertex\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+([-+]?\\b(?:[0-9]*\\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\\b)\\s+endloop\\s+endfacet",
|
129
|
+
"ig"),d=c.match(f);if(d){e.faceCount=d.length;d={};f.lastIndex=0;f.global=false;for(var g=f.exec(c);g!=null;g=f.exec(c)){e.faceNormalBuffer.push(parseFloat(g[1]),parseFloat(g[2]),parseFloat(g[3]));for(var h=0;h<3;h++){var l=parseFloat(g[4+h*3]),m=parseFloat(g[5+h*3]),p=parseFloat(g[6+h*3]),r=l.toFixed(this.decimalPrecision)+"-"+m.toFixed(this.decimalPrecision)+"-"+p.toFixed(this.decimalPrecision),i=d[r];if(i==undefined){i=e.vertexBuffer.length/3;d[r]=i;e.vertexBuffer.push(l);e.vertexBuffer.push(m);
|
130
|
+
e.vertexBuffer.push(p)}e.indexBuffer.push(i)}e.indexBuffer.push(-1)}}e.isTrivial()||b.addChild(e)};
|
131
|
+
a.parseStlBinary=function(b,c){if(!(c.length<84)){var e=0;e+=80;var f=this.readUInt32LittleEndian(c,e);e+=4;if(!(c.length<84+50*f)){var d=new JSC3D.Mesh;d.faceCount=f;d.vertexBuffer=[];d.indexBuffer=[];d.faceNormalBuffer=[];for(var g={},h=0;h<f;h++){d.faceNormalBuffer.push(this.readFloatLittleEndian(c,e));e+=4;d.faceNormalBuffer.push(this.readFloatLittleEndian(c,e));e+=4;d.faceNormalBuffer.push(this.readFloatLittleEndian(c,e));e+=4;for(var l=0;l<3;l++){var m,p,r;m=this.readFloatLittleEndian(c,e);
|
132
|
+
e+=4;p=this.readFloatLittleEndian(c,e);e+=4;r=this.readFloatLittleEndian(c,e);e+=4;var i=m.toFixed(this.decimalPrecision)+"-"+p.toFixed(this.decimalPrecision)+"-"+r.toFixed(this.decimalPrecision),y=g[i];if(y==undefined){y=d.vertexBuffer.length/3;g[i]=y;d.vertexBuffer.push(m);d.vertexBuffer.push(p);d.vertexBuffer.push(r)}d.indexBuffer.push(y)}d.indexBuffer.push(-1);e+=2}d.isTrivial()||b.addChild(d)}}};a.readUInt32LittleEndian=function(b,c){for(var e=0,f=1,d=0;d<4;d++){e+=b[c+d]*f;f*=256}return e};
|
133
|
+
a.readFloatLittleEndian=function(b,c){var e=3,f=b[c+e];e+=-1;var d=-7,g=f&(1<<-d)-1;f>>=-d;for(d+=8;d>0;){g=g*256+b[c+e];e+=-1;d-=8}var h=g&(1<<-d)-1;g>>=-d;for(d+=23;d>0;){h=h*256+b[c+e];e+=-1;d-=8}switch(g){case 0:g=-126;break;case 255:return h?NaN:(f?-1:1)*Infinity;default:h+=Math.pow(2,23);g-=127;break}return(f?-1:1)*h*Math.pow(2,g-23)};a.onload=null;a.onerror=null;a.onprogress=null;a.onresource=null;a.decimalPrecision=3;JSC3D.LoaderSelector.registerLoader("stl",JSC3D.StlLoader);
|