L3D - The Starts of a 3D Lib

Showcase your libraries, tools and other projects that help your fellow love users.
10$man
Citizen
Posts: 77
Joined: Sun Apr 22, 2012 10:40 pm

Re: L3D - The Starts of a 3D Lib

Post by 10$man »

SiENcE wrote:I'm curious about it.
about it... it is what?

Anyhow, I'm trying to add material support for loading .obj files and I can't seem to get Love to read the ambient and diffuse declarations inside the .mtl file.
Here's the code for it in case anyone else can spot the problem before I get it.

Code: Select all

--Make sure to check for mtl file
		if string.sub(RAW_FILE[a], 1, 6) == "mtllib" then
			local RAW_MTL = {}
			for line in love.filesystem.lines(string.sub(RAW_FILE[a], 8)) do
				table.insert(RAW_MTL, line)
			end
			
			--Since there was a material, let's index it
			for c = 1, #RAW_MTL do
				
				--If a new material is being declared
				if string.sub(RAW_MTL[a], 1, 6) == "newmtl" then
					MATER[#MATER+1] = {}
					MATER[#MATER].ID = string.sub(RAW_MTL[a], 8)
				end
				
				if string.sub(RAW_MTL[a], 1, 2) == "Ka" then
					local pointer = string.find(RAW_MTL[a], " ", 4)
					local color1 = string.sub(RAW_MTL[a], 4, pointer - 1)
					newPointer = string.sub(RAW_MTL[a], " ", pointer)
					local color2 = string.sub(RAW_MTL[a], pointer, newPointer - 1)
					pointer = string.sub(RAW_MTL[a], " ", newPointer)
					local color3 = string.sub(RAW_MTL[a], newPointer, pointer - 1)
					MATER[#MATER].AMB = {color1, color2, color3}
				end
				
				if string.sub(RAW_MTL[a], 1, 2) == "Kd" then
					local pointer = string.find(RAW_MTL[a], " ", 4)
					local color1 = string.sub(RAW_MTL[a], 4, pointer - 1)
					newPointer = string.sub(RAW_MTL[a], " ", pointer)
					local color2 = string.sub(RAW_MTL[a], pointer, newPointer - 1)
					pointer = string.sub(RAW_MTL[a], " ", newPointer)
					local color3 = string.sub(RAW_MTL[a], newPointer, pointer - 1)
					MATER[#MATER].DIF = {color1, color2, color3}
				end
			end
		end
		--Done indexing Materials
I know for fact that it does load the file and iterate through all the lines.
I used some creatively placed errors to make sure of that.
It's just not recognizing Ka and Kd inside the material file.

This is how it looks in the .mtl file:

Code: Select all

newmtl Material2
Ka 0.000000 0.000000 0.000000
Kd 1.000000 1.000000 0.000000
Ks 0.330000 0.330000 0.330000
Where Ka is ambient and Kd is diffuse.


Update
Original post updated:
Added - Frustum Culling / Screen clipping :P
Added - Not working material loader
10$man
Citizen
Posts: 77
Joined: Sun Apr 22, 2012 10:40 pm

Re: L3D - The Starts of a 3D Lib

Post by 10$man »

Update
Hello everyone!
I've been hard at work on my .OBJ loader!
Now it supports the use of Materials! (Notice, Materials DOESN'T mean textures)
I've got this working as well as simple frustum culling.
Find it all in the original post!

Haha... Well, turns out materials don't work so well...
There's a severe problem with the order in which materials are drawn
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: L3D - The Starts of a 3D Lib

Post by Nixola »

Could you include a little .love demo with every update?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
10$man
Citizen
Posts: 77
Joined: Sun Apr 22, 2012 10:40 pm

Re: L3D - The Starts of a 3D Lib

Post by 10$man »

Nixola wrote:Could you include a little .love demo with every update?
Uggh... Only because you asked nicely...
Check back in a little bit and there might be one in the OP
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: L3D - The Starts of a 3D Lib

Post by Nixola »

Thanks :ultraglee:
EDIT: It's getting nicer, I think. I like LÖVE 3D libraries ^^
P.S: What's wrong with including a .love? It's only a small file which you already need to have when you tell us there's an update
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
10$man
Citizen
Posts: 77
Joined: Sun Apr 22, 2012 10:40 pm

Re: L3D - The Starts of a 3D Lib

Post by 10$man »

Nixola wrote:Thanks :ultraglee:
EDIT: It's getting nicer, I think. I like LÖVE 3D libraries ^^
P.S: What's wrong with including a .love? It's only a small file which you already need to have when you tell us there's an update
Nicer then what? :P
This is like the first version of the library :P

I would prefer to just upload the library.
It's a bit of a hassle trying to prepare a .love file on my computer.
It's fine though, I'l remember to do that in the future.
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: L3D - The Starts of a 3D Lib

Post by substitute541 »

10$man wrote:
Roland_Yonaba wrote:
substitute541 wrote:LIGHTING IS WORKING PROPERLY! Check the Love2D Wiki page called "Love3D.lua" for more info :D :D :D
First, you should give a link to that wiki page.
Second, consider updating the OP with the newest links.
Third, links on the wiki page (for both the lib and the demo) are not pointing properly where they should. Consider fixing them.
Fourth, why not set a Git/Bitbucket repo, it'll be easy to track your progresses (IMHO).
Fifth, great job.
This topic is about my Library...
That's something for his I guess.

I've come up with how I want to do lighting, but I won't be implementing it until probably... 2 more updates.
I'm working on frustum culling at the moment.
You can use my calculations if you like. It's just simple vector (oh-no) calculus. The concept is this. Find the normal vector of a surface(the one thats pointing straight out of your poly), find the cross product of the 2 vectors that make your poly(specifically, a triangle), find the dot product of the normal vector and the light vector(coordinates), find the magnitude of the normal vector and light vector, and find the angle at which the light is striking in the surface of the poly.
.
.
.
Whew, that's alot.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
10$man
Citizen
Posts: 77
Joined: Sun Apr 22, 2012 10:40 pm

Re: L3D - The Starts of a 3D Lib

Post by 10$man »

substitute541 wrote: You can use my calculations if you like. It's just simple vector (oh-no) calculus. The concept is this. Find the normal vector of a surface(the one thats pointing straight out of your poly), find the cross product of the 2 vectors that make your poly(specifically, a triangle), find the dot product of the normal vector and the light vector(coordinates), find the magnitude of the normal vector and light vector, and find the angle at which the light is striking in the surface of the poly.
.
.
.
Whew, that's alot.
Find the normal vector of a surface(the one thats pointing straight out of your poly), find the cross product of the 2 vectors
What two vectors?
That's only one...
Also, when I load .obj files, I store all the normals and UV coords.
that make your poly(specifically, a triangle)
Again, since I am using .OBJ files, unless the program exports triangles, I often have faces with 4 or 5 sides.


I appreciate your offer to help, but it looks like I'l need to think this one out later.
Also, how did you do lighting effects on the materials of your faces?
Did you just make a darker color for the farther away they are?
Is there any polygonGradient(color1, color2) function? :P
(Or for that matter, any way to set pixels on a loaded bitmap?)
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: L3D - The Starts of a 3D Lib

Post by substitute541 »

10$man wrote:
substitute541 wrote: You can use my calculations if you like. It's just simple vector (oh-no) calculus. The concept is this. Find the normal vector of a surface(the one thats pointing straight out of your poly), find the cross product of the 2 vectors that make your poly(specifically, a triangle), find the dot product of the normal vector and the light vector(coordinates), find the magnitude of the normal vector and light vector, and find the angle at which the light is striking in the surface of the poly.
.
.
.
Whew, that's alot.
Find the normal vector of a surface(the one thats pointing straight out of your poly), find the cross product of the 2 vectors
What two vectors?
That's only one...
Also, when I load .obj files, I store all the normals and UV coords.
that make your poly(specifically, a triangle)
Again, since I am using .OBJ files, unless the program exports triangles, I often have faces with 4 or 5 sides.


I appreciate your offer to help, but it looks like I'l need to think this one out later.
Also, how did you do lighting effects on the materials of your faces?
Did you just make a darker color for the farther away they are?
Is there any polygonGradient(color1, color2) function? :P
(Or for that matter, any way to set pixels on a loaded bitmap?)
... The calculations that I said above...

Edit : Just look at the Light3D code.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
10$man
Citizen
Posts: 77
Joined: Sun Apr 22, 2012 10:40 pm

Re: L3D - The Starts of a 3D Lib

Post by 10$man »

substitute541 wrote:... The calculations that I said above...

Edit : Just look at the Light3D code.
I'l check it out. I'm not promising I'l use it though.


New Example added. Demonstrates the bad .obj loading :death:
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests