Beispiel #1
0
        /// Picks the last empty voxel lying on the ray.

        /**
         *
         */
        public static bool PickLastEmptyVoxel(ColoredCubesVolume volume, Vector3 origin, Vector3 direction, float distance, out PickVoxelResult pickResult)
        {
            validateDistance(distance);

            // 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);
            }

            // Cubiquity's picking code works in volume space whereas we expose an interface that works in world
            // space (for consistancy with other Unity functions). Therefore we apply the inverse of the volume's
            // volume-to-world transform to the ray, to bring it from world space into volume space.
            //
            // Note that we do this by transforming the start and end points of the ray (rather than the direction
            // of the ray) as Unity's Transform.InverseTransformDirection method does not handle scaling.
            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);

            // 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);
        }
Beispiel #2
0
        /// Picks the first solid voxel lying on the ray.
        /**
         *
         */
        public static bool PickFirstSolidVoxel(ColoredCubesVolume volume, Vector3 origin, Vector3 direction, float distance, out PickVoxelResult pickResult)
        {
            validateDistance(distance);

            // 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;
            }

            // Cubiquity's picking code works in volume space whereas we expose an interface that works in world
            // space (for consistancy with other Unity functions). Therefore we apply the inverse of the volume's
            // volume-to-world transform to the ray, to bring it from world space into volume space.
            //
            // Note that we do this by transforming the start and end points of the ray (rather than the direction
            // of the ray) as Unity's Transform.InverseTransformDirection method does not handle scaling.
            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.
            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;
        }
Beispiel #3
0
        /// Picks the last empty voxel lying on the ray.

        /**
         *
         */
        public static bool PickLastEmptyVoxel(ColoredCubesVolume volume, Ray ray, float distance, out PickVoxelResult pickResult)
        {
            return(PickLastEmptyVoxel(volume, ray.origin, ray.direction, distance, out pickResult));
        }
Beispiel #4
0
 // This funcion should be implemented to find the point where the ray
 // pierces the mesh, between the last empty voxel and the first solid voxel.
 /*public static bool PickSurface(ColoredCubesVolume volume, Vector3 origin, Vector3 direction, float distance, PickSurfaceResult pickResult)
 {
 }*/
 /// Picks the first solid voxel lying on the ray.
 /**
  *
  */
 public static bool PickFirstSolidVoxel(ColoredCubesVolume volume, Ray ray, float distance, out PickVoxelResult pickResult)
 {
     return PickFirstSolidVoxel(volume, ray.origin, ray.direction, distance, out pickResult);
 }