Jump to content




3D Rendering API v0.5.1 UPDATED! (Way better erformance + new functionalities)

api lua

64 replies to this topic

#1 Xelostar

  • Members
  • 134 posts
  • LocationOn Earth

Posted 05 June 2016 - 05:23 PM

v0.5.1 is released!


Posted Image


Hello everyone! First of all I want to say that English is not my native language, so please don't get angry if I make any mistakes. I have been trying to create a 3D renderer in computercraft. Please give me some feedback and tell me what you would like to see implemented.

Ideas to be implemented:
  • Vertical rotation of objects
  • Custom vertexshaders
  • Texture support (may not be implemented, because it would probably be very laggy to use real-time)
I have also showed it in my channel. This is the latest version (if the link doesn't work, the name of the video is "ComputerCraft - 3D Renderer v0.5.1 "):


API in action:
http://www.computerc...ine-highscores/

Documentation:
http://www.mediafire...tation.pdf/file

Pastebin downloads:
[ThreeD API minified (smaller file)] - pastebin get meXK8uweThreeD
[ThreeD API (original)I] - pastebin get g1xp8H5X ThreeD
[Engine] - pastebin get DqCTJBza Engine
[First demo] - pastebin get P5b7cAQc Demo1
[Second demo] - pastebin get xTgJQ0hk Demo2
[Third demo] - pastebin get vkaxmF1D Demo3

Complete download (with all files):
http://www.mediafire...ackage.zip/file

Update notes:

Version 0.1:
  • Renders 3D objects
  • Ability to walk around
  • Ability to look left and right
  • Give objects rotation values
Version 0.2:
  • Renders 3D boxes
  • Ability to walk left and right
  • Ability to look up and down
  • Ability to fly up and down
  • More efficient code
Version 0.3:
  • The code is now split into an API and a demo :D
Version 0.4:
  • Now uses a buffer (to avoid flickering)
  • You can now create your own models
  • Square objects look square on screen because the not-square pixels have been compensated for
  • The oriĆ«ntation of objects is now changeable
  • Objects are not rendered when they're not in sight
  • Sky and ground colors are easily changed as background
  • Change sorting algorithm to use table.sort() for better performance
  • Added support for Bomb Bloke's blittle API - Render distance is changeable
  • Using term.blit() to render the screen for better performance
  • Cleaner code
Version 0.5:
  • Added support for multiple renders at the same time
  • Polygons are now only rendered from one side unless specified otherwise. (For better performance)
  • Crash fix
  • Lagspike fixes
  • Performance is better
Version 0.5.1:
  • Added the ability to trace what's on the screen at certain coordinates and returns the index of the object with the index of the polygon of the model that corresponds to that object
  • Added the ability to manually load models as a tabl
  • Added the ability to get the model of an object my model name if it has already been loaded
  • Performance is way better
  • The polygons can now have a character and char color in case the BLittle function isn't used
  • Way cleaner code
  • (Documentation added)
  • (More demos and comments added to the improved engine)

Edited by Xelostar, 22 July 2018 - 02:59 PM.


#2 jv110

  • Members
  • 108 posts
  • LocationIn front of my PC

Posted 06 June 2016 - 04:35 PM

You should do a 3D rendering API, not a program in which you can walk around and add blocks.

#3 ReBraLaCC

  • Members
  • 100 posts
  • LocationSublime Text 2

Posted 06 June 2016 - 08:53 PM

For some reason i cant access the video using the link, whats the name of the video?

#4 Xelostar

  • Members
  • 134 posts
  • LocationOn Earth

Posted 07 June 2016 - 03:46 PM

View Postjv110, on 06 June 2016 - 04:35 PM, said:

You should do a 3D rendering API, not a program in which you can walk around and add blocks.

I will absolutely do that. Thank you for the idea. I will have to try a few things because I have never made an API.

View PostReBraLaCC, on 06 June 2016 - 08:53 PM, said:

For some reason i cant access the video using the link, whats the name of the video?

I have put the name of the video in my first post. The name is "ComputerCraft - 3D Renderer v0.2 "

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 08 June 2016 - 01:29 AM

If you switch the Youtube link from "https" to "http", it'll actually embed into your post.

#6 apemanzilla

  • Members
  • 1,421 posts

Posted 08 June 2016 - 02:07 AM

View PostBomb Bloke, on 08 June 2016 - 01:29 AM, said:

If you switch the Youtube link from "https" to "http", it'll actually embed into your post.

But then it embeds with flash and the only way to access it all with flash disabled is to use the element inspector to get the URL :(

Edited by apemanzilla, 08 June 2016 - 02:07 AM.


#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 08 June 2016 - 03:28 AM

So enable Flash. Firefox has an "ask to activate" option for plugins which makes that pretty easy, and is what I use.

I've also installed an extension to force youtube.com to use the Flash player, as let's face it, their HTML5 player is still a bit rubbish. Once they sort out the overhead and the weirdly increased loading times it might be worth using, but until then, why suffer?

Still, I suppose there's always the option of posting both versions of the link.

#8 Xelostar

  • Members
  • 134 posts
  • LocationOn Earth

Posted 08 June 2016 - 02:50 PM

View PostBomb Bloke, on 08 June 2016 - 01:29 AM, said:

If you switch the Youtube link from "https" to "http", it'll actually embed into your post.

Thank you for this tip!

EDIT:

It doesn't actually work. :/

Edited by Xelostar, 08 June 2016 - 02:52 PM.


#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 09 June 2016 - 01:29 AM

You still had URL tags around it, forcing it to be treated as a link. I've removed them.

#10 Xelostar

  • Members
  • 134 posts
  • LocationOn Earth

Posted 09 June 2016 - 09:07 PM

View PostBomb Bloke, on 09 June 2016 - 01:29 AM, said:

You still had URL tags around it, forcing it to be treated as a link. I've removed them.

Thank you! I am a litle bit new to the computercraft forum. :)

#11 unnamedcoder

  • Members
  • 23 posts

Posted 11 June 2016 - 05:38 PM

Love it! Nice, smooth and efficient, keep it up, it'd be cool if you could implement this into a game engine, for example having map creation, object creation, object placement, etc! Can't wait to see the future updates though!

#12 Xelostar

  • Members
  • 134 posts
  • LocationOn Earth

Posted 12 June 2016 - 05:56 AM

View Postunnamedcoder, on 11 June 2016 - 05:38 PM, said:

Love it! Nice, smooth and efficient, keep it up, it'd be cool if you could implement this into a game engine, for example having map creation, object creation, object placement, etc! Can't wait to see the future updates though!

Thank you for your compliment! :D
I will split my code into an API other people can use and a demo which you can also edit.
I am almost done doing this! :D (I am having a little trouble debugging, but hopefully it will be finished soon. :D)

#13 unnamedcoder

  • Members
  • 23 posts

Posted 12 June 2016 - 08:35 PM

View PostXelostar, on 12 June 2016 - 05:56 AM, said:

Thank you for your compliment! :D
I will split my code into an API other people can use and a demo which you can also edit.
I am almost done doing this! :D (I am having a little trouble debugging, but hopefully it will be finished soon. :D)
Good luck with the debugging, I'd like to know how you add shapes to the world, do you use files to import them, if so could you show me the code to generate the shapes? I'd love to have a go at making an api which allows you to create new objects for the world and import them, sort of like .mdl files

#14 Xelostar

  • Members
  • 134 posts
  • LocationOn Earth

Posted 12 June 2016 - 09:07 PM

View Postunnamedcoder, on 12 June 2016 - 08:35 PM, said:

View PostXelostar, on 12 June 2016 - 05:56 AM, said:

Thank you for your compliment! :D
I will split my code into an API other people can use and a demo which you can also edit.
I am almost done doing this! :D (I am having a little trouble debugging, but hopefully it will be finished soon. :D)
Good luck with the debugging, I'd like to know how you add shapes to the world, do you use files to import them, if so could you show me the code to generate the shapes? I'd love to have a go at making an api which allows you to create new objects for the world and import them, sort of like .mdl files

Well, I was thinking about that myself, but I like working together! :D
I will probably use some kind of table with relatve coordinates and a few things to draw the lines and stuff. The frame currently looks something like this:

shapeFrame = {
    coordinates = {
	    {x = -0.5, y = -0.5, z = -0.5}, -- These are the coordinates for one corner
	    {x = -0.5, y = -0.5, z = 0.5},
	    {x = -0.5, y = 0.5, z = 0.5},
	    {x = -0.5, y = 0.5, z = 0.5},
	    {x = 0.5, y = -0.5, z = 0.5},
	    {x = 0.5, y = -0.5, z = 0.5},
	    {x = 0.5, y = 0.5, z = 0.5},
	    {x = 0.5, y = 0.5, z = 0.5},
    },
    lines = {
	    {1, 5, colors.red}, -- Refer to the index numbers of the coordinates and the color of the line
	    {2, 6, colors.red},
	    {3, 7, colors.red},
	    {4, 8, colors.red},
	    {1, 3, colors.red},
	    {2, 4, colors.red},
	    {5, 7, colors.red},
	    {6, 8, colors.red},
	    {1, 2, colors.red},
	    {3, 4, colors.red},
	    {5, 6, colors.red},
	    {7, 8, colors.red},
    }
}

If you can pull such a thing off, I will make my API able to load those kind of models. If you have a better idea of how a model can be saved, please let me know.

#15 Incinirate

  • Members
  • 216 posts
  • LocationDanktown, Memeland

Posted 12 June 2016 - 09:33 PM

View PostXelostar, on 12 June 2016 - 09:07 PM, said:

View Postunnamedcoder, on 12 June 2016 - 08:35 PM, said:

View PostXelostar, on 12 June 2016 - 05:56 AM, said:

Thank you for your compliment! :D
I will split my code into an API other people can use and a demo which you can also edit.
I am almost done doing this! :D (I am having a little trouble debugging, but hopefully it will be finished soon. :D)
Good luck with the debugging, I'd like to know how you add shapes to the world, do you use files to import them, if so could you show me the code to generate the shapes? I'd love to have a go at making an api which allows you to create new objects for the world and import them, sort of like .mdl files

Well, I was thinking about that myself, but I like working together! :D
I will probably use some kind of table with relatve coordinates and a few things to draw the lines and stuff. The frame currently looks something like this:

shapeFrame = {
	coordinates = {
		{x = -0.5, y = -0.5, z = -0.5}, -- These are the coordinates for one corner
		{x = -0.5, y = -0.5, z = 0.5},
		{x = -0.5, y = 0.5, z = 0.5},
		{x = -0.5, y = 0.5, z = 0.5},
		{x = 0.5, y = -0.5, z = 0.5},
		{x = 0.5, y = -0.5, z = 0.5},
		{x = 0.5, y = 0.5, z = 0.5},
		{x = 0.5, y = 0.5, z = 0.5},
	},
	lines = {
		{1, 5, colors.red}, -- Refer to the index numbers of the coordinates and the color of the line
		{2, 6, colors.red},
		{3, 7, colors.red},
		{4, 8, colors.red},
		{1, 3, colors.red},
		{2, 4, colors.red},
		{5, 7, colors.red},
		{6, 8, colors.red},
		{1, 2, colors.red},
		{3, 4, colors.red},
		{5, 6, colors.red},
		{7, 8, colors.red},
	}
}

If you can pull such a thing off, I will make my API able to load those kind of models. If you have a better idea of how a model can be saved, please let me know.

That's essentially how wavefront objs are, except with faces instead of lines. It is a surprisingly good system.

#16 unnamedcoder

  • Members
  • 23 posts

Posted 13 June 2016 - 02:56 PM

View PostXelostar, on 12 June 2016 - 09:07 PM, said:

Well, I was thinking about that myself, but I like working together! :D
I will probably use some kind of table with relatve coordinates and a few things to draw the lines and stuff. The frame currently looks something like this:

shapeFrame = {
	coordinates = {
		{x = -0.5, y = -0.5, z = -0.5}, -- These are the coordinates for one corner
		{x = -0.5, y = -0.5, z = 0.5},
		{x = -0.5, y = 0.5, z = 0.5},
		{x = -0.5, y = 0.5, z = 0.5},
		{x = 0.5, y = -0.5, z = 0.5},
		{x = 0.5, y = -0.5, z = 0.5},
		{x = 0.5, y = 0.5, z = 0.5},
		{x = 0.5, y = 0.5, z = 0.5},
	},
	lines = {
		{1, 5, colors.red}, -- Refer to the index numbers of the coordinates and the color of the line
		{2, 6, colors.red},
		{3, 7, colors.red},
		{4, 8, colors.red},
		{1, 3, colors.red},
		{2, 4, colors.red},
		{5, 7, colors.red},
		{6, 8, colors.red},
		{1, 2, colors.red},
		{3, 4, colors.red},
		{5, 6, colors.red},
		{7, 8, colors.red},
	}
}

If you can pull such a thing off, I will make my API able to load those kind of models. If you have a better idea of how a model can be saved, please let me know.

I'll have a go at making a program that allows you to edit and create objects, if you wanna work by yourself, I'll leave you to it :)

