vector3 string to vector2

by black strings

HTML

<script src="https://rawgit.com/mrdoob/three.js/dev/build/three.js"></script>

JavaScript

// mock data
var vec3Str = '[{"x":0,"y":0,"z":0},{"x":0,"y":0,"z":0},{"x":0,"y":0,"z":0},{"x":0,"y":0,"z":0}]';

// convert vec3 json form into true vector2 for drawing shape
console.log(toVector2(vec3Str));


function toVector2(vec3Str){
	var vector2s = [];
	var vec2Objs = JSON.parse(vec3Str);
	vec2Objs.forEach(function(vec3){
  	vector2s.push(new THREE.Vector2(vec3.x, vec3.y));
  });
  return vector2s;
}