├── README.md ├── assets └── js │ ├── external.js │ ├── widget.js │ ├── main.js │ ├── basescene.js │ ├── textw.js │ ├── cubescene.js │ └── meshscene.js ├── indexjs.html └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # threejs-mesh-viewer 2 | Mesh viewer with threejs 3 | -------------------------------------------------------------------------------- /assets/js/external.js: -------------------------------------------------------------------------------- 1 | // external modules with cdn 2 | import * as THREE from 'https://cdn.skypack.dev/three@0.129.0'; 3 | import { 4 | GUI 5 | } from 'https://cdn.skypack.dev/three@0.129.0/examples/jsm/libs/dat.gui.module.js'; 6 | 7 | import { 8 | OrbitControls 9 | } from 'https://cdn.skypack.dev/three@0.129.0/examples/jsm/controls/OrbitControls.js'; 10 | import { 11 | OBJLoader 12 | } from 'https://cdn.skypack.dev/three@0.129.0/examples/jsm/loaders/OBJLoader.js'; 13 | import { 14 | GLTFLoader 15 | } from 'https://cdn.skypack.dev/three@0.129.0/examples/jsm/loaders/GLTFLoader.js'; 16 | import { 17 | RGBELoader 18 | } from 'https://cdn.skypack.dev/three@0.129.0/examples/jsm/loaders/RGBELoader.js'; 19 | import { 20 | RoughnessMipmapper 21 | } from 'https://cdn.skypack.dev/three@0.129.0/examples/jsm/utils/RoughnessMipmapper.js'; 22 | 23 | export { 24 | OrbitControls, 25 | THREE, 26 | GLTFLoader, 27 | RGBELoader, 28 | RoughnessMipmapper, 29 | OBJLoader, 30 | GUI 31 | }; 32 | -------------------------------------------------------------------------------- /indexjs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | My Index Page 7 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 |
28 | 29 |
30 | 31 |
32 | 33 | 34 |
35 | 36 | 37 |
38 | 39 | 40 |
41 |
42 | 43 |
44 |
45 | 46 |
    47 |
  • 48 |
    49 | 50 |
    51 | 52 |
    53 |
    54 |
    55 |

    56 | Light Direction: 57 | x 58 | y 59 | z 60 |

    61 |

    62 | Light Color: 63 | r 64 | g 65 | b 66 |

    67 |
    68 | 69 |
  • 70 |