EDIT: could you possibly provide a 2d linedrawing api for me?

Edited by unnamedcoder, 13 June 2016 - 03:16 PM.


#17 Incinirate

  • Members
  • 216 posts
  • LocationDanktown, Memeland

Posted 13 June 2016 - 03:51 PM

View Postunnamedcoder, on 13 June 2016 - 02:56 PM, said:

--snip--
could you possibly provide a 2d linedrawing api for me?

Just use paintutils.drawLine

#18 Xelostar

  • Members
  • 134 posts
  • LocationOn Earth

Posted 13 June 2016 - 03:55 PM

I want to see what you come up with! :)
If you want to have a 2d line drawing API, you could just use:
paintutils.drawLine(x1, y1, x2, y2, color)
But I assume you want something like this:
for lineNr, lineCoordinates in pairs(linesToDraw) do
  paintutils.drawLine(lineCoordinates.x, lineCoordinates.y, lineCoordinates.x2, lineCoordinates.y2, lineColor)
end
Anyway, please let me know when you are getting somewhere! :)

Edited by Xelostar, 13 June 2016 - 04:01 PM.


#19 unnamedcoder

  • Members
  • 23 posts

Posted 14 June 2016 - 12:03 AM

View PostXelostar, on 13 June 2016 - 03:55 PM, said:

I want to see what you come up with! :)
If you want to have a 2d line drawing API, you could just use:
paintutils.drawLine(x1, y1, x2, y2, color)
But I assume you want something like this:
for lineNr, lineCoordinates in pairs(linesToDraw) do
  paintutils.drawLine(lineCoordinates.x, lineCoordinates.y, lineCoordinates.x2, lineCoordinates.y2, lineColor)
end
Anyway, please let me know when you are getting somewhere! :)

Well, at the moment I'm trying to figure out a way to do this, I was thinking that it could be done with layers, the arrow keys will decide which layer you are editing therefore you could create full block shapes, another idea was placing points to connect lines to, I'm still trying to wrap my head around the concept.

#20 Xelostar

  • Members
  • 134 posts
  • LocationOn Earth

Posted 14 June 2016 - 12:36 PM

That is kind of how my 3D printer modeling program works... :P
I advise you to wait until I release my API. Then you can use it to draw what people are creating.
Well, it still is hard to create a program for creating models...
Maybe you can make it so that the user can click somewhere on the screen (2d) and then give a height value to that point. Later the user can connect these points to draw lines. I wish you a lot of succes! :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users