Esempio n. 1
0
 protected override void CombineMesh(BuildingType buildingType, MeshCombiner meshCombiner)
 {
     if (this.IsHomeCombiningEligible())
     {
         BuildingController buildingController = Service.BuildingController;
         SmartEntity        selectedBuilding   = buildingController.SelectedBuilding;
         if (selectedBuilding != null)
         {
             BuildingType  buildingTypeFromBuilding           = base.GetBuildingTypeFromBuilding(selectedBuilding);
             BuildingMover buildingMoverForCombineMeshManager = Service.BuildingController.GetBuildingMoverForCombineMeshManager();
             Vector3       zero = Vector3.zero;
             if (buildingTypeFromBuilding == buildingType)
             {
                 buildingMoverForCombineMeshManager.DeselectBuildingBeforeCombiningMesh(out selectedBuilding, out zero);
             }
             base.CombineMesh(buildingType, meshCombiner);
             if (buildingTypeFromBuilding == buildingType)
             {
                 buildingMoverForCombineMeshManager.SelectBuildingAfterCombiningMesh(selectedBuilding, zero);
             }
         }
         else
         {
             base.CombineMesh(buildingType, meshCombiner);
         }
     }
 }
Esempio n. 2
0
        public static IEnumerable <IDivisibleMesh <TVertex> > Split <TVertex>(
            int maxVerticesPerMesh, IDivisibleMesh <TVertex> mesh)
            where TVertex : struct
        {
            Contracts.Requires.That(maxVerticesPerMesh >= MeshConstants.VerticesPerTriangle);
            Contracts.Requires.That(mesh != null);
            Contracts.Requires.That(mesh.Groups.All(group => group.Vertices <= maxVerticesPerMesh));

            if (mesh.Vertices.Count <= maxVerticesPerMesh)
            {
                yield return(mesh);

                yield break;
            }

            var combiner = new MeshCombiner <TVertex>(maxVerticesPerMesh);

            foreach (var submesh in Split(mesh, combiner))
            {
                yield return(submesh);
            }

            if (combiner.VertexCount > 0)
            {
                yield return(combiner.CreateMesh());
            }
        }
Esempio n. 3
0
 protected override void UncombineMesh(BuildingType buildingType, MeshCombiner meshCombiner)
 {
     if (this.IsHomeCombiningEligible())
     {
         base.UncombineMesh(buildingType, meshCombiner);
     }
 }
Esempio n. 4
0
 private void OnGUI()
 {
     if (GUILayout.Button("Combine"))
     {
         MeshCombiner.MultiCombine(meshesRoot, meshSave);
     }
 }
Esempio n. 5
0
        public static IEnumerable <IDivisibleMesh <TVertex> > CombineAndSplit <TVertex>(
            int maxVerticesPerMesh, IEnumerable <IDivisibleMesh <TVertex> > meshes)
            where TVertex : struct
        {
            Contracts.Requires.That(maxVerticesPerMesh >= MeshConstants.VerticesPerTriangle);
            Contracts.Requires.That(meshes.AllAndSelfNotNull());
            Contracts.Requires.That(
                meshes.All(mesh => mesh.Groups.All(group => group.Vertices <= maxVerticesPerMesh)));

            var combiner = new MeshCombiner <TVertex>(maxVerticesPerMesh);

            foreach (var mesh in meshes.Where(mesh => !mesh.IsEmpty()))
            {
                if (!combiner.TryAdd(mesh))
                {
                    foreach (var submesh in Split(mesh, combiner))
                    {
                        yield return(submesh);
                    }
                }
            }

            if (combiner.VertexCount > 0)
            {
                yield return(combiner.CreateMesh());
            }
        }
