Kaynağa Gözat

Fix camera serialization

master
Palash Bansal 11 ay önce
ebeveyn
işleme
f0f35bfb4a
No account linked to committer's email address

+ 2
- 2
plugins/plugin-template-vite/package.json Dosyayı Görüntüle

@@ -64,8 +64,8 @@
"replace": {
"dependencies": {},
"peerDependencies": {
"threepipe": "^0.0.26",
"@threepipe/plugin-tweakpane": "^0.2.0"
"threepipe": "^0.0.50",
"@threepipe/plugin-tweakpane": "^0.6.1"
}
}
}

+ 8
- 5
src/core/camera/OrthographicCamera2.ts Dosyayı Görüntüle

@@ -228,7 +228,7 @@ export class OrthographicCamera2<TE extends ICameraEventMap = ICameraEventMap> e
this.getWorldPosition(this._positionWorld)

iCameraCommons.setDirty.call(this, options)
if (options?.last !== false)
this._camUi.forEach(u=>u?.uiRefresh?.(false, 'postFrame', 1)) // because camera changes a lot. so we dont want to deep refresh ui on every change
}
@@ -359,11 +359,14 @@ export class OrthographicCamera2<TE extends ICameraEventMap = ICameraEventMap> e
/**
* Serializes this camera with controls to JSON.
* @param meta - metadata for serialization
* @param baseOnly - Calls only super.toJSON, does internal three.js serialization. Set it to true only if you know what you are doing.
* @param _internal - Calls only super.toJSON, does internal three.js serialization and `@serialize` tags. Set it to true only if you know what you are doing. This is used in Serialization->serializer
*/
toJSON(meta?: any, baseOnly = false): any {
if (baseOnly) return super.toJSON(meta)
return ThreeSerialization.Serialize(this, meta, true)
toJSON(meta?: any, _internal = false): any {
if (_internal) return {
...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute)
}
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with _internal=true, that's why we set isThis to false.
}

fromJSON(data: any, meta?: any): this | null {

+ 8
- 4
src/core/camera/PerspectiveCamera2.ts Dosyayı Görüntüle

@@ -341,12 +341,15 @@ export class PerspectiveCamera2<TE extends ICameraEventMap = ICameraEventMap> ex
/**
* Serializes this camera with controls to JSON.
* @param meta - metadata for serialization
* @param baseOnly - Calls only super.toJSON, does internal three.js serialization. Set it to true only if you know what you are doing.
* @param _internal - Calls only super.toJSON, does internal three.js serialization and `@serialize` tags. Set it to true only if you know what you are doing. This is used in Serialization->serializer
*/
toJSON(meta?: any, baseOnly = false): any {
if (baseOnly) return super.toJSON(meta)
toJSON(meta?: any, _internal = false): any {
if (_internal) return {
...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute)
}
// todo add camOptions for backwards compatibility?
return ThreeSerialization.Serialize(this, meta, true)
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with _internal=true, that's why we set isThis to false.
}

fromJSON(data: any, meta?: any): this | null {
@@ -376,6 +379,7 @@ export class PerspectiveCamera2<TE extends ICameraEventMap = ICameraEventMap> ex
// todo: add check for OrbitControls being not deserialized(inited properly) if it doesn't exist yet (if it is not inited properly)
// console.log(JSON.parse(JSON.stringify(data)))
ThreeSerialization.Deserialize(data, this, meta, true)
this.refreshAspect(false)
this.setDirty({change: 'deserialize'})
return this
}

+ 1
- 1
src/core/material/LegacyPhongMaterial.ts Dosyayı Görüntüle

@@ -139,7 +139,7 @@ export class LegacyPhongMaterial<TE extends IMaterialEventMap = IMaterialEventMa
...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute)
}
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with baseOnly=true, that's why we set isThis to false.
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with _internal=true, that's why we set isThis to false.
}

/**

+ 1
- 1
src/core/material/LineMaterial2.ts Dosyayı Görüntüle

@@ -187,7 +187,7 @@ export class LineMaterial2<TE extends IMaterialEventMap = IMaterialEventMap> ext
...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute)
}
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with baseOnly=true, that's why we set isThis to false.
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with _internal=true, that's why we set isThis to false.
}

/**

+ 1
- 1
src/core/material/ObjectShaderMaterial.ts Dosyayı Görüntüle

@@ -126,7 +126,7 @@ export class ObjectShaderMaterial<TE extends IMaterialEventMap = IMaterialEventM
...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute)
}
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with baseOnly=true, that's why we set isThis to false.
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with _internal=true, that's why we set isThis to false.
}

/**

+ 1
- 1
src/core/material/PhysicalMaterial.ts Dosyayı Görüntüle

@@ -206,7 +206,7 @@ export class PhysicalMaterial<TE extends IMaterialEventMap = IMaterialEventMap>
...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute)
}
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with baseOnly=true, that's why we set isThis to false.
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with _internal=true, that's why we set isThis to false.
}

/**

+ 1
- 1
src/core/material/UnlitLineMaterial.ts Dosyayı Görüntüle

@@ -129,7 +129,7 @@ export class UnlitLineMaterial<TE extends IMaterialEventMap = IMaterialEventMap>
...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute)
}
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with baseOnly=true, that's why we set isThis to false.
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with _internal=true, that's why we set isThis to false.
}

/**

+ 1
- 1
src/core/material/UnlitMaterial.ts Dosyayı Görüntüle

@@ -143,7 +143,7 @@ export class UnlitMaterial<TE extends IMaterialEventMap = IMaterialEventMap> ext
...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute)
}
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with baseOnly=true, that's why we set isThis to false.
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with _internal=true, that's why we set isThis to false.
}

/**

+ 1
- 1
website/guide/serialization.md Dosyayı Görüntüle

@@ -111,7 +111,7 @@ class MyMaterial extends ThreeMaterial{
...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute)
}
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with baseOnly=true, that's why we set isThis to false.
return ThreeSerialization.Serialize(this, meta, false) // this will call toJSON again, but with _internal=true, that's why we set isThis to false.
}

/**

Loading…
İptal
Kaydet