void AnimateTexture() { float pixelSize = 1f / resolution; if (animateTexture) { currentTextureAnimT += Time.deltaTime * textureAnimSpeed; } int texI = Mathf.Min(texture.width * texture.height - 1, (int)currentTextureAnimT); if (!Application.isPlaying || !animateTexture) { texI = resolution * resolution; } if (showClosestPoint || Application.isPlaying && animateTexture) { float y = (int)(texI / (float)resolution); float x = texI % resolution; var samplePos = new Vector2(x, y) / resolution + Vector2.one * pixelSize / 2; if (!Application.isPlaying) { y = (int)(sampleIndex / (float)resolution); x = sampleIndex % resolution; samplePos = new Vector2(x, y) / resolution + Vector2.one * pixelSize / 2; } if (!makeTile) { float minSqrDst = 1; Vector2 nearestPos = Vector2.zero; for (int i = 0; i < points.Length; i++) { float s = (samplePos - points[i]).sqrMagnitude; if (s < minSqrDst) { minSqrDst = s; nearestPos = points[i]; } } Vis.DrawSphere(samplePos, sampleRadius / 20f, sampleCol, Style.Unlit); Vis.DrawLine(samplePos, nearestPos, lineWidth / 10, lineCol, Style.Unlit); } } Color[] cols = new Color[resolution * resolution]; for (int i = 0; i < texI; i++) { cols[i] = new Color(values[i], values[i], values[i]); } texture.SetPixels(cols); }
void Update() { if (useUV && Application.isPlaying) { uv.x += Time.deltaTime * speed; if (uv.x > 1) { uv.x = 0; uv.y += inc; if (uv.y > 1) { uv.y = 1; speed = 0; } } transform.forward = RayDir(uv); } var col = Color.red; RayBox(container.position, container.localScale, eye.position, eye.forward); if (dstInsideBox == 0) { col = Color.grey; dstToBox = 999; } Debug.DrawRay(eye.position, eye.forward * dstToBox, col); Debug.DrawRay(eye.position + eye.forward * dstToBox, eye.forward * dstInsideBox, Color.white); if (dstInsideBox == 0) { dstToBox = 0; } else { Vis.DrawSphere(eye.position + eye.forward * dstToBox, .06f, col, Style.Unlit); Vis.DrawSphere(eye.position + eye.forward * (dstToBox + dstInsideBox), .06f, Color.white, Style.Unlit); if (showSamplePoints) { float step = dstInsideBox / numSamples; for (int i = 0; i < numSamples; i++) { Vis.DrawSphere(eye.position + eye.forward * (dstToBox + step * i), .06f, sampleCol, Style.Unlit); } } } }
void Do3D() { var prng = new System.Random(seed); var points = new Vector3[numCells * numCells * numCells]; float cellSize = 1f / numCells; for (int x = 0; x < numCells; x++) { for (int y = 0; y < numCells; y++) { for (int z = 0; z < numCells; z++) { float randomX = (float)prng.NextDouble(); float randomY = (float)prng.NextDouble(); float randomZ = (float)prng.NextDouble(); Vector3 randomOffset = new Vector3(randomX, randomY, randomZ) * cellSize; Vector3 cellCorner = (new Vector3(x, y, z)) * cellSize - Vector3.one * .5f; int index = x + numCells * (y + z * numCells); points[index] = cellCorner + randomOffset; } } } for (int i = 0; i < points.Length; i++) { float radius = debugRadius / 20f; if (Application.isPlaying && animatePoints) { float t = Time.time - i * pointAnimDelay - 5; radius = Mathf.Lerp(0, radius, t * pointGrowSpeed); } if (showAdj) { for (int j = 1; j < offsets3D.Length; j++) { Vis.DrawSphere(points[i] + offsets3D[j], radius, new Color(pointCol.r * adjDimming, pointCol.g * adjDimming, pointCol.b * adjDimming), Style.Unlit); } } Vis.DrawSphere(points[i], radius, pointCol, Style.Unlit); } }
void ShowPoints() { for (int i = 0; i < points.Length; i++) { float radius = debugRadius / 20f; if (Application.isPlaying && animatePoints) { float t = Time.time - i * pointAnimDelay; radius = Mathf.Lerp(0, radius, t * pointGrowSpeed); } if (showAdj) { for (int j = 1; j < offsets.Length; j++) { Vis.DrawSphere(points[i] + offsets[j], radius, new Color(pointCol.r * adjDimming, pointCol.g * adjDimming, pointCol.b * adjDimming), Style.Unlit); } } Vis.DrawSphere(points[i], radius, pointCol, Style.Unlit); } }