84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
Existe-t-il un moyen de faire en sorte qu'un composant continue de tourner sur l'écran comme une animation ?
Groupe de discussion Autodesk Forge WeChat – question pochao
Bonjour, vous pouvez y parvenir en combinant requestAnimationFrame 和 setTimeout ces deux fonctions, merci de voir l'exemple ci-dessous (code ES2015) :
requestAnimationFrame
setTimeout
class RotateExt extends Autodesk.Viewing.Extension { constructor( viewer, options ) { super(); } load() { this.actived = true; viewer.addEventListener( Autodesk.Viewing.SELECTION_CHANGED_EVENT, this.onSelectionChanged ); return true; } unload() { this.actived = false; viewer.removeEventListener( Autodesk.Viewing.SELECTION_CHANGED_EVENT, this.onSelectionChanged ); return true; } onSelectionChanged = ( event ) => { this.model = event.model; this.fragIdsArray = event.fragIdsArray; // 要求第一个动画 frame requestAnimationFrame( this.rotateHandler ); }; /**! * 关键函数 */ rotateHandler = () => { if( !this.actived ) return; const quaternion = new THREE.Quaternion(); // 设置旋转量 - 依 Y 轴旋转构件 60 度 quaternion.setFromAxisAngle( new THREE.Vector3( 0,1,0 ), Math.PI / 3 ); const model = this.model; const fragIdsArray = this.fragIdsArray; fragIdsArray.forEach( ( fragId, idx ) => { const fragProxy = this.viewer.impl.getFragmentProxy( model, fragId ); fragProxy.getAnimTransform(); const position = new THREE.Vector3( fragProxy.position.x, fragProxy.position.y, fragProxy.position.z ); position.applyQuaternion( quaternion ); fragProxy.position = position; fragProxy.quaternion.multiplyQuaternions( quaternion, fragProxy.quaternion ); if( idx === 0 ) { const euler = new THREE.Euler(); euler.setFromQuaternion( fragProxy.quaternion, 0 ); } fragProxy.updateAnimTransform(); }); this.viewer.impl.sceneUpdated( true ); // 500毫秒后要求下一个动画 frame setTimeout( () => { requestAnimationFrame( this.rotateHandler ); }, 500 ); }; } Autodesk.Viewing.theExtensionManager.registerExtension( 'Autodesk.ADN.Viewing.Extension.RotateTool', RotateExt );
Bonjour, vous pouvez y parvenir en combinant
requestAnimationFrame
和setTimeout
ces deux fonctions, merci de voir l'exemple ci-dessous (code ES2015) :