Page 3 of 6

Re: L3D - The Starts of a 3D Lib

Posted: Wed Oct 17, 2012 8:10 pm
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

Re: L3D - The Starts of a 3D Lib

Posted: Wed Oct 17, 2012 9:21 pm
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

Re: L3D - The Starts of a 3D Lib

Posted: Wed Oct 17, 2012 9:49 pm
by Nixola
Could you include a little .love demo with every update?

Re: L3D - The Starts of a 3D Lib

Posted: Wed Oct 17, 2012 10:19 pm
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

Re: L3D - The Starts of a 3D Lib

Posted: Wed Oct 17, 2012 10:32 pm
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

Re: L3D - The Starts of a 3D Lib

Posted: Thu Oct 18, 2012 12:11 am
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.

Re: L3D - The Starts of a 3D Lib

Posted: Thu Oct 18, 2012 2:10 am
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.

Re: L3D - The Starts of a 3D Lib

Posted: Thu Oct 18, 2012 10:26 am
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?)

Re: L3D - The Starts of a 3D Lib

Posted: Thu Oct 18, 2012 10:32 am
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.

Re: L3D - The Starts of a 3D Lib

Posted: Thu Oct 18, 2012 10:45 am
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: