Example #1
0
        public static void ImageImport(Volume originalVolume)
        {
            byte[] data = File.ReadAllBytes(originalVolume.ImportedFile);
            Texture2D tex = new Texture2D(2, 2);
            tex.LoadImage(data);

            FromImage(tex, originalVolume.gameObject, originalVolume.VoxelSize, originalVolume.ZSize, false, originalVolume.ImportedCutoutColor);
        }
Example #2
0
        public void Init(Volume vo)
        {
            voxelObject = vo;

            xSize = voxelObject.XSize;
            ySize = voxelObject.YSize;
            zSize = voxelObject.ZSize;

            title = "Resize";
        }
Example #3
0
 private void Awake()
 {
     //Debug.Log("Frame awake");
     if (transform.parent != null) ParentVolume = transform.parent.GetComponent<Volume>();
     if (ParentVolume != null)
     {
         if(ParentVolume.RuntimOnlyMesh)// || !Application.isPlaying)
             UpdateAllChunks();
     }
     transformMatrix = transform.worldToLocalMatrix;
 }
Example #4
0
        private void OnEnable()
        {
     
            voxelObject = (Volume) target;
            Undo.undoRedoPerformed += () => voxelObject.OnUndoRedo();

            voxelSizeProperty = serializedObject.FindProperty("VoxelSize");
            overlapAmountProperty = serializedObject.FindProperty("OverlapAmount");
            collisionMode = serializedObject.FindProperty("CollisionMode");
            meshingMode = serializedObject.FindProperty("MeshingMode");
            meshCompression = serializedObject.FindProperty("MeshCompression");
            colliderMeshingMode = serializedObject.FindProperty("MeshColliderMeshingMode");
            separateColliderMesh = serializedObject.FindProperty("GenerateMeshColliderSeparately");
            pivotProperty = serializedObject.FindProperty("Pivot");

            voxelSize = voxelSizeProperty.floatValue;
            overlapAmount = overlapAmountProperty.floatValue;
            pivot = pivotProperty.vector3Value;

            selfShadeInt = serializedObject.FindProperty("SelfShadingIntensity");

            drawGrid = voxelObject.DrawGrid;
            drawMesh = voxelObject.DrawMesh;
            runtimeOnlyMesh = serializedObject.FindProperty("RuntimOnlyMesh");

            material = serializedObject.FindProperty("Material");

            if (voxelObject != null && !Application.isPlaying && PrefabUtility.GetPrefabType(voxelObject) != PrefabType.Prefab && PrefabUtility.GetPrefabType(voxelObject) != PrefabType.PrefabInstance)
            {
                string path = Path.Combine(Helper.GetMeshStorePath(), voxelObject.AssetGuid);
                if (!Directory.Exists(path))
                    voxelObject.CreateChunks();
            }

            if (!Application.isPlaying && voxelObject.gameObject.activeSelf && PrefabUtility.GetPrefabType(voxelObject) != PrefabType.Prefab && !voxelObject.RuntimOnlyMesh)
                foreach (var frame in voxelObject.Frames)
                {
                    if (frame.HasDeserialized) frame.UpdateChunks(true);
                    frame.HasDeserialized = false;
                }

            paintMode = voxelObject.PaintMode;

            if (EditorPersistence.SelectBox.BottomLeftFront.X > voxelObject.XSize - 1 ||
                EditorPersistence.SelectBox.BottomLeftFront.Y > voxelObject.YSize - 1 ||
                EditorPersistence.SelectBox.BottomLeftFront.Z > voxelObject.ZSize - 1 ||
                EditorPersistence.SelectBox.TopRightBack.X > voxelObject.XSize - 1 ||
                EditorPersistence.SelectBox.TopRightBack.Y > voxelObject.YSize - 1 ||
                EditorPersistence.SelectBox.TopRightBack.Z > voxelObject.ZSize - 1)
                EditorPersistence.SelectBox = new PicaVoxelBox(0, 0, 0, voxelObject.XSize - 1, voxelObject.YSize - 1, voxelObject.ZSize - 1);
        }
        public void Init(Volume vo)
        {
            voxelObject = vo;

            xSize = voxelObject.XSize;
            ySize = voxelObject.YSize;
            zSize = voxelObject.ZSize;

            xChunkSize = voxelObject.XChunkSize;
            yChunkSize = voxelObject.YChunkSize;
            zChunkSize = voxelObject.ZChunkSize;

            titleContent = new GUIContent("Resize");
        }
        // Use DetectCollision to detect hits manually
        public bool DetectCollision(Vector3 worldPos, out Voxel voxel, out Volume hitObject)
        {
            foreach (GameObject o in GameObject.FindGameObjectsWithTag("PicaVoxelObject"))
            {
                Volume pvo = o.GetComponent<Volume>();
                Voxel? pv = pvo.GetVoxelAtWorldPosition(worldPos);
                if (pv.HasValue && pv.Value.Active)
                {
                    hitObject = pvo;
                    voxel = pv.Value;
                    return true;
                }
            }

            hitObject = null;
            voxel = new Voxel();
            return false;
        }
