Procházet zdrojové kódy

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 před 11 roky
rodič
revize
a133546ea4
1 změnil soubory, kde provedl 11 přidání a 3 odebrání
  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 = {
 THREE.PLYLoader.prototype = {
 
 
@@ -111,7 +115,7 @@ THREE.PLYLoader.prototype = {
 		var currentElement = undefined;
 		var currentElement = undefined;
 		var lineType, lineValues;
 		var lineType, lineValues;
 
 
-		function make_ply_element_property(propertValues) {
+		function make_ply_element_property(propertValues, propertyNameTranslation) {
 			
 			
 			var property = Object();
 			var property = Object();
 
 
@@ -128,6 +132,10 @@ THREE.PLYLoader.prototype = {
 				property.name = propertValues[1]
 				property.name = propertValues[1]
 
 
 			}
 			}
+			
+			if ( property.name in propertyNameTranslation ) {
+				property.name = propertyNameTranslation[property.name];
+			}
 
 
 			return property
 			return property
 			
 			
@@ -174,7 +182,7 @@ THREE.PLYLoader.prototype = {
 				
 				
 			case "property":
 			case "property":
 
 
-				currentElement.properties.push( make_ply_element_property( lineValues ) );
+				currentElement.properties.push( make_ply_element_property( lineValues, this.propertyNameTranslation ) );
 
 
 				break;
 				break;
 				
 				

粤ICP备19079148号