public override void Save(SaveContext saveContext)
        {
            base.Save(saveContext);

            var utility = saveContext.Utility;

            saveContext.WriteObjectListPointerPlaceholder(Meshes);

            // Materials
            saveContext.WriteDICTPointerPlaceholder(ModelMaterials);

            // Shapes
            saveContext.WriteObjectListPointerPlaceholder(Shapes);

            // Mesh Node Visibilities
            saveContext.WriteObjectListPointerPlaceholder(MeshNodeVisibilities);

            utility.Write(Flags);

            utility.Write((uint)FaceCulling);

            utility.Write(LayerId);

            // Load a Skeleton if this model has one
            if (HasSkeleton)
            {
                saveContext.WritePointerPlaceholder(Skeleton);
            }

            /////////////////////////////
            // Begin saving dependent data

            // Save Lists
            saveContext.SaveAndMarkReference(Meshes);
            saveContext.SaveAndMarkReference(Shapes);
            saveContext.SaveAndMarkReference(MeshNodeVisibilities);      // I'm not SURE this is where this goes (no test data at the moment I'm writing this) but all lists seem to follow here

            // Save DICT headers
            saveContext.SaveAndMarkReference(MetaDatas);
            saveContext.SaveAndMarkReference(AnimGroup);
            saveContext.SaveAndMarkReference(ModelMaterials);

            // Now for other interior data...
            MetaDatas?.SaveEntries(saveContext);
            AnimGroup?.SaveEntries(saveContext);

            Meshes.SaveList(saveContext);
            ModelMaterials?.SaveEntries(saveContext);
            Shapes.SaveList(saveContext);
            MeshNodeVisibilities.SaveList(saveContext);

            if (HasSkeleton)
            {
                saveContext.SaveAndMarkReference(Skeleton);
            }
        }
 void SetupMaterial()
 {
     Renderer[] rr = target.GetComponentsInChildren <Renderer> ();
     if (rms == null || rms.Length < rr.Length)
     {
         rms = new ModelMaterials[rr.Length];
     }
     rmsCount = 0;
     for (int k = 0; k < rr.Length; k++)
     {
         rms [rmsCount] = new ModelMaterials();
         Renderer renderer = rr [k];
         if (renderer.transform != target && renderer.GetComponent <HighlightEffect> () != null)
         {
             continue;                     // independent subobject
         }
         if (renderer is SkinnedMeshRenderer)
         {
             SkinnedMeshRenderer smr = (SkinnedMeshRenderer)renderer;
             rms [rmsCount].mesh = new Mesh();
             rms [rmsCount].skinnedMeshRenderer = smr;
         }
         else if (renderer.gameObject.isStatic)
         {
             MeshCollider mc = renderer.GetComponent <MeshCollider> ();
             if (mc != null)
             {
                 rms [rmsCount].mesh = mc.sharedMesh;
             }
         }
         if (rms [rmsCount].mesh == null)
         {
             MeshFilter mf = renderer.GetComponent <MeshFilter> ();
             if (mf != null)
             {
                 rms [rmsCount].mesh = mf.sharedMesh;
             }
         }
         rms [rmsCount].transform       = renderer.transform;
         rms [rmsCount].material        = renderer.sharedMaterial;
         rms [rmsCount].fxMatSeeThrough = Instantiate <Material> (fxMatSeeThrough);
         rms [rmsCount].fxMatGlow       = Instantiate <Material> (fxMatGlow);
         rms [rmsCount].fxMatOutline    = Instantiate <Material> (fxMatOutline);
         rms [rmsCount].fxMatOverlay    = Instantiate <Material> (fxMatOverlay);
         rmsCount++;
     }
     UpdateMaterialProperties();
 }
Esempio n. 3
0
        public ModelRoot(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Version = br.ReadIFFChunk <TerrainVersion>();

                    this.Header = br.ReadIFFChunk <ModelRootHeader>();

                    this.Textures  = br.ReadIFFChunk <ModelTextures>();
                    this.Materials = br.ReadIFFChunk <ModelMaterials>();

                    this.GroupNames       = br.ReadIFFChunk <ModelGroupNames>();
                    this.GroupInformation = br.ReadIFFChunk <ModelGroupInformation>();

                    this.Skybox = br.ReadIFFChunk <ModelSkybox>();

                    this.PortalVertices   = br.ReadIFFChunk <ModelPortalVertices>();
                    this.Portals          = br.ReadIFFChunk <ModelPortals>();
                    this.PortalReferences = br.ReadIFFChunk <ModelPortalReferences>();

                    this.VisibleVertices = br.ReadIFFChunk <ModelVisibleVertices>();
                    this.VisibleBlocks   = br.ReadIFFChunk <ModelVisibleBlocks>();

                    this.StaticLighting = br.ReadIFFChunk <ModelStaticLighting>();

                    this.DoodadSets      = br.ReadIFFChunk <ModelDoodadSets>();
                    this.DoodadPaths     = br.ReadIFFChunk <ModelDoodadPaths>();
                    this.DoodadInstances = br.ReadIFFChunk <ModelDoodadInstances>();

                    this.Fog = br.ReadIFFChunk <ModelFog>();

                    // Optional chunk
                    if ((br.BaseStream.Position != br.BaseStream.Length) && br.PeekChunkSignature() == ModelConvexPlanes.Signature)
                    {
                        this.ConvexPlanes = br.ReadIFFChunk <ModelConvexPlanes>();
                    }

                    // Version-dependent chunk
                    if ((br.BaseStream.Position != br.BaseStream.Length) && br.PeekChunkSignature() == ModelGameObjectFileID.Signature)
                    {
                        this.GameObjectFileID = br.ReadIFFChunk <ModelGameObjectFileID>();
                    }
                }
            }
        }
