|
1 | 1 | <div class="card">
|
2 |
| - <div class="card-image" id="{{ include.id }}" style="height: 200px; width: 500px;"> |
3 |
| - </div> |
| 2 | + <canvas class="card-image" id="{{ include.id }}" style="height: 200px; width: 500px;"> |
| 3 | + </canvas> |
4 | 4 | <div class="card-content">
|
5 | 5 | <div class="content">
|
6 | 6 | {{ include.content }}
|
7 | 7 | </div>
|
8 | 8 | </div>
|
9 | 9 | </div>
|
10 | 10 |
|
11 |
| -<script> |
12 |
| - {{ include.id }}element = document.getElementById("{{ include.id }}") |
13 |
| - scene{{ include.id }} = new THREE.Scene(); |
14 |
| - scene{{ include.id }}.background = new THREE.Color( 0x555555 ); |
15 |
| - renderer{{ include.id }} = new THREE.WebGLRenderer( { antialias: true } ); |
16 |
| - renderer{{ include.id }}.setSize(200,500); |
17 |
| - renderer{{ include.id }}.setPixelRatio( window.devicePixelRatio ) |
18 |
| - {{ include.id }}element.appendChild( renderer{{ include.id }}.domElement ); |
19 |
| - const camera{{ include.id }} = new THREE.PerspectiveCamera( 60, 500/ 300, 0.01, 1000 ); |
20 |
| - camera{{ include.id }}.position.set( 0, 1, 5 ) |
21 |
| - const geometry{{ include.id }} = new THREE.BoxGeometry( 1, 1, 1 ); |
22 |
| - const material{{ include.id }} = new THREE.MeshBasicMaterial( { color: 0x00ff00 } ); |
23 |
| - const cube{{ include.id }} = new THREE.Mesh( geometry{{ include.id }}, material{{ include.id }} ); |
24 |
| - scene{{ include.id }}.add( cube{{ include.id }} ); |
25 |
| - |
26 |
| - camera{{ include.id }}.position.z = 5; |
27 |
| - |
28 |
| - function animate() { |
29 |
| - |
30 |
| - cube{{ include.id }}.rotation.x += 0.01; |
31 |
| - cube{{ include.id }}.rotation.y += 0.01; |
32 |
| - renderer{{ include.id }}.render( scene{{ include.id }}, camera{{ include.id }} ); |
33 |
| - |
34 |
| - } |
35 |
| -</script> |
| 11 | + |
| 12 | +<script src="https://cdn.babylonjs.com/babylon.js"></script> |
| 13 | + |
| 14 | +<script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script> |
| 15 | + |
| 16 | +<script src="https://code.jquery.com/pep/0.4.3/pep.js"></script> |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + <!-- touch-action="none" for best results from PEP --> |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + <script> |
| 25 | + |
| 26 | + const canvas{{ include.id }} = document.getElementById("{{ include.id }}"); // Get the canvas element |
| 27 | + |
| 28 | + const engine{{ include.id }} = new BABYLON.Engine(canvas{{ include.id }}, true); // Generate the BABYLON 3D engine |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + // Add your code here matching the playground format |
| 33 | + |
| 34 | + |
| 35 | + const canvas = document.getElementById("renderCanvas"); // Get the canvas element |
| 36 | + |
| 37 | + const engine = new BABYLON.Engine(canvas, true); // Generate the BABYLON 3D e |
| 38 | + |
| 39 | + // Add your code here matching the playground format |
| 40 | + |
| 41 | + const createScene = function () { |
| 42 | + |
| 43 | + const scene = new BABYLON.Scene(engine); |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + BABYLON.SceneLoader.ImportMeshAsync("", "https://assets.babylonjs.com/meshes/", "box.babylon"); |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + const camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, 15, new BABYLON.Vector3(0, 0, 0)); |
| 52 | + |
| 53 | + camera.attachControl(canvas, true); |
| 54 | + |
| 55 | + const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(1, 1, 0)); |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + return scene; |
| 60 | + |
| 61 | + }; |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + // Register a render loop to repeatedly render the scene |
| 67 | + |
| 68 | + engine{{ include.id }}.runRenderLoop(function () { |
| 69 | + |
| 70 | + scene{{ include.id }}.render(); |
| 71 | + |
| 72 | + }); |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + // Watch for browser/canvas resize events |
| 77 | + |
| 78 | + window.addEventListener("resize", function () { |
| 79 | + |
| 80 | + engine{{ include.id }}.resize(); |
| 81 | + |
| 82 | + }); |
| 83 | + |
| 84 | + </script> |
| 85 | + |
| 86 | + |
0 commit comments