1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-20 22:20:08 -07:00

Fix part detail template

This commit is contained in:
David Hübner 2017-03-10 23:54:10 +01:00
parent b4ba2dc85b
commit a02de20c9a
2 changed files with 10 additions and 24 deletions

View File

@ -1,19 +1,11 @@
ModelViewer = function() {
var container;
var camera, scene, cameraTarget, renderer, controls, object;
var camera, cameraTarget, scene, renderer, controls, object;
var width, height;
this.init = function(containerId) {
container = document.getElementById(containerId);
if (document.defaultView && document.defaultView.getComputedStyle) {
width = parseFloat(document.defaultView.getComputedStyle(container,null).getPropertyValue('width'));
height = parseFloat(document.defaultView.getComputedStyle(container,null).getPropertyValue('height'));
} else {
width = parseFloat(container.currentStyle.width);
height = parseFloat(container.currentStyle.height);
}
this.initScene = function($container) {
width = parseFloat($container.width());
height = parseFloat($container.height());
camera = new THREE.PerspectiveCamera(45, width/height, 0.1, 1000);
camera.position.set(-2, 2, 0.8);
@ -22,7 +14,6 @@ ModelViewer = function() {
scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x000000, 0.001);
var grid = new THREE.GridHelper( 30, 70 );
grid.position.set(30/70,-0.5,30/70);
scene.add( grid );
@ -51,14 +42,13 @@ ModelViewer = function() {
renderer.shadowMap.enabled = true;
renderer.shadowMap.renderReverseSided = false;
container.appendChild(renderer.domElement);
$container.append(renderer.domElement);
controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.addEventListener( 'change', this.render ); // add this only if there is no animation loop (requestAnimationFrame)
// controls.enableDamping = true;
// controls.dampingFactor = 0.25;
controls.enableZoom = true;
};
this.loadStl = function(model) {
@ -80,13 +70,12 @@ ModelViewer = function() {
this.animate = function() {
requestAnimationFrame( this.animate );
controls.update(); // required if controls.enableDamping = true, or if controls.autoRotate = true
this.render();
};
this.render = function() {
renderer.render(scene, camera);
};
};

View File

@ -4,10 +4,7 @@
{{ dump(part) }}
{{ dump(localPart) }}
<div id="model" style="height: 300px; width: 300px; padding: 5px; display: inline-block"></div>
<img src="{{ part.imgUrl }}">
{% endblock %}
@ -23,9 +20,9 @@
<script type="text/javascript">
window.onload = function() {
modelView = new ModelViewer();
modelView.init('model');
{% if localPart.model is defined %}
modelView.loadStl('{{ path('download_model', {'id' : localPart.model.id })}}');
var scene = modelView.initScene($('#model'));
{% if part.model is not null %}
modelView.loadStl('{{ path('download_model', {'id' : part.model.id })}}');
{% endif %}
modelView.render();
};