Browse Source

Fix camera serialization

master
Palash Bansal 11 months ago
parent
commit
f0f35bfb4a
No account linked to committer's email address

+ 2
- 2
plugins/plugin-template-vite/package.json View File

"replace": { "replace": {
"dependencies": {}, "dependencies": {},
"peerDependencies": { "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 View File

this.getWorldPosition(this._positionWorld) this.getWorldPosition(this._positionWorld)


iCameraCommons.setDirty.call(this, options) iCameraCommons.setDirty.call(this, options)
if (options?.last !== false) 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 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
} }
/** /**
* Serializes this camera with controls to JSON. * Serializes this camera with controls to JSON.
* @param meta - metadata for serialization * @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 { fromJSON(data: any, meta?: any): this | null {

+ 8
- 4
src/core/camera/PerspectiveCamera2.ts View File

/** /**
* Serializes this camera with controls to JSON. * Serializes this camera with controls to JSON.
* @param meta - metadata for serialization * @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? // 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 { fromJSON(data: any, meta?: any): this | null {
// todo: add check for OrbitControls being not deserialized(inited properly) if it doesn't exist yet (if it is not inited properly) // 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))) // console.log(JSON.parse(JSON.stringify(data)))
ThreeSerialization.Deserialize(data, this, meta, true) ThreeSerialization.Deserialize(data, this, meta, true)
this.refreshAspect(false)
this.setDirty({change: 'deserialize'}) this.setDirty({change: 'deserialize'})
return this return this
} }

+ 1
- 1
src/core/material/LegacyPhongMaterial.ts View File

...super.toJSON(meta), ...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute) ...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 View File

...super.toJSON(meta), ...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute) ...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 View File

...super.toJSON(meta), ...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute) ...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 View File

...super.toJSON(meta), ...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute) ...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 View File

...super.toJSON(meta), ...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute) ...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 View File

...super.toJSON(meta), ...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute) ...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 View File

...super.toJSON(meta), ...super.toJSON(meta),
...ThreeSerialization.Serialize(this, meta, true), // this will serialize the properties of this class(like defined with @serialize and @serialize attribute) ...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…
Cancel
Save