public override SceneComponent GetObjectData() { var sceneData = new SceneParticleSystem(); sceneData.type = "ParticleSystem"; List <string> enabledModules = new List <string>(); if (unityParticle != null) { // Basic sceneData.maxParticles = unityParticle.maxParticles; sceneData.duration = unityParticle.duration; sceneData.playingSpeed = unityParticle.playbackSpeed; sceneData.isLooping = unityParticle.loop; sceneData.isAutoStarted = unityParticle.playOnAwake; sceneData.gravity = Physics.gravity * unityParticle.gravityModifier; sceneData.rotation = unityParticle.startRotation3D; sceneData.startAttributes = new Vector4(unityParticle.startLifetime, unityParticle.startSize, unityParticle.startSpeed, unityParticle.startDelay); sceneData.startColor = unityParticle.startColor; if (unityParticle.emission.enabled) { sceneData.emissionRate = createCurveData(unityParticle.emission.rate); sceneData.emissionType = unityParticle.emission.type.ToString(); enabledModules.Add("Emission"); } if (unityParticle.textureSheetAnimation.enabled) { sceneData.tsaFrameOverTime = createCurveData(unityParticle.textureSheetAnimation.frameOverTime); sceneData.tsaNumTiles = new Vector2(unityParticle.textureSheetAnimation.numTilesX, unityParticle.textureSheetAnimation.numTilesY); sceneData.tsaCycleCount = unityParticle.textureSheetAnimation.cycleCount; sceneData.tsaAnimationType = unityParticle.textureSheetAnimation.animation.ToString(); enabledModules.Add("TextureSheetAnimation"); } } if (unityParticleRenderer != null) { sceneData.renderAttributes = new Vector4( unityParticleRenderer.minParticleSize, unityParticleRenderer.maxParticleSize, unityParticleRenderer.normalDirection, unityParticleRenderer.sortingFudge); sceneData.renderShapeMode = unityParticleRenderer.renderMode.ToString(); sceneData.renderSortMode = unityParticleRenderer.sortMode.ToString(); enabledModules.Add("Renderer"); } sceneData.renderMaterial = material.name; sceneData.enabledModules = new string[enabledModules.Count]; for (int i = 0; i < enabledModules.Count; ++i) { sceneData.enabledModules[i] = enabledModules[i]; } return(sceneData); }
public static string ExportParticle(ref SceneData sceneData, ref SceneParticleSystem sps, string spaces) { string osgData = spaces + "Duration " + sps.duration + "\n" + spaces + "Playing " + sps.playingSpeed + " " + (sps.isLooping ? 1 : 0) + " " + (sps.isAutoStarted ? 1 : 0) + "\n" + spaces + "MaxParticles " + sps.maxParticles + "\n" + spaces + "Gravity " + sps.gravity.x + " " + sps.gravity.y + " " + sps.gravity.z + "\n" + spaces + "Rotation " + sps.rotation.x + " " + sps.rotation.y + " " + sps.rotation.z + "\n" + spaces + "StartAttributes " + sps.startAttributes.x + " " + sps.startAttributes.y + " " + sps.startAttributes.z + " " + sps.startAttributes.w + "\n" + spaces + "StartColor " + sps.startColor.r + " " + sps.startColor.g + " " + sps.startColor.b + " " + sps.startColor.a + "\n"; for (int i = 0; i < sps.enabledModules.Length; ++i) { string moduleName = sps.enabledModules[i]; osgData += spaces + moduleName + " {\n"; if (moduleName == "Emission") { osgData += spaces + " Type " + sps.emissionType + "\n" + spaces + " Rate " + sps.emissionRate.Length + " {\n"; for (int j = 0; j < sps.emissionRate.Length; ++j) { Vector4 v = sps.emissionRate[j]; osgData += spaces + " " + v.x + " " + v.y + " " + v.z + " " + v.w + "\n"; } osgData += spaces + " }\n"; } else if (moduleName == "TextureSheetAnimation") { osgData += spaces + " Type " + sps.tsaAnimationType + "\n" + spaces + " Tiles " + sps.tsaNumTiles.x + " " + sps.tsaNumTiles.y + "\n" + spaces + " CycleCount " + sps.tsaCycleCount + "\n" + spaces + " FrameOverTime " + sps.tsaFrameOverTime.Length + " {\n"; for (int j = 0; j < sps.tsaFrameOverTime.Length; ++j) { Vector4 v = sps.tsaFrameOverTime[j]; osgData += spaces + " " + v.x + " " + v.y + " " + v.z + " " + v.w + "\n"; } osgData += spaces + " }\n"; } else if (moduleName == "Renderer") { osgData += spaces + " ShapeMode " + sps.renderShapeMode + "\n" + spaces + " SortMode " + sps.renderSortMode + "\n" + spaces + " Attributes " + sps.renderAttributes.x + " " + sps.renderAttributes.y + " " + sps.renderAttributes.z + " " + sps.renderAttributes.w + "\n"; SceneMaterial material = sceneData.resources.GetMaterial(sps.renderMaterial); osgData += spaces + " Material " + material.textureIDs.Length + " {\n"; for (int j = 0; j < material.textureIDs.Length; ++j) { SceneTexture texture = sceneData.resources.GetTexture(material.textureIDs[j], false); if (texture == null) { continue; } Vector4 off = material.textureTilingOffsets[j]; osgData += spaces + " Texture" + j + " \"" + texture.name + "\"" + " \"" + texture.path + "\"\n" + spaces + " TilingOffset" + j + " " + off.x + " " + off.y + " " + off.z + " " + off.w + "\n"; } osgData += spaces + " }\n"; } osgData += spaces + "}\n"; } return(osgData); }
private static string ExportHierarchy(ref SceneData sceneData, SceneGameObject gameObj, int indent, float progressStart, float progressAll) { int needGlobalNodeType = -1; if (gameObj.components.Count <= 0) { return(""); } string osgData = "", osgSubData = "", spaces = ""; for (int i = 0; i < indent; ++i) { spaces += " "; } // Check the main component type as the node type SceneComponent mainComponent = gameObj.components[0]; if (mainComponent.type == "Transform") { SceneTransform st = (SceneTransform)mainComponent; osgData = spaces + "MatrixTransform {\n" + spaces + " referenceFrame RELATIVE\n" + spaces + " Matrix {\n"; needGlobalNodeType = 0; // FIXME: hould convert left-handed to right-handed coordinates Matrix4x4 m = Matrix4x4.TRS(st.localPosition, st.localRotation, st.localScale); osgData += spaces + " " + m[0, 0] + " " + m[1, 0] + " " + m[2, 0] + " " + m[3, 0] + "\n" + spaces + " " + m[0, 1] + " " + m[1, 1] + " " + m[2, 1] + " " + m[3, 1] + "\n" + spaces + " " + m[0, 2] + " " + m[1, 2] + " " + m[2, 2] + " " + m[3, 2] + "\n" + spaces + " " + m[0, 3] + " " + m[1, 3] + " " + m[2, 3] + " " + m[3, 3] + "\n" + spaces + " }\n"; } else { Debug.LogWarning("[UnityToSceneBundle] Unknown main component type: " + mainComponent.type); } if (needGlobalNodeType < 0) { osgData = spaces + "Node {\n"; } osgData += ExportCommonAttr(gameObj.name, spaces, true) + spaces + " num_children "; // Traverse all components to add them to main component type string subSpaces = spaces + " "; int numChildren = gameObj.children.Count; for (int i = 1; i < gameObj.components.Count; ++i) { SceneComponent component = gameObj.components[i]; if (component.type == "Light") { SceneLight sl = (SceneLight)component; osgSubData += spaces + " nwTools::LightData {\n" + subSpaces + "Type " + sl.lightType + "\n" + subSpaces + "Color " + sl.color.r + " " + sl.color.g + " " + sl.color.b + "\n" + subSpaces + "Range " + sl.range + "\n" + subSpaces + "Realtime " + (sl.realtime ? 1 : 0) + " " + (sl.castsShadows ? 1 : 0) + "\n" + spaces + " }\n"; numChildren++; } else if (component.type == "Camera") { SceneCamera sc = (SceneCamera)component; osgSubData += spaces + " nwTools::CameraData {\n" // TODO + spaces + " }\n"; numChildren++; } else if (component.type == "BoxCollider") { //SceneBoxCollider sbc = (SceneBoxCollider)component; // TODO } else if (component.type == "MeshCollider") { //SceneMeshCollider smc = (SceneMeshCollider)component; // TODO } else if (component.type == "ParticleSystem") { SceneParticleSystem sps = (SceneParticleSystem)component; osgSubData += spaces + " nwTools::ParticleSystem {\n" + ExportCommonAttr(sps.type, spaces + " ", false) + ParticleExporter.ExportParticle(ref sceneData, ref sps, subSpaces) + spaces + " }\n"; numChildren++; } else if (component.type == "Terrain") { SceneTerrain st = (SceneTerrain)component; osgSubData += spaces + " Geode {\n" + ExportCommonAttr(st.type, spaces + " ", true) + subSpaces + "num_drawables 1\n"; osgSubData += subSpaces + "nwTools::Terrain {\n" + TerrainExporter.ExportTerrain(ref sceneData, ref st, subSpaces + " ") + subSpaces + "}\n"; osgSubData += spaces + " }\n"; numChildren++; } else if (component.type == "MeshRenderer") { SceneMeshRenderer smr = (SceneMeshRenderer)component; osgSubData += spaces + " Geode {\n" + ExportCommonAttr(smr.type, spaces + " ", true) + subSpaces + "num_drawables 1\n"; SceneMesh mesh = sceneData.resources.GetMesh(smr.mesh); osgSubData += subSpaces + "Geometry {\n" + MeshExporter.ExportGeometry(ref sceneData, ref smr, ref mesh, subSpaces + " ") + subSpaces + "}\n"; osgSubData += spaces + " }\n"; numChildren++; } else if (component.type == "SkinnedMeshRenderer") { SceneSkinnedMeshRenderer smr = (SceneSkinnedMeshRenderer)component; osgSubData += spaces + " Geode {\n" + ExportCommonAttr(smr.type, spaces + " ", true) + subSpaces + "num_drawables 1\n"; SceneMesh mesh = sceneData.resources.GetMesh(smr.mesh); osgSubData += subSpaces + "Geometry {\n" + MeshExporter.ExportSkinnedGeometry(ref sceneData, ref smr, ref mesh, subSpaces + " ") + subSpaces + "}\n"; osgSubData += spaces + " }\n"; numChildren++; } else { Debug.LogWarning("[UnityToSceneBundle] Unknown sub-component type: " + component.type); } } osgData += numChildren + "\n" + osgSubData; // Traverse all child objects float numHierarchy = (float)gameObj.children.Count, numDone = 0.0f; foreach (SceneGameObject childObj in gameObj.children) { osgData += ExportHierarchy(ref sceneData, childObj, indent + 2, 0.0f, 0.0f); numDone += 1.0f; if (progressAll > 0.0f) { float progress = (progressStart + numDone / numHierarchy) / progressAll; EditorUtility.DisplayProgressBar("Scene Bundler", "Exporting hierarchy...", progress); } } osgData += spaces + "}\n"; return(osgData); }