|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <title>klee.js - drag on ground</title> |
| 5 | + <meta charset="utf-8"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 7 | + <link rel="stylesheet" href="css/styles.css" /> |
| 8 | + </head> |
| 9 | + <body> |
| 10 | + |
| 11 | + <script type="importmap"> |
| 12 | + { |
| 13 | + "imports": { |
| 14 | + "three": "./libs/three.module.min.js", |
| 15 | + "klee": "./../dist/klee.js" |
| 16 | + } |
| 17 | + } |
| 18 | + </script> |
| 19 | + |
| 20 | + <script type="module"> |
| 21 | + |
| 22 | + import * as THREE from 'three'; |
| 23 | + import { OrbitControls } from './libs/jsm/controls/OrbitControls.js'; |
| 24 | + import * as KLEE from 'klee'; |
| 25 | + |
| 26 | + // for preloading wrap all in an async function |
| 27 | + (async () => { |
| 28 | + |
| 29 | + // some opinionated default options declared in /src/default.options.js |
| 30 | + // you can overwrite these here or add additional options |
| 31 | + const options = { |
| 32 | + |
| 33 | + debugLevel: 3, |
| 34 | + |
| 35 | + renderer: { |
| 36 | + clearColor: '#103c48' |
| 37 | + }, |
| 38 | + |
| 39 | + camera: { |
| 40 | + properties: { |
| 41 | + position: { x: -2, z: 10 } |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + }; |
| 46 | + |
| 47 | + const orbitControlsOptions = { |
| 48 | + // no type and args here, we need the object direct |
| 49 | + // and args (camera, renderElement are given) |
| 50 | + properties: { |
| 51 | + //autoRotate: true, |
| 52 | + enableDampling: true, |
| 53 | + enablePan: true, |
| 54 | + dampingFactor: 0.25, |
| 55 | + enableZoom: true, |
| 56 | + minDistance: 5, |
| 57 | + maxDistance: 30, |
| 58 | + minPolarAngle: 0.1, |
| 59 | + maxPolarAngle: 1.5 |
| 60 | + } |
| 61 | + |
| 62 | + }; |
| 63 | + |
| 64 | + const lights = [ |
| 65 | + { |
| 66 | + type: 'AmbientLight', |
| 67 | + properties: { |
| 68 | + name: 'light-1', |
| 69 | + intensity: 2, |
| 70 | + color: '#404040' |
| 71 | + } |
| 72 | + }, |
| 73 | + { |
| 74 | + type: 'DirectionalLight', |
| 75 | + properties: { |
| 76 | + name: 'light-2', |
| 77 | + color: '#ffffff', |
| 78 | + intensity: 3, |
| 79 | + castShadow: true, |
| 80 | + shadow: { mapSize: { x: 2048, y: 2048 } }, // INFO: x,y instead of width, height |
| 81 | + position: { x: 30, y: 30, z: 30 } |
| 82 | + } |
| 83 | + }, |
| 84 | + { |
| 85 | + type: 'DirectionalLight', |
| 86 | + properties: { |
| 87 | + name: 'light-3', |
| 88 | + color: '#ffffff', |
| 89 | + intensity: 1, |
| 90 | + position: { x: -30, y: 30, z: -30 } |
| 91 | + } |
| 92 | + } |
| 93 | + ]; |
| 94 | + |
| 95 | + const items = [ // aka meshs |
| 96 | + { |
| 97 | + geometry: { |
| 98 | + type: 'PlaneGeometry', |
| 99 | + args: [16, 16] |
| 100 | + }, |
| 101 | + material: { |
| 102 | + type: 'MeshStandardMaterial', |
| 103 | + properties: { |
| 104 | + color: '#103c48' |
| 105 | + }, |
| 106 | + }, |
| 107 | + properties: { |
| 108 | + receiveShadow: true, |
| 109 | + rotation: { x: Math.PI / -2 }, |
| 110 | + name: 'Floor', |
| 111 | + userData: { |
| 112 | + movingLimiter: true |
| 113 | + } |
| 114 | + } |
| 115 | + }, |
| 116 | + { |
| 117 | + group: 'BoxGroup', |
| 118 | + geometry: { |
| 119 | + type: 'BoxGeometry', |
| 120 | + args: [1, 1, 1] |
| 121 | + }, |
| 122 | + material: { |
| 123 | + type: 'MeshStandardMaterial', |
| 124 | + textures: [ |
| 125 | + { |
| 126 | + map: 'map', |
| 127 | + url: './textures/Wood060_1K_Color.jpg' |
| 128 | + }, |
| 129 | + { |
| 130 | + map: 'normalMap', |
| 131 | + url: './textures/Wood060_1K_Normal.jpg', |
| 132 | + properties: { |
| 133 | + flipY: false |
| 134 | + } |
| 135 | + }, |
| 136 | + { |
| 137 | + map: 'roughnessMap', |
| 138 | + url: './textures/Wood060_1K_Roughness.jpg' |
| 139 | + }, |
| 140 | + { |
| 141 | + map: 'aoMap', |
| 142 | + url: './textures/Wood060_1K_AmbientOcclusion.jpg' |
| 143 | + }, |
| 144 | + { |
| 145 | + map: 'bumpMap', |
| 146 | + url: './textures/Wood060_1K_Displacement.jpg' |
| 147 | + } |
| 148 | + ] |
| 149 | + }, |
| 150 | + properties: { |
| 151 | + name: 'some box 1', |
| 152 | + rotation: { y: Math.PI / 8 }, |
| 153 | + position: { x: -0.5, y: 0.5, z: -0.5 }, |
| 154 | + castShadow: true, |
| 155 | + receiveShadow: true, |
| 156 | + userData: { |
| 157 | + draggable: true, |
| 158 | + dragMaterial: { |
| 159 | + type: 'MeshStandardMaterial', |
| 160 | + properties: { |
| 161 | + color: 0xfa5750, |
| 162 | + transparent: true, |
| 163 | + opacity: 0.6 |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + }, |
| 169 | + { |
| 170 | + cloneOf: 'some box 1', |
| 171 | + group: 'BoxGroup', |
| 172 | + properties: { |
| 173 | + name: 'some box 2', |
| 174 | + rotation: { y: Math.PI / 3 }, |
| 175 | + position: { x: 0.75, y: 1.5, z: -0.5 }, |
| 176 | + castShadow: true, |
| 177 | + receiveShadow: true, |
| 178 | + userData: { |
| 179 | + draggable: true, |
| 180 | + dragMaterial: { |
| 181 | + type: 'MeshStandardMaterial', |
| 182 | + properties: { |
| 183 | + color: 0x104830, |
| 184 | + transparent: true, |
| 185 | + opacity: 0.6 |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + } |
| 190 | + } |
| 191 | + ]; |
| 192 | + |
| 193 | + const gridHelper = { |
| 194 | + type: 'GridHelper', |
| 195 | + args: [50, 50, '#72898f', '#72898f'] |
| 196 | + }; |
| 197 | + |
| 198 | + // initalize app |
| 199 | + KLEE.App.init(THREE, options); |
| 200 | + |
| 201 | + // initalize scene |
| 202 | + KLEE.Scene.init(); |
| 203 | + |
| 204 | + // optional controls |
| 205 | + KLEE.Controls.init(OrbitControls, orbitControlsOptions); |
| 206 | + |
| 207 | + // optional events |
| 208 | + KLEE.Events.init(); |
| 209 | + |
| 210 | + // shed some light |
| 211 | + KLEE.Light.add(lights); |
| 212 | + |
| 213 | + // add a boxes |
| 214 | + KLEE.Item.add(items); |
| 215 | + |
| 216 | + // add a grid |
| 217 | + KLEE.Object3d.add(gridHelper); |
| 218 | + |
| 219 | + // run the app after loading |
| 220 | + KLEE.App.manager.onLoad = () => KLEE.App.run(); |
| 221 | + |
| 222 | + // inspect the scene in console |
| 223 | + console.log(KLEE.App.scene.getObjectByName('BoxGroup')); |
| 224 | + |
| 225 | + })(); |
| 226 | + |
| 227 | + </script> |
| 228 | + |
| 229 | + </body> |
| 230 | +</html> |
0 commit comments