GithubHelp home page GithubHelp logo

iunius118 / cc3dprojector Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 141 KB

for ComputerCraft 1.80pr1 (Minecraft 1.12/1.12.2 with Forge). Require ComputerCraft API to compile.

License: MIT License

Java 100.00%

cc3dprojector's Introduction

CC3DProjector

CC3DProjector is a programmable rendering peripheral for ComputerCraft. Using this peripheral, players can render points, lines and quadrangles on the World.

Requirements

  • Minecraft 1.12.2
  • Minecraft Forge 1.12.2-14.23.5.2859+
  • ComputerCraft 1.80pr1/CC: Tweaked for 1.12.2

Download

Recipe

e = Eye of Ender, d = Diamond, # = Stone

#d#
#e#
###

Lua sample code

local projector = peripheral.find( "3d_projector" )
-- Model script
local model = {
  {"color",3},
  {"alpha",0.5},
  {"translate",{0.5,0.125,0.5}},
  {"oscillate",1,0,2},
  {"translate",{0,0.125,0}},
  {"oscillate",0,0,6},
  {"rotateY",180},
  {"face",{-0.41,0.333333,0.2357},{0,0.666667,0.4714},{0,1,0},{-0.41,0.666667,-0.2357}},
  {"face",{0,0.666667,0.4714},{0.41,0.333333,0.2357},{0.41,0.666667,-0.2357},{0,1,0}},
  {"face",{0.41,0.333333,0.2357},{0,0,0},{0,0.333333,-0.4714},{0.41,0.666667,-0.2357}},
  {"face",{0,0,0},{-0.41,0.333333,0.2357},{-0.41,0.666667,-0.2357},{0,0.333333,-0.4714}},
  {"face",{-0.41,0.666667,-0.2357},{0,1,0},{0.41,0.666667,-0.2357},{0,0.333333,-0.4714}},
  {"face",{0,0,0},{0.41,0.333333,0.2357},{0,0.666667,0.4714},{-0.41,0.333333,0.2357}}
  }

if projector then
  -- Write model script and Start drawing model
  projector.write( model )
  sleep( 15 )  -- for 15 seconds

  -- Read model script from peripheral and Save to file
  local h = fs.open( "model", "w" )
  h.write( textutils.serialize( projector.read() ) )
  h.close()

  -- Clear model and Stop drawing model
  projector.clear()
else
  print( "Peripheral 3d_projector not found" )
end

Script Reference

model = { tCommand1, tCommand2, tCommand3, ... }

Color commands

Color

{ "color", nColor }
  • nColor ( 0 <= nColor <= 15 ): Same as 16 colors of Advanced Computers

Alpha

{ "alpha", nAlpha }
  • nAlpha ( 0.0 <= nAlpha <= 1.0 ): Opacity

Drawing commands

tVertex = { nX, nY, nZ }

Point

{ "point", tVertex }
{ "point", tVertex_1, tVertex_2, ... }  -- up to tVertex_255
  • Same as GL_POINTS mode
  • { "point", v1, v2, v3 } will draw points at v1, v2 and v3

Line

{ "line", tVertex_1, tVertex_2 }
{ "line", tVertex_1, tVertex_2, tVertex_3, ... }  -- up to tVertex_255
  • Same as GL_LINE_STRIP mode
  • { "line", v1, v2, v3 } will draw lines: v1 - v2 - v3

Loop

{ "loop", tVertex_1, tVertex_2, tVertex_3 }
{ "loop", tVertex_1, tVertex_2, tVertex_3, tVertex_4, ... }  -- up to tVertex_255
  • Same as GL_LINE_LOOP mode
  • { "loop", v1, v2, v3 } will draw lines: v1 - v2 - v3 - v1

Face

{ "face", tVertex_1, tVertex_2, tVertex_3, tVertex_4 }
  • Same as GL_QUADS mode, but each face command draws only one quadrilateral

Transformation commands

{ "translate", { nX, nY, nZ } }

Rotate

{ "rotateX", nAngle }
{ "rotateY", nAngle }
{ "rotateZ", nAngle }
  • nAngle: Angle in degrees

Scale

{ "scale", { nX, nY, nZ } }

Oscillation command

{ "oscillate", nType, nPhase, nPeriod }
  • nType ( 0 <= nType <= 3 ): Waveform type: 0 sawtooth, 1 sine, 2 square, 3 triangle
  • nPhase ( 0.0 <= nPhase < 1.0 ): Phase
  • nPeriod ( 0.0 < nPeriod ): Wave period in seconds
  • Generated amplitude is -1 to +1
  • This command works only with transformation command or alpha command

With Transformation command

{ ... , { "oscillate", nType, nPhase, nPeriod }, { "translate", { nX, nY, nZ } }, ... }
-- means { "translate", { nX * oscillate(), nY * oscillate(), nZ * oscillate() } }

{ ... , { "oscillate", nType, nPhase, nPeriod }, { "rotateX", nAngle }, ... }
-- means { "rotateX", nAngle * oscillate() }

{ ... , { "oscillate", nType, nPhase, nPeriod }, { "scale", { nX, nY, nZ } }, ... }
-- means { "scale", { nX * oscillate(), nY * oscillate(), nZ * oscillate() } }

With Alpha command

{ ... , { "oscillate", nType, nPhase, nPeriod }, { "alpha", nAlpha }, ... }
-- means { "alpha", nAlpha * oscillate() + nConstAlpha }
-- nConstAlpha: Alpha value set by Alpha command without Oscillation command

License

  • MIT License

Copyright © 2017 Iunius118

cc3dprojector's People

Contributors

iunius118 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.