From 88c443b4ed8cc1c2373f7964cf703134728820b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=BCbner?= Date: Sat, 8 Apr 2017 11:24:20 +0200 Subject: [PATCH] Add 3D view toggle --- app/Resources/assets/js/ModelViewer.js | 114 ++++++++++++++------ app/Resources/assets/style/modelviewer.scss | 25 +++++ app/Resources/assets/style/style.scss | 1 + app/Resources/views/model/detail.html.twig | 74 ++++++------- app/config/config.yml | 18 +++- gulpfile.js | 3 +- 6 files changed, 159 insertions(+), 76 deletions(-) create mode 100644 app/Resources/assets/style/modelviewer.scss diff --git a/app/Resources/assets/js/ModelViewer.js b/app/Resources/assets/js/ModelViewer.js index 5604ee2..adc096d 100644 --- a/app/Resources/assets/js/ModelViewer.js +++ b/app/Resources/assets/js/ModelViewer.js @@ -1,45 +1,75 @@ -var ModelViewer = function($container) { +var ModelViewer = function($dom_element) { var $this = this; - this.container = $container; + this.container = document.createElement('div'); + + this.dom_element = $dom_element; + + $dom_element.append(this.container); + this.container.style.display = "none"; this.camera = null; this.scene = null; this.renderer = null; this.controls = null; this.object = null; - this.width = parseFloat(this.container.width()); - this.height = parseFloat(this.container.height()); + this.width = parseFloat($dom_element.width()); + this.height = parseFloat($dom_element.height()); this.visible = true; + this.stats = null; this.scale = 1; + this.wireframe = false; + this.rendering = false; + this.initHtml(); this.initScene(); function renderLoop() { - requestAnimationFrame( renderLoop ); - $this.render(); + requestAnimationFrame(renderLoop); + if($this.rendering) { + $this.render(); + } + $this.stats.update(); } renderLoop(); }; +ModelViewer.prototype.initHtml = function () { + $this = this; + + var buttons = document.createElement("div"); + buttons.setAttribute("class", "modelviewer-buttons"); + + var toggleButton = $('