@@ -15,7 +15,7 @@ import { FaCamera, FaImage, FaLightbulb } from "react-icons/fa";
1515import { SiAdobeindesign , SiBabylondotjs } from "react-icons/si" ;
1616
1717import { AdvancedDynamicTexture } from "babylonjs-gui" ;
18- import { BaseTexture , Node , Scene , Sound , Tools , IParticleSystem , ParticleSystem , Sprite } from "babylonjs" ;
18+ import { BaseTexture , Node , Scene , Sound , Tools , IParticleSystem , Sprite } from "babylonjs" ;
1919
2020import { Editor } from "../main" ;
2121
@@ -117,7 +117,9 @@ export interface IEditorGraphState {
117117
118118export class EditorGraph extends Component < IEditorGraphProps , IEditorGraphState > {
119119 private _soundsList : Sound [ ] = [ ] ;
120- private _objectsToCopy : TreeNodeInfo < unknown > [ ] = [ ] ;
120+
121+ public _nodeToCopyTransform : Node | null = null ;
122+ public _objectsToCopy : TreeNodeInfo < unknown > [ ] = [ ] ;
121123
122124 public constructor ( props : IEditorGraphProps ) {
123125 super ( props ) ;
@@ -392,6 +394,7 @@ export class EditorGraph extends Component<IEditorGraphProps, IEditorGraphState>
392394 */
393395 public copySelectedNodes ( ) : void {
394396 this . _objectsToCopy = this . props . editor . layout . graph . getSelectedNodes ( ) ;
397+ this . refresh ( ) ;
395398 }
396399
397400 /**
@@ -402,7 +405,7 @@ export class EditorGraph extends Component<IEditorGraphProps, IEditorGraphState>
402405 return ;
403406 }
404407
405- const newNodes : ( Node | ParticleSystem | Sprite ) [ ] = [ ] ;
408+ const newNodes : ( Node | IParticleSystem | Sprite ) [ ] = [ ] ;
406409 const nodesToCopy = this . _objectsToCopy . map ( ( n ) => n . nodeData ) ;
407410
408411 registerUndoRedo ( {
@@ -432,7 +435,7 @@ export class EditorGraph extends Component<IEditorGraphProps, IEditorGraphState>
432435 } ,
433436 redo : ( ) => {
434437 nodesToCopy . forEach ( ( object ) => {
435- let node : Node | ParticleSystem | Sprite | null = null ;
438+ let node : Node | IParticleSystem | Sprite | null = null ;
436439
437440 defer: {
438441 if ( isAbstractMesh ( object ) ) {
@@ -491,6 +494,91 @@ export class EditorGraph extends Component<IEditorGraphProps, IEditorGraphState>
491494 } ) ;
492495 }
493496
497+ public copySelectedNodeTransform ( node : Node ) : void {
498+ this . _nodeToCopyTransform = node ;
499+ this . refresh ( ) ;
500+ }
501+
502+ public pasteSelectedNodeTransform ( node : Node ) : void {
503+ if ( ! this . _nodeToCopyTransform ) {
504+ return ;
505+ }
506+
507+ const sourcePosition = this . _nodeToCopyTransform [ "position" ] ;
508+ const sourceRotation = this . _nodeToCopyTransform [ "rotation" ] ;
509+ const sourceScaling = this . _nodeToCopyTransform [ "scaling" ] ;
510+ const sourceRotationQuaternion = this . _nodeToCopyTransform [ "rotationQuaternion" ] ;
511+ const sourceDirection = this . _nodeToCopyTransform [ "direction" ] ;
512+
513+ const targetPosition = node [ "position" ] ;
514+ const targetRotation = node [ "rotation" ] ;
515+ const targetScaling = node [ "scaling" ] ;
516+ const targetRotationQuaternion = node [ "rotationQuaternion" ] ;
517+ const targetDirection = node [ "direction" ] ;
518+
519+ const savedTargetPosition = targetPosition ?. clone ( ) ;
520+ const savedTargetRotation = targetRotation ?. clone ( ) ;
521+ const savedTargetScaling = targetScaling ?. clone ( ) ;
522+ const savedTargetRotationQuaternion = targetRotationQuaternion ?. clone ( ) ;
523+ const savedTargetDirection = targetDirection ?. clone ( ) ;
524+
525+ registerUndoRedo ( {
526+ executeRedo : true ,
527+ undo : ( ) => {
528+ if ( savedTargetPosition && targetPosition ) {
529+ targetPosition . copyFrom ( savedTargetPosition ) ;
530+ }
531+
532+ if ( savedTargetRotation && targetRotation ) {
533+ targetRotation . copyFrom ( savedTargetRotation ) ;
534+ }
535+
536+ if ( savedTargetScaling && targetScaling ) {
537+ targetScaling . copyFrom ( savedTargetScaling ) ;
538+ }
539+
540+ if ( targetRotationQuaternion ) {
541+ if ( ! savedTargetRotationQuaternion ) {
542+ node [ "rotationQuaternion" ] = null ;
543+ } else {
544+ targetRotationQuaternion . copyFrom ( savedTargetRotationQuaternion ) ;
545+ }
546+ }
547+
548+ if ( savedTargetDirection && targetDirection ) {
549+ targetDirection . copyFrom ( savedTargetDirection ) ;
550+ }
551+ } ,
552+ redo : ( ) => {
553+ if ( sourcePosition && targetPosition ) {
554+ targetPosition . copyFrom ( sourcePosition ) ;
555+ }
556+
557+ if ( sourceRotation && targetRotation ) {
558+ targetRotation . copyFrom ( sourceRotation ) ;
559+ }
560+
561+ if ( sourceScaling && targetScaling ) {
562+ targetScaling . copyFrom ( sourceScaling ) ;
563+ }
564+
565+ if ( sourceRotationQuaternion ) {
566+ if ( targetRotationQuaternion ) {
567+ targetRotationQuaternion . copyFrom ( sourceRotationQuaternion ) ;
568+ } else {
569+ node [ "rotationQuaternion" ] = sourceRotationQuaternion . clone ( ) ;
570+ }
571+ }
572+
573+ if ( sourceDirection && targetDirection ) {
574+ targetDirection . copyFrom ( sourceDirection ) ;
575+ }
576+ } ,
577+ } ) ;
578+
579+ this . props . editor . layout . inspector . forceUpdate ( ) ;
580+ }
581+
494582 private _handleSearch ( search : string ) {
495583 this . setState ( { search } , ( ) => {
496584 this . refresh ( ) ;
0 commit comments