Skip to content

Commit 1896730

Browse files
committed
move getArrayFromAccessor and createCubicSplineTrackInterpolant into GLTFParser
1 parent 273dacc commit 1896730

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

examples/jsm/loaders/GLTFLoader.js

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,48 +2399,6 @@ function getNormalizedComponentScale( constructor ) {
23992399

24002400
}
24012401

2402-
function getArrayFromAccessor( accessor ) {
2403-
2404-
let outputArray = accessor.array;
2405-
2406-
if ( accessor.normalized ) {
2407-
2408-
const scale = getNormalizedComponentScale( outputArray.constructor );
2409-
const scaled = new Float32Array( outputArray.length );
2410-
2411-
for ( let j = 0, jl = outputArray.length; j < jl; j ++ ) {
2412-
2413-
scaled[ j ] = outputArray[ j ] * scale;
2414-
2415-
}
2416-
2417-
outputArray = scaled;
2418-
2419-
}
2420-
2421-
return outputArray;
2422-
2423-
}
2424-
2425-
function createCubicSplineTrackInterpolant( track ) {
2426-
2427-
track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline( result ) {
2428-
2429-
// A CUBICSPLINE keyframe in glTF has three output values for each input value,
2430-
// representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
2431-
// must be divided by three to get the interpolant's sampleSize argument.
2432-
2433-
const interpolantType = ( this instanceof QuaternionKeyframeTrack ) ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
2434-
2435-
return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
2436-
2437-
};
2438-
2439-
// Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
2440-
track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
2441-
2442-
}
2443-
24442402
function getImageURIMimeType( uri ) {
24452403

24462404
if ( uri.search( /\.jpe?g($|\?)/i ) > 0 || uri.search( /^data\:image\/jpeg/ ) === 0 ) return 'image/jpeg';
@@ -3920,21 +3878,21 @@ class GLTFParser {
39203878
const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output;
39213879

39223880
if ( target.node === undefined ) {
3923-
3881+
39243882
const nodeDependency = parser._invokeOne( function ( ext ) {
39253883

39263884
return ext.loadAnimationTargetFromChannel && ext.loadAnimationTargetFromChannel( channel );
39273885

39283886
} );
39293887

39303888
pendingNodes.push( nodeDependency );
3931-
3889+
39323890
} else {
39333891

39343892
pendingNodes.push( this.getDependency( 'node', name ) );
3935-
3893+
39363894
}
3937-
3895+
39383896
pendingInputAccessors.push( this.getDependency( 'accessor', input ) );
39393897
pendingOutputAccessors.push( this.getDependency( 'accessor', output ) );
39403898
pendingSamplers.push( sampler );
@@ -4393,7 +4351,7 @@ class GLTFParser {
43934351

43944352
const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear;
43954353

4396-
const outputArray = getArrayFromAccessor( outputAccessor );
4354+
const outputArray = this.getArrayFromAccessor( outputAccessor );
43974355

43984356
for ( let j = 0, jl = targetNames.length; j < jl; j ++ ) {
43994357

@@ -4407,7 +4365,7 @@ class GLTFParser {
44074365
// Override interpolation with custom factory method.
44084366
if ( interpolation === 'CUBICSPLINE' ) {
44094367

4410-
createCubicSplineTrackInterpolant( track );
4368+
this.createCubicSplineTrackInterpolant( track );
44114369

44124370
}
44134371

@@ -4419,6 +4377,48 @@ class GLTFParser {
44194377

44204378
}
44214379

4380+
getArrayFromAccessor( accessor ) {
4381+
4382+
let outputArray = accessor.array;
4383+
4384+
if ( accessor.normalized ) {
4385+
4386+
const scale = getNormalizedComponentScale( outputArray.constructor );
4387+
const scaled = new Float32Array( outputArray.length );
4388+
4389+
for ( let j = 0, jl = outputArray.length; j < jl; j ++ ) {
4390+
4391+
scaled[ j ] = outputArray[ j ] * scale;
4392+
4393+
}
4394+
4395+
outputArray = scaled;
4396+
4397+
}
4398+
4399+
return outputArray;
4400+
4401+
}
4402+
4403+
createCubicSplineTrackInterpolant( track ) {
4404+
4405+
track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline( result ) {
4406+
4407+
// A CUBICSPLINE keyframe in glTF has three output values for each input value,
4408+
// representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
4409+
// must be divided by three to get the interpolant's sampleSize argument.
4410+
4411+
const interpolantType = ( this instanceof QuaternionKeyframeTrack ) ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
4412+
4413+
return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
4414+
4415+
};
4416+
4417+
// Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
4418+
track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
4419+
4420+
}
4421+
44224422
}
44234423

44244424
/**

0 commit comments

Comments
 (0)