Exemplo n.º 1
0
    public void DrawGizmos(AbstractVoxelBounds voxelBounds, Color localColor, Color viewColor)
    {
        Gizmos.color  = localColor;
        Gizmos.matrix = VoxelModel;
        voxelBounds.DrawGizmosLocal();

        Gizmos.color  = viewColor;
        Gizmos.matrix = View.inverse * ViewUvToLocal;
        Gizmos.DrawWireCube(0.5f * Vector3.one, 1f * Vector3.one);

        Gizmos.matrix = Matrix4x4.identity;
    }
Exemplo n.º 2
0
    public TriadVoxelizer(ComputeShaderLinker csLinker, Shader voxelizer, AbstractVoxelBounds voxelBounds, int prefferedResolution)
    {
        this.csLinker  = csLinker;
        this.voxelizer = voxelizer;

        this.shaderConstants = ShaderConstants.Instance;

        this.cameraDirection = new VoxelCameraDirection();
        this.renderCam       = new ManuallyRenderCamera((cam) => cameraDirection.FitCameraToVoxelBounds(cam, voxelBounds));

        this.colorTextures = new VoxelTexture[DIRECTIONS.Length];
        for (var i = 0; i < colorTextures.Length; i++)
        {
            colorTextures [i] = GenerateVoxelTexture(prefferedResolution);
        }
        this.resultTex = GenerateVoxelTexture(prefferedResolution);
    }
Exemplo n.º 3
0
    public void FitCameraToVoxelBounds(Camera cam, AbstractVoxelBounds voxelBounds)
    {
        var origin  = voxelBounds.NormalizedToWorldPosition(basisRotationMatrix.MultiplyVector(NORMALIZED_ORIGIN));
        var right   = voxelBounds.NormalizedToWorldPosition(basisRotationMatrix.MultiplyVector(NORMALIZED_RIGHT) + NORMALIZED_ORIGIN) - origin;
        var up      = voxelBounds.NormalizedToWorldPosition(basisRotationMatrix.MultiplyVector(NORMALIZED_UP) + NORMALIZED_ORIGIN) - origin;
        var forward = voxelBounds.NormalizedToWorldPosition(basisRotationMatrix.MultiplyVector(NORMALIZED_FORWARD) + NORMALIZED_ORIGIN) - origin;

        var upLength      = up.magnitude;
        var rightLength   = right.magnitude;
        var forwardLength = forward.magnitude;

        var nearClipPlane = cameraToVoxelDistance;
        var farClipPlane  = nearClipPlane + 2f * forwardLength;

        cam.transform.position = origin - (nearClipPlane / forwardLength + 1f) * forward;
        cam.transform.rotation = Quaternion.LookRotation(forward, up);
        cam.orthographic       = true;
        cam.orthographicSize   = upLength;
        cam.nearClipPlane      = nearClipPlane;
        cam.farClipPlane       = farClipPlane;
        cam.aspect             = rightLength / upLength;
    }
Exemplo n.º 4
0
 public void Init(AbstractVoxelBounds voxelBounds, Matrix4x4 voxelModel)
 {
     LocalBounds    = voxelBounds.LocalBounds;
     VoxelUvToLocal = voxelBounds.VoxelUvToLocalMatrix();
     VoxelModel     = voxelModel;
 }
Exemplo n.º 5
0
 public void Set(AbstractVoxelBounds voxelBounds)
 {
     this.voxelBounds = voxelBounds;
 }