فهرست منبع

LDraw Loader: Include building step count in model (assemble multiple parts per step) (#24868)

* LDraw Loader: Include building step count in model (assemble multiple parts per step)

* LDraw Loader: Switch to building step

* Set consistent .buildingStep property
sbgib 2 سال پیش
والد
کامیت
4fd7f913ba

+ 4 - 4
docs/examples/en/loaders/LDrawLoader.html

@@ -62,7 +62,7 @@
 				// Optionally, use LDrawUtils.mergeObject() from
 				// 'examples/jsm/utils/LDrawUtils.js' to merge all
 				// geometries by material (it gives better runtime
-				// performance, but construction steps are lost)
+				// performance, but building steps are lost)
 				// group = LDrawUtils.mergeObject( group );
 
 				scene.add( group );
@@ -103,10 +103,10 @@
 		type, its .userData member will contain the following members: <br />
 		In a [page:Group], the userData member will contain: <br />
 		<ul>
-			<li>.numConstructionSteps: Only in the root [page:Group], Indicates total number of construction steps in
-			the model. These can be used to set visibility of objects to show different construction steps, which is
+			<li>.numBuildingSteps: Only in the root [page:Group], Indicates total number of building steps in
+			the model. These can be used to set visibility of objects to show different building steps, which is
 			done in the example.</li>
-			<li>.constructionStep: Indicates the construction index of this step.</li>
+			<li>.buildingStep: Indicates the building index of this step.</li>
 			<li>.category: Contains, if not null, the [page:String] category for this piece or model.</li>
 			<li>.keywords: Contains, if not null, an array of [page:String] keywords for this piece or model.</li>
 		</ul>

+ 14 - 13
examples/js/loaders/LDrawLoader.js

@@ -633,7 +633,7 @@
 			result.subobjects = original.subobjects;
 			result.fileName = original.fileName;
 			result.totalFaces = original.totalFaces;
-			result.startingConstructionStep = original.startingConstructionStep;
+			result.startingBuildingStep = original.startingBuildingStep;
 			result.materials = original.materials;
 			result.group = null;
 			return result;
@@ -747,7 +747,7 @@
 			let bfcCCW = true;
 			let bfcInverted = false;
 			let bfcCull = true;
-			let startingConstructionStep = false;
+			let startingBuildingStep = false;
 
 			// Parse all line commands
 			for ( let lineIndex = 0; lineIndex < numLines; lineIndex ++ ) {
@@ -886,7 +886,7 @@
 
 									break;
 								case 'STEP':
-									startingConstructionStep = true;
+									startingBuildingStep = true;
 									break;
 								case 'Author:':
 									author = lp.getToken();
@@ -945,8 +945,9 @@
 							matrix: matrix,
 							fileName: fileName,
 							inverted: bfcInverted,
-							startingConstructionStep: startingConstructionStep
+							startingBuildingStep: startingBuildingStep
 						} );
+						startingBuildingStep = false;
 						bfcInverted = false;
 						break;
 
@@ -1093,7 +1094,7 @@
 				author,
 				subobjects,
 				totalFaces,
-				startingConstructionStep,
+				startingBuildingStep,
 				materials,
 				fileName,
 				group: null
@@ -1246,7 +1247,7 @@
 
 						const subobjectGroup = subobjectInfo;
 						subobject.matrix.decompose( subobjectGroup.position, subobjectGroup.quaternion, subobjectGroup.scale );
-						subobjectGroup.userData.startingConstructionStep = subobject.startingConstructionStep;
+						subobjectGroup.userData.startingBuildingStep = subobject.startingBuildingStep;
 						subobjectGroup.name = subobject.fileName;
 						loader.applyMaterialsToMesh( subobjectGroup, subobject.colorCode, info.materials );
 						subobjectGroup.userData.colorCode = subobject.colorCode;
