public virtual JObject Serialize(SeinJS.ExporterEntry entry, SeinJS.Sein_nodeExtension extension) { var type = GetType(); var className = type.FullName.Replace("SeinNodeClass_", ""); extension.className = string.IsNullOrEmpty(className) ? extension.className : className; var result = new JObject(); if (type.GetField("options") == null) { return(result); } var initOptions = type.GetField("options").GetValue(this); foreach (var pair in initOptions.GetType().GetFields()) { var option = SerializeValue(entry, pair.GetValue(initOptions)); result.Add(pair.Name, new JObject( new JProperty("type", option.type), new JProperty("value", option.value) )); } return(result); }
public virtual SeinJS.SeinNodeOption SerializeValue(SeinJS.ExporterEntry entry, SeinAtlas option) { ExtensionManager.Serialize(ExtensionManager.GetExtensionName(typeof(Sein_atlasExtensionFactory)), entry, entry.root.Extensions, option); var atlasId = Sein_atlasExtensionFactory.GetAtlasIndex(entry, option); return(new SeinJS.SeinNodeOption("Atlas", new JObject(new JProperty("index", atlasId)))); }
public static void Serialize(string extensionName, ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null, object options = null) { var factory = Name2Extensions[extensionName]; factory.Awake(entry); factory.Serialize(entry, extensions, component, options); }
public static void Serialize(Type FactoryClass, ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null) { var factory = Name2Extensions[Class2Extensions[FactoryClass]]; factory.Awake(entry); factory.Serialize(entry, extensions, component); }
public virtual SeinJS.SeinNodeOption SerializeValue(SeinJS.ExporterEntry entry, Matrix4x4 option) { return(new SeinJS.SeinNodeOption("Mat4", new JArray { option.m00, option.m01, option.m02, option.m03, option.m10, option.m11, option.m12, option.m13, option.m20, option.m21, option.m22, option.m23, option.m30, option.m31, option.m32, option.m33 })); }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null, object options = null) { var extension = new Sein_audioListenerExtension(); var listener = component as SeinAudioListener; extension.rotatable = listener.rotatable; AddExtension(extensions, extension); }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null) { var extension = new Sein_ambientLightExtension(); extension.intensity = RenderSettings.ambientIntensity; extension.color = RenderSettings.ambientLight; AddExtension(extensions, extension); }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null) { var extension = new Sein_testExtension(); var test = component as SeinTest; extension.rotateSpeed = test.rotateSpeed; AddExtension(extensions, extension); }
private void ExportMesh(Transform tr, ExporterEntry entry) { var renderer = GetRenderer(tr); var mesh = GetMesh(tr); if (!mesh) { return; } var result = entry.SaveMesh(mesh, renderer); var id = result.key; var needProcessMatrials = result.value; var node = entry.tr2node[tr]; node.Mesh = id; if (needProcessMatrials) { var materialComponents = tr.GetComponents <SeinCustomMaterial>(); int i = 0; var materials = renderer.sharedMaterials; foreach (var primitive in id.Value.Primitives) { if (i >= materials.Length) { Debug.LogError("No material in primitive" + " " + i + " in mesh " + mesh.name + " !"); break; } if (materialComponents.Length == 1 && materials.Length == 1) { ExportComponentMaterial(materialComponents[0], primitive, entry); continue; } bool hasComponent = false; foreach (var materialComponent in materialComponents) { if (materialComponent.unityMaterialName == materials[i].name) { ExportComponentMaterial(materialComponent, primitive, entry); hasComponent = true; break; } } if (!hasComponent) { ExportNormalMaterial(materials[i], primitive, entry); } i += 1; } } }
private void ExportSkin(Transform tr, ExporterEntry entry) { var skinMesh = tr.GetComponent <SkinnedMeshRenderer>(); if (skinMesh != null && skinMesh.enabled && CheckSkinValidity(skinMesh, entry) && skinMesh.rootBone != null) { var node = entry.tr2node[tr]; node.Skin = entry.SaveSkin(tr); } }
public static void Serialize(Component component, ExporterEntry entry, Dictionary <string, Extension> extensions) { foreach (var name in Component2Extensions[component.GetType()]) { var factory = Name2Extensions[name]; factory.Awake(entry); factory.Serialize(entry, extensions, component); } }
private void ExportCamera(Transform tr, ExporterEntry entry) { var node = entry.tr2node[tr]; var camera = tr.GetComponent <UnityEngine.Camera>(); if (camera != null) { node.Camera = entry.SaveCamera(camera); } }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null) { if (!ENTRY_CLIPS.ContainsKey(entry)) { ENTRY_CLIPS.Add(entry, new List <SeinAudioClip>()); ENTRY_URIS.Add(entry, new Dictionary <AudioClip, string>()); } Sein_audioClipsExtension extension; var source = component as SeinAudioSource; if (!extensions.ContainsKey(ExtensionName)) { extension = new Sein_audioClipsExtension(); AddExtension(extensions, extension); } else { extension = (Sein_audioClipsExtension)extensions["Sein_audioClips"]; } var list = ENTRY_CLIPS[entry]; var uris = ENTRY_URIS[entry]; foreach (var c in source.clips) { var clip = c.clip; if (c.clip == null) { throw new Exception("Clip '" + c.name + "' has no audio source!"); } if (list.Contains(clip)) { continue; } var newClip = new Sein_audioClipsExtension.AudioClip(); newClip.name = clip.name; newClip.mode = clip.mode; newClip.isLazy = clip.isLazy; if (uris.ContainsKey(clip.clip)) { newClip.uri = uris[clip.clip]; } else { newClip.uri = SaveAudio(clip.clip); } list.Add(clip); extension.clips.Add(newClip); } }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null) { var animator = component as SeinAnimator; var extension = new Sein_animatorExtension(); extension.name = animator.name; extension.prefixes = animator.prefixes; extension.defaultAnimation = animator.defaultAnimation; extension.modelAnimations = animator.modelAnimations; AddExtension(extensions, extension); }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null, object options = null) { var texture = component as Texture2D; var extension = new Sein_textureImproveExtension(); extension.anisotropic = texture.anisoLevel; // for 3d modle's textures, it always be true extension.isImageCanRelease = true; AddExtension(extensions, extension); }
private bool CheckSkinValidity(SkinnedMeshRenderer skin, ExporterEntry entry) { foreach (Transform tr in skin.bones) { if (!entry.bones.Contains(tr)) { Debug.LogError("Error while exporting skin for " + skin.name + " (skipping skinning export).\nClick for more details:\n \nThe following bones are used but are not selected" + tr.name + "\n"); return(false); } } return(true); }
private void ProcessChildren(ExporterEntry entry) { foreach (var tr in entry.transforms) { if (!tr.gameObject.activeInHierarchy) { continue; } var id = entry.tr2nodeId[tr]; if (!tr.parent || !entry.tr2node.ContainsKey(tr.parent)) { var scene = entry.root.Scene.Value; if (scene.Nodes == null) { scene.Nodes = new List <NodeId>(); } scene.Nodes.Add(id); } else { var parent = entry.tr2node[tr.parent]; if (parent.Children == null) { parent.Children = new List <NodeId>(); } parent.Children.Add(id); } } foreach (var trs in entry.transformsInSameActor.Values) { var names = new Dictionary <string, int>(); foreach (var tr in trs) { var node = entry.tr2node[tr]; if (names.ContainsKey(node.Name)) { names[node.Name] += 1; node.Name += names[node.Name]; } else { names.Add(node.Name, 0); } } } }
public void Export(List <ExporterEntry> entries) { ExporterEntry.Init(); ExtensionManager.BeforeExport(); _isDone = false; _userStopped = false; foreach (var entry in entries) { ExportOne(entry); } FinishExport(); }
public virtual SeinJS.SeinNodeOption SerializeValueUnknown(SeinJS.ExporterEntry entry, object option) { var result = new JObject(); foreach (var pair in option.GetType().GetFields()) { var value = SerializeValue(entry, pair.GetValue(option)); result.Add(pair.Name, new JObject( new JProperty("type", value.type), new JProperty("value", value.value) )); } return(new SeinJS.SeinNodeOption("Object", result)); }
private void ExportAnimations(Transform tr, ExporterEntry entry) { if (tr.GetComponent <UnityEngine.Animation>()) { Debug.LogError("Only support animator now !"); return; } var anim = tr.GetComponent <Animator>(); if (anim) { entry.SaveAnimations(tr); } }
private void ExportExtensions(Transform tr, ExporterEntry entry) { var node = entry.tr2node[tr]; foreach (var component in tr.GetComponents <Component>()) { if (ExtensionManager.Component2Extensions.ContainsKey(component.GetType())) { if (node.Extensions == null) { node.Extensions = new Dictionary <string, Extension>(); } ExtensionManager.Serialize(component, entry, node.Extensions); } } }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null) { var extension = new Sein_nodeExtension(); var node = component as SeinNode; extension.selfType = node.selfType; extension.childrenType = node.childrenType; extension.className = node.className; extension.tag = node.tag; extension.layer = node.layer; extension.persistent = node.persistent; extension.emitComponentsDestroy = node.emitComponentsDestroy; extension.updateOnEverTick = node.updateOnEverTick; extension.isStatic = node.isStatic; extension.skipThisNode = node.skipThisNode; AddExtension(extensions, extension); }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null, object options = null) { if (!ENTRY_ATLASES.ContainsKey(entry)) { ENTRY_ATLASES.Add(entry, new List <SeinAtlas>()); } Sein_atlasExtension extension; var atlas = component as SeinAtlas; if (!extensions.ContainsKey(ExtensionName)) { extension = new Sein_atlasExtension(); AddExtension(extensions, extension); } else { extension = (Sein_atlasExtension)extensions[ExtensionName]; } var list = ENTRY_ATLASES[entry]; if (list.Contains(atlas)) { return; } var tex = AssetDatabase.LoadAssetAtPath <Texture2D>(atlas.atlasPath); if (tex == null) { Utils.ThrowExcption("Atlas '" + atlas.name + "' is not saved!"); } var imageId = entry.SaveImage(tex, true, null, maxSize: Math.Max(tex.width, tex.height), flipY: false); var json = atlas.ReadJson(); json["meta"]["image"] = new JObject(new JProperty("index", imageId.Id)); extension.atlases.Add(new Sein_atlasExtension.Atlas { json = json }); list.Add(atlas); }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null, object options = null) { var extension = new Sein_ambientLightExtension(); var hdrColor = RenderSettings.ambientLight; var r = hdrColor.r; var g = hdrColor.r; var b = hdrColor.b; var d = Math.Max(r, Math.Max(g, b)); if (d >= 0.01) { r /= d; g /= d; b /= d; } extension.intensity = d; extension.color = new Color(r, g, b); AddExtension(extensions, extension); }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null, object options = null) { Sein_rendererExtension extension; if (component == null) { extension = new Sein_rendererExtension { isGlobal = true, gammaCorrection = PlayerSettings.colorSpace == ColorSpace.Linear, //@todo: support hdr useHDR = false, exposure = 0 }; } else { extension = new Sein_rendererExtension { isGlobal = false }; var mr = component as Renderer; var lightmapIndex = mr.lightmapIndex; if (ExporterSettings.Lighting.lightMap && lightmapIndex > -1) { Vector4 lightmapScaleOffset = mr.lightmapScaleOffset; var lightData = LightmapSettings.lightmaps[lightmapIndex]; var lightTexture = lightData.lightmapColor; var lightTextureIndex = entry.SaveTexture(lightTexture, maxSize: ExporterSettings.Lighting.lightMapSize); extension.uvScale = new Vector2(lightmapScaleOffset.x, lightmapScaleOffset.y); extension.uvOffset = new Vector2(lightmapScaleOffset.z, lightmapScaleOffset.w); extension.lightMapIndex = lightTextureIndex.Id; } extension.castShadows = mr.shadowCastingMode == UnityEngine.Rendering.ShadowCastingMode.On; extension.receiveShadows = mr.receiveShadows; } AddExtension(extensions, extension); }
//private static GLTF.Schema.Material ConvertKHRWebGLMaterial(UnityEngine.Material material, ExportorEntry entry) //{ //} public static GLTF.Schema.Material ConvertMaterial(SeinCustomMaterial mat, ExporterEntry entry) { var material = new GLTF.Schema.Material(); if (mat.uniformsTexture.Length != 0) { foreach (var uniform in mat.uniformsTexture) { uniform.id = entry.SaveTexture(uniform.value, mat.transparent); } } if (mat.uniformsCubeTexture.Length != 0) { foreach (var uniform in mat.uniformsCubeTexture) { // todo: support cubemap //int diffuseTextureIndex = processTexture(uniform.value, hasTransparency ? IMAGETYPE.RGBA : IMAGETYPE.RGBA_OPAQUE); //uniform.index = diffuseTextureIndex; //uniform.texCoord = 0; } } if (material.Extensions == null) { material.Extensions = new Dictionary <string, Extension>(); } if (mat.transparent) { material.AlphaMode = AlphaMode.BLEND; } ExtensionManager.Serialize(ExtensionManager.GetExtensionName(typeof(Sein_customMaterialExtensionFactory)), entry, material.Extensions, mat); return(material); }
public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null) { var extension = new Sein_rendererExtension(); var mr = component as Renderer; var lightmapIndex = mr.lightmapIndex; if (ExporterSettings.Lighting.lightMap && lightmapIndex > -1) { Vector4 lightmapScaleOffset = mr.lightmapScaleOffset; var lightData = LightmapSettings.lightmaps[lightmapIndex]; var lightTexture = lightData.lightmapColor; var lightTextureIndex = entry.SaveTextureHDR(lightTexture, ExporterSettings.Lighting.lightMapType, ExporterSettings.Lighting.lightMapSize); extension.uvScale = new Vector2(lightmapScaleOffset.x, lightmapScaleOffset.y); extension.uvOffset = new Vector2(lightmapScaleOffset.z, lightmapScaleOffset.w); extension.lightMapIndex = lightTextureIndex.Id; } extension.castShadows = mr.shadowCastingMode == UnityEngine.Rendering.ShadowCastingMode.On; extension.receiveShadows = mr.receiveShadows; extension.gammaCorrection = PlayerSettings.colorSpace == ColorSpace.Linear; AddExtension(extensions, extension); }
private void ExportOne(ExporterEntry entry) { var root = entry.root; root.Asset = new Asset(); root.Asset.Generator = Config.GeneratorName; root.Asset.Version = "2.0"; root.Asset.Extras = new JProperty("exporterVersion", Config.Version.ToString()); root.Scenes = new List <Scene>(); root.Scenes.Add(new Scene()); root.Scene = new SceneId { Id = 0, Root = root }; // gamma and hdr setting entry.root.Extensions = new Dictionary <string, Extension>(); ExtensionManager.Serialize(ExtensionManager.GetExtensionName(typeof(Sein_rendererExtensionFactory)), entry, entry.root.Extensions); // if ambientMode is not Flat, use sein_imageBaseLighting extension if (ExporterSettings.Lighting.ambient && RenderSettings.ambientMode == UnityEngine.Rendering.AmbientMode.Flat) { ExtensionManager.Serialize(ExtensionManager.GetExtensionName(typeof(Sein_ambientLightExtensionFactory)), entry, entry.root.Extensions); } foreach (Transform tr in entry.transforms) { SkinnedMeshRenderer skin = tr.GetComponent <SkinnedMeshRenderer>(); if (skin) { foreach (Transform bone in skin.bones) { entry.bones.Add(bone); } } } foreach (var tr in entry.transforms) { if (!tr.gameObject.activeInHierarchy) { continue; } ExportNode(tr, entry); } // process children ProcessChildren(entry); // process skinning and bones foreach (var tr in entry.transforms) { if (!tr.gameObject.activeInHierarchy) { continue; } ExportSkin(tr, entry); } // process animations foreach (var tr in entry.transforms) { if (!tr.gameObject.activeInHierarchy) { continue; } ExportAnimations(tr, entry); } // process extensions foreach (var tr in entry.transforms) { if (!tr.gameObject.activeInHierarchy) { continue; } ExportCamera(tr, entry); ExportExtensions(tr, entry); } ExportDone(entry); }
private void ExportDone(ExporterEntry entry) { entry.Finish(); }
private void ExportComponentMaterial(SeinCustomMaterial material, MeshPrimitive primitive, ExporterEntry entry) { primitive.Material = entry.SaveComponentMaterial(material); }