浏览代码

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;