@@ -1795,7 +1796,7 @@
 				this.partsCache.parseModel( text, this.materialLibrary ).then( group => {
 
 					this.applyMaterialsToMesh( group, MAIN_COLOUR_CODE, this.materialLibrary, true );
-					this.computeConstructionSteps( group );
+					this.computeBuildingSteps( group );
 					group.userData.fileName = url;
 					onLoad( group );
 
@@ -1809,7 +1810,7 @@
 			this.partsCache.parseModel( text, this.materialLibrary ).then( group => {
 
 				this.applyMaterialsToMesh( group, MAIN_COLOUR_CODE, this.materialLibrary, true );
-				this.computeConstructionSteps( group );
+				this.computeBuildingSteps( group );
 				group.userData.fileName = '';
 				onLoad( group );
 
@@ -2231,27 +2232,27 @@
 			}
 
 		}
-		computeConstructionSteps( model ) {
+		computeBuildingSteps( model ) {
 
-			// Sets userdata.constructionStep number in THREE.Group objects and userData.numConstructionSteps number in the root THREE.Group object.
+			// Sets userdata.buildingStep number in THREE.Group objects and userData.numBuildingSteps number in the root THREE.Group object.
 
 			let stepNumber = 0;
 			model.traverse( c => {
 
 				if ( c.isGroup ) {
 
-					if ( c.userData.startingConstructionStep ) {
+					if ( c.userData.startingBuildingStep ) {
 
 						stepNumber ++;
 
 					}
 
-					c.userData.constructionStep = stepNumber;
+					c.userData.buildingStep = stepNumber;
 
 				}
 
 			} );
-			model.userData.numConstructionSteps = stepNumber + 1;
+			model.userData.numBuildingSteps = stepNumber + 1;
 
 		}
 

+ 14 - 13
examples/jsm/loaders/LDrawLoader.js

@@ -692,7 +692,7 @@ class LDrawParsedCache {
 		result.subobjects = original.subobjects;
 		result.fileName = original.fileName;
 		result.totalFaces = original.totalFaces;
-		result.startingConstructionStep = original.startingConstructionStep;
+		result.startingBuildingStep = original.startingBuildingStep;
 		result.materials = original.materials;
 		result.group = null;
 		return result;
@@ -819,7 +819,7 @@ class LDrawParsedCache {
 		let bfcInverted = false;
 		let bfcCull = true;
 
-		let startingConstructionStep = false;
+		let startingBuildingStep = false;
 
 		// Parse all line commands
 		for ( let lineIndex = 0; lineIndex < numLines; lineIndex ++ ) {
@@ -994,7 +994,7 @@ class LDrawParsedCache {
 
 							case 'STEP':
 
-								startingConstructionStep = true;
+								startingBuildingStep = true;
 
 								break;
 
@@ -1068,9 +1068,10 @@ class LDrawParsedCache {
 						matrix: matrix,
 						fileName: fileName,
 						inverted: bfcInverted,
-						startingConstructionStep: startingConstructionStep
+						startingBuildingStep: startingBuildingStep
 					} );
 
+					startingBuildingStep = false;
 					bfcInverted = false;
 
 					break;
@@ -1233,7 +1234,7 @@ class LDrawParsedCache {
 			author,
 			subobjects,
 			totalFaces,
-			startingConstructionStep,
+			startingBuildingStep,
 			materials,
 			fileName,
 			group: null
@@ -1389,7 +1390,7 @@ class LDrawPartsGeometryCache {
 
 					const subobjectGroup = subobjectInfo;
 					subobject.matrix.decompose( subobjectGroup.position, subobjectGroup.quaternion, subobjectGroup.scale );
-					subobjectGroup.userData.startingConstructionStep = subobject.startingConstructionStep;
+					subobjectGroup.userData.startingBuildingStep = subobject.startingBuildingStep;
 					subobjectGroup.name = subobject.fileName;
 
 					loader.applyMaterialsToMesh( subobjectGroup, subobject.colorCode, info.materials );
@@ -1958,7 +1959,7 @@ class LDrawLoader extends Loader {
 				.then( group => {
 
 					this.applyMaterialsToMesh( group, MAIN_COLOUR_CODE, this.materialLibrary, true );
-					this.computeConstructionSteps( group );
+					this.computeBuildingSteps( group );
 					group.userData.fileName = url;
 					onLoad( group );
 
@@ -1976,7 +1977,7 @@ class LDrawLoader extends Loader {
 			.then( group => {
 
 				this.applyMaterialsToMesh( group, MAIN_COLOUR_CODE, this.materialLibrary, true );
-				this.computeConstructionSteps( group );
+				this.computeBuildingSteps( group );
 				group.userData.fileName = '';
 				onLoad( group );
 
@@ -2433,9 +2434,9 @@ class LDrawLoader extends Loader {
 
 	}
 
-	computeConstructionSteps( model ) {
+	computeBuildingSteps( model ) {
 
-		// Sets userdata.constructionStep number in Group objects and userData.numConstructionSteps number in the root Group object.
+		// Sets userdata.buildingStep number in Group objects and userData.numBuildingSteps number in the root Group object.
 
 		let stepNumber = 0;
 
@@ -2443,19 +2444,19 @@ class LDrawLoader extends Loader {
 
 			if ( c.isGroup ) {
 
-				if ( c.userData.startingConstructionStep ) {
+				if ( c.userData.startingBuildingStep ) {
 
 					stepNumber ++;
 
 				}
 
-				c.userData.constructionStep = stepNumber;
+				c.userData.buildingStep = stepNumber;
 
 			}
 
 		} );
 
-		model.userData.numConstructionSteps = stepNumber + 1;
+		model.userData.numBuildingSteps = stepNumber + 1;
 
 	}
 

+ 8 - 8
examples/webgl_loader_ldraw.html

@@ -110,8 +110,8 @@
 					displayLines: true,
 					conditionalLines: true,
 					smoothNormals: true,
-					constructionStep: 0,
-					noConstructionSteps: 'No steps.',
+					buildingStep: 0,
+					noBuildingSteps: 'No steps.',
 					flatColors: false,
 					mergeModel: false
 				};
@@ -153,8 +153,8 @@
 
 					} else if ( c.isGroup ) {
 
-						// Hide objects with construction step > gui setting
-						c.visible = c.userData.constructionStep <= guiData.constructionStep;
+						// Hide objects with building step > gui setting
+						c.visible = c.userData.buildingStep <= guiData.buildingStep;
 
 					}
 
@@ -237,7 +237,7 @@
 
 						scene.add( model );
 
-						guiData.constructionStep = model.userData.numConstructionSteps - 1;
+						guiData.buildingStep = model.userData.numBuildingSteps - 1;
 
 						updateObjectsVisibility();
 
@@ -300,13 +300,13 @@
 
 				} );
 
-				if ( model.userData.numConstructionSteps > 1 ) {
+				if ( model.userData.numBuildingSteps > 1 ) {
 
-					gui.add( guiData, 'constructionStep', 0, model.userData.numConstructionSteps - 1 ).step( 1 ).name( 'Construction step' ).onChange( updateObjectsVisibility );
+					gui.add( guiData, 'buildingStep', 0, model.userData.numBuildingSteps - 1 ).step( 1 ).name( 'Building step' ).onChange( updateObjectsVisibility );
 
 				} else {
 
-					gui.add( guiData, 'noConstructionSteps' ).name( 'Construction step' ).onChange( updateObjectsVisibility );
+					gui.add( guiData, 'noBuildingSteps' ).name( 'Building step' ).onChange( updateObjectsVisibility );
 
 				}