Esempio n. 6
0
        public CombineMeshManager()
        {
            Service.Set <CombineMeshManager>(this);
            EventManager eventManager = Service.Get <EventManager>();

            this.meshCombinerGameObjectPool  = MeshCombiner.CreateMeshCombinerObjectPool();
            this.combinedMeshesGameObject    = new GameObject("CombinedMeshes");
            this.homeBaseCobmbineMeshHelper  = new HomeBaseCombineMeshHelper();
            this.battleBaseCombineMeshHelper = new BattleBaseCombineMeshHelper();
            HashSet <BuildingType> hashSet = new HashSet <BuildingType>();

            hashSet.UnionWith(this.homeBaseCobmbineMeshHelper.GetEligibleBuildingTypes());
            hashSet.UnionWith(this.battleBaseCombineMeshHelper.GetEligibleBuildingTypes());
            this.meshCombiners = new Dictionary <BuildingType, MeshCombiner>();
            foreach (BuildingType current in hashSet)
            {
                this.meshCombiners.Add(current, new MeshCombiner(this.meshCombinerGameObjectPool, this.combinedMeshesGameObject, current.ToString()));
            }
            eventManager.RegisterObserver(this, EventId.GameStateChanged, EventPriority.MeshCombineAfterOthers);
            eventManager.RegisterObserver(this, EventId.WorldLoadComplete, EventPriority.MeshCombineAfterOthers);
            eventManager.RegisterObserver(this, EventId.ShaderResetOnEntity, EventPriority.MeshCombineAfterOthers);
            eventManager.RegisterObserver(this, EventId.StartupTasksCompleted, EventPriority.MeshCombineAfterOthers);
            eventManager.RegisterObserver(this, EventId.BuildingConstructed, EventPriority.BeforeDefault);
            eventManager.RegisterObserver(this, EventId.BuildingLevelUpgraded, EventPriority.BeforeDefault);
            eventManager.RegisterObserver(this, EventId.BuildingSwapped, EventPriority.BeforeDefault);
            eventManager.RegisterObserver(this, EventId.ClearableCleared, EventPriority.AfterDefault);
            eventManager.RegisterObserver(this, EventId.WorldReset, EventPriority.BeforeDefault);
            eventManager.RegisterObserver(this, EventId.PostBuildingEntityKilled, EventPriority.Default);
            eventManager.RegisterObserver(this, EventId.BuildingViewReady, EventPriority.Default);
            eventManager.RegisterObserver(this, EventId.BuildingViewFailed, EventPriority.Default);
        }
Esempio n. 7
0
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        MeshCombiner window = (MeshCombiner)EditorWindow.GetWindow(typeof(MeshCombiner));

        window.Show();
        window.UpdateList();
    }
Esempio n. 8
0
 void CombineMesh(GameObject tempModel)
 {
     _meshCombiner = tempModel.AddComponent <MeshCombiner>();
     _meshCombiner.CreateMultiMaterialMesh    = true;
     _meshCombiner.DeactivateCombinedChildren = false;
     _meshCombiner.DestroyCombinedChildren    = true;
     _meshCombiner.CombineMeshes(false);
 }
    static void GeneratePrefab()
    {
        GameObject go = Selection.activeGameObject;

        // If the object has a top level mesh, move it to children
        var topLevelMesh = go.GetComponent <SkinnedMeshRenderer>();

        if (topLevelMesh)
        {
            GameObject lod = new GameObject("LOD0");
            lod.transform.parent = go.transform;
            SkinnedMeshRenderer lodRenderer = lod.AddComponent <SkinnedMeshRenderer>();
            UnityEditorInternal.ComponentUtility.CopyComponent(topLevelMesh);
            UnityEditorInternal.ComponentUtility.PasteComponentValues(lodRenderer);
            GameObject.Destroy(topLevelMesh);
        }

        // Combine mesh if necessary
        if (go.transform.childCount > 2)
        {
            MeshCombiner.MergeSkinnedMesh(go);
        }

        // Validation
        var mesh = go.GetComponentInChildren <SkinnedMeshRenderer>();

        if (mesh == null)
        {
            Debug.LogError("No skinned mesh found in children!");
        }

        // Components
        var renderer  = go.AddComponent <GPUSkinRenderer>();
        var crowdMgr  = go.AddComponent <CrowdManager>();
        var weaponMgr = go.AddComponent <WeaponManager>();
        var collider  = go.AddComponent <CapsuleCollider>();
        var animator  = go.GetComponent <Animator>();

        if (!animator)
        {
            animator = go.AddComponent <Animator>();
        }
        animator.enabled = false;

        // Default values
        renderer.GPUSkinShader       = (Shader)AssetDatabase.LoadAssetAtPath("Assets/Materials/GPUSkinShader.shader", typeof(Shader));
        renderer.GPUSkinShaderSimple = (Shader)AssetDatabase.LoadAssetAtPath("Assets/Materials/GPUSkinShaderSimple.shader", typeof(Shader));

        // Try to fit the collider to the mesh
        if (mesh)
        {
            var bounds = mesh.bounds;
            collider.center = bounds.center;
            collider.radius = new Vector2(bounds.extents.x, bounds.extents.y).magnitude;
            collider.height = bounds.size.z;
        }
    }
