Skip to content

Instantly share code, notes, and snippets.

@tommasoturchi
Created October 21, 2017 15:33
Show Gist options
  • Save tommasoturchi/0922a6b5eaa2192be20e28604c200286 to your computer and use it in GitHub Desktop.
Save tommasoturchi/0922a6b5eaa2192be20e28604c200286 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
import {App, Sphere} from '../src/index';
import {MeshBasicMaterial} from 'three';
import {
ElementModule,
SceneModule,
CameraModule,
RenderingModule,
OrbitControlsModule,
DefineModule,
PerspectiveCamera,
ResizeModule,
DynamicGeometryModule,
VirtualMouseModule
} from 'whs';
import {BasicSphere} from './components/BasicSphere';
import {ParametricSphere} from './components/ParametricSphere';
import DatGUIModule from 'whs/modules/DatGUIModule';
export const DatGUI = new DatGUIModule();
export const VirtualMouse = new VirtualMouseModule();
import DragModule from 'whs/modules/DragModule';
export const Drag = new DragModule();
export class Application extends Component {
render() {
return (
<App modules={[
new ElementModule(),
new SceneModule(),
new DefineModule('camera', new PerspectiveCamera({
position: {
z: 20
}
})),
new RenderingModule(),
new OrbitControlsModule(),
new ResizeModule(),
DatGUI,
VirtualMouse,
Drag
]}
refApp={app => {
console.log(app);
}}
>
<Sphere
geometry={[3, 32, 32]}
material={new MeshBasicMaterial({color: 0xffffff})}
key="1"
/>
<Sphere
geometry={[3, 32, 32]}
material={new MeshBasicMaterial({color: 0x00ff00})}
position={[-3, 0, 3]}
key="2"
/>
<ParametricSphere
position={[0, 6, 0]}
key="3"
refComponent={component => {
//component.material.color.setRGB(1, 1, 0); // Set yellow
}}
/>
</App>
)
}
}
import {
Mesh,
IcosahedronGeometry,
MeshBasicMaterial
} from 'three';
import {
MeshComponent,
DynamicGeometryModule,
Sphere
} from 'whs';
import {reactify} from '../../src/index';
import {
DatGUI,
Drag,
VirtualMouse
} from '../app';
@reactify
export class ParametricSphere extends Sphere {
constructor(params = {}) {
params.modules = (params.modules ? params.modules : []).concat([
new DynamicGeometryModule(),
DatGUI.Mesh({
name: 'Sphere',
geometry: {
radius: {
range: [2, 100]
}
}
}),
Drag.mesh()
]);
super(params);
VirtualMouse.track(this);
}
build() {
const {material, geometry} = this.applyBridge({
geometry: new IcosahedronGeometry(3, 5),
material: new MeshBasicMaterial({color: 0xffffff})
});
return this.applyBridge({mesh: new Mesh(geometry, material)}).mesh;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment