Преглед на файлове

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 преди 10 години
родител
ревизия
a133546ea4
променени са 1 файла, в които са добавени 11 реда и са изтрити 3 реда
  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;