Style article page

This commit is contained in:
Patrick Neff 2019-05-03 21:33:49 +02:00
parent 813b3b36c6
commit b1f9003379
6 changed files with 145 additions and 57 deletions

View File

@ -6,6 +6,9 @@ type = "catalog"
alt = "Urnengrababdeckung mit Umrandung" alt = "Urnengrababdeckung mit Umrandung"
material = "PP4, poliert" material = "PP4, poliert"
article_id = "0001" article_id = "0001"
ornament = "Kreuz"
description = "Hallo Welt"
offer = "/aktionen/preisbeispiel-urnengrab-2019/"
used_for = ["Urnengrab"] used_for = ["Urnengrab"]
keywords = [] keywords = []

View File

@ -3,16 +3,9 @@
{{- end -}} {{- end -}}
{{- define "main" -}} {{- define "main" -}}
<main id="single"> <main class="catalog" id="single">
<article> <article>
{{- partial "single.html" . -}} {{- partial "catalog-article.html" . -}}
<div class="flex column">
<div class="padding">
{{ with .Resources.GetMatch "model/*.glb" }}
<model-viewer model-url="{{ .RelPermalink }}"></model-viewer>
{{ end }}
</div>
</div>
</article> </article>
</main> </main>
{{- end -}} {{- end -}}

View File

@ -0,0 +1,26 @@
<header class="flex column padding">
<h1>{{ .Title }}</h1>
</header>
<div class="content flex column">
<div class="padding">
{{ with .Resources.GetMatch "model/*.glb" }}
<div class="left" id="model-viewer">
<model-viewer model-url="{{ .RelPermalink }}"></model-viewer>
</div>
{{ else }}
{{- with .Resources.GetMatch "bilder/*" -}}
{{- $orig := . -}}
{{ partial "figure.html" (dict "ctx" . "image" . "lightbox" true "class" "featured left" "showTitle" false "showDescription" false)}}
{{- end -}}
{{- end -}}
<p class="type">Typ: {{ range $index, $value := .Params.used_for }}{{ if $index }}, {{end}}{{ . }}{{end}}</p>
{{ with .Params.material }}<p class="material">Material: {{ . }}</p>{{ end }}
{{ with .Params.offer }}<p class="offer"><a href="{{ . }}">Angebot</a></p>{{ end }}
{{ with .Params.ornament }}<p class="ornament">Ornament: {{ . }}</p>{{ end }}
{{ with .Params.description }}<p class="description">{{ . }}</p>{{ end }}
<p class="article-id">Art. Nr.: {{ .Params.article_id }}</p>
{{ with .Content }}
{{ . }}
{{ end }}
</div>
</div>

View File

@ -270,9 +270,13 @@ figure.small {
} }
} }
figure.left { .left {
float: left; float: left;
margin-right: $gutter-width; margin-right: $gutter-width;
}
figure.left {
margin-right: $gutter-width;
max-width: $min-column-width; max-width: $min-column-width;
padding: 0.5rem 0; padding: 0.5rem 0;
float: left float: left
@ -420,3 +424,15 @@ a.btn-primary {
canvas { canvas {
background: white; background: white;
} }
#model-viewer{
width: $min-column-width;
height: $min-column-width;
}
@media screen and (min-width: 500px) {
#model-viewer{
width: $min-column-width-desktop;
height: $min-column-width-desktop;
}
}

View File

@ -54,3 +54,18 @@
max-width: $min-column-width-desktop; max-width: $min-column-width-desktop;
} }
} }
.catalog {
p {
font-size: 1.2rem;
&.material {
font-weight: bold
}
&.type {
font-style: italic;
}
&.article-id {
font-size: 1rem;
}
}
}

View File

@ -1,7 +1,5 @@
<template> <template>
<div> <canvas ref="renderer"></canvas>
<canvas id="model-viewer" ref="renderer"></canvas>
</div>
</template> </template>
<script> <script>
@ -22,47 +20,79 @@ export default {
data() { data() {
return { return {
renderer: null, renderer: null,
size: { }
w: 800,
h: 600,
}, },
computed: {
size() {
return {
w: document.getElementById('model-viewer').offsetWidth,
h: document.getElementById('model-viewer').offsetHeight,
}
} }
}, },
mounted() { mounted() {
var scene, camera, renderer this.setup()
renderer = this.renderer = new WebGLRenderer({canvas: this.$refs.renderer, antialias: true}) this.loadGltf(this.modelUrl)
this.renderer.setClearColor(0xffffff) },
this.renderer.setSize(this.size.w, this.size.h) methods: {
this.renderer.gammaOutput = true; setup() {
this.renderer.gammaFactor = 2.2 this.setupCamera()
this.renderer.toneMapping = LinearToneMapping; this.setupScene()
this.renderer.toneMappingExposure = Math.pow( 0.94, 5.0 ); this.setupRenderer()
this.renderer.shadowMap.enabled = true; this.setupLight()
this.renderer.shadowMap.type = PCFShadowMap; this.setupControls()
scene = this.scene = new Scene() },
setupControls() {
var controls = new OrbitControls( this.camera, this.renderer.domElement );
controls.addEventListener( 'change', this.render ); // call this only in static scenes (i.e., if there is no animation loop)
controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
controls.dampingFactor = 0.25;
controls.screenSpacePanning = false;
controls.minDistance = 1.1;
controls.maxDistance = 1.1;
controls.minPolarAngle = Math.PI / 4;
controls.maxPolarAngle = Math.PI - Math.PI / 4;
controls.minAzimuthAngle = -(Math.PI / 4);
controls.maxAzimuthAngle = Math.PI / 4;
},
setupScene() {
this.scene = new Scene()
},
getWidth() {
return document.getElementById('model-viewer').offsetWidth
},
getHeight() {
return document.getElementById('model-viewer').offsetHeight
},
getAspectRatio() {
return this.getWidth() / this.getHeight()
},
setupCamera() {
this.camera = new PerspectiveCamera(60, this.getAspectRatio(), 0.1, 300)
this.camera.position.z = 1.1;
this.camera.position.y = .3
},
setupLight() {
var directionalLight = new DirectionalLight(0xffffff, 1) var directionalLight = new DirectionalLight(0xffffff, 1)
directionalLight.position.set(-3, 20 ,-1000) directionalLight.position.set(-3, 20 ,-1000)
this.scene.add(directionalLight) this.scene.add(directionalLight)
var directionalLight2 = new DirectionalLight(0xffffff, 1) var directionalLight2 = new DirectionalLight(0xffffff, 1)
directionalLight2.position.set(-3, 20 ,100) directionalLight2.position.set(-3, 20 ,100)
this.scene.add(directionalLight2) this.scene.add(directionalLight2)
camera = this.camera = new PerspectiveCamera(60, this.size.w/this.size.h, 0.1, 300)
this.camera.position.z = 1.1;
this.camera.position.y = .3
this.loadGltf(this.modelUrl)
var controls = new OrbitControls( camera, renderer.domElement );
controls.addEventListener( 'change', this.render ); // call this only in static scenes (i.e., if there is no animation loop)
controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
controls.dampingFactor = 0.25;
controls.screenSpacePanning = false;
controls.minDistance = 1.1;
controls.maxDistance = 2;
controls.minPolarAngle = Math.PI / 4;
controls.maxPolarAngle = Math.PI - Math.PI / 4;
controls.minAzimuthAngle = -(Math.PI / 4);
controls.maxAzimuthAngle = Math.PI / 4;
}, },
methods: { setupRenderer() {
this.renderer = new WebGLRenderer({canvas: this.$refs.renderer, antialias: true, alpha: true})
this.renderer.setClearColor(0xffffff)
this.renderer.setClearAlpha(0)
this.renderer.setSize(this.getWidth(), this.getHeight())
this.renderer.gammaOutput = true;
this.renderer.gammaFactor = 2.2
this.renderer.toneMapping = LinearToneMapping;
this.renderer.toneMappingExposure = Math.pow( 0.94, 5.0 );
this.renderer.shadowMap.enabled = true;
this.renderer.shadowMap.type = PCFShadowMap;
window.addEventListener('resize', this.setCanvasSize)
},
loadObjMtl(objPath, mtlPath) { loadObjMtl(objPath, mtlPath) {
var objLoader = new OBJLoader() var objLoader = new OBJLoader()
objLoader.setPath('/') objLoader.setPath('/')
@ -83,21 +113,26 @@ export default {
var gltfLoader = new GLTFLoader() var gltfLoader = new GLTFLoader()
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
gltfLoader.load(gltfPath, gltf => resolve(gltf), undefined, error => reject(error)) gltfLoader.load(gltfPath, gltf => resolve(gltf), undefined, error => reject(error))
}).then(gltf => { })
console.log(gltf) .then(gltf => {
this.readGLTF(gltf)
})
.catch(error => console.log(error))
},
readGLTF(gltf) {
gltf.scene.position.x = -0.5 gltf.scene.position.x = -0.5
gltf.scene.rotation.set(0, 0, 0) gltf.scene.rotation.set(0, 0, 0)
this.scene.add(gltf.scene) this.scene.add(gltf.scene)
this.render() this.render()
}).catch(error => console.log(error))
},
addObject(object) {
this.scene.add(object)
}, },
readGLB(gltf) { readGLB(gltf) {
this.addObject(gltf.scene) this.addObject(gltf.scene)
this.render() this.render()
}, },
setCanvasSize() {
this.renderer.setSize(this.getWidth(), this.getHeight())
this.camera.aspepct = this.getAspectRatio()
},
render() { render() {
requestAnimationFrame(this.render) requestAnimationFrame(this.render)
this.renderer.render(this.scene, this.camera) this.renderer.render(this.scene, this.camera)