71 |
72 |
73 |
74 | 75 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /assets/js/widget.js: -------------------------------------------------------------------------------- 1 | // basic object 2 | import { 3 | OrbitControls, 4 | THREE, 5 | GLTFLoader, 6 | RGBELoader, 7 | RoughnessMipmapper, 8 | OBJLoader, 9 | GUI 10 | } from "./external.js"; 11 | 12 | 13 | class BaseWidget { 14 | constructor(model = null, view = null) { 15 | this._model = model; 16 | this._view = view; 17 | } 18 | check_null(obj, message) { 19 | if (obj === null) { 20 | throw message; 21 | } 22 | return obj; 23 | } 24 | get model() { 25 | return this.check_null(this._model, "model is null"); 26 | } 27 | set model(m) { 28 | if (typeof(m) === "object") { 29 | this._model = m; 30 | } 31 | } 32 | get view() { 33 | return this.check_null(this._view, "model is null"); 34 | } 35 | set view(v) { 36 | if (typeof v === "object") { 37 | this._view = v; 38 | } 39 | } 40 | } 41 | 42 | class CameraWidget extends BaseWidget { 43 | constructor(camera_pos_x, 44 | camera_pos_y, camera_pos_z, scene_width, scene_height, 45 | fovy, near, far) { 46 | const aspect_ratio = scene_width / scene_height; 47 | let model = { 48 | x: camera_pos_x, 49 | y: camera_pos_y, 50 | z: camera_pos_z, 51 | scene_width: scene_width, 52 | scene_height: scene_height, 53 | aspect_ratio: aspect_ratio, 54 | fovy: fovy, 55 | near: near, 56 | far: far 57 | }; 58 | const camera = new THREE.PerspectiveCamera(fovy, aspect_ratio, near, far); 59 | camera.position.set(model.x, model.y, model.z); 60 | let view = camera; 61 | super(model, view); 62 | } 63 | update() { 64 | let camera = this.view; 65 | camera.position.set(this.model.x, this.model.y, this.model.z); 66 | camera.far = this.model.far; 67 | camera.near = this.model.near; 68 | camera.aspect = this.model.aspect_ratio; 69 | this.view = camera; 70 | } 71 | set_model(model) { 72 | for (const key in model) { 73 | if (!this.model.hasOwnProperty(key)) { 74 | throw "model has unexpected key " + key; 75 | } 76 | } 77 | this.model = model; 78 | this.update(); 79 | } 80 | move_z(amount) { 81 | this.model.z = amount; 82 | this.update(); 83 | } 84 | move_x(amount) { 85 | this.model.x = amount; 86 | this.update(); 87 | } 88 | move_y(amount) { 89 | this.model.y = amount; 90 | this.update(); 91 | } 92 | set_far(amount) { 93 | this.model.far = amount; 94 | this.update(); 95 | } 96 | set_near(amount) { 97 | this.model.near = amount; 98 | this.update(); 99 | } 100 | set_fovy(amount) { 101 | this.model.fovy = amount; 102 | this.update(); 103 | } 104 | set_scene_width(amount) { 105 | this.model.scene_width = amount; 106 | this.model.aspect_ratio = this.model.scene_width / 107 | this.model.scene_height; 108 | this.update(); 109 | } 110 | set_scene_height(amount) { 111 | this.model.scene_height = amount; 112 | this.model.aspect_ratio = this.model.scene_width / 113 | this.model.scene_height; 114 | this.update(); 115 | } 116 | } 117 | 118 | export { 119 | BaseWidget, 120 | CameraWidget 121 | }; 122 | -------------------------------------------------------------------------------- /assets/js/main.js: -------------------------------------------------------------------------------- 1 | import { 2 | OrbitControls, 3 | THREE, 4 | GLTFLoader, 5 | RGBELoader, 6 | RoughnessMipmapper, 7 | OBJLoader, 8 | GUI 9 | } from "./external.js"; 10 | import { 11 | CubeScene 12 | } from "./cubescene.js"; 13 | import { 14 | MeshScene 15 | } from "./meshscene.js"; 16 | 17 | import { 18 | TextPartWidget 19 | } from "./textw.js"; 20 | 21 | // ----------- scene globals ---------------------- 22 | 23 | function recreate_obj() { 24 | let objtag = document.createElement("object"); 25 | let old_obj = document.getElementById("render-zone"); 26 | old_obj.parentNode.removeChild(old_obj); 27 | objtag.id = "render-zone"; 28 | objtag.width = 800; 29 | objtag.height = 600; 30 | document.body.prepend(objtag); 31 | } 32 | var active_scene = null; 33 | 34 | 35 | var TextParts = new TextPartWidget(); 36 | 37 | function scene_select() { 38 | 39 | let buttons = document.getElementsByName("scene"); 40 | let selected; 41 | for (var i = 0; i < buttons.length; i++) { 42 | let btn = buttons[i]; 43 | if (btn.checked === true) { 44 | selected = btn.value; 45 | } 46 | } 47 | 48 | if (selected === "cube") { 49 | if (active_scene !== null) { 50 | recreate_obj(); 51 | active_scene.clear(); 52 | } 53 | active_scene = new CubeScene( 54 | "render-zone", 55 | ); 56 | active_scene.text_w = TextParts; 57 | active_scene.init(); 58 | active_scene.render_scene(); 59 | } else if (selected === "demotic-mesh") { 60 | if (active_scene !== null) { 61 | recreate_obj(); 62 | active_scene.clear(); 63 | } 64 | 65 | active_scene = new MeshScene( 66 | "render-zone", 67 | // "./assets/obj/Houghton_MS_Ostraca_3150/Houghton_MS_Ostraca_3150.obj" 68 | "./assets/obj/houghton_ms_ostraca_3150/scene.gltf" 69 | ); 70 | active_scene.text_w = TextParts; 71 | active_scene.init(); 72 | // active_scene.render_scene(); 73 | } else if (selected === "rosetta-mesh") { 74 | if (active_scene !== null) { 75 | recreate_obj(); 76 | active_scene.clear(); 77 | } 78 | 79 | active_scene = new MeshScene( 80 | "render-zone", 81 | // "./assets/obj/Houghton_MS_Ostraca_3150/Houghton_MS_Ostraca_3150.obj" 82 | "./assets/obj/rosetta_stone/scene.gltf" 83 | ); 84 | active_scene.text_w = TextParts; 85 | active_scene.init(); 86 | // active_scene.render_scene(); 87 | } else if (selected === "osiris-mesh") { 88 | if (active_scene !== null) { 89 | recreate_obj(); 90 | active_scene.clear(); 91 | } 92 | 93 | active_scene = new MeshScene( 94 | "render-zone", 95 | // "./assets/obj/Houghton_MS_Ostraca_3150/Houghton_MS_Ostraca_3150.obj" 96 | "./assets/obj/osiris_chapel_temple_of_seti_i_abydos/scene.gltf" 97 | ); 98 | active_scene.text_w = TextParts; 99 | active_scene.init(); 100 | // active_scene.render_scene(); 101 | } 102 | } 103 | 104 | 105 | function add_text_editable_event() { 106 | let tparts_length = TextParts.text_parts.length; 107 | if (tparts_length > 0) { 108 | tparts_length--; 109 | } 110 | TextParts.add_text_editable_event(tparts_length); 111 | } 112 | 113 | 114 | function add_new_text_part() { 115 | TextParts.new_text_part(); 116 | add_text_editable_event(); 117 | } 118 | 119 | function add_listeners() { 120 | let buttons = document.getElementsByName("scene"); 121 | let selected; 122 | for (var i = 0; i < buttons.length; i++) { 123 | let btn = buttons[i]; 124 | btn.addEventListener("change", scene_select); 125 | } 126 | let tpartbtn = document.getElementById("add-text-part"); 127 | tpartbtn.addEventListener("click", add_new_text_part); 128 | } 129 | 130 | add_listeners(); 131 | -------------------------------------------------------------------------------- /assets/js/basescene.js: -------------------------------------------------------------------------------- 1 | // object grouping common scene elements like gui etc 2 | import { 3 | OrbitControls, 4 | THREE, 5 | GLTFLoader, 6 | RGBELoader, 7 | RoughnessMipmapper, 8 | OBJLoader, 9 | GUI 10 | } from "./external.js"; 11 | 12 | // basic utilities 13 | 14 | 15 | /** 16 | from SO: https://stackoverflow.com/a/5191133/7330813 17 | by: Andrew Marshall 18 | * @param num The number to round 19 | * @param precision The number of decimal places to preserve 20 | */ 21 | function roundUp(num, precision) { 22 | precision = Math.pow(10, precision) 23 | return Math.ceil(num * precision) / precision 24 | } 25 | 26 | import { 27 | CameraWidget 28 | } from "./widget.js"; 29 | 30 | 31 | class BaseScene { 32 | constructor(render_zone_id = "render-zone") { 33 | this._render_zone = document.getElementById(render_zone_id); 34 | this._width = this.render_zone.width; 35 | this._height = this.render_zone.height; 36 | this._camera = null; 37 | this._scene = null; 38 | this._renderer = null; 39 | 40 | // camera related 41 | this._camera_pos_x = null; 42 | this._camera_pos_y = null; 43 | this._camera_pos_z = null; 44 | 45 | // controllers 46 | this._camera_controller = null; 47 | this._effect_controller = null; 48 | 49 | // lights 50 | this._ambient_light = null; 51 | this._light = null; 52 | this._light_helper = null; 53 | 54 | // colors 55 | this._diffuse_color = new THREE.Color(); 56 | this._specular_color = new THREE.Color(); 57 | 58 | // materials 59 | this._shading = null; 60 | this._wire_material = null; 61 | this._flat_material = null; 62 | this._gouraud_material = null; 63 | this._phong_material = null; 64 | this._textured_material = null; 65 | this._reflective_material = null; 66 | 67 | // other textures etc 68 | this._texture_cube = null; 69 | 70 | 71 | // gui elements 72 | this._gui = null; 73 | 74 | this._text_w = null; 75 | } 76 | check_null(obj, message) { 77 | if (obj === null) { 78 | throw message; 79 | } 80 | return obj; 81 | } 82 | get text_w() { 83 | if (this._text_w === null) { 84 | throw "text widget is none"; 85 | } 86 | return this._text_w; 87 | } 88 | set text_w(s) { 89 | this._text_w = s; 90 | } 91 | get render_zone() { 92 | return this.check_null(this._render_zone, "render zone is null"); 93 | } 94 | get width() { 95 | return this.check_null(this._width, "cube width is null"); 96 | } 97 | set width(s) { 98 | this._width = s; 99 | } 100 | get height() { 101 | return this.check_null(this._height, "cube height is null"); 102 | } 103 | set height(s) { 104 | this._height = s; 105 | } 106 | get camera() { 107 | return this.check_null(this._camera, "camera is null"); 108 | } 109 | set camera(s) { 110 | this._camera = s; 111 | } 112 | get camera_pos_x() { 113 | return this.check_null(this._camera_pos_x, "camera pos x is null"); 114 | } 115 | set camera_pos_x(x) { 116 | this._camera_pos_x = x; 117 | } 118 | get camera_pos_y() { 119 | return this.check_null(this._camera_pos_y, "camera pos y is null"); 120 | } 121 | set camera_pos_y(y) { 122 | this._camera_pos_y = y; 123 | } 124 | get camera_pos_z() { 125 | return this.check_null(this._camera_pos_z, "camera pos z is null"); 126 | } 127 | set camera_pos_z(z) { 128 | this._camera_pos_z = z; 129 | } 130 | 131 | // camera controls 132 | get camera_controller() { 133 | return this.check_null(this._camera_controller, 134 | "camera controller is null"); 135 | } 136 | set camera_controller(s) { 137 | this._camera_controller = s; 138 | } 139 | get ambient_light() { 140 | return this.check_null(this._ambient_light, 141 | "ambient light is null"); 142 | } 143 | set ambient_light(s) { 144 | this._ambient_light = s; 145 | } 146 | get light() { 147 | return this.check_null(this._light, 148 | "light is null"); 149 | } 150 | set light(s) { 151 | this._light = s; 152 | } 153 | get light_helper() { 154 | return this.check_null(this._light_helper, "light helper is null"); 155 | } 156 | set light_helper(s) { 157 | this._light_helper = s; 158 | } 159 | 160 | get gui() { 161 | return this.check_null(this._gui, "gui is null"); 162 | } 163 | get shading() { 164 | return this.check_null(this._shading, 165 | "shading is null"); 166 | } 167 | set shading(s) { 168 | this._shading = s; 169 | } 170 | 171 | get wire_material() { 172 | return this.check_null(this._wire_material, 173 | "wire material is null"); 174 | } 175 | set wire_material(s) { 176 | this._wire_material = s; 177 | } 178 | 179 | get flat_material() { 180 | return this.check_null(this._flat_material, 181 | "flat material is null"); 182 | } 183 | set flat_material(s) { 184 | this._flat_material = s; 185 | } 186 | 187 | get gouraud_material() { 188 | return this.check_null(this._gouraud_material, 189 | "gouraud material is null"); 190 | } 191 | set gouraud_material(s) { 192 | this._gouraud_material = s; 193 | } 194 | 195 | get phong_material() { 196 | return this.check_null(this._phong_material, 197 | "phong material is null"); 198 | } 199 | set phong_material(s) { 200 | this._phong_material = s; 201 | } 202 | get textured_material() { 203 | return this.check_null(this._textured_material, 204 | "textured material is null"); 205 | } 206 | set textured_material(s) { 207 | this._textured_material = s; 208 | } 209 | 210 | get reflective_material() { 211 | return this.check_null(this._reflective_material, 212 | "reflective material is null"); 213 | } 214 | set reflective_material(s) { 215 | this._reflective_material = s; 216 | } 217 | 218 | get texture_cube() { 219 | return this.check_null(this._texture_cube, 220 | "texture cube is null"); 221 | } 222 | set texture_cube(s) { 223 | this._texture_cube = s; 224 | } 225 | 226 | get diffuse_color() { 227 | return this.check_null(this._diffuse_color, 228 | "diffuse color is null"); 229 | } 230 | set diffuse_color(s) { 231 | this._diffuse_color = s; 232 | } 233 | 234 | get specular_color() { 235 | return this.check_null(this._specular_color, 236 | "specular color is null"); 237 | } 238 | set specular_color(s) { 239 | this._specular_color = s; 240 | } 241 | get renderer() { 242 | return this.check_null(this._renderer, 243 | "renderer is null"); 244 | } 245 | set renderer(s) { 246 | this._renderer = s; 247 | } 248 | 249 | get scene() { 250 | return this.check_null(this._scene, 251 | "scene is null"); 252 | } 253 | set scene(s) { 254 | this._scene = s; 255 | } 256 | } 257 | export { 258 | BaseScene, 259 | roundUp 260 | }; 261 | -------------------------------------------------------------------------------- /assets/js/textw.js: -------------------------------------------------------------------------------- 1 | // text area js 2 | 3 | class TextPartModel { 4 | constructor(index = null, 5 | editable = null, 6 | light_info = null, 7 | text = null) { 8 | this._index = index; 9 | this._is_editable = editable; 10 | this._light_info = light_info; 11 | this._text = text; 12 | } 13 | get index() { 14 | if (this._index === null) { 15 | throw "index is null"; 16 | } 17 | return this._index; 18 | } 19 | get text() { 20 | if (this._text === null) { 21 | throw "text is null"; 22 | } 23 | return this._text; 24 | } 25 | set text(t) { 26 | this._text = t; 27 | } 28 | set index(i) { 29 | this._index = i; 30 | } 31 | get is_editable() { 32 | if (this._is_editable === null) { 33 | throw "text is null"; 34 | } 35 | return this._is_editable; 36 | } 37 | set is_editable(s) { 38 | this._is_editable = s; 39 | } 40 | get light_info() { 41 | if (this._light_info === null) { 42 | throw "light info is null"; 43 | } 44 | return this._light_info; 45 | } 46 | set light_info(s) { 47 | this._light_info = s; 48 | } 49 | static from_html_is_editable(model, el) { 50 | let rbtn = el.getElementById("text-part-radio-" + model.index + 51 | "editable"); 52 | model.is_editable = rbtn.checked; 53 | return model; 54 | } 55 | static from_html_text(model, el) { 56 | let rbtn = el.getElementById("text-part-" + model.index); 57 | model.text = rbtn.text; 58 | return model; 59 | } 60 | static from_html_light_info(model, el) { 61 | let xdir = el.getElementById("x-light-direction-" + model.index); 62 | let ydir = el.getElementById("y-light-direction-" + model.index); 63 | let zdir = el.getElementById("z-light-direction-" + model.index); 64 | let rc = el.getElementById("r-light-color-" + model.index); 65 | let gc = el.getElementById("g-light-color-" + model.index); 66 | let bc = el.getElementById("b-light-color-" + model.index); 67 | let linfo = { 68 | "direction": { 69 | x: xdir, 70 | y: ydir, 71 | z: zdir 72 | }, 73 | "color": { 74 | r: rc, 75 | g: gc, 76 | b: bc 77 | } 78 | } 79 | model.light_info = linfo; 80 | return model; 81 | } 82 | static from_html(index, el) { 83 | let model = new TextPartModel(index); 84 | // 85 | model = TextPartModel.from_html_is_editable(model, el); 86 | model = TextPartModel.from_html_light_info(model, el); 87 | model = TextPartModel.from_html_text(model, el); 88 | return model; 89 | } 90 | } 91 | 92 | class TextPartView { 93 | constructor(model = null) { 94 | this._model = model; 95 | this.name = "text-part"; 96 | } 97 | get model() { 98 | if (this._model === null) { 99 | throw "model is null"; 100 | } 101 | return this._model; 102 | } 103 | mk_radio_btn(is_editable) { 104 | let editable = document.createElement("input"); 105 | editable.type = "radio"; 106 | if (is_editable) { 107 | editable.id = this.name + "-radio-" + this.model.index + "-editable"; 108 | } else { 109 | editable.id = this.name + "-radio-" + this.model.index + "-not-editable"; 110 | } 111 | editable.name = this.name + "-radio-" + this.model.index + "-name"; 112 | if (is_editable) { 113 | editable.value = "not-editable"; 114 | editable.checked = this.model.is_editable; 115 | } else { 116 | editable.value = "not-editable"; 117 | editable.checked = !this.model.is_editable; 118 | } 119 | return editable; 120 | } 121 | mk_radio() { 122 | // create editable radio button 123 | let editable = this.mk_radio_btn(true); 124 | // create editable radio button label 125 | let elabel = document.createElement("label"); 126 | elabel.htmlFor = editable.id; 127 | elabel.appendChild(document.createTextNode("Editable")); 128 | // create line break 129 | let br = document.createElement("br"); 130 | // create non editable radio button 131 | let non_edit = this.mk_radio_btn(false); 132 | // create non editable radio button label 133 | let e_nlabel = document.createElement("label"); 134 | e_nlabel.htmlFor = non_edit.id; 135 | e_nlabel.appendChild(document.createTextNode("Not Editable")); 136 | 137 | // container 138 | let div = document.createElement("div"); 139 | div.id = "text-part-switch-" + this.model.index; 140 | div.appendChild(editable); 141 | div.appendChild(elabel); 142 | div.appendChild(br); 143 | div.appendChild(non_edit); 144 | div.appendChild(e_nlabel); 145 | return div 146 | } 147 | mk_light_dir() { 148 | let plight_dir = document.createElement("p"); 149 | plight_dir.id = "light-direction-info-" + this.model.index; 150 | // xval 151 | let xval = document.createElement("span"); 152 | xval.textNode = "x: " + this.model.light_info["direction"].x; 153 | xval.id = "x-light-direction-" + this.model.index; 154 | let yval = document.createElement("span"); 155 | yval.id = "y-light-direction-" + this.model.index; 156 | yval.textNode = " y: " + this.model.light_info["direction"].y; 157 | let zval = document.createElement("span"); 158 | zval.textNode = " z: " + this.model.light_info["direction"].z; 159 | zval.id = "z-light-direction-" + this.model.index; 160 | plight_dir.appendChild(document.createTextNode("Light Direction: ")); 161 | plight_dir.appendChild(xval); 162 | plight_dir.appendChild(yval); 163 | plight_dir.appendChild(zval); 164 | return plight_dir; 165 | } 166 | mk_light_color() { 167 | let plight_color = document.createElement("p"); 168 | plight_color.id = "light-color-info-" + this.model.index; 169 | // xval 170 | let xvalc = document.createElement("span"); 171 | xvalc.textNode = "r: " + this.model.light_info["color"].r; 172 | xvalc.id = "r-light-color-" + this.model.index; 173 | let yvalc = document.createElement("span"); 174 | yvalc.textNode = " g: " + this.model.light_info["color"].g; 175 | yvalc.id = "g-light-color-" + this.model.index; 176 | let zvalc = document.createElement("span"); 177 | zvalc.textNode = " b: " + this.model.light_info["color"].b; 178 | zvalc.id = "b-light-color-" + this.model.index; 179 | plight_color.appendChild(document.createTextNode("Light Color: ")); 180 | plight_color.appendChild(xvalc); 181 | plight_color.appendChild(yvalc); 182 | plight_color.appendChild(zvalc); 183 | return plight_color; 184 | } 185 | mk_light_info() { 186 | let plight_dir = this.mk_light_dir(); 187 | // light color 188 | let plight_color = this.mk_light_color(); 189 | // 190 | let div = document.createElement("div"); 191 | div.id = "text-light-info-" + this.model.index; 192 | div.appendChild(plight_dir); 193 | div.appendChild(plight_color); 194 | return div; 195 | } 196 | mk_text_part() { 197 | let tpart = document.createElement("textarea"); 198 | tpart.id = "text-part-" + this.model.index; 199 | tpart.readOnly = true; 200 | tpart.text = this.model.text; 201 | return tpart; 202 | } 203 | to_html() { 204 | let tpart = this.mk_text_part(); 205 | let light_info = this.mk_light_info(); 206 | let radios = this.mk_radio(); 207 | // 208 | let li = document.createElement("li"); 209 | li.id = "text-part-container-" + this.model.index; 210 | li.appendChild(radios); 211 | li.appendChild(light_info); 212 | li.appendChild(tpart); 213 | return li; 214 | } 215 | to_json() { 216 | let jd = {}; 217 | jd["light_info"] = this.model.light_info; 218 | jd["text"] = this.model.text; 219 | jd["index"] = this.model.index; 220 | return jd; 221 | } 222 | } 223 | class TextPartControl { 224 | constructor(model = null, view = null) { 225 | this._model = model; 226 | this._view = view; 227 | } 228 | get model() { 229 | if (this._model === null) { 230 | throw "model is null"; 231 | } 232 | return this._model; 233 | } 234 | get view() { 235 | if (this._view === null) { 236 | throw "view is null"; 237 | } 238 | return this._view; 239 | } 240 | update_from_html(el) { 241 | let index = this.model.index; 242 | let nmodel = TextPartModel.from_html(index, el); 243 | this.view = new TextPartView(nmodel); 244 | this.model = nmodel; 245 | } 246 | static from_html(index, el) { 247 | let model = TextPartModel.from_html(index, el); 248 | let view = new TextPartView(model); 249 | return new TextPartControl(model, view); 250 | } 251 | to_html() { 252 | return this.view.to_html(); 253 | } 254 | 255 | change_light_info(x, y, z, vs, is_dir) { 256 | if (this.model.is_editable) { 257 | let vals = [] 258 | let middle; 259 | if (is_dir) { 260 | middle = "direction"; 261 | } else { 262 | middle = "color"; 263 | } 264 | for (const key in vs) { 265 | vals.push({ 266 | k: key, 267 | v: vs[key], 268 | id: key + "-light-" + middle + "-" + this.model.index 269 | }); 270 | } 271 | for (const key in vals) { 272 | let id = vals[key].id; 273 | let val = vals[key].v; 274 | let t = document.getElementById(id); 275 | if (t.firstChild) { 276 | t.removeChild(t.firstChild); 277 | } 278 | let txt = " " + vals[key].k + ": " + val; 279 | t.appendChild(document.createTextNode(txt)); 280 | } 281 | } 282 | } 283 | change_light_direction(x, y, z) { 284 | let vs = { 285 | x: x, 286 | y: y, 287 | z: z 288 | }; 289 | this.change_light_info(x, y, z, vs, true); 290 | } 291 | change_light_color(x, y, z) { 292 | let vs = { 293 | r: x, 294 | g: y, 295 | b: z 296 | }; 297 | this.change_light_info(x, y, z, vs, false); 298 | } 299 | change_text(txt) { 300 | if (this.model.is_editable) { 301 | this.model.text = txt; 302 | } 303 | } 304 | change_editable(is_editable) { 305 | this.model.is_editable = is_editable; 306 | let tarea = document.getElementById("text-part-" + this.model.index); 307 | tarea.readOnly = !is_editable; 308 | } 309 | } 310 | class TextPartWidget { 311 | constructor() { 312 | this.text_parts = []; 313 | this.id = "text-parts"; 314 | this.new_text_part(); 315 | } 316 | add_to_text_part(index) { 317 | let linfo = { 318 | "direction": { 319 | "x": null, 320 | "y": null, 321 | "z": null 322 | }, 323 | "color": { 324 | "r": null, 325 | "g": null, 326 | "b": null 327 | } 328 | }; 329 | let model = new TextPartModel(index, false, linfo, "") 330 | let view = new TextPartView(model); 331 | let control = new TextPartControl(model, view); 332 | this.text_parts.push(control); 333 | this.to_html(); 334 | } 335 | new_text_part() { 336 | this.add_to_text_part(this.text_parts.length); 337 | } 338 | add_text_editable_event(index) { 339 | let tid = this.text_parts[index].model.index; 340 | let tarea = document.getElementById("text-part-" + tid); 341 | let rid1 = "text-part-radio-" + tid + "-editable"; 342 | let rid2 = "text-part-radio-" + tid + "-not-editable"; 343 | tarea.addEventListener("change", (e) => { 344 | this.change_text_event(e); 345 | }); 346 | let rbtn1 = document.getElementById(rid1); 347 | rbtn1.addEventListener("change", (e) => { 348 | this.change_editable_event(e) 349 | }); 350 | let rbtn2 = document.getElementById(rid2); 351 | // rbtn2.addEventListener("change", this.change_editable_event); 352 | rbtn2.addEventListener("change", (e) => { 353 | this.change_editable_event(e); 354 | }); 355 | 356 | } 357 | change_text_event(e) { 358 | // change text event handle 359 | let target = e.target; 360 | let str = "text-part-"; 361 | let id = target.id; 362 | let idnb = id.slice(str.length); 363 | let tpart = this.text_parts[parseInt(idnb)]; 364 | tpart.model.text = target.text; 365 | } 366 | change_editable_event(e) { 367 | let target = e.target; 368 | let sid = target.id; 369 | let start = sid.indexOf("not-editable"); 370 | let rstr = "text-part-radio-"; 371 | let check = false; 372 | let index = null; 373 | if (start === -1) { 374 | // editable radio button 375 | if (target.checked === true) { 376 | check = target.checked === true; 377 | } 378 | let sindex = sid.indexOf("-editable"); 379 | let index_str = target.id.slice(rstr.length, sindex); 380 | index = parseInt(index_str); 381 | } else { 382 | // not editable radio button 383 | if (target.checked) { 384 | check = target.checked === false; 385 | } 386 | // 387 | let sindex = sid.indexOf("-not-editable"); 388 | let index_str = target.id.slice(rstr.length, sindex); 389 | index = parseInt(index_str); 390 | } 391 | this.text_parts[index].change_editable(check); 392 | } 393 | get_editables() { 394 | let parts = []; 395 | for (const k in this.text_parts) { 396 | if (this.text_parts[k].model.is_editable) { 397 | parts.push(k); 398 | } 399 | } 400 | return parts; 401 | } 402 | change_light_direction(x, y, z) { 403 | let eds = this.get_editables(); 404 | for (var i = 0; i < eds.length; i++) { 405 | this.text_parts[eds[i]].change_light_direction(x, y, z); 406 | } 407 | } 408 | change_light_color(x, y, z) { 409 | let eds = this.get_editables(); 410 | for (var i = 0; i < eds.length; i++) { 411 | this.text_parts[eds[i]].change_light_color(x, y, z); 412 | } 413 | } 414 | to_html() { 415 | let ul = document.getElementById(this.id); 416 | while (ul.firstChild) { 417 | ul.removeChild(ul.firstChild); 418 | } 419 | for (const k in this.text_parts) { 420 | ul.appendChild(this.text_parts[k].to_html()); 421 | } 422 | } 423 | } 424 | export { 425 | TextPartWidget 426 | } 427 | -------------------------------------------------------------------------------- /assets/js/cubescene.js: -------------------------------------------------------------------------------- 1 | // cube scene 2 | import { 3 | OrbitControls, 4 | THREE, 5 | GLTFLoader, 6 | RGBELoader, 7 | RoughnessMipmapper, 8 | OBJLoader, 9 | GUI 10 | } from "./external.js"; 11 | 12 | import { 13 | CameraWidget 14 | } from "./widget.js"; 15 | 16 | import { 17 | BaseScene, 18 | roundUp 19 | } from "./basescene.js"; 20 | 21 | class CubeScene extends BaseScene { 22 | constructor(render_zone_id = "render-zone") { 23 | super(render_zone_id); 24 | 25 | this._cube_width = 1.0; 26 | this._cube_height = 1.0; 27 | this._cube_depth = 1; 28 | this._cube = null; 29 | } 30 | check_null(obj, message) { 31 | if (obj === null) { 32 | throw message; 33 | } 34 | return obj; 35 | } 36 | get cube() { 37 | return this.check_null(this._cube, "scene cube is null"); 38 | } 39 | set cube(s) { 40 | this._cube = s; 41 | } 42 | get cube_width() { 43 | return this.check_null(this._cube_width, 44 | "cube width is null"); 45 | } 46 | set cube_width(s) { 47 | this._cube_width = s; 48 | } 49 | 50 | get cube_height() { 51 | return this.check_null(this._cube_height, 52 | "cube height is null"); 53 | } 54 | set cube_height(s) { 55 | this._cube_height = s; 56 | } 57 | 58 | get cube_depth() { 59 | return this.check_null(this._cube_depth, 60 | "cube depth is null"); 61 | } 62 | set cube_depth(s) { 63 | this._cube_depth = s; 64 | } 65 | 66 | init_materials() { 67 | const materialColor = new THREE.Color(); 68 | materialColor.setRGB(1.0, 1.0, 1.0); 69 | 70 | this.wire_material = new THREE.MeshBasicMaterial({ 71 | color: 0xFFFFFF, 72 | wireframe: true 73 | }); 74 | 75 | this.flat_material = new THREE.MeshPhongMaterial({ 76 | color: materialColor, 77 | specular: 0x000000, 78 | flatShading: true, 79 | side: THREE.DoubleSide 80 | }); 81 | 82 | this.gouraud_material = new THREE.MeshLambertMaterial({ 83 | color: materialColor, 84 | side: THREE.DoubleSide 85 | }); 86 | 87 | this.phong_material = new THREE.MeshPhongMaterial({ 88 | color: materialColor, 89 | side: THREE.DoubleSide 90 | }); 91 | 92 | // this.textured_material = new THREE.MeshPhongMaterial({ 93 | // color: materialColor, 94 | // map: textureMap, 95 | // side: THREE.DoubleSide 96 | // }); 97 | 98 | // this.reflective_material = new THREE.MeshPhongMaterial({ 99 | // color: materialColor, 100 | // envMap: textureCube, 101 | // side: THREE.DoubleSide 102 | // }); 103 | } 104 | init_renderer() { 105 | this.renderer = new THREE.WebGLRenderer({ 106 | antialias: true 107 | }); 108 | this.renderer.setPixelRatio(window.devicePixelRatio); 109 | this.renderer.setSize(this.width, this.height); 110 | this.renderer.outputEncoding = THREE.sRGBEncoding; 111 | this.render_zone.appendChild(this.renderer.domElement); 112 | } 113 | init_camera() { 114 | // specify the camera with perspective projection 115 | const aspect_ratio = this.width / this.height; 116 | const fovy = 45; 117 | const near = 0.1; 118 | const far = 500; 119 | this.camera = new CameraWidget(0, 0, -20, this.width, this.height, 120 | fovy, near, far); 121 | } 122 | 123 | init_scene() { 124 | this.scene = new THREE.Scene(); 125 | this.scene.background = new THREE.Color(0xAAAAAA); 126 | 127 | this.scene.add(this.ambient_light); 128 | this.scene.add(this.light); 129 | this.scene.add(this.light_helper); 130 | } 131 | init_light() { 132 | this.ambient_light = new THREE.AmbientLight(0x333333); // 0.2 133 | 134 | this.light = new THREE.DirectionalLight(0xFFFFFF, 1.0); 135 | this.light_helper = new THREE.DirectionalLightHelper(this.light, 1); 136 | } 137 | init() { 138 | // set up camera 139 | this.init_camera(); 140 | 141 | // set up lights 142 | this.init_light(); 143 | 144 | // set up the renderer 145 | this.init_renderer(); 146 | 147 | // camera controls 148 | this.camera_controller = new OrbitControls(this.camera.view, this.renderer.domElement); 149 | this.render_scene = this.render_scene.bind(this); 150 | this.camera_controller.addEventListener("change", this.render_scene); 151 | 152 | // MATERIALS 153 | this.init_materials(); 154 | // init scene 155 | this.init_scene(); 156 | // GUI 157 | this.setup_gui(); 158 | } 159 | 160 | set_effect_controller() { 161 | 162 | this.effect_controller = { 163 | shininess: 40.0, 164 | ka: 0.17, 165 | kd: 0.51, 166 | ks: 0.2, 167 | metallic: true, 168 | 169 | r: 0.121, 170 | g: 0.73, 171 | b: 0.66, 172 | 173 | lr: 0.04, 174 | lg: 0.01, // non-zero so that fractions will be shown 175 | lb: 1.0, 176 | 177 | // bizarrely, if you initialize these with negative numbers, the sliders 178 | // will not show any decimal places. 179 | lx: 0.32, 180 | ly: 0.39, 181 | lz: 0.7, 182 | depth: 15, 183 | width: 1.0, 184 | height: 1.0, 185 | newShading: "flat", 186 | // 187 | far: this.camera.model.far, 188 | near: this.camera.model.near, 189 | fovy: this.camera.model.fov, 190 | camera_pos_x: this.camera.model.x, 191 | camera_pos_y: this.camera.model.y, 192 | camera_pos_z: this.camera.model.z 193 | }; 194 | } 195 | 196 | create_new_cube() { 197 | if (this._cube !== null) { 198 | 199 | this._cube.geometry.dispose(); 200 | this.scene.remove(this._cube); 201 | } 202 | const cubeGeometry = new THREE.BoxGeometry(this.cube_width, this.cube_height, 203 | this.cube_depth); 204 | let mat; 205 | if (this.shading === "wireframe") { 206 | mat = this.wire_material; 207 | } else if (this.shading === "flat") { 208 | mat = this.flat_material; 209 | } else if (this.shading === "smooth") { 210 | mat = this.gouraud_material; 211 | } else if (this.shading === "glossy") { 212 | mat = this.phong_material; 213 | } else if (this.shading === "textured") { 214 | mat = this.textured_material; 215 | } else { 216 | mat = this.reflective_material; 217 | } 218 | this._cube = new THREE.Mesh( 219 | cubeGeometry, 220 | mat 221 | ); // if no match, pick Phong 222 | 223 | this.scene.add(this.cube); 224 | } 225 | 226 | update_cube() { 227 | if (this.effect_controller.width !== this.cube_width || 228 | this.effect_controller.height !== this.cube_height || 229 | this.effect_controller.depth !== this.cube_depth || 230 | this.effect_controller.newShading !== this.shading) { 231 | 232 | this.cube_width = this.effect_controller.width; 233 | this.cube_height = this.effect_controller.height; 234 | this.cube_depth = this.effect_controller.depth; 235 | this.shading = this.effect_controller.newShading; 236 | 237 | this.create_new_cube(); 238 | 239 | } 240 | } 241 | render_scene() { 242 | this.update_cube(); 243 | // this.update_camera(); 244 | 245 | // We're a bit lazy here. We could check to see if any material attributes changed and update 246 | // only if they have. But, these calls are cheap enough and this is just a demo. 247 | this.phong_material.shininess = this.effect_controller.shininess; 248 | 249 | // texturedMaterial.shininess = this.effect_controller.shininess; 250 | 251 | this.diffuse_color.setRGB(this.effect_controller.r, 252 | this.effect_controller.g, this.effect_controller.b); 253 | if (this.effect_controller.metallic) { 254 | 255 | // make colors match to give a more metallic look 256 | this.specular_color.copy(this.diffuse_color); 257 | 258 | } else { 259 | // more of a plastic look 260 | this.specular_color.setRGB(1, 1, 1); 261 | } 262 | 263 | this.diffuse_color.multiplyScalar(this.effect_controller.kd); 264 | this.flat_material.color.copy(this.diffuse_color); 265 | this.gouraud_material.color.copy(this.diffuse_color); 266 | this.phong_material.color.copy(this.diffuse_color); 267 | // texturedMaterial.color.copy(diffuseColor); 268 | 269 | this.specular_color.multiplyScalar(this.effect_controller.ks); 270 | this.phong_material.specular.copy(this.specular_color); 271 | // texturedMaterial.specular.copy(specularColor); 272 | 273 | // Ambient's actually controlled by the light for this demo 274 | this.ambient_light.color.setRGB(this.effect_controller.r, 275 | this.effect_controller.g, 276 | this.effect_controller.b * this.effect_controller.ka); 277 | 278 | let lx, ly, lz, lr, lg, lb; 279 | lx = this.effect_controller.lx; 280 | ly = this.effect_controller.ly; 281 | lz = this.effect_controller.lz; 282 | lr = this.effect_controller.lr; 283 | lg = this.effect_controller.lg; 284 | lb = this.effect_controller.lb; 285 | 286 | this.light.position.set(lx, ly, lz); 287 | this.light.color.setRGB(lr, lg, lb); 288 | 289 | this.text_w.change_light_direction( 290 | roundUp(lx, 3), 291 | roundUp(ly, 3), 292 | roundUp(lz, 3) 293 | ); 294 | this.text_w.change_light_color( 295 | roundUp(lr, 3), roundUp(lg, 3), roundUp(lb, 3) 296 | ); 297 | 298 | 299 | // skybox is rendered separately, so that it is always behind the teapot. 300 | if (this.shading === "reflective") { 301 | 302 | this.scene.background = this.texture_cube; 303 | 304 | } else { 305 | 306 | this.scene.background = null; 307 | } 308 | 309 | // update camera 310 | 311 | this.renderer.render(this.scene, this.camera.view); 312 | } 313 | 314 | set_material_coeff_menu(container) { 315 | 316 | container = this.gui.addFolder("Material control"); 317 | 318 | container.add(this.effect_controller, "shininess", 1.0, 400.0, 319 | 1.0).name("shininess").onChange(this.render_scene); 320 | container.add(this.effect_controller, "kd", 0.0, 1.0, 321 | 0.025).name("diffuse strength").onChange(this.render_scene); 322 | container.add(this.effect_controller, "ks", 0.0, 1.0, 323 | 0.025).name("specular strength").onChange(this.render_scene); 324 | container.add(this.effect_controller, 325 | "metallic").onChange(this.render_scene); 326 | } 327 | 328 | /** 329 | set material color menu 330 | */ 331 | set_material_color_menu(container) { 332 | container = this.gui.addFolder("Material color"); 333 | 334 | container.add(this.effect_controller, "r", 0.0, 1.0, 335 | 0.025).name("r").onChange(this.render_scene); 336 | container.add(this.effect_controller, "g", 0.0, 1.0, 337 | 0.025).name("g").onChange(this.render_scene); 338 | container.add(this.effect_controller, "b", 0.0, 1.0, 339 | 0.025).name("b").onChange(this.render_scene); 340 | } 341 | 342 | set_light_menu(container) { 343 | container = this.gui.addFolder("Lighting"); 344 | 345 | container.add(this.effect_controller, "lr", 0.0, 1.0, 346 | 0.025).name("r").onChange(this.render_scene); 347 | container.add(this.effect_controller, "lg", 0.0, 1.0, 348 | 0.025).name("g").onChange(this.render_scene); 349 | container.add(this.effect_controller, "lb", 0.0, 1.0, 350 | 0.025).name("b").onChange(this.render_scene); 351 | container.add(this.effect_controller, "ka", 0.0, 1.0, 352 | 0.025).name("ambient").onChange(this.render_scene); 353 | 354 | // light (directional) 355 | 356 | container = this.gui.addFolder("Light direction"); 357 | 358 | container.add(this.effect_controller, "lx", -1.0, 1.0, 359 | 0.025).name("x").onChange(this.render_scene); 360 | container.add(this.effect_controller, "ly", -1.0, 1.0, 361 | 0.025).name("y").onChange(this.render_scene); 362 | container.add(this.effect_controller, "lz", -1.0, 1.0, 363 | 0.025).name("z").onChange(this.render_scene); 364 | } 365 | 366 | set_mesh_geometry_control_menu(container) { 367 | container = this.gui.addFolder("Geometry control"); 368 | container.add(this.effect_controller, "width", 1.0, 100.0, 369 | 1.0).name("cube width").onChange(this.render_scene); 370 | container.add(this.effect_controller, "height", 1.0, 100.0, 371 | 1.0).name("cube height").onChange(this.render_scene); 372 | container.add(this.effect_controller, "depth", 1.0, 100.0, 373 | 1.0).name("cube depth").onChange(this.render_scene); 374 | } 375 | set_camera_control_menu(container) { 376 | 377 | container = this.gui.addFolder("Camera Control"); 378 | container.add(this.effect_controller, "far", 1.0, 500.0, 379 | 1.0).name("far plane distance").onChange(this.render_scene); 380 | container.add(this.effect_controller, "near", 0.001, 0.1, 381 | 0.001).name("near plane distance").onChange(this.render_scene); 382 | 383 | // 384 | // container.add(this.effect_controller, "fovy", 1, 120, 385 | // 1).name("field of view").onChange(this.render_scene); 386 | 387 | // 388 | container.add(this.effect_controller, "camera_pos_x", -this.width, this.width, 389 | 1.0).name("cam x").onChange(this.render_scene); 390 | container.add(this.effect_controller, "camera_pos_y", -this.height, this.height, 391 | 1.0).name("cam y").onChange(this.render_scene); 392 | container.add(this.effect_controller, "camera_pos_z", 393 | -this.effect_controller.far, 394 | this.effect_controller.far, 1.0).name("cam z").onChange(this.render_scene); 395 | } 396 | 397 | setup_gui() { 398 | this.set_effect_controller(); 399 | 400 | this._gui = new GUI(); 401 | 402 | let container; 403 | 404 | // material attributes 405 | this.set_material_coeff_menu(container); 406 | 407 | // material (color) 408 | this.set_material_color_menu(container); 409 | 410 | // set light menu 411 | this.set_light_menu(container); 412 | 413 | // mesh geometry control menu 414 | this.set_mesh_geometry_control_menu(container); 415 | 416 | // camera control menu 417 | // this.set_camera_control_menu(container, gui); 418 | 419 | // shading 420 | 421 | this.gui.add(this.effect_controller, 422 | "newShading", ["wireframe", "flat", 423 | "smooth", 424 | "glossy" 425 | //"textured", "reflective" 426 | ]).name("Shading").onChange(this.render_scene); 427 | } 428 | clear() { 429 | this.scene.clear(); 430 | this.gui.destroy(); 431 | } 432 | } 433 | export { 434 | CubeScene 435 | }; 436 | -------------------------------------------------------------------------------- /assets/js/meshscene.js: -------------------------------------------------------------------------------- 1 | // mesh scene 2 | import { 3 | OrbitControls, 4 | THREE, 5 | GLTFLoader, 6 | RGBELoader, 7 | RoughnessMipmapper, 8 | OBJLoader, 9 | GUI 10 | } from "./external.js"; 11 | import { 12 | CameraWidget 13 | } from "./widget.js"; 14 | 15 | import { 16 | BaseScene, 17 | roundUp 18 | } from "./basescene.js"; 19 | 20 | class MeshScene extends BaseScene { 21 | constructor(render_zone_id = "render-zone", mesh_url = null) { 22 | super(render_zone_id); 23 | this._mesh_url = mesh_url; 24 | 25 | this._effect_controller = null; 26 | 27 | 28 | this._mesh = null; 29 | 30 | } 31 | get mesh() { 32 | return this.check_null(this._mesh, "scene mesh is null"); 33 | } 34 | set mesh(s) { 35 | this._mesh = s; 36 | } 37 | 38 | get mesh_url() { 39 | return this.check_null(this._mesh_url, "mesh url null"); 40 | } 41 | 42 | init_materials() { 43 | const materialColor = new THREE.Color(); 44 | materialColor.setRGB(1.0, 1.0, 1.0); 45 | 46 | this.wire_material = new THREE.MeshBasicMaterial({ 47 | color: 0xFFFFFF, 48 | wireframe: true 49 | }); 50 | 51 | this.flat_material = new THREE.MeshPhongMaterial({ 52 | color: materialColor, 53 | specular: 0x000000, 54 | flatShading: true, 55 | side: THREE.DoubleSide 56 | }); 57 | 58 | this.gouraud_material = new THREE.MeshLambertMaterial({ 59 | color: materialColor, 60 | side: THREE.DoubleSide 61 | }); 62 | 63 | this.phong_material = new THREE.MeshPhongMaterial({ 64 | color: materialColor, 65 | side: THREE.DoubleSide 66 | }); 67 | 68 | // this.textured_material = new THREE.MeshPhongMaterial({ 69 | // color: materialColor, 70 | // map: textureMap, 71 | // side: THREE.DoubleSide 72 | // }); 73 | 74 | // this.reflective_material = new THREE.MeshPhongMaterial({ 75 | // color: materialColor, 76 | // envMap: textureCube, 77 | // side: THREE.DoubleSide 78 | // }); 79 | } 80 | init_renderer() { 81 | this.renderer = new THREE.WebGLRenderer({ 82 | antialias: true 83 | }); 84 | this.renderer.setPixelRatio(window.devicePixelRatio); 85 | this.renderer.setSize(this.width, this.height); 86 | this.renderer.outputEncoding = THREE.sRGBEncoding; 87 | this.render_zone.appendChild(this.renderer.domElement); 88 | } 89 | init_camera() { 90 | // specify the camera with perspective projection 91 | const aspect_ratio = this.width / this.height; 92 | const fovy = 45; 93 | const near = 0.1; 94 | const far = 500; 95 | this.camera = new CameraWidget(0, 0, -20, this.width, this.height, 96 | fovy, near, far); 97 | } 98 | 99 | init_scene() { 100 | this.scene = new THREE.Scene(); 101 | this.scene.background = new THREE.Color(0xAAAAAA); 102 | 103 | this.scene.add(this.ambient_light); 104 | this.scene.add(this.light); 105 | this.scene.add(this.light_helper); 106 | this.scene.add(this.mesh); 107 | } 108 | init_light() { 109 | this.ambient_light = new THREE.AmbientLight(0x333333); // 0.2 110 | 111 | this.light = new THREE.DirectionalLight(0xFFFFFF, 1.0); 112 | this.light_helper = new THREE.DirectionalLightHelper(this.light, 1); 113 | } 114 | init_mesh_obj() { 115 | const loader = new OBJLoader(); 116 | const mesh = loader.load( 117 | this.mesh_url, 118 | (obj) => { 119 | this.mesh = obj; 120 | this.init_scene(); 121 | this.render_scene(); 122 | }, 123 | (xhr) => { 124 | console.log((xhr.loaded / xhr.total * 100) + '% loaded'); 125 | }, 126 | (error) => { 127 | console.log('An error happened: ' + error); 128 | } 129 | ); 130 | } 131 | init_mesh_gltf() { 132 | const loader = new GLTFLoader(); 133 | const mesh = loader.load( 134 | this.mesh_url, 135 | (gltf) => { 136 | this.mesh = gltf.scene; 137 | this.init_scene(); 138 | this.render_scene(); 139 | }, 140 | (xhr) => { 141 | console.log((xhr.loaded / xhr.total * 100) + '% loaded'); 142 | }, 143 | (error) => { 144 | console.log('An error happened: ' + error); 145 | } 146 | ); 147 | 148 | } 149 | init_mesh() { 150 | let ext = this.mesh_url.split(".").pop(); 151 | if (ext === "gltf") { 152 | this.init_mesh_gltf(); 153 | } else if (ext === "obj") { 154 | this.init_mesh_obj(); 155 | } 156 | } 157 | init() { 158 | // set up camera 159 | this.init_camera(); 160 | 161 | // set up lights 162 | this.init_light(); 163 | 164 | // set up the renderer 165 | this.init_renderer(); 166 | 167 | // camera controls 168 | this.camera_controller = new OrbitControls(this.camera.view, this.renderer.domElement); 169 | this.render_scene = this.render_scene.bind(this); 170 | this.camera_controller.addEventListener("change", this.render_scene); 171 | 172 | // GUI 173 | this.setup_gui(); 174 | 175 | // MATERIALS 176 | this.init_materials(); 177 | 178 | // init mesh 179 | this.init_mesh(); 180 | 181 | // init scene 182 | // this.init_scene(); 183 | } 184 | 185 | set_effect_controller() { 186 | 187 | this.effect_controller = { 188 | shininess: 40.0, 189 | ka: 0.17, 190 | kd: 0.51, 191 | ks: 0.2, 192 | metallic: true, 193 | 194 | r: 0.121, 195 | g: 0.73, 196 | b: 0.66, 197 | 198 | lr: 0.04, 199 | lg: 0.01, // non-zero so that fractions will be shown 200 | lb: 1.0, 201 | 202 | // bizarrely, if you initialize these with negative numbers, the sliders 203 | // will not show any decimal places. 204 | lx: 0.32, 205 | ly: 0.39, 206 | lz: 0.7, 207 | scale_x: 1.0, 208 | scale_y: 1.0, 209 | scale_z: 1.0, 210 | rotate_axis_x: 1.0, 211 | rotate_axis_y: 1.0, 212 | rotate_axis_z: 1.0, 213 | rotate_angle: 0, 214 | translate_x: 0, 215 | translate_y: 0, 216 | translate_z: 0, 217 | apply_tfn: false, 218 | newShading: "flat", 219 | // 220 | }; 221 | } 222 | 223 | update_mesh() { 224 | const should_apply = this.effect_controller.apply_tfn; 225 | if (should_apply) { 226 | // 227 | const s_x = this.effect_controller.scale_x; 228 | const s_y = this.effect_controller.scale_y; 229 | const s_z = this.effect_controller.scale_z; 230 | // 231 | const r_x = this.effect_controller.rotate_axis_x; 232 | const r_y = this.effect_controller.rotate_axis_y; 233 | const r_z = this.effect_controller.rotate_axis_z; 234 | // 235 | const m_x = this.effect_controller.translate_x; 236 | const m_y = this.effect_controller.translate_y; 237 | const m_z = this.effect_controller.translate_z; 238 | 239 | // rotation angle 240 | let rotation_degree = this.effect_controller.rotate_angle; 241 | rotation_degree /= (2 * Math.PI); 242 | 243 | // translate -> rotate -> scale 244 | let matrix = new THREE.Matrix4(); 245 | 246 | // 247 | let rotation_vec = new THREE.Vector3(r_x, r_y, r_z); 248 | rotation_vec.normalize(); 249 | // 250 | matrix = matrix.makeRotationAxis(rotation_vec, rotation_degree); 251 | matrix.setPosition(new THREE.Vector3(m_x, m_y, m_z)); 252 | 253 | // translate -> rotation 254 | this.mesh.applyMatrix4(matrix); 255 | 256 | // scale 257 | let matrix2 = new THREE.Matrix4(); 258 | matrix2 = matrix2.makeScale(s_x, s_y, s_z); 259 | // 260 | this.mesh.applyMatrix4(matrix2); 261 | 262 | } 263 | } 264 | render_scene() { 265 | // this.update_camera(); 266 | 267 | // We're a bit lazy here. We could check to see if any material attributes changed and update 268 | // only if they have. But, these calls are cheap enough and this is just a demo. 269 | this.phong_material.shininess = this.effect_controller.shininess; 270 | 271 | // texturedMaterial.shininess = this.effect_controller.shininess; 272 | 273 | this.diffuse_color.setRGB(this.effect_controller.r, 274 | this.effect_controller.g, this.effect_controller.b); 275 | if (this.effect_controller.metallic) { 276 | 277 | // make colors match to give a more metallic look 278 | this.specular_color.copy(this.diffuse_color); 279 | 280 | } else { 281 | // more of a plastic look 282 | this.specular_color.setRGB(1, 1, 1); 283 | } 284 | 285 | this.diffuse_color.multiplyScalar(this.effect_controller.kd); 286 | this.flat_material.color.copy(this.diffuse_color); 287 | this.gouraud_material.color.copy(this.diffuse_color); 288 | this.phong_material.color.copy(this.diffuse_color); 289 | // texturedMaterial.color.copy(diffuseColor); 290 | 291 | this.specular_color.multiplyScalar(this.effect_controller.ks); 292 | this.phong_material.specular.copy(this.specular_color); 293 | // texturedMaterial.specular.copy(specularColor); 294 | 295 | // Ambient's actually controlled by the light for this demo 296 | this.ambient_light.color.setRGB(this.effect_controller.r, 297 | this.effect_controller.g, 298 | this.effect_controller.b * this.effect_controller.ka); 299 | 300 | // 301 | let lx, ly, lz, lg, lr, lb; 302 | lx = this.effect_controller.lx; 303 | ly = this.effect_controller.ly; 304 | lz = this.effect_controller.lz; 305 | lr = this.effect_controller.lr; 306 | lg = this.effect_controller.lg; 307 | lb = this.effect_controller.lb; 308 | 309 | this.light.position.set(lx, ly, lz); 310 | this.light.color.setRGB(lr, lg, lb); 311 | 312 | this.text_w.change_light_direction( 313 | roundUp(lx, 3), 314 | roundUp(ly, 3), 315 | roundUp(lz, 3) 316 | ); 317 | this.text_w.change_light_color( 318 | roundUp(lr, 3), roundUp(lg, 3), roundUp(lb, 3) 319 | ); 320 | 321 | this.shading = this.effect_controller.newShading; 322 | 323 | 324 | // update mesh 325 | this.update_mesh(); 326 | 327 | // skybox is rendered separately, so that it is always behind the teapot. 328 | if (this.shading === "reflective") { 329 | 330 | this.scene.background = this.texture_cube; 331 | 332 | } else { 333 | 334 | this.scene.background = null; 335 | } 336 | 337 | // update camera 338 | 339 | this.renderer.render(this.scene, this.camera.view); 340 | } 341 | 342 | set_material_coeff_menu(container) { 343 | 344 | container = this.gui.addFolder("Material control"); 345 | 346 | container.add(this.effect_controller, "shininess", 1.0, 400.0, 347 | 1.0).name("shininess").onChange(this.render_scene); 348 | container.add(this.effect_controller, "kd", 0.0, 1.0, 349 | 0.025).name("diffuse strength").onChange(this.render_scene); 350 | container.add(this.effect_controller, "ks", 0.0, 1.0, 351 | 0.025).name("specular strength").onChange(this.render_scene); 352 | container.add(this.effect_controller, 353 | "metallic").onChange(this.render_scene); 354 | } 355 | 356 | /** 357 | set material color menu 358 | */ 359 | set_material_color_menu(container) { 360 | container = this.gui.addFolder("Material color"); 361 | 362 | container.add(this.effect_controller, "r", 0.0, 1.0, 363 | 0.025).name("r").onChange(this.render_scene); 364 | container.add(this.effect_controller, "g", 0.0, 1.0, 365 | 0.025).name("g").onChange(this.render_scene); 366 | container.add(this.effect_controller, "b", 0.0, 1.0, 367 | 0.025).name("b").onChange(this.render_scene); 368 | } 369 | 370 | set_light_menu(container) { 371 | container = this.gui.addFolder("Lighting"); 372 | 373 | container.add(this.effect_controller, "lr", 0.0, 1.0, 374 | 0.025).name("r").onChange(this.render_scene); 375 | container.add(this.effect_controller, "lg", 0.0, 1.0, 376 | 0.025).name("g").onChange(this.render_scene); 377 | container.add(this.effect_controller, "lb", 0.0, 1.0, 378 | 0.025).name("b").onChange(this.render_scene); 379 | container.add(this.effect_controller, "ka", 0.0, 1.0, 380 | 0.025).name("ambient").onChange(this.render_scene); 381 | 382 | // light (directional) 383 | 384 | container = this.gui.addFolder("Light direction"); 385 | 386 | container.add(this.effect_controller, "lx", -1.0, 1.0, 387 | 0.025).name("x").onChange(this.render_scene); 388 | container.add(this.effect_controller, "ly", -1.0, 1.0, 389 | 0.025).name("y").onChange(this.render_scene); 390 | container.add(this.effect_controller, "lz", -1.0, 1.0, 391 | 0.025).name("z").onChange(this.render_scene); 392 | } 393 | 394 | set_mesh_geometry_control_menu(container, gui) { 395 | container = this.gui.addFolder("Geometry control"); 396 | container.add(this.effect_controller, "scale_x", 0.1, 2.0, 397 | 0.1).name("scale x"); 398 | container.add(this.effect_controller, "scale_y", 0.1, 2.0, 399 | 0.1).name("scale y"); 400 | container.add(this.effect_controller, "scale_z", 0.1, 2.0, 401 | 0.1).name("scale z"); 402 | 403 | container.add(this.effect_controller, "rotate_axis_x", 0.0, 1.0, 404 | 0.1).name("rotation axis x"); 405 | 406 | container.add(this.effect_controller, "rotate_axis_y", 0.0, 1.0, 407 | 0.1).name("rotation axis y"); 408 | 409 | container.add(this.effect_controller, "rotate_axis_z", 0.0, 1.0, 410 | 0.1).name("rotation axis z"); 411 | 412 | container.add(this.effect_controller, "rotate_angle", 0.0, 360.0, 413 | 1.0).name("rotation angle"); 414 | 415 | container.add(this.effect_controller, "translate_x", -10.0, 10.0, 416 | 1.0).name("translate x"); 417 | container.add(this.effect_controller, "translate_y", -10.0, 10.0, 418 | 1.0).name("translate y"); 419 | container.add(this.effect_controller, "translate_z", -10, 10.0, 420 | 1.0).name("translate z"); 421 | container.add(this.effect_controller, "apply_tfn", 422 | false).name("should apply"); 423 | var obj = { 424 | apply: () => { 425 | console.log("applied transformation") 426 | } 427 | } 428 | container.add(obj, "apply").name("apply").onChange(this.render_scene); 429 | } 430 | set_camera_control_menu(container, gui) { 431 | 432 | container = gui.addFolder("Camera Control"); 433 | container.add(this.effect_controller, "far", 1.0, 500.0, 434 | 1.0).name("far plane distance").onChange(this.render_scene); 435 | container.add(this.effect_controller, "near", 0.001, 0.1, 436 | 0.001).name("near plane distance").onChange(this.render_scene); 437 | 438 | // 439 | // container.add(this.effect_controller, "fovy", 1, 120, 440 | // 1).name("field of view").onChange(this.render_scene); 441 | 442 | // 443 | container.add(this.effect_controller, "camera_pos_x", -this.width, this.width, 444 | 1.0).name("cam x").onChange(this.render_scene); 445 | container.add(this.effect_controller, "camera_pos_y", -this.height, this.height, 446 | 1.0).name("cam y").onChange(this.render_scene); 447 | container.add(this.effect_controller, "camera_pos_z", 448 | -this.effect_controller.far, 449 | this.effect_controller.far, 1.0).name("cam z").onChange(this.render_scene); 450 | } 451 | setup_gui() { 452 | this.set_effect_controller(); 453 | 454 | this._gui = new GUI(); 455 | 456 | let container; 457 | 458 | // material attributes 459 | this.set_material_coeff_menu(container); 460 | 461 | // material (color) 462 | this.set_material_color_menu(container); 463 | 464 | // set light menu 465 | this.set_light_menu(container); 466 | 467 | // mesh geometry control menu 468 | this.set_mesh_geometry_control_menu(container); 469 | 470 | // camera control menu 471 | // this.set_camera_control_menu(container, gui); 472 | 473 | // shading 474 | 475 | this.gui.add(this.effect_controller, 476 | "newShading", ["wireframe", "flat", 477 | "smooth", 478 | "glossy" 479 | //"textured", "reflective" 480 | ]).name("Shading").onChange(this.render_scene); 481 | } 482 | clear() { 483 | this.scene.clear(); 484 | this.gui.destroy(); 485 | } 486 | 487 | } 488 | 489 | export { 490 | MeshScene 491 | }; 492 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------