meshing-around
Validation
Validation module
Validation~Num function
Source code
Num ← °0typeValidation~Char function
Source code
Char ← °1typeValidation~Box function
Source code
Box ← °2typeValidation~Vec₂ function
Source code
Vec₂ ← ⊃(Num|°[2]△)Validation~Vec₃ function
Source code
Vec₃ ← ⊃(Num|°[3]△)Validation~Quat function
Source code
Quat ← ⊃(Num|°[4]△)Validation~ColorImg function
Source code
ColorImg ← ⊃(Num|⊃(°3⊣|°3⧻)△)Validation~AlphaImg function
Source code
AlphaImg ← ⊃(Num|⊃(°2⊣|°3⧻)△)Validation~GreyscaleImg function
Source code
GreyscaleImg ← ⊃(Num|°2⧻△)Transform
Transform module
Transform is used to represent the translation, rotation, and scale of an object.
Transform~ data boxed
Transform~Forward function
Get the 3D vector pointing in the object’s local forward direction.
Source code
Forward ← ˜QRot 0_1_0 RotationTransform~Right function
Get the 3D vector pointing in the object’s local right direction.
Source code
Right ← ˜QRot 1_0_0 RotationTransform~Up function
Get the 3D vector pointing in the object’s local up direction.
Source code
Up ← ˜QRot 0_0_1 RotationTransform~Rotate function
Source code
Rotate ← °⊸Rotation Qqp⊸⊙RotationTransform~V function
Source code
V ← °1≍"Transform"IDMaterial
Material module
Materials are used to represent a particular set of shading values.
Each field of a material contains a texture, which will be mapped to the surface of any triangle using it.
To use a single value rather than a texture, ¤¤ the value.
Material~ data boxed
Material~V function
Source code
V ← °1≍"Material"IDMesh
Mesh module
A mesh represents a single object to render. It holds a set of triangles, their normal vectors, their UV coordinates, the materials to shade with, which triangles use which materials, a transform, and a set of textures to be moved around with the mesh.
Mesh~ data boxed
Mesh~InitNormals function
Source code
InitNormals ← ⍥(°⊸Normals≡TriNorm⊸Triangles)≍¤˙⊟₃∞ ⊸NormalsMesh~CalculateNormals function
Source code
CalculateNormals ← °⊸Normals≡TriNorm⊸TrianglesMesh~InitUVs function
Source code
InitUVs ← ⍥(°⊸UVs ˜↯0 ˜⊂3_2 ⧻⊸Triangles)≍↯1_3_2 ∞ ⊸UVsMesh~InitMaterialIndex function
Source code
InitMaterialIndex ← ⍥(°⊸MaterialIndex˜↯0 ¤⧻⊸Triangles)≍¤∞ ⊸MaterialIndexMesh~ApplyScale function
Source code
ApplyScale ← °⊸Transform≈Scale↯3 1°⊸Triangles⧋×⊸⊃Transform≈Scale TrianglesMesh~ApplyRot function
Source code
ApplyRot ← °⊸Transform≈Rotation RQuat0˙⊟₃0°⊸⊃(Normals|Triangles) ∩⌞QRot⊸⊃(Transform≈Rotation|Normals|Triangles)Mesh~ApplyPos function
Source code
ApplyPos ← °⊸Transform≈Position⊚3°⊸Triangles⧋+⊸⊃Transform≈Position TrianglesMesh~ApplyTransform function
Source code
ApplyTransform ← ApplyPos ApplyRot ApplyScaleMesh~Rotate function
Source code
Rotate ← °⊸Mesh~Transform≈Rotation Qqp⊸⊙Mesh~Transform≈RotationMesh~Call function
Source code
Call ← InitUVs InitMaterialIndex InitNormals NewMesh~V function
Source code
V ← °1≍"Mesh"IDRenderConfig
RenderConfig module
A RenderConfig defines some parameters for rendering a mesh, which aren’t specific to the mesh. Using the same RenderConfig with multiple meshes should result in a set of renders which can be composed into a single scene, as though they were rendered from the same camera.
RenderConfig~ data boxed
RenderConfig~AspectRatio function
Source code
AspectRatio ← /÷SizeRenderConfig~HalfwayVec function
Source code
HalfwayVec ← ÷⊸⩜⌵+⊃(¯Light|Camera≈Forward)RenderConfig~V function
Source code
V ← °1≍"RenderConfig"IDRenderOutput
RenderOutput module
RenderOutput~ data boxed
RenderOutput~ApplyTexture‼ index macro
Source code
ApplyTexture‼ ← °⊸^0^1˜⬚0⊡⟜(⌊⧋×△₂)⊙⊸⊃(UVs|^0)RenderOutput~ApplyTexture! index macro
Source code
ApplyTexture! ← ApplyTexture‼^⊙◌RenderOutput~GenUVs function
Source code
GenUVs ← ( ⬚NaN GenMeshProp‼Mesh~UVs UVs )RenderOutput~GenPos function
Source code
GenPos ← ( ⬚∞GenMeshProp‼Mesh~Triangles Pos⊙Mesh~ApplyTransform )RenderOutput~GenMaterials function
Source code
GenMaterials ← ( ⤚⊓(⊃MaterialIndex UVs|⍚⊃(Material~Albedo|Material~Roughness|Material~Reflectivity) Mesh~Materials) ⊞=⇡◡⋅⋅⧻ ⨬NaN_NaN∘⊙¤ ∩₃⌞(/+≡◇(⬚0⊡⌊⧋×⊸⊙△₂)) °⊸⊃(Material≈Albedo|Material≈Roughness|Material≈Reflectivity) )RenderOutput~ApplyTexFromSet‼ index macro
Source code
ApplyTexFromSet‼ ← ( ∪⌞∘(°□⊡)⊙⊙Mesh~TextureSet ˜ApplyTexture‼^0^1 )RenderOutput~ApplyTexFromSet! index macro
Source code
ApplyTexFromSet! ← ( ∪⌞∘(°□⊡)⊙⊙Mesh~TextureSet ˜ApplyTexture‼^⊙◌ )RenderOutput~ConvertTanNormals function
Source code
ConvertTanNormals ← ( ⊙(⊃(⍜⍉(-⌞°⊂)Mesh~Triangles|⍜⍉(Inv₂-⌞°⊂)Mesh~UVs|Mesh~Normals)Mesh~ApplyTransform ÷⊸⧋(√/+˙×)≡(⊂˜Mmp)) ⍉⧋˜Mvp Normal⟜⤚(⬚0⊏Index) °⊸Normal )RenderOutput~Call function
Source code
Call ← °⊸UVs˜↯0△ ⊸TriCoords NewRenderOutput~V function
Source code
V ← °1≍"RenderOutput"IDImageAndDepth
ImageAndDepth module
ImageAndDepth~ data boxed
ImageAndDepth~Combine function
Source code
Combine ← ImageAndDepth CombineByDepth ∩°ImageAndDepthConstants
Suzanne constant
Suzanne is a constant containing the “Suzanne” mesh used by Blender as a Mesh instance.
The Suzanne constant does not have a UV map.
Monadic functions
TriNorm function
Find the normal vector for a triangle
Source code
TriNorm ← ÷⊸⩜⌵Cross°⊟-¤°⊂DrawTri function
Rasterize a triangle PixelLocs ? 2DTriangle
Source code
DrawTri ← ( ⊓⌊⌈⊸⊃/↧/↥ ⧋⤙+⇡⤚- ⊙(⊚˜InTri°⍉) +°¤)STL function
Import an STL file as a Mesh. STL files do not contain UV coordinates.
There are two types of STL, ASCII and binary.
The inverse of this function can decode either, just make sure to &fras or &frab appropriately.
The STL function always generates binary STL.
Source code
STL ← ⌅(GenSTL|DecodeSTL)OBJ function
Import an OBJ file as a Mesh. OBJ files should be read with &fras. For use with this library, the OBJ file must only contain triangles, and must contain UV coordinates.
Source code
OBJ ← ⌅(GenOBJ|DecodeOBJ)Dyadic functions
WorldToView function
Convert from World-space coordinates to View-space coordinates
Source code
WorldToView ← ( ◡⊓Mesh~Triangles (⊃(Camera~Position|Camera~Rotation|Camera~Scale)RC~Camera) ⧋˜- ˜(QRot ⍜(↘1°⍉)¯) ⧋˜÷ ⧋(⊏0_2_1) °⊸Mesh~Triangles)CullBackfaces function
Filter out faces by direction facing relative to camera
Source code
CullBackfaces ← ( ˜⤚⊓(¯RC~Camera≈Up|⊃(Mesh~Normals|Mesh~Triangles|Mesh~UVs|Mesh~MaterialIndex)) ∩₄⌞▽⊸≡⌞(>0Dot) °⊸⊃(Mesh~Normals|Mesh~Triangles|Mesh~UVs|Mesh~MaterialIndex))InTri function
Check if a point is within a triangle Boolean ? 2DTriangle Point
Source code
InTri ← ( °⊟⤚-⌞°⊂ ∩⌞÷Det₂⟜₂(¯∩˜-∩⌟₂∩⌞Det₂) ×⊃(×∩≥₀|≤₁+))RenderPreview function
Fast render that does not output a depth map for compositing. Use for real-time rendering or scene previewing.
Source code
RenderPreview ← ( Mesh!( ApplyTransform InitNormals ) ◡⊓(⊃(Mesh~Triangles|Mesh~Normals)|RC~Camera≈Forward) ∩⌟˜▽⊙⟜(<₀⧋Dot) °⊸⊃Mesh~Triangles Mesh~Normals WorldToView ⊃↓( /↧⤙˜↯0 ⋅RC~Size | °(-⊸¬)¯⧋Dot⊓(Mesh~Normals|RC~Light) | ⍖÷₃≡/+⧋⊃↘₂↙₂Mesh~Triangles) ∩⌞⊏ ÷₂+₁ ∪⌟×∘ ∧(˜⍜⊙⬚0⊡≡⊙◌⊙¤ DrawTri) ⇌°⍉)Tetradic functions
CombineByDepth function
Pick the closer of two depth-value pairs
Source code
CombineByDepth ← ˜(⍜-×⊙⊙⊃<↧)Hexadic functions
RenderMesh function
Full-featured renderer. Performs the core steps of the full rendering process.
Source code
RenderMesh ← ( Mesh!( ApplyTransform InitNormals InitMaterialIndex ) WorldToView ◡⊓(⊃Mesh~Triangles Mesh~Normals|⊃(RC~Camera≈Forward|⤙˜↯∞ RC~Size)) ⊃(÷₃⧋(/+⊣)|⧋↙₂) ⟜∩₃⌟˜▽⊙⊙(°⊏<₀⧋Dot) ⊙(∪⌞∘(+×⊙(⊃/↧(¤¤)÷₂))∩⌞⊏⍖) ⤚⋅(⇌°⍉∧(⍜⊙⬚0⊡≡⊙◌¤ ⊙DrawTri)) ⊙⊙⊃↓( | ↯⋅⊃(˜⊂3RC~Size|RC~AmbientColor) | ⍜(°⊂⍉)⟜(Inv₂-⌞)+×⊙(⊃/↧(¤¤)÷₂)⊓(⧋↙₂Mesh~Triangles|RC~Size) | ↥₀¯⧋Dot⊓(Mesh~Normals|RC~Light) | Mesh~Normals | Mesh~MaterialIndex ) ⟜⊓⌞( ⬚∞⊏ | ⬚NaN⊏ | ⬚0⊏ | ⬚0⊏ | ⇌⤸₁⍉⧋˜Mvp⊙(⤸0_1_3_2⍉)˜-⇡⊸△₂°⊂⤸₂⬚NaN⊏⍉⇌ ) RO)