Esempio n. 10
0
    void OnSceneGUI()
    {
        MeshCombiner mc = target as MeshCombiner;

        if (Handles.Button(mc.transform.position + Vector3.up * 1.8f, Quaternion.LookRotation(Vector3.up), 0.3f, 0.3f, Handles.CylinderHandleCap))
        {
            mc.AdvancedMerge();
        }
    }
Esempio n. 11
0
        /// <summary>
        /// パーツが子以下の改装にメッシュを持っていた場合、1つのメッシュとなるように結合する。
        /// </summary>
        static async Task combinePartMeshesAsync(this _StructurePartBase part)
        {
            // 子孫にメッシュが存在すれば、引っ張ってきて結合。1つのメッシュにする。
            // (ただしパーツだった場合は、結合対象から除外する)
            var buildTargets = queryTargets_Recursive_(part.gameObject).ToArray();

            if (buildTargets.Length == 1)
            {
                return;
            }

            var meshElements = await combineChildMeshesAsync_(buildTargets, part.transform);

            //
            replaceOrAddComponents_CombinedMeshAndMaterials_(part.gameObject, meshElements);
            removeOrigineComponents_(buildTargets.Skip(1));

            return;


            IEnumerable <GameObject> queryTargets_Recursive_(GameObject go_) =>
            (
                from child in go_.Children()
                    where child.GetComponent <_StructurePartBase>() == null
                from x in queryTargets_Recursive_(child)
                select x
            )
            .Prepend(go_);

            async Task <MeshElements> combineChildMeshesAsync_(IEnumerable <GameObject> targets_, Transform tf_)
            {
                var combineElementFunc =
                    MeshCombiner.BuildNormalMeshElements(targets_, tf_, isCombineSubMeshes: true);

                return(await Task.Run(combineElementFunc));
            }

            void removeOrigineComponents_(IEnumerable <GameObject> targets_)
            {
                foreach (var go in targets_)
                {
                    go.DestroyComponentIfExists <MeshFilter>();
                    go.DestroyComponentIfExists <Renderer>();
                }
            }

            void replaceOrAddComponents_CombinedMeshAndMaterials_(GameObject gameObject_, MeshElements me_)
            {
                var mf = gameObject_.GetComponent <MeshFilter>().As() ?? gameObject_.AddComponent <MeshFilter>();

                mf.sharedMesh = me_.CreateMesh();

                var mr = gameObject_.GetComponent <MeshRenderer>().As() ?? gameObject_.AddComponent <MeshRenderer>();

                mr.materials = me_.materials;
            }
        }
Esempio n. 12
0
    void OnSceneGUI()
    {
        MeshCombiner mc = target as MeshCombiner;

        if (Handles.Button(mc.transform.position + (Vector3.up * 5), Quaternion.LookRotation(Vector3.up), 1, 1, Handles.CylinderHandleCap))
        {
            mc.CombineMeshes();
        }
    }
Esempio n. 13
0
    public override void OnInspectorGUI()
    {
        MeshCombiner meshCombiner = target as MeshCombiner;

        base.OnInspectorGUI();
        if (GUILayout.Button("Combine Meshes"))
        {
            meshCombiner.CombineMeshes();
        }
    }
Esempio n. 14
0
    public static void CombineMesh()
    {
        GameObject go = Selection.activeGameObject;

        if (go == null)
        {
            return;
        }
        MeshCombiner.Combine(go);
    }
Esempio n. 15
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        MeshCombiner combiner = (MeshCombiner)target;

        if (GUILayout.Button("Combine"))
        {
            combiner.CombineMeshes();
        }
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        MeshCombiner mc = target as MeshCombiner;

        if (GUILayout.Button("Combine Meshes"))
        {
            mc.CombineMeshes();
        }
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        MeshCombiner meshCombiner = (MeshCombiner)target;

        if (GUILayout.Button("Combinar"))
        {
            meshCombiner.Combine();
        }
    }
