public dynamic LoadComponent(Stream stream, int index, NotLoaded comp) { stream.Position = comp.offset; try { switch (comp.classID1) { case UnityClassID.AnimationClip: { AnimationClip animationClip = new AnimationClip(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, animationClip, comp); animationClip.LoadFrom(stream); return animationClip; } case UnityClassID.Animator: { Animator animator = new Animator(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, animator, comp); animator.LoadFrom(stream); return animator; } case UnityClassID.AnimatorController: { AnimatorController animatorController = new AnimatorController(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, animatorController, comp); animatorController.LoadFrom(stream); return animatorController; } case UnityClassID.AssetBundle: { AssetBundle assetBundle = new AssetBundle(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, assetBundle, comp); assetBundle.LoadFrom(stream); return assetBundle; } case UnityClassID.AudioClip: { if (loadingReferencials) { return comp; } AudioClip ac = new AudioClip(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, ac, comp); ac.LoadFrom(stream); return ac; } case UnityClassID.AudioListener: { AudioListener audioListener = new AudioListener(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, audioListener, comp); audioListener.LoadFrom(stream); return audioListener; } case UnityClassID.AudioSource: { AudioSource audioSrc = new AudioSource(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, audioSrc, comp); audioSrc.LoadFrom(stream); return audioSrc; } case UnityClassID.Avatar: { if (loadingReferencials) { return comp; } Avatar avatar = new Avatar(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, avatar, comp); avatar.LoadFrom(stream); return avatar; } case UnityClassID.BoxCollider: { BoxCollider boxCol = new BoxCollider(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, boxCol, comp); boxCol.LoadFrom(stream); return boxCol; } case UnityClassID.Camera: { Camera camera = new Camera(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, camera, comp); camera.LoadFrom(stream); return camera; } case UnityClassID.CapsuleCollider: { CapsuleCollider capsuleCol = new CapsuleCollider(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, capsuleCol, comp); capsuleCol.LoadFrom(stream); return capsuleCol; } case UnityClassID.Cubemap: { Cubemap cubemap = new Cubemap(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, cubemap, comp); cubemap.LoadFrom(stream); Parser.Textures.Add(cubemap); return cubemap; } case UnityClassID.EllipsoidParticleEmitter: { EllipsoidParticleEmitter ellipsoid = new EllipsoidParticleEmitter(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, ellipsoid, comp); ellipsoid.LoadFrom(stream); return ellipsoid; } case UnityClassID.FlareLayer: { FlareLayer flareLayer = new FlareLayer(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, flareLayer, comp); flareLayer.LoadFrom(stream); return flareLayer; } case UnityClassID.Light: { Light light = new Light(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, light, comp); light.LoadFrom(stream); return light; } case UnityClassID.LinkToGameObject: { LinkToGameObject link = new LinkToGameObject(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, link, comp); link.LoadFrom(stream); return link; } case UnityClassID.LinkToGameObject223: { LinkToGameObject223 link = new LinkToGameObject223(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, link, comp); link.LoadFrom(stream); return link; } case UnityClassID.LinkToGameObject225: { LinkToGameObject225 link = new LinkToGameObject225(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, link, comp); link.LoadFrom(stream); return link; } case UnityClassID.GameObject: { GameObject gameObj = new GameObject(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, gameObj, comp); gameObj.LoadFrom(stream); return gameObj; } case UnityClassID.Material: { Material mat = new Material(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, mat, comp); mat.LoadFrom(stream); return mat; } case UnityClassID.Mesh: { if (loadingReferencials) { return comp; } Mesh mesh = new Mesh(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, mesh, comp); mesh.LoadFrom(stream); return mesh; } case UnityClassID.MeshCollider: { MeshCollider meshCol = new MeshCollider(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, meshCol, comp); meshCol.LoadFrom(stream); return meshCol; } case UnityClassID.MeshFilter: { MeshFilter meshFilter = new MeshFilter(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, meshFilter, comp); meshFilter.LoadFrom(stream); return meshFilter; } case UnityClassID.MeshRenderer: { MeshRenderer meshRenderer = new MeshRenderer(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, meshRenderer, comp); meshRenderer.LoadFrom(stream); return meshRenderer; } default: if (comp.classID2 == UnityClassID.MonoBehaviour) { if (Types.Count > 0) { MonoBehaviour monoBehaviour = new MonoBehaviour(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, monoBehaviour, comp); monoBehaviour.LoadFrom(stream); return monoBehaviour; } else { string message = comp.classID2 + " unhandled because of absence of Types in Cabinet (*.assets)"; if (!reported.Contains(message)) { Report.ReportLog(message); reported.Add(message); } return comp; } } else { string message = "Unhandled class: " + comp.classID1 + "/" + comp.classID2; if (!reported.Contains(message)) { Report.ReportLog(message); reported.Add(message); } } break; case UnityClassID.MonoScript: { if (loadingReferencials) { return comp; } MonoScript monoScript = new MonoScript(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, monoScript, comp); monoScript.LoadFrom(stream); return monoScript; } case UnityClassID.MultiLink: { MultiLink multi = new MultiLink(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, multi, comp); multi.LoadFrom(stream); return multi; } case UnityClassID.ParticleAnimator: { ParticleAnimator particleAnimator = new ParticleAnimator(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, particleAnimator, comp); particleAnimator.LoadFrom(stream); return particleAnimator; } case UnityClassID.ParticleRenderer: { ParticleRenderer particleRenderer = new ParticleRenderer(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, particleRenderer, comp); particleRenderer.LoadFrom(stream); return particleRenderer; } case UnityClassID.ParticleSystem: { ParticleSystem particleSystem = new ParticleSystem(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, particleSystem, comp); particleSystem.LoadFrom(stream); return particleSystem; } case UnityClassID.ParticleSystemRenderer: { ParticleSystemRenderer particleSystemRenderer = new ParticleSystemRenderer(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, particleSystemRenderer, comp); particleSystemRenderer.LoadFrom(stream); return particleSystemRenderer; } case UnityClassID.Projector: { Projector projector = new Projector(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, projector, comp); projector.LoadFrom(stream); return projector; } case UnityClassID.Rigidbody: { RigidBody rigidBody = new RigidBody(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, rigidBody, comp); rigidBody.LoadFrom(stream); return rigidBody; } case UnityClassID.Shader: { Shader shader = new Shader(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, shader, comp); shader.LoadFrom(stream); return shader; } case UnityClassID.SkinnedMeshRenderer: { SkinnedMeshRenderer sMesh = new SkinnedMeshRenderer(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, sMesh, comp); sMesh.LoadFrom(stream); return sMesh; } case UnityClassID.SphereCollider: { SphereCollider sphereCol = new SphereCollider(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, sphereCol, comp); sphereCol.LoadFrom(stream); return sphereCol; } case UnityClassID.Sprite: { Sprite sprite = new Sprite(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, sprite, comp); sprite.LoadFrom(stream); return sprite; } case UnityClassID.SpriteRenderer: { SpriteRenderer spriteRenderer = new SpriteRenderer(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, spriteRenderer, comp); spriteRenderer.LoadFrom(stream); return spriteRenderer; } case UnityClassID.TextAsset: { if (loadingReferencials) { return comp; } TextAsset ta = new TextAsset(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, ta, comp); ta.LoadFrom(stream); return ta; } case UnityClassID.Texture2D: { if (loadingReferencials) { return comp; } Texture2D tex = new Texture2D(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, tex, comp); tex.LoadFrom(stream); Parser.Textures.Add(tex); return tex; } case UnityClassID.Transform: { Transform trans = new Transform(this, comp.pathID, comp.classID1, comp.classID2); ReplaceSubfile(index, trans, comp); trans.LoadFrom(stream); return trans; } } } catch { Report.ReportLog("Failed to load " + comp.classID1 + "/" + comp.classID2 + " PathID=" + comp.pathID); foreach (NotLoaded notLoaded in RemovedList) { if (notLoaded == comp) { RemovedList.Remove(notLoaded); Components.RemoveAt(index); notLoaded.replacement = null; Components.Insert(index, notLoaded); break; } } } return null; }
public void MergeTexture(Texture2D tex) { if (tex.file != Parser.file) { Texture2D dstTex = Parser.file.Parser.GetTexture(tex.m_Name); bool isNew = false; if (dstTex == null) { dstTex = new Texture2D(Parser.file); isNew = true; } tex.CopyAttributesTo(dstTex); tex.CopyImageTo(dstTex); if (isNew) { if (Parser.file.Bundle != null) { Parser.file.Bundle.AddComponent(dstTex); } Textures.Add(dstTex); } Changed = true; } }
public static void ReplaceTexture(Texture2D tex, ImportedTexture texture) { if (tex == null) { throw new Exception("This type of replacing a texture requires an existing texture with the same name"); } Texture2D t2d = new Texture2D(null, tex.pathID, tex.classID1, tex.classID2); t2d.LoadFrom(texture); tex.m_MipMap = t2d.m_MipMap; tex.m_Width = t2d.m_Width; tex.m_Height = t2d.m_Height; tex.m_CompleteImageSize = t2d.m_CompleteImageSize; tex.m_TextureFormat = t2d.m_TextureFormat; tex.m_ImageCount = t2d.m_ImageCount; tex.m_TextureDimension = t2d.m_TextureDimension; tex.image_data = t2d.image_data; }
public void AddTexture(ImportedTexture image) { Texture2D tex = new Texture2D(Parser.file); Textures.Add(tex); tex.LoadFrom(image); if (Parser.file.Bundle != null) { Parser.file.Bundle.AddComponent(tex); } Changed = true; }
public void MergeTexture(ImportedTexture tex) { string texName; Match m = Regex.Match(tex.Name, @"(.+)-([^-]+)(\..+)", RegexOptions.CultureInvariant); if (m.Success) { texName = m.Groups[1].Value; } else { texName = Path.GetFileNameWithoutExtension(tex.Name); } Texture2D dstTex = Parser.file.Parser.GetTexture(texName); bool isNew = false; if (dstTex == null) { dstTex = new Texture2D(Parser.file); isNew = true; } dstTex.LoadFrom(tex); if (isNew) { if (Parser.file.Bundle != null) { Parser.file.Bundle.AddComponent(dstTex); } Textures.Add(dstTex); } Changed = true; }
private void Export(string dest, Material mat, Texture2D tex) { DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(dest)); if (!dir.Exists) { dir.Create(); } usedTextures = new List<Texture2D>(1); using (StreamWriter writer = new StreamWriter(dest, false)) { writer.WriteLine("Metasequoia Document"); writer.WriteLine("Format Text Ver 1.0"); writer.WriteLine(); if (mat != null) { writer.WriteLine("Material 1 {"); string s = "\t\"" + mat.m_Name + "\" vcol(1) col(0.800 0.800 0.800 1.000) dif(0.500) amb(0.100) emi(0.500) spc(0.100) power(30.00)"; if (tex != null) { string extension = tex.m_TextureFormat == TextureFormat.DXT1 || tex.m_TextureFormat == TextureFormat.DXT5 ? ".dds" : ".tga"; s += " tex(\"" + tex.m_Name + extension + "\")"; usedTextures.Add(tex); } writer.WriteLine(s); writer.WriteLine("}"); } Mesh mesh = Operations.GetMesh(morphObj); Random rand = new Random(); int vertListIdx = 0; for (int i = 0; i < mesh.m_Shapes.shapes.Count; i++) { float[] color = new float[3]; for (int k = 0; k < color.Length; k++) { color[k] = (float)((rand.NextDouble() / 2) + 0.5); } writer.WriteLine("Object \"" + mesh.m_Shapes.channels[i].name + "\" {"); writer.WriteLine("\tvisible 0"); writer.WriteLine("\tshading 1"); writer.WriteLine("\tcolor " + color[0].ToFloatString() + " " + color[1].ToFloatString() + " " + color[2].ToFloatString()); writer.WriteLine("\tcolor_type 1"); SB3Utility.Mqo.ExporterCommon.WriteMeshObject(writer, vertLists[vertListIdx++], faceList, mat != null ? 0 : -1, colorLists[i]); writer.WriteLine("}"); } writer.WriteLine("Eof"); } }
private void ConvertTexture2D(Texture2D tex2D, string name) { ImportedTexture iTex = ImportedHelpers.FindTexture(name, TextureList); if (iTex != null) { return; } using (MemoryStream memStream = new MemoryStream()) { tex2D.Export(memStream); memStream.Position = 0; iTex = new ImportedTexture(memStream, name); } TextureList.Add(iTex); }
public void CopyImageTo(Texture2D dst) { dst.m_Name = m_Name; dst.m_Width = m_Width; dst.m_Height = m_Height; dst.m_CompleteImageSize = m_CompleteImageSize; dst.m_TextureFormat = m_TextureFormat; dst.m_ImageCount = m_ImageCount; dst.m_TextureDimension = m_TextureDimension; dst.image_data = (byte[])image_data.Clone(); }
public void CopyAttributesTo(Texture2D dst) { dst.m_MipMap = m_MipMap; dst.m_isReadable = m_isReadable; dst.m_ReadAllowed = m_ReadAllowed; m_TextureSettings.CopyTo(dst.m_TextureSettings); dst.m_LightmapFormat = m_LightmapFormat; dst.m_ColorSpace = m_ColorSpace; }
public Texture2D Clone(AssetCabinet file) { Component tex = file.Bundle != null ? file.Bundle.FindComponent(m_Name, UnityClassID.Texture2D) : file.Parser.GetTexture(m_Name); if (tex == null) { file.MergeTypeDefinition(this.file, UnityClassID.Texture2D); tex = new Texture2D(file); if (file.Bundle != null) { file.Bundle.AddComponent(m_Name, tex); } CopyAttributesTo((Texture2D)tex); CopyImageTo((Texture2D)tex); } else if (tex is NotLoaded) { NotLoaded notLoaded = (NotLoaded)tex; if (notLoaded.replacement != null) { tex = notLoaded.replacement; } else { tex = file.LoadComponent(file.SourceStream, notLoaded); } } return (Texture2D)tex; }