Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf8bc4b

Browse files
committed
Merge remote-tracking branch 'alteredq/facematerial-refactoring' into dev
2 parents cc47bed + d97ce0d commit bf8bc4b

File tree

5 files changed

+123
-97
lines changed

5 files changed

+123
-97
lines changed

build/three.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8579,6 +8579,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
85798579

85808580
scene: new THREE.Scene(),
85818581
geometries: {},
8582+
face_materials: {},
85828583
materials: {},
85838584
textures: {},
85848585
objects: {},
@@ -8726,9 +8727,22 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
87268727

87278728
q = 0;
87288729

8730+
// use materials from the model file
8731+
// if there is no material specified in the object
8732+
87298733
if ( ! o.material ) {
87308734

8731-
material = new THREE.MeshFaceMaterial();
8735+
material = new THREE.MeshFaceMaterial( result.face_materials[ o.geometry ] );
8736+
8737+
}
8738+
8739+
// use materials from the model file
8740+
// if there is just empty face material
8741+
// (must create new material as each model has its own face material)
8742+
8743+
if ( ( material instanceof THREE.MeshFaceMaterial ) && material.materials.length === 0 ) {
8744+
8745+
material = new THREE.MeshFaceMaterial( result.face_materials[ o.geometry ] );
87328746

87338747
}
87348748

@@ -8943,9 +8957,10 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
89438957

89448958
};
89458959

8946-
function handle_mesh( geo, id ) {
8960+
function handle_mesh( geo, mat, id ) {
89478961

89488962
result.geometries[ id ] = geo;
8963+
result.face_materials[ id ] = mat;
89498964
handle_objects();
89508965

89518966
};
@@ -8991,9 +9006,9 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
89919006

89929007
function create_callback_geometry( id ) {
89939008

8994-
return function( geo ) {
9009+
return function( geo, mat ) {
89959010

8996-
handle_mesh( geo, id );
9011+
handle_mesh( geo, mat, id );
89979012

89989013
counter_models -= 1;
89999014

@@ -9046,9 +9061,10 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
90469061

90479062
function create_callback_embed( id ) {
90489063

9049-
return function( geo ) {
9064+
return function( geo, mat ) {
90509065

90519066
result.geometries[ id ] = geo;
9067+
result.face_materials[ id ] = mat;
90529068

90539069
}
90549070

0 commit comments

Comments
 (0)