The Sinewav3 Plugin example 'Tentacles', is based on the Three.js geometry/heierarchy2 example Find out more in the Create a Plugin article at sinewav3.com.
Last active
April 17, 2018 16:03
-
-
Save cliffhall/3c1a2cbbdefbc06ff7cde5ca2420eaec to your computer and use it in GitHub Desktop.
Sinewav3 Plugin Example 'Tentacles'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Body of the plugin's render() function, | |
// which takes one argument, the Visualizer context, | |
// and is called for each frame. | |
// Calculate rotation values | |
let speed = 0.001; | |
let time = Date.now() * speed; | |
var rx = Math.sin( time * 0.7 ) * 0.2; | |
var ry = Math.sin( time * 0.3 ) * 0.1; | |
var rz = Math.sin( time * 0.2 ) * 0.1; | |
// Position the root object based on settings | |
// | |
// NOTE: Doing this in render() instead of just | |
// in setup() allows the user to reposition the | |
// object during visualization. Otherwise they'd | |
// have to set it, visualize, determine it's not | |
// exactly where they want it, exit, set it again, | |
// etc. | |
var root = context.memory.root; | |
context.memory.locate(root); | |
// Set the rotation values on all the boxes | |
root.traverse( function ( object ) { | |
object.rotation.x = rx; | |
object.rotation.y = ry; | |
object.rotation.z = rz; | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Body of the plugin's setup() function, | |
// which takes one argument, the Visualizer context, | |
// and is called once, prior to the rendering loop | |
// Create a function to position the root object | |
// based on the current setting values | |
context.memory.locate = function(root) { | |
root.position.set( | |
context.plugin.getSettingValue('Position','X Pos'), | |
context.plugin.getSettingValue('Position','Y Pos'), | |
context.plugin.getSettingValue('Position','Z Pos') | |
) | |
}; | |
// Create and register geometry | |
// | |
// Registering it allows Sinewav3 to clean up | |
// once the visualzation is done. Otherwise, | |
// you need to write a destroy() function and | |
// free the memory yourself. | |
var geometry = new THREE.BoxGeometry( 100, 100, 100 ); | |
context.registerGeometry( 'geo', geometry ); | |
// Create and register a material | |
// | |
// As with geometry, be sure and register materials | |
var material = new THREE.MeshNormalMaterial(); | |
context.registerMaterial( 'mat', material ); | |
// Create, position, and remember the root object | |
var root = new THREE.Mesh( geometry, material ); | |
context.memory.locate(root); | |
context.memory.root = root; | |
// Add the root object to the scene. | |
// | |
// NOTE: Sinewav3 handles this for you so that it | |
// can also register the object and remove it later | |
// after visualzation. | |
context.addToScene( root ); | |
// -------------------- | |
// Create the tentacles | |
// -------------------- | |
var amount = 200, object, parent = root; | |
for ( var i = 0; i < amount; i ++ ) { | |
object = new THREE.Mesh( geometry, material ); | |
object.position.x = 100; | |
parent.add( object ); | |
parent = object; | |
} | |
parent = root; | |
for ( var i = 0; i < amount; i ++ ) { | |
object = new THREE.Mesh( geometry, material ); | |
object.position.x = - 100; | |
parent.add( object ); | |
parent = object; | |
} | |
parent = root; | |
for ( var i = 0; i < amount; i ++ ) { | |
object = new THREE.Mesh( geometry, material ); | |
object.position.y = - 100; | |
parent.add( object ); | |
parent = object; | |
} | |
parent = root; | |
for ( var i = 0; i < amount; i ++ ) { | |
object = new THREE.Mesh( geometry, material ); | |
object.position.y = 100; | |
parent.add( object ); | |
parent = object; | |
} | |
parent = root; | |
for ( var i = 0; i < amount; i ++ ) { | |
object = new THREE.Mesh( geometry, material ); | |
object.position.z = - 100; | |
parent.add( object ); | |
parent = object; | |
} | |
parent = root; | |
for ( var i = 0; i < amount; i ++ ) { | |
object = new THREE.Mesh( geometry, material ); | |
object.position.z = 100; | |
parent.add( object ); | |
parent = object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment