Skip to content

Commit

Permalink
load font
Browse files Browse the repository at this point in the history
  • Loading branch information
torinmb committed Jun 15, 2019
1 parent e5c3057 commit f961f50
Show file tree
Hide file tree
Showing 12 changed files with 1,127 additions and 10 deletions.
1 change: 1 addition & 0 deletions fonts/Helvetica-msdf.json

Large diffs are not rendered by default.

Binary file added fonts/Helvetica.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
865 changes: 865 additions & 0 deletions fonts/Helvetica2.json

Large diffs are not rendered by default.

Binary file added fonts/Helvetica2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fonts/msdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@
<link rel="shortcut icon" href="/manifest/favicon.ico">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta charset="UTF-8">
<style>
body {
margin: 0px;
}
</style>
</head>
<body>

<!--
To configure starting state of the checkbox from markup:
<renderer pie="true">
-->

<las-renderer spSculptureId="-LMyIqwl4kMxIUlMoj0p">
<las-renderer spSculptureId="-LhN4h_eCne8kYRnnc42">
<!-- Placeholders to improve time to first paint -->

<!-- Check for JavaScript -->
Expand Down
228 changes: 228 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@webcomponents/webcomponentsjs": "latest",
"lit-element": "latest",
"load-bmfont": "^1.4.0",
"three": "^0.105.2"
}
}
10 changes: 6 additions & 4 deletions src/Sculpture.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { defaultVertexSource, sculptureStarterCode, fragFooter} from './core-gls
import { sketch } from './sketch.js'

export class Sculpture {
constructor(size, sculptureData) {
constructor(size, fontTexture, sculptureData) {
this.size = size
this.vertexShader = defaultVertexSource;

this.fontTexture = fontTexture;
// this.geometry = new THREE.BoxGeometry(size, size, size);
let fragSource = sculptureStarterCode;
if(sculptureData) {
Expand All @@ -16,7 +16,8 @@ export class Sculpture {
}
this.fragmentShader = fragSource;
fragSource += fragFooter;
this.geometry = new THREE.SphereBufferGeometry(size, 400, 400);
this.geometry = new THREE.BoxBufferGeometry(1.0, 1.0, 1.0);
// this.geometry = new THREE.SphereBufferGeometry(size, 400, 400);
this.mesh = new THREE.Mesh(
this.geometry,
this.generateMaterial(defaultVertexSource, fragSource)
Expand Down Expand Up @@ -51,7 +52,8 @@ export class Sculpture {
stepSize: { value: 0.8 },
size: { value: this.size },
raySize: { value: this.raySize },
minStep: { value: this.minStep }
minStep: { value: this.minStep },
msdf: { value: this.fontTexture }
},
vertexShader,
fragmentShader: fragmentShader,
Expand Down
13 changes: 13 additions & 0 deletions src/loadFont.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as THREE from 'three';
import * as loadFont from 'load-bmfont'

// A utility to load a font, then a texture
export const loadFonts = (opt, cb) => {
console.log(loadFont);
loadFont.default(opt.font, function (err, font) {
if (err) throw err
THREE.ImageUtils.loadTexture(opt.image, undefined, function (tex) {
cb(font, tex)
})
})
};
4 changes: 3 additions & 1 deletion src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import {renderScene} from './there-scene.js'
import { LitElement, html } from 'lit-element';
// import {loadFonts} from './loadFont.js';

export class StartLitElement extends LitElement {

Expand Down Expand Up @@ -43,6 +44,7 @@ export class StartLitElement extends LitElement {
<style>
:host { display: block; }
:host([hidden]) { display: none; }
canvas {
height: 100vh;
}
Expand All @@ -61,7 +63,7 @@ export class StartLitElement extends LitElement {
console.log('spSculptureId', this.spSculptureId);
const canvasEl = this.shadowRoot.getElementById('container');
if (this.spSculptureId) {
console.log('getting Sculp');
console.log('getting SC')
fetch(`https://shader-park-core.firebaseio.com/sculptures/${this.spSculptureId}.json`)
.then(res => res.json())
.then(data => renderScene(canvasEl, data));
Expand Down
7 changes: 4 additions & 3 deletions src/there-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { Sculpture } from './Sculpture.js'
export const renderScene = (container, sculptureData) => {
// const container = document.querySelector('.container');
const scene = new THREE.Scene();

const texture = new THREE.TextureLoader().load('fonts/msdf.png');
const camera = new THREE.PerspectiveCamera(35, container.clientWidth / container.clientHeight, 1, 1000);
camera.position.set(0, 0, 5);
camera.position.set(0, 0, 2);

const raycaster = new THREE.Raycaster();

const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
// renderer.setClearColor('0x000000');
// render.setClearColor('0x000000');
renderer.setSize(container.clientWidth, container.clientHeight);
renderer.setPixelRatio(window.devicePixelRatio);
Expand All @@ -30,7 +31,7 @@ export const renderScene = (container, sculptureData) => {
document.addEventListener('mousemove', onDocumentMouseMove, false);

let objectsToRaycast = [];
let sculpture = new Sculpture(1, sculptureData);
let sculpture = new Sculpture(1, texture, sculptureData);
scene.add(sculpture.mesh);
objectsToRaycast.push(sculpture.mesh);

Expand Down

0 comments on commit f961f50

Please sign in to comment.