mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
反光组件序列化和载入。
This commit is contained in:
parent
cfd5a5ae53
commit
ebf1fbd138
@ -76,7 +76,7 @@ ReflectorComponent.prototype.render = function () {
|
||||
options: {
|
||||
512: '512*512',
|
||||
1024: '1024*1024',
|
||||
2018: '2048*2048'
|
||||
2048: '2048*2048'
|
||||
},
|
||||
value: '1024',
|
||||
onChange: this.onChangeReflect.bind(this)
|
||||
|
||||
@ -28,6 +28,9 @@ import RectAreaLightSerializer from './light/RectAreaLightSerializer';
|
||||
import AudioSerializer from './audio/AudioSerializer';
|
||||
import AudioListenerSerializer from './audio/AudioListenerSerializer';
|
||||
|
||||
// objects
|
||||
import ReflectorSerializer from './objects/ReflectorSerializer';
|
||||
|
||||
/**
|
||||
* 场景序列化/反序列化类
|
||||
* @author tengge / https://github.com/tengge1
|
||||
@ -98,6 +101,10 @@ Converter.prototype.sceneToJson = function (scene, list) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj instanceof THREE.Reflector) {
|
||||
json = (new ReflectorSerializer()).toJSON(obj);
|
||||
}
|
||||
|
||||
switch (obj.constructor.name) {
|
||||
case 'Scene':
|
||||
json = (new SceneSerializer()).toJSON(obj);
|
||||
@ -105,6 +112,9 @@ Converter.prototype.sceneToJson = function (scene, list) {
|
||||
case 'Group':
|
||||
json = (new GroupSerializer()).toJSON(obj);
|
||||
break;
|
||||
case 'Reflector':
|
||||
json = (new ReflectorSerializer()).toJSON(obj);
|
||||
break;
|
||||
case 'Mesh':
|
||||
json = (new MeshSerializer()).toJSON(obj);
|
||||
break;
|
||||
@ -254,6 +264,9 @@ Converter.prototype.sceneFromJson = function (jsons, options, audioListener) {
|
||||
case 'GroupSerializer':
|
||||
obj = (new GroupSerializer()).fromJSON(objJson);
|
||||
break;
|
||||
case 'ReflectorSerializer':
|
||||
obj = (new ReflectorSerializer()).fromJSON(objJson);
|
||||
break;
|
||||
case 'MeshSerializer':
|
||||
obj = (new MeshSerializer()).fromJSON(objJson);
|
||||
break;
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
import BaseSerializer from '../BaseSerializer';
|
||||
import MeshSerializer from '../core/MeshSerializer';
|
||||
import GeometriesSerializer from '../geometry/GeometriesSerializer';
|
||||
|
||||
/**
|
||||
* ReflectorSerializer
|
||||
* @author tengge / https://github.com/tengge1
|
||||
*/
|
||||
function ReflectorSerializer() {
|
||||
BaseSerializer.call(this);
|
||||
}
|
||||
|
||||
ReflectorSerializer.prototype = Object.create(BaseSerializer.prototype);
|
||||
ReflectorSerializer.prototype.constructor = ReflectorSerializer;
|
||||
|
||||
ReflectorSerializer.prototype.toJSON = function (obj) {
|
||||
var json = MeshSerializer.prototype.toJSON.call(this, obj);
|
||||
|
||||
if (json.userData.mesh) {
|
||||
json.userData.mesh = (new MeshSerializer()).toJSON(json.userData.mesh);
|
||||
}
|
||||
|
||||
return json;
|
||||
};
|
||||
|
||||
ReflectorSerializer.prototype.fromJSON = function (json) {
|
||||
var geometry = (new GeometriesSerializer()).fromJSON(json.geometry);
|
||||
var obj = new THREE.Reflector(geometry, {
|
||||
color: json.userData.color,
|
||||
textureWidth: parseInt(json.userData.size),
|
||||
textureHeight: parseInt(json.userData.size),
|
||||
clipBias: json.userData.clipBias,
|
||||
recursion: json.userData.recursion ? 1 : 0
|
||||
});
|
||||
|
||||
MeshSerializer.prototype.fromJSON.call(this, json, obj);
|
||||
|
||||
if (obj.userData.mesh) {
|
||||
obj.userData.mesh = (new MeshSerializer()).fromJSON(obj.userData.mesh);
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
export default ReflectorSerializer;
|
||||
Loading…
x
Reference in New Issue
Block a user