Jump to content

chloe

Modz Gold Member
  • Posts

    44
  • Joined

  • Last visited

  • Days Won

    16

Posts posted by chloe

  1. 9 hours ago, 3dxBromeo said:

    Chloe, 

    Thank you. I'm not a coder and frankly don't have the patience to be one. But thank you for putting this out there for us builders. I'm running through my worlds cleaning them up when I came across this particular error using the latest build of your application:

    Optimizing file 'C:\...\Pool Party Club.world'...

    ERROR: Failed to parse file content.

    Input string '0.238' is not a valid integer. Path 'objects[0].c[0]', line 1, position 264.

     

    Hmm... I check this if I am home again. Currently I am in the hospital. I wonder why you have a float color value. 

  2. 17 hours ago, Icarus said:

    Thank you for sorting Chloe. Coz I am a fan of this tool, I had to test the new version straight. :D

    Was asking cause people are saying ingame, that the file-size of a room is related to get lags or not, when you make a room public and it is crowded. Something like a room should not be bigger than 500kb. But I think it is more related to textures and lights in a room.

     

     

    You can use it as an indicater... like the number of objects too. But there are a difference if you have just blocks or more complex objects. And sure lights and animated objects cost performance too.

     

  3. On 2/23/2018 at 11:36 AM, Icarus said:

    Hey Cloe,

     

    tested the new version. But somehow it makes the files bigger. From 565kb to 651kb after running it. Strange...

     

    Any Idea?

     

    Ica

     

     

    chloe.PNG

     

     

    That is normal since the values are now stored as float and no longer as integer. I did changed that to support modded DLLs. 3dx don't care if you import floats (with decimals) or integers. So the file size is a bit bigger but after import (either with a modded DLL or the default one) you will not notice any change or different behavior but you maybe get a higher precision using a mod.

     

    Kisses Chloe

     

     

    @Ica: For a follow up check the conversation between Ayon and Alex on the first page.

  4. 3 hours ago, Ayon said:

    hi There:)

    I am pretty sure the doors you saw were part of the old 3DXChat 1.0

    They are not available in the new WE but I believe they can still be used in game.

     

    I have not tried this myself yet, But I assume if you can open the .world file and replace the name of a prop to door_1 or _door_2  the game should load them.

     

    Example would be:

    Open WE in game, add say a single light cube to an empty room. Save it.

    Open the .world file and replace the name of the Light Cube with "door_1"

     

    Again I have not tried this with the WE, but I assume it would work.

     

     

    At least the round bar stools can be brought back in game with the same trick :)

    • Thanks 1
  5. TamaraX reported that she needed to run my tool 5 times before 0 duplicates were found. O don't know were my logic hole is but anyway, I have implemented a multi pass so really every duplicate object should be deleted after a single run:

     

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using Newtonsoft.Json;
    
    namespace World
    {
        public class XCollectedObject
        {
            public bool isgroup { get; set; }
            public XObject obj  { get; set; }
            public IXHasChildren container  { get; set; }
            public string  hash { get; set; }
        }
    
        public interface IXHasChildren
        {
            List<XObject> objects { get; set; }
        }
    
        public class XRespawn
        {
            public int[] p { get; set; }
            public double r { get; set; }
        }
    
        public class XObject : IXHasChildren
        {
            public string n { get; set; }
            public int[] p { get; set; }
            public int[] r { get; set; }
            public int[] s { get; set; }
            public int[] c { get; set; }
            public string m { get; set; }
    
            public List<XObject> objects { get; set; }
    
            public override string ToString()
            {
                StringBuilder sb = new StringBuilder();
    
                sb.Append("{");
                sb.AppendFormat("n:{0}", n);
                sb.Append(",");
    
                if (n == "group")
                {
                    sb.Append("objects:[");
                    bool first = true;
    
                    foreach(var obj in objects)
                    {
                        if (!first) sb.Append(",");
                        first = false;
    
                        sb.Append(obj.ToString());
                    }
                    sb.Append("]");
                }
                else
                {
                    sb.AppendFormat("{0}:[{1},{2},{3}]", "p", p[0], p[1], p[2]);
    
                    if (r != null)
                    {
                        sb.Append(",");
                        sb.AppendFormat("{0}:[{1},{2},{3}]", "r", r[0], r[1], r[2]);
                    }
    
                    if (s != null)
                    {
                        sb.Append(",");
                        sb.AppendFormat("{0}:[{1},{2},{3}]", "s", s[0], s[1], s[2]);
                    }
    
                    if (c != null)
                    {
                        sb.Append(",");
                        sb.AppendFormat("{0}:[{1},{2},{3}]", "c", c[0], c[1], c[2]);
                    }
                    sb.Append("}");
                }
    
                sb.Append("}");
    
                return sb.ToString();
            }
        }
    
        public class XDoc : IXHasChildren
        {
            public XRespawn respawn { get; set; }
            public double oceanlevel { get; set; }
            public string weather { get; set; }
    
            public List<XObject>  objects { get; set; }
        }
    
        class Program
        {
            static void Collect(ref List<XCollectedObject> list, IXHasChildren container)
            {
                foreach (var obj in container.objects)
                {
                    var c = new XCollectedObject()
                    {
                        isgroup = obj.n == "group",
                        obj = obj,
                        container = container,
                        hash = obj.ToString()
                    };
    
                    list.Add(c);
    
                    if (c.isgroup)
                    {
                        Collect(ref list, c.obj);
                    }
                }
            }
    
            static int RemoveDuplicates(ref List<XCollectedObject> list)
            {
                List<XCollectedObject> unique = new List<XCollectedObject>();
    
                foreach (var objA in list)
                {
                    bool duplicate = false;
    
                    foreach (var objB in unique)
                    {
                        if (objA.hash == objB.hash)
                        {
                            // remove object from parent container
                            objA.container.objects.Remove(objA.obj);
    
                            duplicate = true;
                            break;
                        }
                    }
    
                    if (!duplicate) unique.Add(objA);
                }
    
                // find empty containers
                foreach (var objA in list)
                {
                    if (objA.isgroup)
                    {
                        if (objA.obj.objects.Count == 0)
                        {
                            objA.container.objects.Remove(objA.obj);
                        }
                    }
                }
    
                return list.Count - unique.Count;
            }
    
            static int RemoveDuplicates(string json, out string cleanJson)
            {
                int counter = 0;
                XDoc doc = JsonConvert.DeserializeObject<XDoc>(json);
                List<XCollectedObject> allObjects = new List<XCollectedObject>();
    
                Collect(ref allObjects, doc);
    
                counter = RemoveDuplicates(ref allObjects);
    
                cleanJson = JsonConvert.SerializeObject(
                    doc,
                    Formatting.None,
                    new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }
                );
                
                return counter;
            }
    
            static void Main(string[] args)
            {
                int totalCounter = 0;
                int counter = 0;
    
                if (args.Length == 0)
                {
                    Console.WriteLine("Please specify a filename :)");
                    return;
                }
    
                string fileName = args[0];
                string json = File.ReadAllText(fileName);
                string cleanJson = null;
    
                // max 10 loops
                for (int i = 0; i < 10; i++)
                {
                    counter = RemoveDuplicates(json, out cleanJson);
                    totalCounter += counter;
    
                    if (counter > 0)
                    {
                        json = cleanJson;
                    }
                    else
                    {
                        break;
                    }
                }
    
                Console.WriteLine("{0} duplicate objects found.", totalCounter);
    
                File.WriteAllText(fileName.Substring(0, fileName.Length - 6) + "_xxx_clean_xxx.world", cleanJson);
            }
        }
    }

     

    ChloeCleanTheWorld1_2.zip

    • Like 2
  6. Hello all,

     

    I had yesterday a big problem with the World Editor. For whatever reason everything was duplicated. Maybe it was me, maybe a bug, I don't know. Anyway, it was to late to load my last saved work because I changed to much. 

    I was frustrate but than I said to myself: Chloe, calm down, you can code :) So I wrote a little command line tool for the new JSON-World format to remove duplicate objects. Also inside of groups. I didn't had many but if you work on complex structures it can happen that you duplicate a block by accident.

     

     

    The usage is pretty straightforward:

     

    ChloeCleanTheWorld.exe "c:\...\awesome.world"

     

     

    The check routine does not considering material. So if you have two objects with the same size and position on top each other with different materials, one of them will be removed!

     

    If you like to write your own version, here is the (quick and dirty) code:

     

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using Newtonsoft.Json;
    
    namespace World
    {
        public interface IXHasChidren
        {
            List<XObject> objects { get; set; }
        }
    
        public class XRespawn
        {
            public int[] p { get; set; }
            public double r { get; set; }
        }
    
        public class XObject : IXHasChidren
        {
            private string _tostring = null;
    
            public string n { get; set; }
            public int[] p { get; set; }
            public int[] r { get; set; }
            public int[] s { get; set; }
            public int[] c { get; set; }
            public string m { get; set; }
    
            public List<XObject> objects { get; set; }
    
            public override string ToString()
            {
                if (_tostring != null) return _tostring;
    
                StringBuilder sb = new StringBuilder();
    
                sb.Append("{");
                sb.AppendFormat("n:{0}", n);
                sb.Append(",");
    
                if (n == "group")
                {
                    sb.Append("objects:[");
                    bool first = true;
    
                    foreach(var obj in objects)
                    {
                        if (!first) sb.Append(",");
                        first = false;
    
                        sb.Append(obj.ToString());
                    }
                    sb.Append("]");
                }
                else
                {
                    sb.AppendFormat("{0}:[{1},{2},{3}]", "p", p[0], p[1], p[2]);
    
                    if (r != null)
                    {
                        sb.Append(",");
                        sb.AppendFormat("{0}:[{1},{2},{3}]", "r", r[0], r[1], r[2]);
                    }
    
                    if (s != null)
                    {
                        sb.Append(",");
                        sb.AppendFormat("{0}:[{1},{2},{3}]", "s", s[0], s[1], s[2]);
                    }
    
                    if (c != null)
                    {
                        sb.Append(",");
                        sb.AppendFormat("{0}:[{1},{2},{3}]", "c", c[0], c[1], c[2]);
                    }
                    sb.Append("}");
                }
    
                sb.Append("}");
    
                _tostring = sb.ToString();
                return _tostring;
            }
        }
    
        public class XDoc : IXHasChidren
        {
            public XRespawn respawn { get; set; }
            public double oceanlevel { get; set; }
            public string weather { get; set; }
    
            public List<XObject>  objects { get; set; }
        }
    
        class Program
        {
            static void RemoveDuplicates(IXHasChidren container)
            {
                List<XObject> uniqueObjects = new List<XObject>();
    
                foreach (var objA in container.objects)
                {
                    bool duplicate = false;
    
                    foreach (var objB in uniqueObjects)
                    {
                        if (objA != objB)
                        {
                            if (objA.ToString() == objB.ToString())
                            {
                                duplicate = true;
                                break;
                            }
                        }
    
                    }
    
                    if (!duplicate) uniqueObjects.Add(objA);
                }
    
                Console.WriteLine("{0} duplicate objects found.", container.objects.Count - uniqueObjects.Count);
                container.objects = uniqueObjects;
            }
    
            static void Main(string[] args)
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Please specify a filename :)");
                    return;
                }
    
                string fileName = args[0];
                string json = File.ReadAllText(fileName);
                XDoc doc = JsonConvert.DeserializeObject<XDoc>(json);
                
                RemoveDuplicates(doc);
    
                foreach (var objA in doc.objects)
                {
                    if (objA.n == "group")
                    {
                        RemoveDuplicates(objA);
                    }
                }
    
                string cleanJson = JsonConvert.SerializeObject(
                    doc,
                    Formatting.None,
                    new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }
                );
    
                File.WriteAllText(fileName.Substring(0, fileName.Length - 6) + "_xxx_clean_xxx.world", cleanJson);
            }
        }
    }

     

    Have fun and take care!

     

    Chloe

     

     

    ChloeCleanTheWorld.zip

     

     


     

     

    I have changed the code to do deep search of duplicate objects inside groups. Means more duplicate objects are now found :)

     

    Please use the tool with care! 

     

    ChloeCleanTheWorld1_1.zip

     

    SOURCE CODE:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using Newtonsoft.Json;
    
    namespace World
    {
        public class XCollectedObject
        {
            public bool isgroup { get; set; }
            public XObject obj  { get; set; }
            public IXHasChildren container  { get; set; }
            public string  hash { get; set; }
        }
    
        public interface IXHasChildren
        {
            List<XObject> objects { get; set; }
        }
    
        public class XRespawn
        {
            public int[] p { get; set; }
            public double r { get; set; }
        }
    
        public class XObject : IXHasChildren
        {
            public string n { get; set; }
            public int[] p { get; set; }
            public int[] r { get; set; }
            public int[] s { get; set; }
            public int[] c { get; set; }
            public string m { get; set; }
    
            public List<XObject> objects { get; set; }
    
            public override string ToString()
            {
                StringBuilder sb = new StringBuilder();
    
                sb.Append("{");
                sb.AppendFormat("n:{0}", n);
                sb.Append(",");
    
                if (n == "group")
                {
                    sb.Append("objects:[");
                    bool first = true;
    
                    foreach(var obj in objects)
                    {
                        if (!first) sb.Append(",");
                        first = false;
    
                        sb.Append(obj.ToString());
                    }
                    sb.Append("]");
                }
                else
                {
                    sb.AppendFormat("{0}:[{1},{2},{3}]", "p", p[0], p[1], p[2]);
    
                    if (r != null)
                    {
                        sb.Append(",");
                        sb.AppendFormat("{0}:[{1},{2},{3}]", "r", r[0], r[1], r[2]);
                    }
    
                    if (s != null)
                    {
                        sb.Append(",");
                        sb.AppendFormat("{0}:[{1},{2},{3}]", "s", s[0], s[1], s[2]);
                    }
    
                    if (c != null)
                    {
                        sb.Append(",");
                        sb.AppendFormat("{0}:[{1},{2},{3}]", "c", c[0], c[1], c[2]);
                    }
                    sb.Append("}");
                }
    
                sb.Append("}");
    
                return sb.ToString();
            }
        }
    
        public class XDoc : IXHasChildren
        {
            public XRespawn respawn { get; set; }
            public double oceanlevel { get; set; }
            public string weather { get; set; }
    
            public List<XObject>  objects { get; set; }
        }
    
        class Program
        {
            static void Collect(ref List<XCollectedObject> list, IXHasChildren container)
            {
                foreach (var obj in container.objects)
                {
                    var c = new XCollectedObject()
                    {
                        isgroup = obj.n == "group",
                        obj = obj,
                        container = container,
                        hash = obj.ToString()
                    };
    
                    list.Add(c);
    
                    if (c.isgroup)
                    {
                        Collect(ref list, c.obj);
                    }
                }
            }
    
            static void RemoveDuplicates(ref List<XCollectedObject> list)
            {
                List<XCollectedObject> unique = new List<XCollectedObject>();
    
                foreach (var objA in list)
                {
                    bool duplicate = false;
    
                    foreach (var objB in unique)
                    {
                        if (objA.hash == objB.hash)
                        {
                            // remove object from parent container
                            objA.container.objects.Remove(objA.obj);
    
                            duplicate = true;
                            break;
                        }
                    }
    
                    if (!duplicate) unique.Add(objA);
                }
    
                // find empty containers
                foreach (var objA in list)
                {
                    if (objA.isgroup)
                    {
                        if (objA.obj.objects.Count == 0)
                        {
                            objA.container.objects.Remove(objA.obj);
                        }
                    }
                }
                Console.WriteLine("{0} duplicate objects found.", list.Count - unique.Count);
            }
    
            static void Main(string[] args)
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Please specify a filename :)");
                    return;
                }
    
                string fileName = args[0];
                string json = File.ReadAllText(fileName);
                XDoc doc = JsonConvert.DeserializeObject<XDoc>(json);
    
                List<XCollectedObject> allObjects = new List<XCollectedObject>();
    
                Collect(ref allObjects, doc);
                RemoveDuplicates(ref allObjects);
    
                string cleanJson = JsonConvert.SerializeObject(
                    doc,
                    Formatting.None,
                    new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }
                );
    
                File.WriteAllText(fileName.Substring(0, fileName.Length - 6) + "_xxx_clean_xxx.world", cleanJson);
            }
        }
    }

     

    • Like 2
  7. Remove duplicate objects (World JSON Files)

    View File

    Hello all,

     

    I had yesterday a big problem with the World Editor. For whatever reason everything was duplicated. Maybe it was me, maybe a bug, I don't know. Anyway, it was to late to load my last saved work because I changed to much.

     

    I was frustrate but than I said to myself: Chloe, calm down, you can code :) So I wrote a little command line tool for the new JSON-World format to remove duplicate objects. Also inside of groups. I didn't had many but if you work on complex structures it can happen that you duplicate a block by accident.

     

    The usage is pretty straightforward:

     

    ChloeCleanTheWorld.exe "c:\...\awesome.world"

     

    The check routine does not considering material. So if you have two objects with the same size and position on top each other with different materials, one of them will be removed!

     

    Have fun and take care!

     

    Chloe

     

    -----------------------------

     

    I have changed the code to do deep search of duplicate objects inside groups. Means more duplicate objects are now found :)

     

    Please use the tool with care!

     

    Chloe

    ---------------------------------

     

    TamaraX reported that she needed to run my tool 5 times before 0 duplicates were found. O don't know were my logic hole is but anyway, I have implemented a multi pass so really every duplicate object should be deleted after a single run:

    ---------------------------------

    Now with UI and installer (and auto update)

    ---------------------------------

     

     

    Did this for Chloe

    Tamara

     


     

    • Like 2
    • Thanks 1
×
×
  • Create New...

Important Information

By using and viewing this site, you agree to our Terms of Use.