소스 검색

Merge pull request #11343 from kaisalmen/Issue11270

OBJLoader: Allow flat and smooth shading within the same material definition for a specific object
Mr.doob 8 년 전
부모
커밋
7ba811c6b7
3개의 변경된 파일116개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      examples/js/loaders/OBJLoader.js
  2. 47 0
      examples/obj/cubes/cubes.mtl
  3. 57 0
      examples/obj/cubes/cubes.obj

+ 12 - 1
examples/js/loaders/OBJLoader.js

@@ -615,7 +615,18 @@ THREE.OBJLoader.prototype = {
 				// Example asset: examples/models/obj/cerberus/Cerberus.obj
 
 				var value = result[ 1 ].trim().toLowerCase();
-				state.object.smooth = ( value === '1' || value === 'on' );
+				/*
+				 * http://paulbourke.net/dataformats/obj/
+				 * or
+				 * http://www.cs.utah.edu/~boulos/cs3505/obj_spec.pdf
+				 *
+				 * From chapter "Grouping" Syntax explanation "s group_number":
+				 * "group_number is the smoothing group number. To turn off smoothing groups, use a value of 0 or off.
+				 * Polygonal elements use group numbers to put elements in different smoothing groups. For free-form
+				 * surfaces, smoothing groups are either turned on or off; there is no difference between values greater
+				 * than 0."
+				 */
+				state.object.smooth = ( value !== '0' && value !== 'off' );
 
 				var material = state.object.currentMaterial();
 				if ( material ) {

+ 47 - 0
examples/obj/cubes/cubes.mtl

@@ -0,0 +1,47 @@
+newmtl red
+Ka 1.000000 0.000000 0.000000
+Kd 1.000000 0.000000 0.000000
+Ks 0.000000 0.000000 0.000000
+Tr 1.000000
+illum 1
+Ns 0.000000
+
+newmtl blue
+Ka 0.000000 0.000000 1.000000
+Kd 0.000000 0.000000 1.000000
+Ks 0.000000 0.000000 0.000000
+Tr 1.000000
+illum 1
+Ns 0.000000
+
+newmtl green
+Ka 0.000000 1.000000 0.000000
+Kd 0.000000 1.000000 0.000000
+Ks 0.000000 0.000000 0.000000
+Tr 1.000000
+illum 1
+Ns 0.000000
+
+newmtl lightblue
+Ka 0.000000 1.000000 1.000000
+Kd 0.000000 1.000000 1.000000
+Ks 0.000000 0.000000 0.000000
+Tr 1.000000
+illum 1
+Ns 0.000000
+
+newmtl orange
+Ka 1.000000 0.647059 0.000000
+Kd 1.000000 0.647059 0.000000
+Ks 0.000000 0.000000 0.000000
+Tr 1.000000
+illum 1
+Ns 0.000000
+
+newmtl purple
+Ka 0.825806 0.000000 0.825806
+Kd 0.825806 0.000000 0.825806
+Ks 0.000000 0.000000 0.000000
+Tr 1.000000
+illum 1
+Ns 0.000000

+ 57 - 0
examples/obj/cubes/cubes.obj

@@ -0,0 +1,57 @@
+mtllib cubes.mtl
+
+# cube 01: pair of group and material per side/quad
+o cube 01
+
+v -10.00000 10.00000 10.00000
+v -10.00000 -10.00000 10.00000
+v 10.00000 -10.00000 10.00000
+v 10.00000 10.00000 10.00000
+v -10.00000 10.00000 -10.00000
+v -10.00000 -10.00000 -10.00000
+v 10.00000 -10.00000 -10.00000
+v 10.00000 10.00000 -10.00000
+
+g front
+usemtl red
+f 1 2 3 4
+g back
+usemtl blue
+f 8 7 6 5
+g right
+usemtl green
+f 4 3 7 8
+g top
+usemtl lightblue
+f 5 1 4 8
+g left
+usemtl orange
+f 5 6 2 1
+g bottom
+usemtl purple
+f 2 6 7 3
+
+# cube 02: one pair of group and material with different smoothing groups
+o cube 02
+
+v 20.00000 10.00000 10.00000
+v 20.00000 -10.00000 10.00000
+v 40.00000 -10.00000 10.00000
+v 40.00000 10.00000 10.00000
+v 20.00000 10.00000 -10.00000
+v 20.00000 -10.00000 -10.00000
+v 40.00000 -10.00000 -10.00000
+v 40.00000 10.00000 -10.00000
+
+g cube 02 one group
+usemtl blue
+s 0
+f 9 10 11 12
+f 16 15 14 13
+s 1
+f 12 11 15 16
+f 13 9 12 16
+s 2
+f 13 14 10 9
+s off
+f 10 14 15 11