{"id":17013136,"url":"https://github.com/kariaro/h3d","last_synced_at":"2025-06-10T22:05:01.281Z","repository":{"id":192436272,"uuid":"686696884","full_name":"Kariaro/h3d","owner":"Kariaro","description":"3D Raster for ComputerCraft","archived":false,"fork":false,"pushed_at":"2023-09-16T19:18:27.000Z","size":135,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-22T11:36:54.903Z","etag":null,"topics":["computercraft","raster"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kariaro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-03T16:47:18.000Z","updated_at":"2024-09-28T11:55:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"4b10c127-2b96-4394-a373-292fbfc470dc","html_url":"https://github.com/Kariaro/h3d","commit_stats":null,"previous_names":["kariaro/h3d"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kariaro%2Fh3d","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kariaro%2Fh3d/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kariaro%2Fh3d/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kariaro%2Fh3d/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kariaro","download_url":"https://codeload.github.com/Kariaro/h3d/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kariaro%2Fh3d/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259159655,"owners_count":22814492,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computercraft","raster"],"created_at":"2024-10-14T06:12:29.690Z","updated_at":"2025-06-10T22:05:01.238Z","avatar_url":"https://github.com/Kariaro.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# H3D\nA graphics library for ComputerCraft made by HaruCoded (2023)\n\nThis project was inspired by:\n+ [Pine3D (Xella)](https://github.com/Xella37/Pine3D)\n+ [V3D (Exerro)](https://github.com/exerro/v3d)\n+ [C3D (9551-Dev)](https://github.com/9551-Dev/C3D)\n\n# Documentation\n\n## Basic Setup\nFirst you need to create a raster and a geometry buffer\n```lua\nlocal h3d = require 'h3d'\n\n-- Create a default raster pipeline\nlocal raster, geometry = h3d.create_default_pipeline()\n\n-- Update the size of each layer\nlocal width, height = term.getSize(2)\nraster.set_size(width, height)\n\n-- Clear layers with values, should be done before each new frame\nraster.set_layer('depth', math.huge)\nraster.set_layer('color', 36)\n```\n\nThen you need to create a camera matrix\n```lua\nlocal camera = h3d.camera_matrix()\n\t:perspective(90, width / height, 0.01, 10000)\n```\n\nThen you can render geometry\n```lua\nraster.drawGeometry(geometry\n\t.position(-1, -1, 1)\n\t.position( 0, -1, 1)\n\t.position( 0,  0, 1)\n\t.color(0.33, 0.83, 0.00)\n\t.color(0.33, 0.83, 0.00)\n\t.color(0.33, 0.83, 0.00)\n\t.build(), camera)\n\nraster.drawGeometry(geometry\n\t.position(-0.50, -0.25, 1)\n\t.position( 0.00,  0.50, 1)\n\t.position( 0.50, -0.25, 1)\n\t.color(0.00, 0.50, 0.16)\n\t.color(0.00, 0.50, 0.16)\n\t.color(0.00, 0.50, 0.16)\n\t.build(), camera)\n```\n\nLastly you draw the rendered pixels to the screen\n```lua\n-- Setup color palette\nterm.setGraphicsMode(2)\nfor i=0,6*6*6 do\n\tlocal r = (math.floor(i     ) % 6) / 6.0\n\tlocal g = (math.floor(i /  6) % 6) / 6.0\n\tlocal b = (math.floor(i / 36) % 6) / 6.0\n\tterm.setPaletteColor(i, r, g, b)\nend\n\n-- Draw color layer to screen\nterm.drawPixels(1, 1, raster.get_layer('color'))\n\n-- Wait for a newline and reset the palette afterwards\nlocal wait = io.read()\nterm.setGraphicsMode(0)\nfor i=0,15 do\n\tlocal c = 2^i\n\tterm.setPaletteColor(c, term.nativePaletteColor(c))\nend\n```\n\n## Attributes\n\n### `Default`\n**Note:** *All attributes are zero indexed*\n\nFor normal attributes you can access them in a shader by using `gl_vertex` and `gl_face`\n\nIf the attribute only has one component you can access them using `gl_vertex / gl_face ('attribute_name')`\n\nIf it has more than one component you need to specify which index you want `gl_vertex / gl_face ('attribute_name', attribute_index)`\n\n___\n### `h3d.AttributeType.Position`\nThe position attribute is required and is used to place the triangles on screen\n\nIn a shader you can access the position with `gl_x`, `gl_y`, `gl_z`\n\nThe position value can be added to a geometry builder using `geometry.position(x, y, z)`\n\n___\n### `h3d.AttributeType.Texture`\nThe texture attribute is optional and can be used to draw texture\n\nIn a shader you can access the texture with `gl_uv_x`, `gl_uv_y`\n\nThe texture can be added to a geometry builder using `geometry.texture(x, y)`\n\nTo set the current texture you call `raster.set_texture(texture)`\n\n___\n### `h3d.AttributeType.Color`\nThe color attribute is optional and can be used to draw colors\n\nIn a shader you can access the color with `gl_r`, `gl_g`, `gl_b`\n\nThe color can be added to a geometry builder using `geometry.color(r, g, b)`\n\n## Custom pipeline\n\n```lua\nlocal raster, geometry = h3d.create_pipeline({\n\tvertex_attributes = {\n\t\t-- Position AttributeType is required\n\t\th3d.attr('position', 3, h3d.AttributeType.Position),\n\n\t\t-- Texture is optional\n\t\th3d.attr('uv', 2, h3d.AttributeType.Texture),\n\n\t\t-- Color is optional\n\t\th3d.attr('color', 3, h3d.AttributeType.Color),\n\n\t\t-- Custom attribute\n\t\th3d.attr('test', 3),\n\t},\n\tface_attributes = {\n\t\t-- Face attributes are applied to the entire triangle\n\t\th3d.attr('color', 1),\n\t},\n\tlayers = {\n\t\t-- Layers can be used to draw color, normal, depth information\n\t\t-- You can also use layers to write ids to them and use it\n\t\t-- for selection\n\t\t'color',\n\t\t'depth'\n\t},\n\tfrag_shader = [[\n\t\tif gl_layer('depth') \u003e gl_depth then\n\t\t\tgl_set_layer('depth', gl_depth)\n\t\t\tgl_set_layer('color', gl_face('color'))\n\t\tend\n\t]]\n})\n```\n\n# Shader\nA shader can be used to create more advanced effects to scenes such as lighting\n\n## Language\nThe language is a simplified version of lua with only `local` and `if` statements,\nthere are no `elseif` statements so you need to nest `else`\n\n```lua\nif a then\n\t-- First\nelse\n\tif b then\n\t\t-- Second\n\tend\nend\n```\n\n## Builtin Variables\n### `gl_x`\n- Get the fragment x coordinate\n\n### `gl_y`\n- Get the fragment y coordinate\n\n### `gl_z` / `gl_depth`\n- Get the fragment z coordinate\n\n### `gl_uv_x`\n- **Note:** *This value is only present if you added a texture attribute*\n- Get the uv x coordinate\n\n### `gl_uv_y`\n- **Note:** *This value is only present if you added a texture attribute*\n- Get the uv y coordinate\n\n### `gl_r`\n- **Note:** *This value is only present if you added a color attribute*\n- Get the red color value\n\n### `gl_g`\n- **Note:** *This value is only present if you added a color attribute*\n- Get the green color value\n\n### `gl_b`\n- **Note:** *This value is only present if you added a color attribute*\n- Get the blue color value\n\n### `gl_HasTexture`\n- Get if a texture is currently loaded\n\n## Builtin Functions\n### `gl_vertex(name, index)`\n- Returns - Number: The vertex attribute with the specified name and the given index\n\n### `gl_face(name, index)`\n- Returns - Number: The face attribute with the specified name and the given index\n\n### `gl_tex(u, v)`\n- Returns - Number: The texture pixel value at the specified `uv` coordinate\n\n### `gl_layer(name)`\n- Returns - Number: The value inside the layer with the specified name\n\n### `gl_set_layer(name, value)`\n- Description: Set the value of a layer\n\n## Builtin Math\n### `min(...)`\n- Returns - Number: The minimum value\n\n### `max(...)`\n- Returns - Number: The maximum value\n\n### `floor(value)`\n- Returns - Integer: The floor value\n\n### `ceil(value)`\n- Returns - Integer: The ceil value\n\n\n# PLUA Format\nPreProcessed Lua files\n\nThese are used to automatically generate code\n\n```lua\n{%\n-- Compile time code\n%}\n\n{!\n-- Insert this into the code as a string\n!}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkariaro%2Fh3d","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkariaro%2Fh3d","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkariaro%2Fh3d/lists"}