Example #7
0
        private void Awake()
        {
            voxelObject = GetComponent<Volume>();

            // If we can't find a Volume component, check to see if this is a baked Volume
            if (voxelObject == null)
            {
                for(int i=0;i<transform.childCount;i++)
                    if (transform.GetChild(i).name.ToLower().StartsWith("frame")) NumFrames++;

                // If we found some Frame objects, we're on a baked Volume
                if (NumFrames > 0) isBakedVolume = true;
            }
            else
            {
                NumFrames = voxelObject.NumFrames;
            }

            Reset();
            if (PlayOnAwake) Play();
        }
Example #8
0
 /// <summary>
 /// Initialise this frame and copy the voxels from a source frame
 /// </summary>
 /// <param name="sourceFrame"></param>
 public void GenerateNewFrame(Frame sourceFrame)
 {
     ParentVolume = transform.parent.GetComponent<Volume>();
     Voxels = new Voxel[XSize * YSize * ZSize];
     Helper.CopyVoxelsInBox(ref sourceFrame.Voxels, ref Voxels, new PicaVoxelPoint(XSize, YSize, ZSize), new PicaVoxelPoint(XSize, YSize, ZSize), false);
     CreateChunks();
     SaveForSerialize();
 }
Example #9
0
 /// <summary>
 /// Initialise this frame with an array of empty voxels
 /// </summary>
 public void GenerateNewFrame()
 {
     ParentVolume = transform.parent.GetComponent<Volume>();
     Voxels = new Voxel[XSize * YSize * ZSize];
     for (int i = 0; i < Voxels.Length; i++) Voxels[i].Value = 128;
     SaveForSerialize();
 }
Example #10
0
        /// <summary>
        /// Generates a 32x32x32 frame, filled with white voxels of value 128
        /// </summary>
        public void GenerateBasic(FillMode fillMode)
        {
            ParentVolume = ParentVolume.GetComponent<Volume>();
            Voxels = new Voxel[XSize * YSize * ZSize];
            for (int x = 0; x < XSize; x++)
                for (int y = 0; y < YSize; y++)
                    for (int z = 0; z < ZSize; z++)
                    {
                        int index = x + XSize * (y + YSize * z);
                        if (fillMode == FillMode.AllVoxels || (fillMode == FillMode.BaseOnly && y == 0))
                            Voxels[index].State = VoxelState.Active;
                        Voxels[index].Value = 128;
                        Voxels[index].Color = ParentVolume.PaletteColors[0];
                    }

            SaveForSerialize();
        }
Example #11
0
 // Use this for initialization
 private void Start()
 {
     voxelObject = GetComponent<Volume>();
 }
 public static void MagicaVoxelImport(Volume existingVolume)
 {
     using (BinaryReader stream = new BinaryReader(new FileStream(existingVolume.ImportedFile, FileMode.Open)))
     {
         FromMagica(stream, existingVolume.gameObject, existingVolume.VoxelSize, false);
     }
 }
Example #13
0
 public void Dispose()
 {
     Voxels.Clear();
     Voxels = null;
     VoxelObject = null;
 }
Example #14
0
 public Batch(Volume voxelObject)
 {
     VoxelObject = voxelObject;
 }
Example #15
0
 /// <summary>
 /// Initialise this frame with an array of empty voxels
 /// </summary>
 public void GenerateNewFrame()
 {
     ParentVolume = transform.parent.GetComponent<Volume>();
     Voxels = new Voxel[XSize * YSize * ZSize];
     SaveForSerialize();
 }