Esempio n. 4
0
        void SetupMaterial()
        {
            if (target == null)
            {
                return;
            }
            SpriteRenderer[] rr = target.GetComponentsInChildren <SpriteRenderer>();
            if (rms == null || rms.Length < rr.Length)
            {
                rms = new ModelMaterials[rr.Length];
            }
            rmsCount      = 0;
            hasSpriteMask = false;
            if (aspectRatio < 0.01f)
            {
                aspectRatio = 0.01f;
            }

            for (int k = 0; k < rr.Length; k++)
            {
                rms[rmsCount] = new ModelMaterials();
                Renderer renderer = rr[k];
                rms[rmsCount].renderer = renderer;

                if (renderer is SpriteMask)
                {
                    hasSpriteMask = true;
                    continue;
                }

                if (!renderer.isVisible)
                {
                    rmsCount++;
                    continue;
                }

                rms[rmsCount].currentRenderIsVisible = true;

                if (renderer.transform != target && renderer.GetComponent <HighlightEffect2D>() != null)
                {
                    continue; // independent subobject
                }
                rms[rmsCount].center      = center;
                rms[rmsCount].aspectRatio = aspectRatio;
                if (autoSize && renderer is SpriteRenderer)
                {
                    SpriteRenderer spriteRenderer = (SpriteRenderer)renderer;
                    ComputeSpriteCenter(rmsCount, spriteRenderer.sprite);
                }
                rms[rmsCount].transform       = renderer.transform;
                rms[rmsCount].fxMatMask       = Instantiate <Material>(fxMatSpriteMask);
                rms[rmsCount].fxMatDepthWrite = Instantiate <Material>(fxMatSpriteDepthWrite);
                rms[rmsCount].fxMatGlow       = Instantiate <Material>(fxMatSpriteGlow);
                rms[rmsCount].fxMatOutline    = Instantiate <Material>(fxMatSpriteOutline);
                rms[rmsCount].fxMatSeeThrough = Instantiate <Material>(fxMatSpriteSeeThrough);
                rms[rmsCount].fxMatOverlay    = Instantiate <Material>(fxMatSpriteOverlay);
                rms[rmsCount].fxMatShadow     = Instantiate <Material>(shadow3D ? fxMatSpriteShadow3D : fxMatSpriteShadow);

                if (outlineExclusive)
                {
                    rms[rmsCount].fxMatMask.renderQueue       += 115;
                    rms[rmsCount].fxMatOutline.renderQueue    += 115;
                    rms[rmsCount].fxMatGlow.renderQueue       += 115;
                    rms[rmsCount].fxMatSeeThrough.renderQueue += 115;
                }

                if (glowOnTop)
                {
                    rms[rmsCount].fxMatGlow.renderQueue += 100;
                }
                if (outlineOnTop)
                {
                    rms[rmsCount].fxMatOutline.renderQueue += 100;
                }

                rmsCount++;
            }

            UpdateMaterialProperties();
        }
