From 7ad6866ef9d7188aeae355a2929e452cbf1ad3bd Mon Sep 17 00:00:00 2001 From: Nathan Pointer Date: Sun, 19 Mar 2023 22:03:03 -0700 Subject: [PATCH 1/3] rm distanceMaterial --- package/package.json | 2 +- package/src/three/DistanceMaterial.ts | 135 -------------------------- 2 files changed, 1 insertion(+), 136 deletions(-) delete mode 100644 package/src/three/DistanceMaterial.ts diff --git a/package/package.json b/package/package.json index 39ee559..9fb53e4 100644 --- a/package/package.json +++ b/package/package.json @@ -1,6 +1,6 @@ { "name": "three-landscape", - "version": "0.9.0", + "version": "0.9.1", "description": "", "module": "dist/index.js", "types": "dist/index.d.ts", diff --git a/package/src/three/DistanceMaterial.ts b/package/src/three/DistanceMaterial.ts deleted file mode 100644 index 7a3bcef..0000000 --- a/package/src/three/DistanceMaterial.ts +++ /dev/null @@ -1,135 +0,0 @@ -import glsl from "glslify"; -import { normalFunctions, colorFunctions, glslNoise } from "../util/util"; -import { aperiodic, samplers } from "../util/samplers"; -import mixers from "../util/mixers"; -import sort from "../util/sort"; -import { ShaderMaterial } from "three"; - -// TODO: figure out how to use the same shader for both distant and close up -// simplified version of the shader that calculates the distant diffuse and normal maps -export function DistanceMaterial(parent) { - return new ShaderMaterial({ - uniforms: { - ...parent.uniforms, - diffuseMode: { value: true }, - normalMap: { value: parent.normalMap } - }, - vertexShader: glsl` - precision highp float; - varying vec2 vUv; - - void main() { - vUv = uv; - gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); - } - `, - fragmentShader: glsl` - const int SURFACES = ${parent.props.surfaces.length}; - uniform int surfaceSamples; - precision highp sampler2DArray; - uniform bool diffuseMode; - uniform sampler2D[2] splats; - uniform float displacementScale; - varying vec2 vUv; - varying vec3 vHeightNormal; - - uniform float[SURFACES] surfaceNormalStrength; - uniform float[SURFACES] surfaceNormalY; - uniform float[SURFACES] surfaceRepeat; - uniform bool[SURFACES] surfaceGridless; - uniform bool[SURFACES] surfaceTriplanar; - uniform vec4[SURFACES] surfaceTint; - uniform float[SURFACES] surfaceSaturation; - - uniform sampler2DArray diffuseArray; - uniform sampler2DArray normalArray; - uniform sampler2D normalMap; - - ${normalFunctions} - ${colorFunctions} - ${glslNoise} - - ${mixers} - ${samplers} - ${aperiodic} - - void main() { - vec4 t0 = texture2D(splats[0], vUv); - vec4 t1 = texture2D(splats[1], vUv); - vec2[8] surfaces = vec2[8]( - ${Array(2) - .fill(0) - .map((v, i) => { - const index = i.toString(); - return glsl` - vec2(${((i * 4 + 0) / 8.0).toString()}, t${index}.r), - vec2(${(i * 4 + 1) / 8.0}, t${index}.g), - vec2(${(i * 4 + 2) / 8.0}, t${index}.b), - vec2(${(i * 4 + 3) / 8.0}, t${index}.a)`; - }) - .join(",")} - ); - ${sort("surfaces")} - - float[SURFACES] weights; - float Z = 0.0; // fix this - float weightSum = 0.0; - for(int i = 0; i < surfaceSamples; i++) weightSum += surfaces[i].y; - - int index = int(surfaces[0].x * 8.0); - float k = noise(vec3(vUv.xy*200.0, 0.0)); // slower but may need to do it if at texture limit - - if(diffuseMode){ - gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); - for(int i = 0; i < surfaceSamples; i++){ - int index = int(surfaces[i].x * 8.0); - float N = surfaceNormalY[index]; - float R = surfaceRepeat[index]; - float P = surfaceNormalStrength[index]; - bool gridless = surfaceGridless[index]; - - weights[i] = surfaces[i].y / weightSum; - - // we don't bother with triplanar if the surface is distant, but we probably should - vec4 diffuse; - if(gridless){ - diffuse = AperiodicLinearSample(diffuseArray, vec3(vUv, surfaces[i].x * 8.0), R * vec2(1,N), k); - } else { - diffuse = LinearSample(diffuseArray, vec3(vUv, surfaces[i].x * 8.0), R * vec2(1,N), k); - } - - diffuse = saturation(diffuse, surfaceSaturation[index]); - diffuse = diffuse * surfaceTint[index]; - - vec4 weightedDiffuse = diffuse * surfaces[i].y; - gl_FragColor += weightedDiffuse; - } - } - else { - gl_FragColor = texture(normalMap, vUv); - // gl_FragColor = zeroN; - for(int i = 0; i < surfaceSamples; i++){ - int index = int(surfaces[i].x * 8.0); - float N = surfaceNormalY[index]; - float R = surfaceRepeat[index]; - float P = surfaceNormalStrength[index]; - bool gridless = surfaceGridless[index]; - - weights[i] = surfaces[i].y / weightSum; - - // we don't bother with triplanar if the surface is distant - vec4 normal; - if(gridless){ - normal = AperiodicNormalSample(normalArray, vec3(vUv, surfaces[i].x * 8.0), R * vec2(1,N), k); - } else { - normal = NormalSample(normalArray, vec3(vUv, surfaces[i].x * 8.0), R * vec2(1,N), k); - } - - vec4 weightedNormal = slerp(zeroN, normal, weights[i] * P); - gl_FragColor = blend_rnm(gl_FragColor, weightedNormal); - } - } - } - ` - }); -} From 59359dfbfce0596a96dfb8b28191b85e382d6ca0 Mon Sep 17 00:00:00 2001 From: Nathan Pointer Date: Sun, 19 Mar 2023 22:10:58 -0700 Subject: [PATCH 2/3] cleanup --- package/src/three/MacroMaterial.ts | 1 + package/src/three/TerrainMaterial.tsx | 4 +- package/src/three/TextureMerger.js | 374 ------------------ package/src/three/materialScene.ts | 1 + package/src/three/shaderMaterial.ts | 65 --- .../{three => util}/generateTextureArray.ts | 0 package/src/{three => util}/getImageData.ts | 0 .../splatPreProcessMaterial.ts | 2 +- 8 files changed, 5 insertions(+), 442 deletions(-) delete mode 100644 package/src/three/TextureMerger.js delete mode 100644 package/src/three/shaderMaterial.ts rename package/src/{three => util}/generateTextureArray.ts (100%) rename package/src/{three => util}/getImageData.ts (100%) rename package/src/{three => util}/splatPreProcessMaterial.ts (98%) diff --git a/package/src/three/MacroMaterial.ts b/package/src/three/MacroMaterial.ts index 7f164b6..fbace69 100644 --- a/package/src/three/MacroMaterial.ts +++ b/package/src/three/MacroMaterial.ts @@ -2,6 +2,7 @@ import { RepeatWrapping } from "three"; import glsl from "glslify"; import { ShaderMaterial } from "three"; +// used to help generate macro level details that break up terrain similarities when zoomed out export function MacroMaterial(parent) { parent.props.macroMap.wrapT = RepeatWrapping; parent.props.macroMap.wrapS = RepeatWrapping; diff --git a/package/src/three/TerrainMaterial.tsx b/package/src/three/TerrainMaterial.tsx index 77017b4..1b4484b 100644 --- a/package/src/three/TerrainMaterial.tsx +++ b/package/src/three/TerrainMaterial.tsx @@ -7,8 +7,8 @@ import mixers from "../util/mixers"; import sort from "../util/sort"; import { dynamicHeightUtils } from "../util/dynamicHeight"; import noise from "../util/noise"; -import { memGenerateTextureArray } from "./generateTextureArray"; -import { materialScene } from "./materialScene"; +import { memGenerateTextureArray } from "../util/generateTextureArray"; +import { materialScene } from "./MaterialScene"; import { TerrainMaterialOptions } from "../components/TerrainMaterial"; export default class TerrainMaterial extends CustomShaderMaterial { diff --git a/package/src/three/TextureMerger.js b/package/src/three/TextureMerger.js deleted file mode 100644 index 32df090..0000000 --- a/package/src/three/TextureMerger.js +++ /dev/null @@ -1,374 +0,0 @@ -import * as THREE from "three"; - -var TextureMergerRectangle = function (x, y, width, height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.finalX = x + width; - this.finalY = y + height; -}; - -TextureMergerRectangle.prototype.set = function (x, y, x2, y2, width, height) { - this.x = x; - this.y = y; - this.finalX = x2; - this.finalY = y2; - (this.width = width), (this.height = height); - return this; -}; - -TextureMergerRectangle.prototype.fits = function (texture) { - var tw = texture.image.width; - var th = texture.image.height; - if (tw <= this.width && th <= this.height) { - return true; - } - return false; -}; - -TextureMergerRectangle.prototype.fitsPerfectly = function (texture) { - var tw = texture.image.width; - var th = texture.image.height; - return tw == this.width && th == this.height; -}; - -TextureMergerRectangle.prototype.overlaps = function (rect) { - return ( - this.x < rect.x + rect.width && - this.x + this.width > rect.x && - this.y < rect.y + rect.height && - this.y + this.height > rect.y - ); -}; - -var TextureMerger = function (texturesObj, maxSize) { - this.MAX_TEXTURE_SIZE = maxSize || 4096; - - if (!texturesObj) { - return; - } - this.dataURLs = new Object(); - for (var textureName in texturesObj) { - console.log(textureName); - var txt = texturesObj[textureName]; - - if (txt instanceof THREE.CompressedTexture) { - throw new Error("CompressedTextures are not supported."); - } - - if (typeof txt.image.toDataURL == "undefined") { - var tmpCanvas = document.createElement("canvas"); - tmpCanvas.width = txt.image.naturalWidth; - tmpCanvas.height = txt.image.naturalHeight; - tmpCanvas.getContext("2d").drawImage(txt.image, 0, 0); - this.dataURLs[textureName] = tmpCanvas.toDataURL(); - } else { - this.dataURLs[textureName] = txt.image.toDataURL(); - } - } - this.canvas = document.createElement("canvas"); - this.textureCount = 0; - this.maxWidth = 0; - this.maxHeight = 0; - var explanationStr = ""; - for (textureName in texturesObj) { - this.textureCount++; - var texture = texturesObj[textureName]; - texture.area = texture.image.width * texture.image.height; - if (texture.image.width > this.maxWidth) { - this.maxWidth = texture.image.width; - } - if (texture.image.height > this.maxHeight) { - this.maxHeight = texture.image.height; - } - explanationStr += textureName + ","; - } - explanationStr = explanationStr.substring(0, explanationStr.length - 1); - this.textureCache = new Object(); - // node - // |___ children: Array(2) of node - // |___ rectangle: TextureMergerRectangle - // |___ textureName: String - // |___ upperNode: node - this.node = new Object(); - this.node.rectangle = new TextureMergerRectangle( - 0, - 0, - this.maxWidth * this.textureCount, - this.maxHeight * this.textureCount - ); - this.textureOffsets = new Object(); - this.allNodes = []; - this.insert(this.node, this.findNextTexture(texturesObj), texturesObj); - - this.ranges = new Object(); - var imgSize = this.calculateImageSize(texturesObj); - this.canvas.width = imgSize.width; - this.canvas.height = imgSize.height; - var context = this.canvas.getContext("2d"); - this.context = context; - for (textureName in this.textureOffsets) { - var texture = texturesObj[textureName]; - var offsetX = this.textureOffsets[textureName].x; - var offsetY = this.textureOffsets[textureName].y; - var imgWidth = texture.image.width; - var imgHeight = texture.image.height; - - for (var y = offsetY; y < offsetY + imgHeight; y += imgHeight) { - for (var x = offsetX; x < offsetX + imgWidth; x += imgWidth) { - context.drawImage(texture.image, x, y, imgWidth, imgHeight); - } - } - - var range = new Object(); - range.startU = offsetX / imgSize.width; - range.endU = (offsetX + imgWidth) / imgSize.width; - range.startV = 1 - offsetY / imgSize.height; - range.endV = 1 - (offsetY + imgHeight) / imgSize.height; - this.ranges[textureName] = range; - } - - this.makeCanvasPowerOfTwo(); - this.mergedTexture = new THREE.CanvasTexture(this.canvas); - this.mergedTexture.wrapS = THREE.ClampToEdgeWrapping; - this.mergedTexture.wrapT = THREE.ClampToEdgeWrapping; - this.mergedTexture.minFilter = THREE.NearestFilter; - this.mergedTexture.magFilter = THREE.NearestFilter; - this.mergedTexture.needsUpdate = true; -}; - -TextureMerger.prototype.isTextureAlreadyInserted = function ( - textureName, - texturesObj -) { - var texture = texturesObj[textureName]; - var img = this.dataURLs[textureName]; - for (var tName in texturesObj) { - if (tName == textureName) { - continue; - } - var txt = texturesObj[tName]; - var tImg = this.dataURLs[tName]; - if ( - img == tImg && - txt.offset.x == texture.offset.x && - txt.offset.y == texture.offset.y && - txt.offset.z == texture.offset.z && - txt.repeat.x == texture.repeat.x && - txt.repeat.y == texture.repeat.y && - txt.flipX == texture.flipX && - txt.flipY == texture.flipY && - txt.wrapS == texture.wrapS && - txt.wrapT == texture.wrapT - ) { - if (this.textureOffsets[tName]) { - return this.textureOffsets[tName]; - } - } - } - return false; -}; - -TextureMerger.prototype.insert = function (node, textureName, texturesObj) { - var texture = texturesObj[textureName]; - var res = this.isTextureAlreadyInserted(textureName, texturesObj); - if (res) { - this.textureOffsets[textureName] = res; - var newTextureName = this.findNextTexture(texturesObj); - if (!(newTextureName == null)) { - this.insert(node, newTextureName, texturesObj); - } - return; - } - var tw = texture.image.width; - var th = texture.image.height; - if (node.upperNode) { - var minArea = - this.maxWidth * this.textureCount + this.maxHeight * this.textureCount; - var minAreaNode = 0; - var inserted = false; - for (var i = 0; i < this.allNodes.length; i++) { - var curNode = this.allNodes[i]; - if (!curNode.textureName && curNode.rectangle.fits(texture)) { - this.textureOffsets[textureName] = { - x: curNode.rectangle.x, - y: curNode.rectangle.y, - }; - var calculatedSize = this.calculateImageSize(texturesObj); - var calculatedArea = calculatedSize.width + calculatedSize.height; - if ( - calculatedArea < minArea && - calculatedSize.width <= this.MAX_TEXTURE_SIZE && - calculatedSize.height <= this.MAX_TEXTURE_SIZE - ) { - var overlaps = false; - for (var tName in this.textureOffsets) { - if (tName == textureName) { - continue; - } - var cr = curNode.rectangle; - var ox = this.textureOffsets[tName].x; - var oy = this.textureOffsets[tName].y; - var oimg = texturesObj[tName].image; - var rect1 = new TextureMergerRectangle(cr.x, cr.y, tw, th); - var rect2 = new TextureMergerRectangle( - ox, - oy, - oimg.width, - oimg.height - ); - if (rect1.overlaps(rect2)) { - overlaps = true; - } - } - if (!overlaps) { - minArea = calculatedArea; - minAreaNode = this.allNodes[i]; - inserted = true; - } - } - delete this.textureOffsets[textureName]; - } - } - if (inserted) { - this.textureOffsets[textureName] = { - x: minAreaNode.rectangle.x, - y: minAreaNode.rectangle.y, - }; - minAreaNode.textureName = textureName; - if (!minAreaNode.children) { - var childNode1 = new Object(); - var childNode2 = new Object(); - childNode1.upperNode = minAreaNode; - childNode2.upperNode = minAreaNode; - minAreaNode.children = [childNode1, childNode2]; - var rx = minAreaNode.rectangle.x; - var ry = minAreaNode.rectangle.y; - var maxW = this.maxWidth * this.textureCount; - var maxH = this.maxHeight * this.textureCount; - childNode1.rectangle = new TextureMergerRectangle( - rx + tw, - ry, - maxW - (rx + tw), - maxH - ry - ); - childNode2.rectangle = new TextureMergerRectangle( - rx, - ry + th, - maxW - rx, - maxH - (ry + th) - ); - this.allNodes.push(childNode1); - this.allNodes.push(childNode2); - } - var newTextureName = this.findNextTexture(texturesObj); - if (!(newTextureName == null)) { - this.insert(node, newTextureName, texturesObj); - } - } else { - throw new Error("Error: Try to use smaller textures."); - } - } else { - // First node - var recW = node.rectangle.width; - var recH = node.rectangle.height; - node.textureName = textureName; - var childNode1 = new Object(); - var childNode2 = new Object(); - childNode1.upperNode = node; - childNode2.upperNode = node; - node.children = [childNode1, childNode2]; - childNode1.rectangle = new TextureMergerRectangle(tw, 0, recW - tw, th); - childNode2.rectangle = new TextureMergerRectangle(0, th, recW, recH - th); - this.textureOffsets[textureName] = { - x: node.rectangle.x, - y: node.rectangle.y, - }; - var newNode = node.children[0]; - this.allNodes = [node, childNode1, childNode2]; - var newTextureName = this.findNextTexture(texturesObj); - if (!(newTextureName == null)) { - this.insert(newNode, newTextureName, texturesObj); - } - } -}; - -TextureMerger.prototype.makeCanvasPowerOfTwo = function (canvas) { - var setCanvas = false; - if (!canvas) { - canvas = this.canvas; - setCanvas = true; - } - var oldWidth = canvas.width; - var oldHeight = canvas.height; - var newWidth = Math.pow(2, Math.round(Math.log(oldWidth) / Math.log(2))); - var newHeight = Math.pow(2, Math.round(Math.log(oldHeight) / Math.log(2))); - var newCanvas = document.createElement("canvas"); - newCanvas.width = newWidth; - newCanvas.height = newHeight; - newCanvas.getContext("2d").drawImage(canvas, 0, 0, newWidth, newHeight); - if (setCanvas) { - this.canvas = newCanvas; - } -}; - -TextureMerger.prototype.calculateImageSize = function (texturesObj) { - var width = 0; - var height = 0; - for (var textureName in this.textureOffsets) { - var texture = texturesObj[textureName]; - var tw = texture.image.width; - var th = texture.image.height; - var x = this.textureOffsets[textureName].x; - var y = this.textureOffsets[textureName].y; - if (x + tw > width) { - width = x + tw; - } - if (y + th > height) { - height = y + th; - } - } - return { width: width, height: height }; -}; - -TextureMerger.prototype.findNextTexture = function (texturesObj) { - var maxArea = -1; - var foundTexture; - for (var textureName in texturesObj) { - var texture = texturesObj[textureName]; - if (!this.textureCache[textureName]) { - if (texture.area > maxArea) { - maxArea = texture.area; - foundTexture = textureName; - } - } - } - if (maxArea == -1) { - return null; - } - this.textureCache[foundTexture] = true; - return foundTexture; -}; - -TextureMerger.prototype.rescale = function (canvas, scale) { - var resizedCanvas = document.createElement("canvas"); - resizedCanvas.width = canvas.width * scale; - resizedCanvas.height = canvas.height * scale; - var resizedContext = resizedCanvas.getContext("2d"); - resizedContext.drawImage( - canvas, - 0, - 0, - canvas.width, - canvas.height, - 0, - 0, - resizedCanvas.width, - resizedCanvas.height - ); - //this.debugCanvas(resizedCanvas); - return resizedCanvas; -}; - -export default TextureMerger; diff --git a/package/src/three/materialScene.ts b/package/src/three/materialScene.ts index afb5a40..824a18f 100644 --- a/package/src/three/materialScene.ts +++ b/package/src/three/materialScene.ts @@ -1,5 +1,6 @@ import { Scene, Mesh, PlaneGeometry, OrthographicCamera, AmbientLight } from "three"; +// used to help render a material out to a texture export function materialScene(mat) { const camera = new OrthographicCamera(-0.5, 0.5, -0.5, 0.5, 1, 10); const scene = new Scene(); diff --git a/package/src/three/shaderMaterial.ts b/package/src/three/shaderMaterial.ts deleted file mode 100644 index b0d9484..0000000 --- a/package/src/three/shaderMaterial.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { MeshStandardMaterial } from 'three'; -import * as THREE from 'three' -import CustomShaderMaterial, { iCSMUpdateParams } from "three-custom-shader-material/vanilla"; - -export function shaderMaterial( - uniforms: { - [name: string]: - | THREE.CubeTexture - | THREE.Texture - | Int32Array - | Float32Array - | THREE.Matrix4 - | THREE.Matrix3 - | THREE.Quaternion - | THREE.Vector4 - | THREE.Vector3 - | THREE.Vector2 - | THREE.Color - | number - | boolean - | Array - | null - }, - vertexShader: string, - fragmentShader: string, - baseMaterial = MeshStandardMaterial, - onInit?: (material?: CustomShaderMaterial) => void -) { - const material = class extends CustomShaderMaterial { - public key: string = '' - constructor(parameters = {}, ...rest) { - console.log(parameters, rest); - - const entries = Object.entries(uniforms) - // Create unforms and shaders - // @ts-ignore - super({ - uniforms: entries.reduce((acc, [name, value]) => { - const uniform = THREE.UniformsUtils.clone({ [name]: { value } }) - return { - ...acc, - ...uniform, - } - }, {}), - baseMaterial, - vertexShader, - fragmentShader, - }) - // Create getter/setters - entries.forEach(([name]) => - Object.defineProperty(this, name, { - get: () => this.uniforms[name].value, - set: (v) => (this.uniforms[name].value = v), - }) - ) - - // Assign parameters, this might include uniforms - Object.assign(this, parameters) - // Call onInit - if (onInit) onInit(this) - } - } as unknown as typeof THREE.ShaderMaterial & { key: string } - material.key = THREE.MathUtils.generateUUID() - return material -} \ No newline at end of file diff --git a/package/src/three/generateTextureArray.ts b/package/src/util/generateTextureArray.ts similarity index 100% rename from package/src/three/generateTextureArray.ts rename to package/src/util/generateTextureArray.ts diff --git a/package/src/three/getImageData.ts b/package/src/util/getImageData.ts similarity index 100% rename from package/src/three/getImageData.ts rename to package/src/util/getImageData.ts diff --git a/package/src/three/splatPreProcessMaterial.ts b/package/src/util/splatPreProcessMaterial.ts similarity index 98% rename from package/src/three/splatPreProcessMaterial.ts rename to package/src/util/splatPreProcessMaterial.ts index a2df6d4..7078025 100644 --- a/package/src/three/splatPreProcessMaterial.ts +++ b/package/src/util/splatPreProcessMaterial.ts @@ -1,6 +1,6 @@ import { ShaderMaterial } from "three"; import glsl from "glslify"; -import sort from "../util/sort"; +import sort from "./sort"; export function splatPreProcessMaterial(splats, surfaceSamples = 4.0, channelCount = 4.0) { console.log({surfaceSamples}) From 1fa00f27a3d124fe61418f89ddb595a1c3c6ccfd Mon Sep 17 00:00:00 2001 From: Nathan Pointer Date: Sun, 19 Mar 2023 22:27:50 -0700 Subject: [PATCH 3/3] cleanup --- package/src/three/TerrainMaterial.tsx | 4 ++-- .../src/three/{materialScene.ts => createMaterialScene.ts} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename package/src/three/{materialScene.ts => createMaterialScene.ts} (94%) diff --git a/package/src/three/TerrainMaterial.tsx b/package/src/three/TerrainMaterial.tsx index 1b4484b..dcb71db 100644 --- a/package/src/three/TerrainMaterial.tsx +++ b/package/src/three/TerrainMaterial.tsx @@ -8,7 +8,7 @@ import sort from "../util/sort"; import { dynamicHeightUtils } from "../util/dynamicHeight"; import noise from "../util/noise"; import { memGenerateTextureArray } from "../util/generateTextureArray"; -import { materialScene } from "./MaterialScene"; +import { createMaterialScene } from "./createMaterialScene"; import { TerrainMaterialOptions } from "../components/TerrainMaterial"; export default class TerrainMaterial extends CustomShaderMaterial { @@ -454,7 +454,7 @@ export default class TerrainMaterial extends CustomShaderMaterial { if (this.farMaterial) return; // already initialized this.farMaterial = new TerrainMaterial({ ...props, parent: this }); - const { camera, scene } = materialScene(this.farMaterial); + const { camera, scene } = createMaterialScene(this.farMaterial); this.farCamera = camera; this.farScene = scene; const maxSize = this.getMaxTextureSize(); diff --git a/package/src/three/materialScene.ts b/package/src/three/createMaterialScene.ts similarity index 94% rename from package/src/three/materialScene.ts rename to package/src/three/createMaterialScene.ts index 824a18f..b0502a6 100644 --- a/package/src/three/materialScene.ts +++ b/package/src/three/createMaterialScene.ts @@ -1,7 +1,7 @@ import { Scene, Mesh, PlaneGeometry, OrthographicCamera, AmbientLight } from "three"; // used to help render a material out to a texture -export function materialScene(mat) { +export function createMaterialScene(mat) { const camera = new OrthographicCamera(-0.5, 0.5, -0.5, 0.5, 1, 10); const scene = new Scene(); // ideally we would use a copy of the original geometry here