Exemplo n.º 1
0
        private VoxDatam ProcessVoxFile(VoxDatam model)
        {
            var voxel = VoxImport.VoxImportMethods.Load(voxAssetPath);

            filename = Path.GetFileNameWithoutExtension(voxAssetPath);
            if (model == null)
            {
                model = ScriptableObject.CreateInstance <VoxDatam>();
            }
            model.name = filename + " Vox";
            var priorID = model.data.id;

            if (priorID == 0)
            {
                priorID = Bootstrap.GenerateUniqueID();
            }
            model.data = new VoxData {
                id = priorID
            };
            uint[]    pallete = voxel.palette.values;
            Color32[] colors  = VoxImport.VoxImportMethods.CreateColor32FromPelatte(pallete);
            model.data.InitializeColors(colors.Length);
            for (int i = 0; i < colors.Length; i++)
            {
                model.data.colorsR[i] = colors[i].r;
                model.data.colorsG[i] = colors[i].g;
                model.data.colorsB[i] = colors[i].b;
            }
            var  voxData = voxel.chunkChild[0].xyzi.voxels;
            byte voxelValue;

            model.data.size = new int3(voxData.x, voxData.y, voxData.z);
            model.data.InitializeData();
            int3 localPosition;

            for (localPosition.x = 0; localPosition.x < model.data.size.x; localPosition.x++)
            {
                for (localPosition.y = 0; localPosition.y < model.data.size.y; localPosition.y++)
                {
                    for (localPosition.z = 0; localPosition.z < model.data.size.z; localPosition.z++)
                    {
                        int modelVoxelIndex = VoxelRaycastSystem.GetVoxelArrayIndex(localPosition, model.data.size);
                        voxelValue = (byte)voxData.voxels[(int)localPosition.x, (int)localPosition.y, (int)localPosition.z];
                        if (voxelValue != 255)
                        {
                            model.data.data[modelVoxelIndex] = (byte)(voxelValue + 1);
                        }
                        else
                        {
                            model.data.data[modelVoxelIndex] = (byte)0;
                        }
                    }
                }
            }
            model.data.scale = scale;
            return(model);
        }
Exemplo n.º 2
0
        public void SaveVox(AssetImportContext ctx)
        {
            bool isPreExisting = vox != null;

            vox = ProcessVoxFile(vox);
            string startFolder = System.IO.Path.GetDirectoryName(voxAssetPath); //FileUtil.GetProjectRelativePath(voxAssetPath);

            ctx.AddObjectToAsset(vox.name, vox);
            ctx.SetMainObject(vox);
        }
Exemplo n.º 3
0
 public Entity SpawnModel(float3 spawnPosition, VoxDatam model)
 {
     if (model != null)
     {
         int    id    = Bootstrap.GenerateUniqueID();
         Entity world = World.EntityManager.CreateEntity(worldArchtype);
         worlds.Add(id, world);
         worldLookups.Add(id, new WorldChunkMap {
             chunks = new Dictionary <int3, Entity>()
         });
         World.EntityManager.SetComponentData(world, new Translation {
             Value = spawnPosition
         });
         UpdateModel(world, model.data, null, id);
         return(world);
     }
     else
     {
         return(new Entity());
     }
 }
Exemplo n.º 4
0
        private void NewWay()
        {
            GUILayout.Space(15);
            GUILayout.Label("Chose a Monster:");
            VoxDatam newMonster = EditorGUILayout.ObjectField(monster, typeof(VoxDatam), false) as VoxDatam;

            if (newMonster != monster)
            {
                monster    = newMonster;
                vox        = monster;
                outputPath = Path.GetDirectoryName(Path.GetFullPath(AssetDatabase.GetAssetPath(vox))) + "\\";
            }
            GUILayout.Label("Chose a Skeleton:");
            SkeletonDatam newSkeleton = EditorGUILayout.ObjectField(skeleton, typeof(SkeletonDatam), false) as SkeletonDatam;

            if (newSkeleton != skeleton)
            {
                skeleton = newSkeleton;
            }
            if (vox == null)
            {
                return;
            }
            //GUILayout.Space(10);
            //GUILayout.Label("   Located at: " + outputPath);
            // chose a vox

            /*GUILayout.Space(15);
             * GUILayout.Label("Chose a Vox Model:");
             * VoxDatam newVox = EditorGUILayout.ObjectField(vox, typeof(VoxDatam)) as VoxDatam;
             * if (newVox != vox)
             * {
             *  vox = newVox;
             *  outputPath = Path.GetDirectoryName(Path.GetFullPath(AssetDatabase.GetAssetPath(vox))) + "\\";
             * }*/
            // Grab is mesh!
            //GUILayout.Space(15);
            //GUILayout.Label("Chose a Skeleton:");
            //skeleton = EditorGUILayout.ObjectField(skeleton, typeof(SkeletonDatam)) as SkeletonDatam;
            // chose animations
            if (animations.Count > 0)
            {
                if (GUILayout.Button("Bake Animator"))
                {
                    BakeVox();
                }
            }
            GUILayout.Label("Add Animation:");
            newAnim = EditorGUILayout.ObjectField(newAnim, typeof(AnimationClip), true) as AnimationClip;
            // if (GUILayout.Button("Clear Animations"))
            {
                //    animations.Clear();
            }
            for (int i = 0; i < animations.Count; i++)
            {
                if (GUILayout.Button(animations[i].name + " [-]"))
                {
                    animations.RemoveAt(i);
                    break;
                }
            }
            if (newAnim != null)
            {
                animations.Add(newAnim);
                newAnim = null;
            }
            //isPlaceUpwards = GUILayout.Toggle(isPlaceUpwards, "Place Half Height Upwards?");

            /* if (GUILayout.Button("Create Instance"))
             * {
             *   CreateSkinny();
             * }
             * GUILayout.Space(5);
             * if (GUILayout.Button("Bake Weighted Mesh"))
             * {
             *   BakeWeightedMesh();
             * }*/
            GUILayout.Space(5);

            if (newSkinny)
            {
                GUILayout.Space(5);
                if (GUILayout.Button("Kill Dude Instance"))
                {
                    DestroyImmediate(newSkinny);
                }
            }
        }