basicExample.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>BabylonJS Viewer - Basic usage</title>
  8. <style>
  9. </style>
  10. </head>
  11. <body>
  12. <!-- <babylon>
  13. <model normalize.unit-size="true" title="Modèle 3D" subtitle="DS STEEL" thumbnail="http://strains.fr/wp-content/uploads/2018/01/icon_3D-DESIGN.png"
  14. url="/assets/ycone2.babylon">
  15. </model>
  16. <camera behaviors.auto-rotate="0">
  17. </camera>
  18. <templates nav-bar="false" overlay="false" loading-screen="false"></templates>
  19. </babylon> -->
  20. <babylon id="viewer" templates.main.params.fill-screen="true" templates.loading-screen="false" extends="extended" model.loader=".gltf"></babylon>
  21. <div id="viewport" touch-action="none"></div>
  22. <script src="viewer.js"></script>
  23. <script>
  24. // The following lines are redundant.
  25. // They are only here to show how you could achive the tag initialization on your own.
  26. // a simple way of disabling auto init
  27. // BabylonViewer.viewerGlobals.disableInit = true;
  28. // Initializing the viewer on specific HTML tags.
  29. //BabylonViewer.InitTags('babylon');
  30. // this model - https://ugcorigin.s-microsoft.com/18/g009sv831rsm/953/003/004/08586805844133072215834575026/1521022566175.gltf
  31. // has a problem with its materials / texures. should be rendered only after onComplete
  32. // https://babylonjs.com/Assets/FlightHelmet/glTF/FlightHelmet_Materials.gltf
  33. /*var config = {
  34. extends: 'extended',
  35. model: {
  36. url: "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF/Duck.gltf",
  37. },
  38. templates: {
  39. loadingScreen: false
  40. },
  41. camera: {
  42. behaviors: {
  43. autoRotate: false,
  44. framing: false,
  45. bouncing: false
  46. }
  47. },
  48. engine: {
  49. disableResize: true
  50. }
  51. }*/
  52. var config = {
  53. extends: 'extended',
  54. // configuration: "./assets/environment/config.json",
  55. model: {
  56. url: "https://babylonjs.com/Assets/FlightHelmet/glTF/FlightHelmet_Materials.gltf",
  57. },
  58. templates: {
  59. main: {
  60. params: {
  61. fillScreen: true
  62. }
  63. }
  64. },
  65. lab: {
  66. assetsRootURL: "./assets/environment/"
  67. }
  68. }
  69. // create viewer
  70. var viewerElement = document.getElementById("viewport");
  71. // var viewer = new BabylonViewer.DefaultViewer(viewerElement, config);
  72. /*viewer.onModelLoadedObservable.add(() => {
  73. //viewer.engine.setHardwareScalingLevel(0.5);
  74. var canvas = viewer.engine.getRenderingCanvas();
  75. var filesInput = new BABYLON.FilesInput(viewer.engine, null, canvas, null);
  76. filesInput._onReloadCallback = function (modelFile) {
  77. viewer.loadModel(modelFile, true);
  78. };
  79. filesInput.monitorElementForDragNDrop(canvas);
  80. });*/
  81. /*viewer.onInitDoneObservable.add(() => {
  82. });*/
  83. BabylonViewer.viewerManager.getViewerPromiseById("viewer").then((viewer) => {
  84. viewer.onInitDoneObservable.add(() => {
  85. })
  86. document.addEventListener("keyup", (evt) => {
  87. if (evt.key === 'l')
  88. viewer.initModel("https://api.remix3d.com/v3/creations/0000000900000000801e172a00000000/gltf/streams/manifest?parameters=eyJmb3JtYXQiOiJHTFRGIiwiY2xpZW50Ijoid2ViIiwidXNhZ2UiOiJWaWV3In01");
  89. if (evt.key === 'a') {
  90. viewer.updateConfiguration({
  91. camera: {
  92. behaviors: {
  93. autoRotate: false
  94. }
  95. }
  96. })
  97. }
  98. if (evt.key === 'p') {
  99. viewer.updateConfiguration({
  100. camera: {
  101. panningSensibility: 0
  102. }
  103. })
  104. }
  105. if (evt.key === 't') {
  106. viewer.updateConfiguration()
  107. }
  108. if (evt.key === 'r') {
  109. //viewer.sceneManager.scene.registerBeforeRender(() => {
  110. viewer.updateConfiguration({
  111. lab: {
  112. globalLightRotation: 0.01
  113. }
  114. })
  115. //});
  116. }
  117. if (evt.key === 'd') {
  118. viewer.sceneManager.scene.debugLayer.show();
  119. }
  120. });
  121. })
  122. // create viewer
  123. //var viewerElement = document.getElementById("viewport");
  124. /*let config = {
  125. // any other configuration you already have
  126. model: {
  127. loader: '.gltf'
  128. }
  129. }
  130. let viewer = new BabylonViewer.DefaultViewer(viewerElement, config);*/
  131. </script>
  132. </body>
  133. </html>