Esempio n. 18
0
    public override void OnInspectorGUI()
    {
        MeshCombiner targetScript = (MeshCombiner)target;

        base.OnInspectorGUI();
        if (GUILayout.Button("Combine mesh"))
        {
            Undo.RecordObject(targetScript, "Combine mesh");
            targetScript.CombineMesh();
        }
    }
Esempio n. 19
0
    void OnSceneGUI()
    {
        MeshCombiner mc  = target as MeshCombiner;
        Vector3      pos = new Vector3();

        pos.Set(0f, 0f, 0f);
        if (Handles.Button(pos, Quaternion.LookRotation(Vector3.up), 1, 1, Handles.CylinderCap))
        {
            mc.CombineMeshes();
        }
    }
 public override Mesh getMesh(GameObject putMeshOnGO)
 {
     return(MeshCombiner.start().add(new Extruder[]
     {
         this.leftRailExtruder,
         this.rightRailExtruder,
         TrackBeamExtruder [0],
         TrackBeamExtruder [1],
         TrackBeamExtruder [2],
         TrackBeamExtruder [3],
         SupportBeamExtruder,
         SupportBottomBeamExtruder
     }).add(TrackBeamExtruder).end(putMeshOnGO.transform.worldToLocalMatrix));
 }
Esempio n. 21
0
    public override void OnInspectorGUI()
    {
        MeshCombiner cm = target as MeshCombiner;

        if (GUILayout.Button("Combine meshes"))
        {
            cm.Combining();
        }

        if (GUILayout.Button("Edit"))
        {
            cm.Edit();
        }
    }
Esempio n. 22
0
    static List <GameObject> CombineRecursively(GameObject go, GameObject root, List <GameObject> children)
    {
        if (go == null)
        {
            return(null);
        }
        for (int i = 0; i < go.transform.childCount; i++)
        {
            MeshCombiner.CombineRecursively(go.transform.GetChild(i).gameObject, root, children);
        }

        // StaticBatchingUtility.Combine(go, root);
        children.Add(go);
        return(children);
    }
Esempio n. 23
0
 public Cuadrante(Mapa <T> mapa, int cuadranteX, int cuadranteZ, bool generaGameObject)
 {
     this.generaGameObject = generaGameObject;
     this.mapa             = mapa;
     this.cuadranteX       = cuadranteX;
     this.cuadranteZ       = cuadranteZ;
     this.contenedorCapas  = new Dictionary <int, Capa <T> >();
     /*---------------------------------------------------------*/
     if (generaGameObject)
     {
         gameObject = new GameObject("Cuadrante_" + cuadranteX + "_" + cuadranteZ);
         gameObject.transform.parent        = mapa.gameObject.transform;
         gameObject.transform.localPosition = new Vector3(cuadranteX * mapa.cuadranteTam, 0, cuadranteZ * mapa.cuadranteTam);
         this.meshCombiner = this.gameObject.AddComponent <MeshCombiner>();
     }
 }
Esempio n. 24
0
        /// <summary>
        /// この GameObject をルートとしたメッシュを結合する、メッシュ生成デリゲートを列挙して返す。
        /// ただし LodOptionalMeshTops に登録した「LODメッシュ」のみを対象とする。
        /// デフォルトメッシュは結合対象にはならない。
        /// またLODに null を登録した場合は、ルートから検索して最初に発見したメッシュを
        /// 加工せずに採用するため、この関数では配列に null を格納して返される。
        /// 返される要素数は、 LodOptionalMeshTops.Length と同じ。
        /// </summary>
        public Func <MeshElements>[] GetMeshCombineFuncPerObjects()
        {
            var qResult = Enumerable.Empty <Func <MeshElements> >();

            if (this.LodOptionalMeshTops.Length == 0)
            {
                return(qResult.ToArray());
            }

            return(this.LodOptionalMeshTops
                   .Select(x => x.objectTop)
                   .Select(lod => lod != null
                   ? MeshCombiner.BuildNormalMeshElements(lod.ChildrenAndSelf(), this.transform)
                   : null
                           )
                   .ToArray());
        }
Esempio n. 25
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        MeshCombiner mc = (MeshCombiner)target;

        if (GUILayout.Button("Combine Mesh Basic"))
        {
            mc.CombineMeshBasic();
        }
        if (GUILayout.Button("Combine Mesh Advanced"))
        {
            mc.CombineMeshAdvanced();
        }
        if (GUILayout.Button("Save Mesh"))
        {
            mc.SaveMesh();
        }
    }
