This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Xenthera's profile picture

[Cc2D] Computercraft 3D - Import Blender Files Into Computercraft!

Started by Xenthera, 26 September 2013 - 03:02 PM
Xenthera #1
Posted 26 September 2013 - 05:02 PM
After coding my first demo, I decided to take it a step farther. I added proper polygon support and added a feature to import Blender files and render them. They render in wireframe, but it's the thought that counts!

HOW TO IMPORT A MODEL FROM BLENDER
SpoilerStep 1:
If you haven't already, download blender from here
Step 2:
Download this plugin script io_export_babylon.py
Step 3:
Copy this file into the \script\addons directory where you’ve installed Blender (for instance “C:\Program Files (x86)\Blender Foundation\Blender\2.68\scripts\addons” in my specific case).
You need to activate the plug-in in the user preferences. Go to “File” –> “User Preferences” and the “Addons” tab. Search for “babylon” and activate it by checking the case.



(You may have to re-enable babylon.js every time you start blender)
Step 4:
Add a mesh to blender, in this case i'll be using an icosphere





Step 5:

Click File/Export/babylon.js
Then save that file to a location of your choice




Step 6:
Close blender, and open the file in your preferred text editor



Step 7:

Go to the 3d demo file supplied in this post and create this:




Important: Change the 20 to about 35 for this icosphere. It may vary depending on your model though (It's the scale)

Step 8:
Go back to the icosphere.babylon file, find where it says "vertices":[a whole bunch of numbers]
and copy all the numbers into icosphereVertices






Do the same with indices, and copy it to icosphereFaces





Result




Step 9:
Scroll down to where it says "ENTER NAME OF MODEL TO BE RENDERED HERE" (in the 3d file, not the icosphere.babylon file) and paste the mesh name into
render([mesh],modelAxisRotation,makeA3DPoint)



Step 10:
Open minecraft, Setup a computer and monitor like shown below, then run the 3d file in computercraft



monitor right cc2d 3d


Final Result:



warning: keep the polygons simple. even this icosphere doesn't run that well.

Demo 1: Blender Default Cube



Nothing special, you saw this in the last demo. What makes it important though, is the fact that it was exported from Blender. Moving on…


Demo 2: My model (warning, modeling is terrible. Proceed at own risk)

In Blender



Converted for CC:




Demo 3: Suzanne the monkey

Due to the shear amount of vertices/faces this one is about 0.5 fps


If that's not awesome, then… I give up. :P/>


JUST LIKE LAST TIME:
To use it, you need CC2D
Download it HERE

Download the 3D demo with this

pastebin get 4r4RVhE9 3d

TO RUN IT:
Make a setup like shown in the demo pictures (maximum size monitor will work fine)


Then run this:

monitor right cc2d 3d


Z to toggle between Perspective and Orthographic





OLD DEMO
SpoilerWell, after seeing NitrogenFingers' 3D demo, I was intrigued. So I set out to find a way I could learn/do it myself.
Here's my attempt


However, unlike nitro's demo, I don't use matrices. Those still make my head hurt. :S

To use it, you need CC2D
Download it HERE

Download the 3D demo with this

pastebin get camy46mt 3d

TO RUN IT:
First make a setup like shown in the picture


Then run this:

monitor right cc2d 3d


Z to toggle between Perspective and Orthographic
Edited on 28 September 2013 - 01:00 PM
TheOutcast5 #2
Posted 27 September 2013 - 07:46 AM
Are we gonna start seeing 3D animations?
je06 #3
Posted 27 September 2013 - 09:11 PM
I'm Speech less…
nitrogenfingers #4
Posted 28 September 2013 - 12:17 AM
Aw, everyone is so down on matrices. I think they're cool…

This is a nice demo. Good stuff :)/>
Xenthera #5
Posted 28 September 2013 - 01:52 AM
Aw, everyone is so down on matrices. I think they're cool…

This is a nice demo. Good stuff :)/>

Thanks a lot! I like matrices too, I just don't understand them when it comes to 3d stuff yet. ;)/>
Tjakka5 #6
Posted 28 September 2013 - 02:42 PM
Wait wha…

Woooooooow.
That is amazing!
je06 #7
Posted 28 September 2013 - 04:06 PM
You should make it into a game engine.
Xenthera #8
Posted 28 September 2013 - 04:11 PM
You should make it into a game engine.

It's not very practical though unfortunately. :(/>
It's more of a tech demo than anything.
billysback #9
Posted 28 September 2013 - 08:59 PM
You should make it into a game engine.
I attempted to make some 3D games using Nitro's 3D test-thing (I know Nitro was planning on using it in a game, but he was going to use it as more of an aesthetic than a gameplay mechanic, as far as I knew, anyway) and the result was, basically, that CC isn't fast enough. Maybe with some extreme optimizing you could get it to render a simple game at an acceptable rate, but use shapes more complex than cuboids and I doubt you'll be able to do much.

The best way to get 3D in CC would probably be using a similar or identical method to Gopher's 3D test, someone has already adapted that in to a game and I had a shot at adding sprite capabilities in to it. (I failed, mainly due to the fact it wasn't my code, so I didn't really understand it properly)…

Either way, what Xenthera said is true, this is awesome (which it is by the way xenthera :P/>) but it can't really be used for anything more than a tech demo, or an aesthetic…

Also, as a suggestion, could you try applying colours to the vertices, then the "stronger" (larger-numbered) colour is drawn when drawing a line between two vertices? I haven't actually looked at the code, so I don't know how hard this would be to implement, or even how you're rendering the models, but it would be cool to get a bit of colour in there, even if you just gave each vertex a random or same colour…
Xenthera #10
Posted 28 September 2013 - 09:53 PM
Also, as a suggestion, could you try applying colours to the vertices, then the "stronger" (larger-numbered) colour is drawn when drawing a line between two vertices? I haven't actually looked at the code, so I don't know how hard this would be to implement, or even how you're rendering the models, but it would be cool to get a bit of colour in there, even if you just gave each vertex a random or same colour…

It wouldn't be hard to implement. It is however more math, which in turn is more of a performance hit.
Lego Stax #11
Posted 29 September 2013 - 04:59 PM
Finally! Someone has done it! One day when I was messing around in Blender, I thought of something like this, but of course, I have no skills with 3D rendering. Anyway, is there a way to turn this into an editor? Possibly like Blender, but in ComputerCraft? Obviously it would be much harder, and it would have no where near the skills of Blender, but it would be epic! It would definitely be a hit on the forums.
Xenthera #12
Posted 29 September 2013 - 06:05 PM
Finally! Someone has done it! One day when I was messing around in Blender, I thought of something like this, but of course, I have no skills with 3D rendering. Anyway, is there a way to turn this into an editor? Possibly like Blender, but in ComputerCraft? Obviously it would be much harder, and it would have no where near the skills of Blender, but it would be epic! It would definitely be a hit on the forums.

That would be an awesome idea.. I'll think about how I can do it and have a shot at it.