Skip to content

Instantly share code, notes, and snippets.

@DefinitelyMaybe
Created April 11, 2020 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DefinitelyMaybe/c91606144574da2c5ededc35ed1624b4 to your computer and use it in GitHub Desktop.
Save DefinitelyMaybe/c91606144574da2c5ededc35ed1624b4 to your computer and use it in GitHub Desktop.
Example of rollup buble conversion.
/**
* @author mrdoob / http://mrdoob.com/
*/
var GridHelper = /*@__PURE__*/(function (LineSegments) {
function GridHelper ( size, divisions, color1, color2 ) {
size = size || 10;
divisions = divisions || 10;
color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
var center = divisions / 2;
var step = size / divisions;
var halfSize = size / 2;
var vertices = [], colors = [];
for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
vertices.push( - halfSize, 0, k, halfSize, 0, k );
vertices.push( k, 0, - halfSize, k, 0, halfSize );
var color = i === center ? color1 : color2;
color.toArray( colors, j ); j += 3;
color.toArray( colors, j ); j += 3;
color.toArray( colors, j ); j += 3;
color.toArray( colors, j ); j += 3;
}
var geometry = new BufferGeometry();
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
LineSegments.call( this, geometry, material );
this.type = 'GridHelper';
}
if ( LineSegments ) GridHelper.__proto__ = LineSegments;
GridHelper.prototype = Object.create( LineSegments && LineSegments.prototype );
GridHelper.prototype.constructor = GridHelper;
GridHelper.prototype.copy = function copy ( source ) {
LineSegments.prototype.copy.call( this, source );
this.geometry.copy( source.geometry );
this.material.copy( source.material );
return this;
};
GridHelper.prototype.clone = function clone () {
return new GridHelper().copy( this );
};
return GridHelper;
}(LineSegments));
/**
* @author mrdoob / http://mrdoob.com/
*/
import { LineSegments } from '../objects/LineSegments.js';
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
import { BufferGeometry } from '../core/BufferGeometry.js';
import { Color } from '../math/Color.js';
class GridHelper extends LineSegments {
constructor ( size, divisions, color1, color2 ) {
size = size || 10;
divisions = divisions || 10;
color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
var center = divisions / 2;
var step = size / divisions;
var halfSize = size / 2;
var vertices = [], colors = [];
for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
vertices.push( - halfSize, 0, k, halfSize, 0, k );
vertices.push( k, 0, - halfSize, k, 0, halfSize );
var color = i === center ? color1 : color2;
color.toArray( colors, j ); j += 3;
color.toArray( colors, j ); j += 3;
color.toArray( colors, j ); j += 3;
color.toArray( colors, j ); j += 3;
}
var geometry = new BufferGeometry();
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
super( geometry, material );
this.type = 'GridHelper';
}
copy ( source ) {
super.copy( source );
this.geometry.copy( source.geometry );
this.material.copy( source.material );
return this;
}
clone () {
return new GridHelper().copy( this );
}
}
export { GridHelper };
import buble from 'rollup-plugin-buble';
...
export default [
{
input: 'src/Three.js',
plugins: [
glconstants(),
glsl()
],
output: {
format: 'umd',
name: 'THREE',
file: 'build/three.js',
indent: '\t'
}
},
{
input: 'src/Three.js',
plugins: [
glconstants(),
glsl()
],
output: [
{
format: 'esm',
file: 'build/three.module.js',
indent: '\t'
}
]
},
{
input: 'src/Three.js',
plugins: [
glconstants(),
glsl(),
buble( {
transforms: {
arrow: true,
classes: true
// other transforms possible too
}
} )
],
output: {
format: 'umd',
name: 'THREE',
file: 'build/three.legacy.js',
indent: '\t'
}
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment