mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-02-01 16:08:17 +00:00
Geometry转Json对象。
This commit is contained in:
parent
3a19fb5c9c
commit
709d925c53
@ -6,6 +6,7 @@ import Toolbar from './ui/Toolbar';
|
||||
import Menubar from './menu/Menubar';
|
||||
import Panel from './panel/Panel';
|
||||
import UI from './ui/UI';
|
||||
import RemoveObjectCommand from './command/RemoveObjectCommand';
|
||||
|
||||
/**
|
||||
* Application
|
||||
|
||||
@ -388,6 +388,7 @@ Editor.prototype = {
|
||||
|
||||
save: function () {
|
||||
var obj = SceneUtils.toJSON(this.scene);
|
||||
console.log(JSON.stringify(obj));
|
||||
},
|
||||
|
||||
//
|
||||
|
||||
60
src/utils/GeometryUtils.js
Normal file
60
src/utils/GeometryUtils.js
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 判断是否是three.js内置类
|
||||
* @param {*} geometry 几何体
|
||||
*/
|
||||
function isBuildInGeometry(geometry) {
|
||||
if (geometry instanceof THREE.BoxBufferGeometry ||
|
||||
geometry instanceof THREE.BoxGeometry ||
|
||||
geometry instanceof THREE.CircleBufferGeometry ||
|
||||
geometry instanceof THREE.CircleGeometry ||
|
||||
geometry instanceof THREE.ConeBufferGeometry ||
|
||||
geometry instanceof THREE.ConeGeometry ||
|
||||
geometry instanceof THREE.CylinderBufferGeometry ||
|
||||
geometry instanceof THREE.CylinderGeometry ||
|
||||
geometry instanceof THREE.DodecahedronBufferGeometry ||
|
||||
geometry instanceof THREE.DodecahedronGeometry ||
|
||||
geometry instanceof THREE.ExtrudeBufferGeometry ||
|
||||
geometry instanceof THREE.ExtrudeGeometry ||
|
||||
geometry instanceof THREE.IcosahedronBufferGeometry ||
|
||||
geometry instanceof THREE.IcosahedronGeometry ||
|
||||
geometry instanceof THREE.LatheBufferGeometry ||
|
||||
geometry instanceof THREE.LatheGeometry ||
|
||||
geometry instanceof THREE.OctahedronBufferGeometry ||
|
||||
geometry instanceof THREE.OctahedronGeometry ||
|
||||
geometry instanceof THREE.ParametricBufferGeometry ||
|
||||
geometry instanceof THREE.ParametricGeometry ||
|
||||
geometry instanceof THREE.PlaneBufferGeometry ||
|
||||
geometry instanceof THREE.PlaneGeometry ||
|
||||
geometry instanceof THREE.PolyhedronBufferGeometry ||
|
||||
geometry instanceof THREE.PolyhedronGeometry ||
|
||||
geometry instanceof THREE.RingBufferGeometry ||
|
||||
geometry instanceof THREE.RingGeometry ||
|
||||
geometry instanceof THREE.ShapeBufferGeometry ||
|
||||
geometry instanceof THREE.ShapeGeometry ||
|
||||
geometry instanceof THREE.SphereBufferGeometry ||
|
||||
geometry instanceof THREE.SphereGeometry ||
|
||||
geometry instanceof THREE.TetrahedronBufferGeometry ||
|
||||
geometry instanceof THREE.TetrahedronGeometry ||
|
||||
geometry instanceof THREE.TextBufferGeometry ||
|
||||
geometry instanceof THREE.TextGeometry ||
|
||||
geometry instanceof THREE.TorusBufferGeometry ||
|
||||
geometry instanceof THREE.TorusGeometry ||
|
||||
geometry instanceof THREE.TorusKnotBufferGeometry ||
|
||||
geometry instanceof THREE.TorusKnotGeometry ||
|
||||
geometry instanceof THREE.TubeBufferGeometry ||
|
||||
geometry instanceof THREE.TubeGeometry
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 几何体工具类
|
||||
*/
|
||||
const GeometryUtils = {
|
||||
isBuildInGeometry: isBuildInGeometry
|
||||
};
|
||||
|
||||
export default GeometryUtils;
|
||||
@ -1,3 +1,5 @@
|
||||
import GeometryUtils from './GeometryUtils';
|
||||
|
||||
/**
|
||||
* 场景转JSON对象
|
||||
* @param {*} scene 场景
|
||||
@ -8,13 +10,12 @@ function toJSON(scene) {
|
||||
scene.traverse(function (item) {
|
||||
list.push(obj3dToJson(item));
|
||||
});
|
||||
console.log(list);
|
||||
return list;
|
||||
};
|
||||
|
||||
/**
|
||||
* 将场景中的对象转换为Json
|
||||
* @param {*} item
|
||||
* @param {*} item Object3D对象
|
||||
*/
|
||||
function obj3dToJson(item) {
|
||||
var obj = {
|
||||
@ -22,7 +23,7 @@ function obj3dToJson(item) {
|
||||
uuid: item.uuid,
|
||||
castShadow: item.castShadow,
|
||||
children: item.children.map(function (child) {
|
||||
return child.id;
|
||||
return child.uuid;
|
||||
}),
|
||||
frustumCulled: item.frustumCulled,
|
||||
matrix: item.matrix,
|
||||
@ -30,10 +31,20 @@ function obj3dToJson(item) {
|
||||
name: item.name,
|
||||
parent: item.parent == null ? null : item.parent.uuid,
|
||||
position: item.position,
|
||||
quaternion: item.quaternion,
|
||||
quaternion: {
|
||||
x: item.quaternion.x,
|
||||
y: item.quaternion.y,
|
||||
z: item.quaternion.z,
|
||||
w: item.quaternion.w
|
||||
},
|
||||
receiveShadow: item.receiveShadow,
|
||||
renderOrder: item.renderOrder,
|
||||
rotation: item.rotation,
|
||||
rotation: {
|
||||
x: item.rotation.x,
|
||||
y: item.rotation.y,
|
||||
z: item.rotation.z,
|
||||
order: item.rotation.order
|
||||
},
|
||||
scale: item.scale,
|
||||
up: item.up,
|
||||
userData: item.userData
|
||||
@ -68,10 +79,29 @@ function obj3dToJson(item) {
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* 将Geometry转换为Json对象
|
||||
* @param {*} geometry 几何体
|
||||
*/
|
||||
function geometryToJson(geometry) {
|
||||
var obj = {
|
||||
name: geometry.name,
|
||||
type: geometry.type,
|
||||
userData: geometry.userData,
|
||||
uuid: geometry.uuid
|
||||
};
|
||||
if (GeometryUtils.isBuildInGeometry) { // three.js内置类
|
||||
obj.parameters = geometry.parameters;
|
||||
} else {
|
||||
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将材质转换为Json对象
|
||||
* @param {*} material 材质
|
||||
*/
|
||||
function materialToJson(material) {
|
||||
var obj = {
|
||||
alphaMap: material.alphaMap,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
export { default as Ajax } from './Ajax';
|
||||
export { default as CssUtils } from './CssUtils';
|
||||
export { default as JsUtils } from './JsUtils';
|
||||
export { default as GeometryUtils } from './GeometryUtils';
|
||||
export { default as SceneUtils } from './SceneUtils';
|
||||
export { default as Socket } from './Socket';
|
||||
Loading…
x
Reference in New Issue
Block a user