コード例 #1
0
        public override void Deserialize(string serialized)
        {
            var args = serialized.Split(' ');

            float[] param = new float[12];

            _Name      = LDrawConfig.GetFileName(args, 14);
            _Extension = LDrawConfig.GetExtension(args, 14);
            for (int i = 0; i < param.Length; i++)
            {
                int argNum = i + 2;
                if (!Single.TryParse(args[argNum], out param[i]))
                {
                    Debug.LogError(
                        String.Format(
                            "Something wrong with parameters in {0} sub-file reference command. ParamNum:{1}, Value:{2}",
                            _Name,
                            argNum,
                            args[argNum]));
                }
            }

            _Model = LDrawModel.Create(_Name, LDrawConfig.Instance.GetSerializedPart(_Name));

            _Matrix = new Matrix4x4(
                new Vector4(param[3], param[6], param[9], 0),
                new Vector4(param[4], param[7], param[10], 0),
                new Vector4(param[5], param[8], param[11], 0),
                new Vector4(param[0], param[1], param[2], 1)
                );
        }
コード例 #2
0
 private void GenerateModelButton()
 {
     if (GUILayout.Button("Generate"))
     {
         _CurrentPart = _CurrentType == GeneratingType.ByName ? _CurrentPart
             : LDrawConfig.Instance.GetModelByFileName(_ModelNames[_CurrentIndex]);
         // good test 949ac01
         var model = LDrawModel.Create(_CurrentPart, LDrawConfig.Instance.GetSerializedPart(_CurrentPart));
         var go    = model.CreateMeshGameObject(LDrawConfig.Instance.ScaleMatrix);
         go.transform.LocalReflect(Vector3.up);
     }
 }
コード例 #3
0
        /// FileFormatVersion 1.0.2;

        #region factory

        public static LDrawModel Create(string name, string path)
        {
            if (_models.ContainsKey(name))
            {
                return(_models[name]);
            }
            var model = new LDrawModel();

            model.Init(name, path);

            return(model);
        }
コード例 #4
0
        public static LDrawCommand DeserializeCommand(string line, LDrawModel parent)
        {
            LDrawCommand command = null;
            int          type;
            var          args = line.Split(' ');

            //first arg is the command type
            if (Int32.TryParse(args[0], out type))
            {
                var commandType = (CommandType)type;

                switch (commandType)
                {
                case CommandType.SubFile:
                    command = new LDrawSubFile();
                    break;

                case CommandType.Triangle:
                    command = new LDrawTriangle();
                    break;

                case CommandType.Quad:
                    command = new LDrawQuad();
                    break;
                }
            }

            //if it is a valid command
            if (command != null)
            {
                //parse the second arg for color code
                if (!int.TryParse(args[1], out command._ColorCode))
                {
                    command._Color = args[1];
                }
                //set the parent ldraw
                command._Parent = parent;
                command.Deserialize(line);
            }

            return(command);
        }
コード例 #5
0
        public static LDrawCommand DeserializeCommand(string line, LDrawModel parent)
        {
            LDrawCommand command = null;
            int          type;
            var          args = line.Split(' ');

            if (Int32.TryParse(args[0], out type))
            {
                var commandType = (CommandType)type;

                switch (commandType)
                {
                case CommandType.Comment:
                    command = new LDrawComment();
                    break;

                case CommandType.SubFile:
                    command = new LDrawSubFile();
                    break;

                case CommandType.Triangle:
                    command = new LDrawTriangle();
                    break;

                case CommandType.Quad:
                    command = new LDrawQuad();
                    break;
                }
            }

            if (command != null)
            {
                if (!(command is LDrawComment) && !int.TryParse(args[1], out command._ColorCode))
                {
                    command._Color = args[1];
                }
                command._Parent = parent;
                command.Deserialize(line);
            }

            return(command);
        }
コード例 #6
0
        public override void Deserialize(string serialized)
        {
            //args are seperated by spaces
            var args = serialized.Split(' ');

            //there are 12 args after the command type and color that matter
            float[] param = new float[12];

            //get the file name and extension from the last arg in the line
            _Name      = LDrawConfig.GetFileName(args, 14);
            _Extension = LDrawConfig.GetExtension(args, 14);
            for (int i = 0; i < param.Length; i++)
            {
                //offset by two to skip the command type and color
                int argNum = i + 2;
                if (!Single.TryParse(args[argNum], out param[i]))
                {
                    Debug.LogError(
                        String.Format(
                            "Something wrong with parameters in {0} sub-file reference command. ParamNum:{1}, Value:{2}",
                            _Name,
                            argNum,
                            args[argNum]));
                }
            }

            //create the LDrawModel by fetching the part file by name from the blueprints base parts
            _Model = LDrawModel.Create(_Name, LDrawConfig.Instance.GetSerializedPart(_Name));

            //create the TRS matrix from the parameters
            //- part location arg 0-2 goes on end of TRS matrix
            //- transformation matrix assembled in top left 3x3 of 4x4 matrix
            _Matrix = new Matrix4x4();
            _Matrix.SetRow(0, new Vector4(param[3], param[4], param[5], param[0]));
            _Matrix.SetRow(1, new Vector4(param[6], param[7], param[8], param[1]));
            _Matrix.SetRow(2, new Vector4(param[9], param[10], param[11], param[2]));
            _Matrix.SetRow(3, new Vector4(0, 0, 0, 1));
        }