Ejemplo n.º 1
0
        public void Spawn(float dis, float gap, int count, int pos)
        {
            MainConstruct mainConstruct = BlueprintConverter.Convert(bp, ConversionDamageMode.IgnoreDamage, false);

            Team_id = IsKing ? InstanceSpecification.i.Factions.Factions.Find(f => f.FactionSpec.AbreviatedName == "K").Id : InstanceSpecification.i.Factions.Factions.Find(f => f.FactionSpec.AbreviatedName == "C").Id;
            BlueprintConverter.Initiate(mainConstruct, PlanetList.MainFrame.FramePositionToUniversalPosition(VLoc(gap, count, pos, dis)), VDir(), Team_id, null, SpawnPositioning.OriginOrCentre);
        }
Ejemplo n.º 2
0
        // private static float lastTime = 1.0f;

        private static MainConstruct getTarget(MainConstruct mc)
        {
            var ais = mc.iBlockTypeStorage.MainframeStore;

            if (mc.Destroyed || ais.Count <= 0)
            {
                return(null);
            }
            var target = ais.Blocks[0].Node.targetManager.GetPrimaryTarget();

            if (target != null && target.C.GetTargetableType() == enumTargetableType.Constructable)
            {
                return(target.C as MainConstruct);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public void Spawn(float dis, float gap, float gap2, int count, int pos)
        {
            MainConstruct val = BlueprintConverter.Convert(bp, SpawnInstructions.None);

            /*val.Drone.myJustLoadedDrones.Clear();
             * foreach (MainConstruct m in val.MainArrayBasics.SVList)
             * {
             *  m.GenUniqueID();
             *  val.Drone.myJustLoadedDrones.Add(m);
             * }*/
            team_id = (IsKing ? InstanceSpecification.i.Factions.Factions.Find((InstanceFaction f) => f.FactionSpec.Name == "KING").Id :
                       InstanceSpecification.i.Factions.Factions.Find((InstanceFaction f) => f.FactionSpec.Name == "CHAL").Id);
            //BrilliantSkies.Core.Types.Vector3d vector3D = new BrilliantSkies.Core.Types.Vector3d(VLoc(gap, count, pos, dis));
            //vector3D.y += offset;
            BlueprintInitialisation bpinit = new BlueprintInitialisation(val);

            bpinit.Positioning = new BlueprintPositioning(PlanetList.MainFrame.FramePositionToUniversalPosition(VLoc(gap, gap2, count, pos, dis, offset)), VDir());
            bpinit.Run(team_id);
            //BlueprintConverter.Initiate(val, PlanetList.MainFrame.FramePositionToUniversalPosition(VLoc(gap, gap2, count, pos, dis, offset)), VDir(), team_id, null, 0);
        }
Ejemplo n.º 4
0
        static bool Prefix(Playback __instance, MainConstruct ____construct, Playback.SoundPlayCallback ____playback, float volumeMod, float pitchMod)
        {
            if (!overridePlayback)
            {
                return(true);
            }
            string       us      = __instance.HashLabel.Us;
            SoundRequest request = new SoundFinder().GetRequest(____construct.CentreOfMass, us);

            if (request != null)
            {
                request = new SoundRequestBreadBoard(request)
                {
                    MinDistance    = volumeMod * __instance.Volume.RndBetween,
                    Pitch          = pitchMod * __instance.Pitch.RndBetween,
                    DelayInRequest = __instance.Delay.RndBetween
                };
                ____playback.Enqueue(request);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public void PreLateUpdate()
        {
            FtdKeyMap ftdKeyMap = ProfileManager.Instance.GetModule <FtdKeyMap>();

            float axis         = Input.GetAxis("Mouse ScrollWheel");
            bool  shiftPressed = Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift);

            orbitcam.distance -= axis * (shiftPressed ? 200 : 50);
            int count = StaticConstructablesManager.constructables.Count;

            if (lastCount > count)              //Ein Teilnehmer ist von uns gegangen.
            {
                lastCount = count;
                int foundIt = StaticConstructablesManager.constructables.FindIndex((mc) => mc.UniqueId == orbitID);
                if (foundIt == -1)                  //Das aktuelle Ziel der Orbitkamera wurde zerstört.
                {
                    orbitIndex %= count;
                }
                else
                {
                    orbitIndex = foundIt;
                }
            }

            orbitcam.xSpeed = (shiftPressed ? 1000 : 250);
            orbitcam.ySpeed = (shiftPressed ? 480 : 120);
            if (Input.GetKeyUp(ftdKeyMap.GetKeyDef(KeyInputsFtd.PauseGame).Key))              //Default Pause-Key is F11.
            {
                Time.timeScale = (Time.timeScale > 0 ? 0 : 1);
            }
            if (Input.GetKeyUp(ftdKeyMap.GetKeyDef(KeyInputsFtd.InventoryUi).Key))              //Default Inventory-Key is E.
            {
                orbitIndex = (orbitIndex + 1) % count;
            }
            if (Input.GetKeyUp(ftdKeyMap.GetKeyDef(KeyInputsFtd.Interact).Key))              //Default Interaction-Key is Q.
            {
                if (orbitIndex == 0)
                {
                    orbitIndex = count;
                }
                orbitIndex--;
            }
            if (Input.GetMouseButtonUp(0) && count != 0)          //Linke Maustaste und mindestens noch einer da
            {
                flycam.enabled   = false;
                orbitcam.enabled = true;
            }
            else if (Input.GetMouseButtonUp(1))                //Rechte Maustaste
            {
                flycam.enabled            = true;
                orbitcam.enabled          = false;
                flycam.transform.rotation = orbitcam.transform.rotation;
            }
            if (flycam.enabled)
            {
                Vector3 movement = ftdKeyMap.GetMovemementDirection() * (shiftPressed ? 5 : 1);
                flycam.transform.position += flycam.transform.localRotation * movement;
            }
            else if (orbitcam.enabled)
            {
                if (count == 0)                  //Alle tot!
                {
                    flycam.enabled   = true;
                    orbitcam.enabled = false;
                }
                else
                {
                    MainConstruct currentConstruct = StaticConstructablesManager.constructables[orbitIndex];
                    orbitID = currentConstruct.UniqueId;
                    orbitcam.OrbitTarget = new PositionAndRotationReturnUniverseCoord(new UniversalTransform(PlanetList.MainFrame.FramePositionToUniversalPosition(currentConstruct.CentreOfMass), currentConstruct.SafeRotation));
                }
            }
        }
Ejemplo n.º 6
0
    private static void Start(CSharpBoxClass cSharpBox)
    {
        cSharpBox.ClearLogs();

        MainConstruct mainConstruct = cSharpBox.MainConstruct as MainConstruct;

        string outPutFolderPath = Get.ProfilePaths.ProfileRootDir().Append(mainConstruct.GetBlueprintName()).ToString() + string.Format("-{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now);
        string texFolderPath    = Path.Combine(outPutFolderPath, "Textures");

        Directory.CreateDirectory(outPutFolderPath);
        Directory.CreateDirectory(texFolderPath);

        //TextureDefinition getTexDef(MaterialDefinition I) => Configured.i.Textures.Find(I.ColorTextureReference.Reference.Guid);
        IEnumerable <TextureDefinition> textureDefinitionList = Configured.i.Materials.Components
                                                                .Select(I => Configured.i.Textures.Find(I.ColorTextureReference.Reference.Guid))
                                                                .Where(I => I != null)
                                                                .Distinct();

        StringBuilder sb = new StringBuilder();

        foreach (TextureDefinition textureDefinition in textureDefinitionList)
        {
            ModSource modSource = textureDefinition.Source;

            if (modSource != ModSource.File && modSource != ModSource.Resources)
            {
                continue;
            }

            byte[] encodeResult = null;

            try
            {
                encodeResult = ForcedEncodeToJPG(textureDefinition.Texture.GetTexture());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                continue;
            }

            if (encodeResult != null)
            {
                string texName = TexNameGenerate(textureDefinition);

                File.WriteAllBytes(Path.Combine(texFolderPath, texName + ".jpg"), encodeResult);

                cSharpBox.Log("newmtl " + texName);
                cSharpBox.Log("map_Kd " + Path.Combine("Textures", texName + ".jpg"));
                cSharpBox.Log(string.Empty);

                sb.Append("newmtl " + texName + "\n");
                sb.Append("map_Kd " + Path.Combine("Textures", texName + ".jpg") + "\n");
                sb.Append("\n");
            }
        }

        using (StreamWriter sw = new StreamWriter(Path.Combine(outPutFolderPath, "Test.mtl")))
        {
            sw.Write(sb.ToString());
        }



        List <AllConstruct> allConstructList = new List <AllConstruct>();

        mainConstruct.AllBasicsRestricted.GetAllConstructsBelowUsAndIncludingUs(allConstructList);

        foreach (AllConstruct allConstruct in allConstructList)
        {
            if (!(allConstruct.Chunks is ConstructableMeshMerger))
            {
                continue;
            }

            Dictionary <MaterialDefinition, List <Mesh> > meshListDictionary = new Dictionary <MaterialDefinition, List <Mesh> >();

            foreach (ICarriedObjectReference iCOR in allConstruct.CarriedObjects.Objects)
            {
                MeshRenderer meshRenderer = iCOR.ObjectItself.GetComponent <MeshRenderer>();
                MeshFilter   meshFilter   = iCOR.ObjectItself.GetComponent <MeshFilter>();

                if (meshRenderer == null || meshFilter == null)
                {
                    continue;
                }

                KeyValuePair <Guid, MaterialDefinition> item = Configured.i.Materials.DictionaryOfComponents.FirstOrDefault(d => d.Value.Material == meshRenderer.sharedMaterial);

                if (item.Equals(default(KeyValuePair <Guid, MaterialDefinition>)))
                {
                    continue;
                }

                if (!meshListDictionary.ContainsKey(item.Value))
                {
                    meshListDictionary.Add(item.Value, new List <Mesh>());
                }

                Mesh newMesh = UnityEngine.Object.Instantiate(meshFilter.sharedMesh);
                IEnumerable <Vector3> newVertexList = newMesh.vertices.Select(d => meshFilter.transform.localToWorldMatrix.MultiplyPoint(d));
                newVertexList = newVertexList.Select(d => allConstruct.myTransform.worldToLocalMatrix.MultiplyPoint(d));
                newMesh.SetVertices(newVertexList.ToList());

                meshListDictionary[item.Value].Add(newMesh);
            }

            ConstructableMeshMerger meshMerger = allConstruct.Chunks as ConstructableMeshMerger;
            cSharpBox.Log("AllBlockVertex Count : " + meshMerger.VertexCount);

            foreach (KeyValuePair <int, List <ChunkMesh> > chunkMeshListDictionary in meshMerger.D)
            {
                bool found;
                MaterialDefinition materialDefinition = Configured.i.Materials.FindUsingTheRuntimeId(chunkMeshListDictionary.Key, out found);

                bool flag_0 = chunkMeshListDictionary.Value.Count == 0;
                bool flag_1 = chunkMeshListDictionary.Value.All(d => d.VertCount == 0);

                if (!found || flag_0 || flag_1)
                {
                    continue;
                }

                if (!meshListDictionary.ContainsKey(materialDefinition))
                {
                    meshListDictionary.Add(materialDefinition, new List <Mesh>());
                }

                meshListDictionary[materialDefinition].AddRange(chunkMeshListDictionary.Value.Select(d => d.GetMesh()));
            }



            int  subConstructIndex = allConstruct.PersistentSubConstructIndex;
            bool isSubConstruct    = subConstructIndex != -1;

            Vector3    localPosition = Vector3.zero;
            Quaternion localRotation = Quaternion.identity;

            if (isSubConstruct)
            {
                MainConstruct mc = allConstruct.Main;
                localPosition = mc.SafeGlobalToLocal(allConstruct.SafePosition);
                localRotation = mc.SafeGlobalRotationToLocalRotation(allConstruct.SafeRotation);
            }

            List <Mesh> meshList = new List <Mesh>();

            foreach (KeyValuePair <MaterialDefinition, List <Mesh> > meshListDictionaryData in meshListDictionary)
            {
                List <Vector3> vertices        = new List <Vector3>();
                List <Vector3> normals         = new List <Vector3>();
                List <Vector2> uv              = new List <Vector2>();
                List <int>     triangles       = new List <int>();
                int            loadVertexCount = 0;

                foreach (Mesh mesh in meshListDictionaryData.Value)
                {
                    vertices.AddRange(mesh.vertices);
                    normals.AddRange(mesh.normals);
                    uv.AddRange(mesh.uv);
                    triangles.AddRange(mesh.triangles.Select(d => d + loadVertexCount));
                    loadVertexCount += mesh.vertexCount;
                }

                if (isSubConstruct)
                {
                    vertices = vertices.Select(I => localRotation * I + localPosition).ToList();
                }

                TextureDefinition textureDefinition = Configured.i.Textures.Find(meshListDictionaryData.Key.ColorTextureReference.Reference.Guid);

                Mesh newMesh = new Mesh
                {
                    indexFormat = UnityEngine.Rendering.IndexFormat.UInt32,
                    name        = TexNameGenerate(textureDefinition)
                };

                newMesh.SetVertices(vertices);
                newMesh.SetNormals(normals);
                newMesh.SetUVs(0, uv);
                newMesh.SetTriangles(triangles, 0);

                FlipHorizontal(newMesh);
                meshList.Add(newMesh);

                cSharpBox.Log("vertexCount : " + newMesh.vertices.Length);
            }



            string fileName = $"Test ({OutputCount++})";

            if (subConstructIndex == -1)
            {
                fileName = "MainConstruct";
            }
            else
            {
                fileName = $"SubConstruct_{subConstructIndex}";
            }

            MeshToFile(meshList, Path.Combine(outPutFolderPath, fileName + ".obj"));
        }
    }