mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
保存载入曲线。
This commit is contained in:
parent
da54e3cce0
commit
a396397b5c
@ -19,11 +19,14 @@ function Spline(points) {
|
||||
|
||||
this.castShadow = true;
|
||||
|
||||
this.userData.points = points || [
|
||||
new THREE.Vector3(10, 20, 40),
|
||||
new THREE.Vector3(0, 30, -10),
|
||||
new THREE.Vector3(-40, 10, -20),
|
||||
];
|
||||
Object.assign(this.userData, {
|
||||
type: 'Spline',
|
||||
points: points || [
|
||||
new THREE.Vector3(10, 20, 40),
|
||||
new THREE.Vector3(0, 30, -10),
|
||||
new THREE.Vector3(-40, 10, -20),
|
||||
]
|
||||
});
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@ import ParticleEmitterSerializer from './objects/ParticleEmitterSerializer';
|
||||
import PerlinTerrainSerializer from './objects/PerlinTerrainSerializer';
|
||||
import WaterSerializer from './objects/WaterSerializer';
|
||||
import ClothSerializer from './objects/ClothSerializer';
|
||||
import SplineSerializer from './objects/SplineSerializer';
|
||||
|
||||
/**
|
||||
* 场景序列化/反序列化类
|
||||
@ -127,6 +128,8 @@ Converter.prototype.sceneToJson = function (scene, list) {
|
||||
json = (new WaterSerializer()).toJSON(obj);
|
||||
} else if (obj.userData.type === 'Cloth') {
|
||||
json = (new ClothSerializer()).toJSON(obj);
|
||||
} else if (obj.userData.type === 'Spline') {
|
||||
json = (new SplineSerializer()).toJSON(obj);
|
||||
} else if (obj instanceof THREE.Scene) {
|
||||
json = (new SceneSerializer()).toJSON(obj);
|
||||
} else if (obj instanceof THREE.Group) {
|
||||
@ -348,6 +351,9 @@ Converter.prototype.sceneFromJson = function (jsons, options) {
|
||||
case 'ClothSerializer':
|
||||
obj = (new ClothSerializer()).fromJSON(objJson);
|
||||
break;
|
||||
case 'SplineSerializer':
|
||||
obj = (new SplineSerializer()).fromJSON(objJson);
|
||||
break;
|
||||
}
|
||||
|
||||
if (obj) {
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
import BaseSerializer from '../BaseSerializer';
|
||||
import MeshSerializer from '../core/MeshSerializer';
|
||||
import Spline from '../../object/line/Spline';
|
||||
|
||||
/**
|
||||
* SplineSerializer
|
||||
* @author tengge / https://github.com/tengge1
|
||||
*/
|
||||
function SplineSerializer() {
|
||||
BaseSerializer.call(this);
|
||||
}
|
||||
|
||||
SplineSerializer.prototype = Object.create(BaseSerializer.prototype);
|
||||
SplineSerializer.prototype.constructor = SplineSerializer;
|
||||
|
||||
SplineSerializer.prototype.toJSON = function (obj) {
|
||||
var json = MeshSerializer.prototype.toJSON.call(this, obj);
|
||||
|
||||
return json;
|
||||
};
|
||||
|
||||
SplineSerializer.prototype.fromJSON = function (json, parent) {
|
||||
var obj = parent || new Spline(json.userData.points.map(n => {
|
||||
return new THREE.Vector3().copy(n);
|
||||
}));
|
||||
|
||||
MeshSerializer.prototype.fromJSON.call(this, json, obj);
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
export default SplineSerializer;
|
||||
Loading…
x
Reference in New Issue
Block a user