Explorar el Código

Add property name translation for PLYLoader

The property names in PLY files are given as strings, some
implementations may use different names for common properties.
This commit adds a translation mechanism based on a map,
which is specified via the constructor.

Example with no translation:
  loader = new THREE.PLYLoader();

Example with translation:
  loader = new THREE.PLYLoader({
	  		diffuse_red: 'red',
			diffuse_green: 'green',
			diffuse_blue: 'blue'
		});
Sven-Kristofer Pilz hace 10 años
padre
commit
a133546ea4
Se han modificado 1 ficheros con 11 adiciones y 3 borrados
  1. 11 3
      examples/js/loaders/PLYLoader.js

+ 11 - 3
examples/js/loaders/PLYLoader.js

@@ -19,7 +19,11 @@
  */
 
 
-THREE.PLYLoader = function () {};
+THREE.PLYLoader = function ( propertyNameTranslation ) {
+
+	this.propertyNameTranslation = propertyNameTranslation === undefined? {} : propertyNameTranslation;
+	
+};
 
 THREE.PLYLoader.prototype = {
 
@@ -111,7 +115,7 @@ THREE.PLYLoader.prototype = {
 		var currentElement = undefined;
 		var lineType, lineValues;
 
-		function make_ply_element_property(propertValues) {
+		function make_ply_element_property(propertValues, propertyNameTranslation) {
 			
 			var property = Object();
 
@@ -128,6 +132,10 @@ THREE.PLYLoader.prototype = {
 				property.name = propertValues[1]
 
 			}
+			
+			if ( property.name in propertyNameTranslation ) {
+				property.name = propertyNameTranslation[property.name];
+			}
 
 			return property
 			
@@ -174,7 +182,7 @@ THREE.PLYLoader.prototype = {
 				
 			case "property":
 
-				currentElement.properties.push( make_ply_element_property( lineValues ) );
+				currentElement.properties.push( make_ply_element_property( lineValues, this.propertyNameTranslation ) );
 
 				break;