Created
January 17, 2013 05:06
-
-
Save hapticdata/4553801 to your computer and use it in GitHub Desktop.
convert a toxiclibs.js trianglemesh into a three.js BufferGeometry, needs testing
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
define(function( require ){ | |
var THREE = require('three'); | |
/** | |
* take a toxiclibs.js mesh and turn it into a THREE.BufferGeometry | |
* @param {toxi.geom.mesh.TriangleMesh} mesh | |
* @type {THREE.BufferGeometry} | |
*/ | |
return function( mesh ){ | |
var geometry = new THREE.BufferGeometry(); | |
//3 points per face, 3 axis per point | |
var totalFloats = mesh.faces.length * 3 * 3; | |
var vertices = new Float32Array( totalFloats ); | |
var normals = new Float32Array( totalFloats ); | |
//start at 0, stride with 3 | |
mesh.getMeshAsVertexArray( vertices, 0, 3 ); | |
mesh.getFaceNormalsAsArray( normals, 0, 3 ); | |
geometry.attributes = { | |
position: { | |
itemSize: 3, | |
array: vertices, | |
numItems: totalFloats | |
}, | |
normal: { | |
itemSize: 3, | |
array: normals, | |
numItems: totalFloats | |
} | |
}; | |
return geometry; | |
}; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment