Skip to content

Instantly share code, notes, and snippets.

View fernandojsg's full-sized avatar

Fernando Serrano fernandojsg

View GitHub Profile
@fernandojsg
fernandojsg / spheres.js
Created September 20, 2016 13:44
Spheres brush
/* globals AFRAME THREE */
AFRAME.registerBrush('spheres', {
init: function (color, width) {
// Initialize the material based on the stroke color
this.material = new THREE.MeshStandardMaterial({
color: this.data.color,
roughness: 0.5,
metalness: 0.5,
side: THREE.DoubleSide,
shading: THREE.FlatShading
@fernandojsg
fernandojsg / example.json
Last active August 15, 2017 08:59
GLTF three.js example
{
"asset": {
"version": "2.0",
"generator": "THREE.JS GLTFExporter"
},
"scenes": [
{
"nodes": [
0,
1,
@fernandojsg
fernandojsg / gltf_bookmarklet.js
Last active September 1, 2017 13:54
THREE.js and AFRAME glTF exporter bookmarklet
javascript:(function(){
var link = document.createElement( 'a' ); link.style.display = 'none'; document.body.appendChild( link );
function save( blob, filename ) { link.href = URL.createObjectURL( blob ); link.download = filename; link.click(); }
function saveString( text, filename ) { save( new Blob( [ text ], { type: 'application/json' } ), filename );}
var script=document.createElement('script');
script.src='https://threejs.org/examples/js/exporters/GLTFExporter.js';
script.onload = function () {
var exporter = new THREE.GLTFExporter();
@fernandojsg
fernandojsg / timer.js
Last active April 5, 2018 15:53
Timing
//-----------------------------------------------------------------------------
// Loop measuring delta and total time with perf.now()
//-----------------------------------------------------------------------------
var prevTime = performance.now();
var total = 0;
for (var i=0;i< 1000; i++) {
var newTime = performance.now();
var delta = newTime - prevTime;
total += delta;
prevTime = newTime;
function existsInArray(array, items) {
var all = true;
for (i = 0; i < items.length; i++) {
all &= array.indexOf(items[i]) !== -1;
}
return all;
}
if (!existsInArray(['a', 'c'], ['c'])) {
@fernandojsg
fernandojsg / ecsy.code-snippets
Last active June 21, 2019 18:58
ECSY code snippets for VSCode
{
"ECSY System": {
"scope": "javascript",
"prefix": "sys",
"body": [
"export class ${1:SystemName} extends System {",
" init() {",
" return {",
" queries: {",
" ${2:entities}: { components: [${3:Component}] }",
@fernandojsg
fernandojsg / datatypes.js
Created July 31, 2019 15:29
datatypes example
class Vector3 {
constructor(x, y, z) {
this.set(x,y,z);
}
copy(src) {
this.x = src.x;
this.y = src.y;
this.z = src.z;
}
@fernandojsg
fernandojsg / custom-elements-demo.html
Last active August 12, 2019 16:53
Immersive custom elements demo
<html>
<head>
<script src="https://rawcdn.githack.com/MozillaReality/immersive-custom-elements/v0.1.0/build/immersive-custom-elements.js"></script>
</head>
<body>
<img-360 src="360-landscape.jpg" width="640" height="360"></img-360>
<video-360 src="myvideo.mp4" width="640" height="360"></video-360>
</body>
</html>
@fernandojsg
fernandojsg / components.js
Last active August 27, 2019 23:39
Ways to create a component
var entity = world.createEntity();
// 0
var component = entity.addComponent(ComponentB);
component.value = 23;
component.other = 'test',
// 1
entity.addComponent(ComponentA);
entity.addComponent(ComponentB, {value: 23, other: 'test'});
@fernandojsg
fernandojsg / ecsy-devtools.js
Created November 7, 2019 10:49
ECSY devtools
setInterval(() => window.dispatchEvent(new CustomEvent('refreshData', { 'detail':
{
"world": {
"enabled": true
},
"lastExecutedSystem": "RendererSystem",
"numEntities": 18,
"systems": [
{
"name": "EnvironmentSystem",