Ejemplo n.º 1
0
        static void CreateCogBlockVolume()
        {
            int width  = 256;
            int height = 32;
            int depth  = 256;

            CogBlockVolumeData data = Cubiquity.VolumeDataAsset.CreateEmptyVolumeData <CogBlockVolumeData>(new Region(0, 0, 0, width - 1, height - 1, depth - 1));

            GameObject obj = CogBlockVolume.CreateGameObject(data);

            // And select it, so the user can get straight on with editing.
            Selection.activeGameObject = obj;

            int            floorThickness = 8;
            QuantizedColor floorColor     = CubSub.HexColor.QuantHex("FF5555FF");

            for (int z = 0; z <= depth - 1; z++)
            {
                for (int y = 0; y < floorThickness; y++)
                {
                    for (int x = 0; x <= width - 1; x++)
                    {
                        data.SetVoxel(x, y, z, floorColor);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static bool PickLastEmptyVoxel(CogBlockVolume volume, Vector3 origin, Vector3 direction, float distance, out PickVoxelResult pickResult)
        {
            // This 'out' value needs to be initialised even if we don't hit
            // anything (in which case it will be left at it's default value).
            pickResult = new PickVoxelResult();

            // Can't hit it the volume if there's no data.
            if ((volume.data == null) || (volume.data.volumeHandle == null))
            {
                return(false);
            }

            //again, transforming to volume space
            Vector3 target = origin + direction * distance;

            origin    = volume.transform.InverseTransformPoint(origin);
            target    = volume.transform.InverseTransformPoint(target);
            direction = target - origin;

            // Now call through to the Cubiquity dll to do the actual picking.
            pickResult = new PickVoxelResult();
            uint hit = CubiquityDLL.PickLastEmptyVoxel((uint)volume.data.volumeHandle,
                                                       origin.x, origin.y, origin.z,
                                                       direction.x, direction.y, direction.z,
                                                       out pickResult.volumeSpacePos.x, out pickResult.volumeSpacePos.y, out pickResult.volumeSpacePos.z);

            //transform back out into worldspace
            pickResult.worldSpacePos = volume.transform.TransformPoint((Vector3)(pickResult.volumeSpacePos));

            // Return true if we hit a surface.
            return(hit == 1);
        }
Ejemplo n.º 3
0
        public static bool PickFirstSolidVoxel(CogBlockVolume volume, Vector3 origin, Vector3 direction, float distance, out PickVoxelResult pickResult)
        {
            //initialization of an empty struct
            pickResult = new PickVoxelResult();

            // Can't hit it the volume if there's no data.
            if ((volume.data == null) || (volume.data.volumeHandle == null))
            {
                return(false);
            }

            //As noted by cubiquity, where cubqity's picking code works in volume space, Unity needs to work in world space...
            // Cubiquity's picking code works in volume space whereas we expose an interface that works in world

            //Grab our ray's components and transform them for volume space.
            Vector3 target = origin + direction * distance;

            origin    = volume.transform.InverseTransformPoint(origin);
            target    = volume.transform.InverseTransformPoint(target);
            direction = target - origin;

            // Now call through to the Cubiquity dll to do the actual picking.
            //Recall that CubiquityDLL will only have to work with ColoredCubeData, but that we are translating that boldface into CogBlockVolume data.
            uint hit = CubiquityDLL.PickFirstSolidVoxel((uint)volume.data.volumeHandle,
                                                        origin.x, origin.y, origin.z,
                                                        direction.x, direction.y, direction.z,
                                                        out pickResult.volumeSpacePos.x, out pickResult.volumeSpacePos.y, out pickResult.volumeSpacePos.z);

            // The result is in volume space, but again it is more convienient for Unity users to have the result
            // in world space. Therefore we apply the volume's volume-to-world transform to the volume space position.
            pickResult.worldSpacePos = volume.transform.TransformPoint((Vector3)(pickResult.volumeSpacePos));

            // Return true if we hit a surface.
            return(hit == 1);
        }
Ejemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            CogBlockVolumeRenderer renderer = target as CogBlockVolumeRenderer;

            float labelWidth = 120.0f;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Receive Shadows:", GUILayout.Width(labelWidth));
            renderer.receiveShadows = EditorGUILayout.Toggle(renderer.receiveShadows);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Cast Shadows:", GUILayout.Width(labelWidth));
            renderer.castShadows = EditorGUILayout.Toggle(renderer.castShadows);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            renderer.material = EditorGUILayout.ObjectField("Material: ", renderer.material, typeof(Material), true) as Material;
            EditorGUILayout.EndHorizontal();



            if (!GUI.changed)
            {
                return;
            }

            CogBlockVolume vol = renderer.gameObject.GetComponentInChildren <CogBlockVolume>() as CogBlockVolume;

            if (vol != null)
            {
                //Debug.Log("GuiChange detected");
                //for some reason, trying to get the octreenode from here resulted in CATASTROPHIC MELTDOWN where OctreeNodeAlt reported no children.
                //Do I understand? Nupe. This works better anyway by talking only to volume
                vol.RelayComponentChanges = true;
            }
        }
Ejemplo n.º 5
0
 public static bool PickLastEmptyVoxel(CogBlockVolume volume, Ray ray, float distance, out PickVoxelResult pickResult)
 {
     //split ray into origin and direction again
     return(PickLastEmptyVoxel(volume, ray.origin, ray.direction, distance, out pickResult));
 }
Ejemplo n.º 6
0
 public static bool PickFirstSolidVoxel(CogBlockVolume volume, Ray ray, float distance, out PickVoxelResult pickResult)
 {
     //we want our ray divided into an origin and a direction
     return(PickFirstSolidVoxel(volume, ray.origin, ray.direction, distance, out pickResult));
 }
 public void OnEnable()
 {
     volume = target as CogBlockVolume;
 }