@@ -36,7 +36,8 @@ export class Part {
3636 warned : Set < string > = new Set ( ) ; // Set to track warnings for this part, preventing duplicate warnings
3737 private _childrenByName : { [ name : string ] : Part } = { } ; // For quick access to children by name
3838 private _childrenByType : { [ type : string ] : Array < Part > } = { } ; // For quick access to children by type
39- constructor ( { name } : { name ?: string } = { } ) {
39+ render : boolean ; // Whether this part should be rendered, default true
40+ constructor ( { name, render } : { name ?: string , render ?: boolean } = { } ) {
4041 this . id = generateUID ( ) ;
4142 this . name = name || "New Object" ;
4243 this . type = "Part" ;
@@ -45,6 +46,7 @@ export class Part {
4546 this . top = undefined ;
4647 this . ready = true ;
4748 this . base = "Part" ;
49+ this . render = typeof render !== "undefined" ? render : true ;
4850 this . type = this . constructor . name || "Part" ; // Default type is the class name
4951 this . debugEmoji = "🧩" ; // Default emoji for debugging
5052 }
@@ -162,9 +164,6 @@ export class Part {
162164 } ) ;
163165 }
164166 addChild ( child : Part ) {
165- if ( child . name == "LightSource" ) {
166- console . log ( this , child )
167- }
168167 if ( this . _childrenByName [ child . name ] ) {
169168 this . top ?. warn ( `Child with name <${ child . name } > already exists in <${ this . name } >. Skipping addition. (Child has ID <${ child . id } >).` ) ;
170169 return ;
@@ -201,7 +200,11 @@ export class Part {
201200 ( this as any ) [ attribute ] = value ;
202201 return value ;
203202 }
204-
203+ preFrame ( ) {
204+ this . childrenArray . forEach ( child => {
205+ child . preFrame ( ) ;
206+ } ) ;
207+ }
205208 act ( delta : number ) {
206209 if ( ! this . ready ) {
207210 return ;
@@ -212,6 +215,7 @@ export class Part {
212215 tie . target . attr ( tie . targetAttribute , value ) ;
213216 }
214217 } ) ;
218+ if ( ! this . render ) return ;
215219 this . childrenArray . forEach ( child => {
216220 child . act ( delta ) ;
217221 } ) ;
@@ -408,11 +412,11 @@ export class Part {
408412 // Deep clone children
409413 this . _cloneAndAddChildren ( clone , memo ) ;
410414
411- // Deep clone ties, registrations, flats
415+ // Deep clone ties, registrations, flats -- these actually dont need to be cloned, the just need to be re-assigned
412416 // Ties
413417 const clonedTies = new Set < Tie > ( ) ;
414418 this . ties . forEach ( tie => {
415- const clonedTarget = memo . get ( tie . target ) || tie . target ; // Get cloned target if available, else use original
419+ const clonedTarget = tie . target ; // pass reference
416420 clonedTies . add ( {
417421 target : clonedTarget ,
418422 localAttribute : tie . localAttribute ,
@@ -425,27 +429,17 @@ export class Part {
425429 const clonedRegistrations : { [ key : string ] : any } = { } ;
426430 for ( const regKey in this . registrations ) {
427431 const regValue = this . registrations [ regKey ] ;
428- if ( regValue instanceof Part ) {
429- clonedRegistrations [ regKey ] = regValue . clone ( memo ) ;
430- } else if ( regValue instanceof Vector ) {
431- clonedRegistrations [ regKey ] = regValue . clone ( ) ;
432- } else if ( typeof regValue === 'object' && regValue !== null ) {
433- clonedRegistrations [ regKey ] = { ...regValue } ; // Shallow copy for now, can be made deeper if needed
434- } else {
435- clonedRegistrations [ regKey ] = regValue ;
436- }
432+ clonedRegistrations [ regKey ] = regValue ; // Pass reference
437433 }
438434 clone . registrations = clonedRegistrations ;
439-
440435 // Flats
441436 const clonedFlats = { colliders : [ ] as Collider [ ] } ;
442437 if ( this . flats . colliders ) {
443438 clonedFlats . colliders = this . flats . colliders . map ( ( collider : Collider ) => {
444- return collider . clone ( memo ) ;
439+ return collider ; // pass reference
445440 } ) ;
446441 }
447442 clone . flats = clonedFlats ;
448-
449443 // Copy other simple properties that are not handled by constructor or special logic
450444 clone . id = generateUID ( ) ; // Generate new ID
451445 clone . name = this . name ; // Copy name
@@ -455,9 +449,9 @@ export class Part {
455449 clone . _layoutWidth = this . _layoutWidth ; // Copy layout width
456450 clone . _superficialWidth = this . _superficialWidth ; // Copy superficial width
457451 clone . _superficialHeight = this . _superficialHeight ; // Copy superficial height
452+ clone . base = this . base ; // Copy base
458453 clone . warned = new Set ( this . warned ) ; // Copy warned set
459454
460-
461455 return clone ;
462456 }
463457
0 commit comments