Esempio n. 26
0
    public void OnSceneGUI()
    {
        MeshCombiner mc = (MeshCombiner)base.target;

        EditorGUI.BeginChangeCheck();
        float areaOfEffect = Handles.RadiusHandle(Quaternion.identity, mc.transform.position, mc._Test);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(target, "Changed Area Of Effect");
            mc._Test = areaOfEffect;
        }

        if (Handles.Button(mc.transform.position + Vector3.up * 20, Quaternion.LookRotation(Vector3.up), 1, 1, Handles.SphereHandleCap))
        {
            mc.CombineMeshes();
        }
    }
Esempio n. 27
0
    IEnumerator ChunkUpdate()
    {
        if (!IsInitialised)
        {
            VoxelIndex     = GenerateVoxelIndex();
            CurrentVoxels  = new BlockTypes[ChunkSize, ChunkHeight, ChunkSize];
            VoxelInstances = new GameObject[ChunkSize, ChunkHeight, ChunkSize];
            IsInitialising = true;

            yield return(new WaitForEndOfFrame());
        }

        for (int x = 0; x < ChunkSize; x++)
        {
            for (int z = 0; z < ChunkSize; z++)
            {
                for (int y = 0; y < ChunkHeight; y++)
                {
                    UpdateVoxel(x, y, z);
                }

                if (IsInitialising)
                {
                    yield return(new WaitForEndOfFrame());
                }
            }
        }

        MeshCombiner.combineMeshWithMaterials(VoxelInstances, gameObject);

        if (SpawnPlayerAfterUpdate)
        {
            SpawnPlayerAfterUpdate = false;
            SpawnPlayer();
        }

        if (IsInitialising && !IsInitialised)
        {
            IsInitialised  = true;
            IsInitialising = false;
        }

        yield break;
    }
Esempio n. 28
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        MeshCombiner mc_target = (MeshCombiner)target;

        EditorGUILayout.LabelField("Press the button to combine the meshes in childs :)");
        if (GUILayout.Button("Combine Meshes"))
        {
            mc_target.CombineMeshes();
        }

        /*if (GUILayout.Button("Show Childs"))
         * {
         *  mc_target.SeeChilds();
         * }
         * if (GUILayout.Button("Hide Childs"))
         * {
         *  mc_target.HideChilds();
         * }*/
    }
Esempio n. 29
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        MeshCombiner mc = target as MeshCombiner;

        if (GUILayout.Button("Combine Meshes"))
        {
            mc.CombineMeshes();
        }

        if (GUILayout.Button("Export Mesh To OBJ"))
        {
            string path = EditorUtility.SaveFilePanel("Export Mesh To OBJ", "Assets", this.name + ".obj", "obj");
            if (!string.IsNullOrEmpty(path))
            {
                mc.ExportMeshToOBJ(path);
            }
        }
    }
Esempio n. 30
0
 private void DoMeshCombine()
 {
     if (_rootTransform)
     {
         Transform combined = MeshCombiner.CombineMeshes(_rootTransform);
         if (combined != _rootTransform)
         {
             combined.transform.Translate(Vector3.right * 0.75f);
         }
         else
         {
             Debug.LogWarning("Root transform does not have multiple meshes, nothing was generated");
         }
     }
     else
     {
         Debug.LogError("Root Transform is null. Set one from your scene and re-enable the script");
     }
     enabled = false;
 }
Esempio n. 31
0
    void Start()
    {
        _combiner = new MeshCombiner(containerfab);
        var particles = new List<GameObject>();
        var willbedestroyed = new List<GameObject>();
        for (var i = 0; i < count; i++) {
            var fab = particlefabs[Random.Range(0, particlefabs.Length)];
            var pos = radius * Mathf.Pow(Random.value, CUBIC_ROOT) * Random.onUnitSphere;
            var inst = (GameObject)Instantiate(fab, pos, Random.rotationUniform);
            if (wasted != null)
                inst.transform.SetParent(wasted, false);
            else
                willbedestroyed.Add(inst);
            particles.Add(inst);
        }
        _combiner.Rebuild(particles);
        _combiner.SetParent(transform, false);

        foreach (var go in willbedestroyed)
            Destroy(go);
    }