Esempio n. 5
0
 // Assumes that order of ModelMaterials is as shown
 public Material Dispatcher(ModelMaterials material)
 {
     Material[] materials = { body,     broom,    stick,       clothes, clothesAccent, eyeWhite, hair, mouth, teeth, leftEye,
                              rightEye, stocking, stockingTop, shorts };
     return(materials[(int)material]);
 }
        private void SetupMaterial()
        {
            //HACK: хайлайт где-то протекает с пустым таргетом, пока закостылим
            if (!target)
            {
                return;
            }

            Renderer[] renderers = target.GetComponentsInChildren <Renderer>();
            if (modelMaterials == null || modelMaterials.Length < renderers.Length)
            {
                modelMaterials = new ModelMaterials[renderers.Length];
            }

            for (int i = 0; i < renderers.Length; i++)
            {
                Renderer renderer = renderers[i];
                modelMaterials[i]          = new ModelMaterials();
                modelMaterials[i].renderer = renderer;

                if (!renderer.isVisible)
                {
                    continue;
                }

                if (renderer.transform != target && renderer.GetComponent <HighlightEffect>() != null)
                {
                    continue;                     // independent subobject
                }

                if (renderer is SkinnedMeshRenderer)
                {
                    // ignore cloth skinned renderers
                    modelMaterials[i].cloth = renderer.GetComponent <Cloth>() != null;
                    SkinnedMeshRenderer smr = (SkinnedMeshRenderer)renderer;
                    modelMaterials [i].mesh = new Mesh();
                    modelMaterials [i].skinnedMeshRenderer = smr;
                }
                else if (renderer.gameObject.isStatic)
                {
                    MeshCollider mc = renderer.GetComponent <MeshCollider> ();
                    if (mc != null)
                    {
                        modelMaterials [i].mesh = mc.sharedMesh;
                    }
                }

                if (modelMaterials [i].mesh == null)
                {
                    MeshFilter mf = renderer.GetComponent <MeshFilter> ();
                    if (mf != null)
                    {
                        modelMaterials [i].mesh = mf.sharedMesh;
                    }
                }

                modelMaterials[i].transform              = renderer.transform;
                modelMaterials [i].fxMatGlow             = Instantiate <Material> (fxMatGlow);
                modelMaterials[i].fxMatOutline           = Instantiate <Material>(fxMatOutline);
                modelMaterials[i].fxMatSeeThrough        = Fork(fxMatSeeThrough, renderer.sharedMaterials);
                modelMaterials[i].fxMatOverlay           = Fork(fxMatOverlay, renderer.sharedMaterials);
                modelMaterials[i].originalMesh           = modelMaterials[i].mesh;
                modelMaterials[i].currentRenderIsVisible = true;

                if (modelMaterials [i].skinnedMeshRenderer == null)
                {
                    // check if scale is negative
                    BakeTransform(i, true);
                }
            }

            UpdateMaterialProperties();
        }
        void SetupMaterial()
        {
                        #if UNITY_EDITOR
            staticChildren = false;
                        #endif

            if (target == null || fxMatMask == null)
            {
                return;
            }

            Renderer[] rr = target.GetComponentsInChildren <Renderer> ();
            if (rms == null || rms.Length < rr.Length)
            {
                rms = new ModelMaterials[rr.Length];
            }

            rmsCount = 0;
            for (int k = 0; k < rr.Length; k++)
            {
                rms [rmsCount] = new ModelMaterials();
                Renderer renderer = rr [k];
                rms [rmsCount].renderer = renderer;
                rms [rmsCount].renderWasVisibleDuringSetup = renderer.isVisible;

                if (renderer.transform != target && renderer.GetComponent <HighlightEffect> () != null)
                {
                    continue;                     // independent subobject
                }
                if (OnRendererHighlightStart != null)
                {
                    if (!OnRendererHighlightStart(renderer))
                    {
                        rmsCount++;
                        continue;
                    }
                }

                if (renderer is SkinnedMeshRenderer)
                {
                    // ignore cloth skinned renderers
                    rms [rmsCount].skinnedMesh = true;
                    rms [rmsCount].mesh        = ((SkinnedMeshRenderer)renderer).sharedMesh;
                    CheckCommandBuffers();
                }
                else if (Application.isPlaying && renderer.isPartOfStaticBatch)
                {
                    // static batched objects need to have a mesh collider in order to use its original mesh
                    MeshCollider mc = renderer.GetComponent <MeshCollider> ();
                    if (mc != null)
                    {
                        rms [rmsCount].mesh = mc.sharedMesh;
                    }
                }
                else
                {
                    MeshFilter mf = renderer.GetComponent <MeshFilter> ();
                    if (mf != null)
                    {
                        rms [rmsCount].mesh = mf.sharedMesh;

                                                #if UNITY_EDITOR
                        if (renderer.gameObject.isStatic && renderer.GetComponent <MeshCollider> () == null)
                        {
                            staticChildren = true;
                        }
                                                #endif
                    }
                }

                if (rms [rmsCount].mesh == null)
                {
                    continue;
                }

                rms [rmsCount].transform       = renderer.transform;
                rms [rmsCount].material        = renderer.sharedMaterial;
                rms [rmsCount].fxMatGlow       = Instantiate <Material> (fxMatGlow);
                rms [rmsCount].fxMatInnerGlow  = Instantiate <Material> (fxMatInnerGlow);
                rms [rmsCount].fxMatOutline    = Instantiate <Material> (fxMatOutline);
                rms [rmsCount].fxMatSeeThrough = Fork(fxMatSeeThrough, rms [rmsCount].mesh);
                rms [rmsCount].fxMatOverlay    = Fork(fxMatOverlay, rms [rmsCount].mesh);
                rms [rmsCount].fxMatTarget     = Instantiate <Material> (fxMatTarget);
                rms [rmsCount].originalMesh    = rms [rmsCount].mesh;
                if (!rms [rmsCount].skinnedMesh)
                {
                    // check if scale is negative
                    BakeTransform(rmsCount, true);
                }
                rmsCount++;
            }

            UpdateMaterialProperties();
        }