Trying to upload 3D Mesh/objects

Monkey Forums/Monkey Beginners/Trying to upload 3D Mesh/objects

En929(Posted 2016) [#1]
I was having trouble uploading the 3D "house.obj" that I made in Google Sketchup. But instead of the "house," I get a square instead. Thus, what I'm doing wrong?

Strict
Import mojo
Import minib3d


Class Game Extends App
	
	Field Camera:TCamera
	Field Light:TLight

	Field Started:Bool

       '-----This is the object that I tried to upload------
	Field house: TMesh

	Method OnCreate%()
		SetUpdateRate 30
		Return 0
	End


	Method OnUpdate%()
		If Not Started Then Return 0
		If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error ""
		If KeyDown(KEY_LEFT) Then TurnEntity(Camera, 0, 1, 0)
		If KeyDown(KEY_RIGHT) Then TurnEntity(Camera, 0, -1, 0)
		If KeyDown(KEY_UP) Then MoveEntity(Camera, 0, 0, 0.1)
		If KeyDown(KEY_DOWN) Then MoveEntity(Camera, 0, 0, -0.1)

		UpdateWorld()
		Return 0
	End

	
	Method Init:Void()		
		If Started Then Return
			Started = True	
			Local MovingObjects%=1	
			SetRender()		
		
			Camera = CreateCamera()
			Camera.CameraClsColor(0,0,80)

 '----This "house" object is what I tried to upload. But instead of this object, I got a square--------

			house = LoadMesh("house.obj")
			house.PositionEntity -0.5,-2.5,8
	
			Light=CreateLight(1)
			Light.MoveEntity -10,10,10
			Light.TurnEntity 35,-40,0
	End


	Method OnRender%()
		Init()
		RenderWorld()
		Return 0
	End
End




ratking(Posted 2016) [#2]
You probably have to upload the .obj so someone can have a look at it.


En929(Posted 2016) [#3]
Let's see if this works. Here's the 3D object: https://drive.google.com/file/d/0ByiDhl3zSCYGLWxZTGJIUVV2eXM/view?usp=sharing


taumel(Posted 2016) [#4]
I expected something slightly different, i mean a house, like ceiling and stuff.

Anyway it works (*) but you might want to add triangle defs for the inner walls as well and add vertices once you deal with normals, lighting and so on.

Exporting and importing 3d data (and animations) correctly and efficiently can be a beast of its own.

(*) Autsch, i didn't test in context with your code but my own stuff, sorry about that. Well, at least you know that the model works.


En929(Posted 2016) [#5]
Taumel, when I run the above code, I don't see the house that I made. I only see a cube.


ratking(Posted 2016) [#6]
For me it tells me that loading the file fails, seems like the OBJ loader of miniB3D is broken?

**File not found house.obj



En929(Posted 2016) [#7]
That seems to be the conclusion that I'm coming to Ratking. That's the error I got. I don't know if Mini3D accepts objects. I saw Midimaster's tutorials and while Midimaster uploaded sprites to Mini3D, I never saw any 3D objects with the .obj or .3ds extensions attached to them or at least I don't know how to do it.


ratking(Posted 2016) [#8]
Yeah. Even B3D seems to fail. The only thing that works for me so far are the b3d base64 txt zombie models from the examples of miniB3D.


AdamRedwoods(Posted 2016) [#9]
It's not finding the file. I forget why that happens, but try copying the files manually into the output folder.


ImmutableOctet(SKNG)(Posted 2016) [#10]
Just to confirm, you guys have added "*.obj" to your supported binary files, right?

Something like this:


I'm unsure if MiniB3D automatically does that. Guessing from when it was last updated, I'm going to say it doesn't. Check your output "data" folder to see if the file was copied.


En929(Posted 2016) [#11]
ImmutableOctet(SKNG) and AdamRedwoods, I tried those things and I still get the cube instead of the 3D object I created. Thus, I'm starting to assume that MiniB3D doesn't take .obj extentions.


ImmutableOctet(SKNG)(Posted 2016) [#12]
@En929: Have you tried using "data/house.obj" instead of just "house.obj"?


En929(Posted 2016) [#13]
Yes, I've tried referencing the folder where the object is in writing: "TestPracticeII.data\house.obj" and I've tried: "C:\MonkeyX77a\TestPracticeII.data\house.obj" but it still doesn't work. Have a similar URL? Did it work?


ImmutableOctet(SKNG)(Posted 2016) [#14]
I just ran the example with and without the addition to 'BINARY_FILES'. That fixes it here. It loads the file as intended. For some reason adding "data/" to the path makes it fail, but whatever, it works. You're sure the data folder and main source file have matching names, right? I'm using the version of MiniB3D that's on GitHub. I only added 'Public' to the collision module so it would actually build.



Not sure if Sketchup exported your model correctly, but it loads regardless.

MiniB3D: https://github.com/adamredwoods/minib3d-monkey - As long as you name the module's folder "minib3d", and place it in one of your "modules" folders, it just works.

I even tried a different model, and it loads without an issue. It even told me about the lack of an MTL file.


ratking(Posted 2016) [#15]
Yeah, #BINARY_FILES += "*.obj" works fine for me, too. Didn't know about that.

[EDIT] But funnily I always have to do the building twice. The first time the "data" folder of the HTML5 build gets deleted, nothing appears. Only with the second time everything gets created properly...


En929(Posted 2016) [#16]
Thanks, I finally got it to work. Yay, I can be making 3D web games soon!!! I had to change the code a bit to reference the particular folder that the object was in and change the slashes from this way \ to this way / . But, It seems like the way that I referenced my object now is the long way, but I finally got my house to appear.

Thus, I changed the code section from:

house = LoadMesh("house.obj")

into this:

house = LoadMesh("C:/MonkeyX77a/modules/minib3d/TestPracticeII.data/house.obj")


Thus the second one worked and it seems like the ONLY way that worked, and the second one even included the "brick.jpg" texture that I forgot to include in this internet link:

"https://drive.google.com/file/d/0ByiDhl3zSCYGLWxZTGJIUVV2eXM/view?usp=sharing"


But, I think there shoud be a better and shorter way of referencing the folder instead of the long code the I made. Does anybody know?



Strict
Import mojo
Import minib3d


Class Game Extends App
	
	Field Camera:TCamera
	Field Light:TLight

	Field Started:Bool
	
	'I need help here
	Field house: TMesh

	Method OnCreate%()
		SetUpdateRate 30
		Return 0
	End


	Method OnUpdate%()
	
		If Not Started Then Return 0
		If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error ""
		If KeyDown(KEY_LEFT) Then TurnEntity(Camera, 0, 1, 0)
		If KeyDown(KEY_RIGHT) Then TurnEntity(Camera, 0, -1, 0)
		If KeyDown(KEY_UP) Then MoveEntity(Camera, 0, 0, 0.1)
		If KeyDown(KEY_DOWN) Then MoveEntity(Camera, 0, 0, -0.1)


		UpdateWorld()
		Return 0
	End

	
	Method Init:Void()		
		If Started Then Return
			Started = True	
			Local MovingObjects%=1	
			SetRender()		
			
			Light=CreateLight(1)
			Light.MoveEntity -10,10,10
			Light.TurnEntity 35,-40,0
		
			Camera = CreateCamera()
			Camera.CameraClsColor(0,0,80)

'----this is what I changed the code to, but it seems long and wrong.-----
			house = LoadMesh("C:/MonkeyX77a/modules/minib3d/TestPracticeII.data/house.obj")
			house.PositionEntity -0.5,-2.5,8
	

	End


	Method OnRender%()
		Init()
		RenderWorld()
		Return 0
	End
End




Function Main%()
	New Game
	Return 0
End




ratking(Posted 2016) [#17]
Of course that doesn't make sense, because now the project won't work anywhere else than your computer.


En929(Posted 2016) [#18]
Yes, that's what I don't want Ratking. I want it to be able to work on the web and everywhere else. But, so far it's been the only way that it works. I'll keep trying.


Danilo(Posted 2016) [#19]
See Resource Paths in Monkey and try to use "monkey://data/house.obj" or "monkey://internal/house.obj".


En929(Posted 2016) [#20]
I'm sorry that it has been a moment sense I responded (I've been doing graduate work), but it seems like on my computer, the only path that seems to work in getting my "house.obj" to show is when I use the references:

"house = LoadMesh("C:/MonkeyX77a/TestPracticeII.data/house.obj")"

or

"house = LoadMesh("C:/MonkeyX77a/house.obj")"


The above formula are the exact places where the object is on my computer. That is, one is located in a folder called TestPracticeII.data AND the other is located directly inside of the Monkey77a folder (where my source files are located - I know it's crazy).

I even tried using:

1) "monkey://data/house.obj"
2) "monkey://TestPracticeII.data/house.obj"
3)"monkey://internal/house.obj"


But, it seems that in order for me to see the object displayed (at least on my computer), I have to reference the "C:" drive as in ""C:/MonkeyX77a/" in order to see anything.

I'm using the free version of Monkey and I downloaded the Mini3d from: https://github.com/adamredwoods/minib3d-monkey

And the mini3d folder is inside of the "modules" folder. I don't why my mesh is not showing when I don't explicitly reference the C drive.

I will finally ask this: Does the zip file that could be donwloaded from the github link above contain all of the updates? I can say that I only downloaded the Zip file, but I didn't add none of the patches because I assumed that all of the pitches were included inside of the zip file that could be downloaded and I assumed everything would work out of the box. Well, everything has been working out of the box except this. Thus, I truly don't know why I'm not seeing my mesh, but some of you are seeing it without referencing your C drives.


ImmutableOctet(SKNG)(Posted 2016) [#21]
@En929: You should probably try updating your Monkey installation. Judging by your folder name, you're two years out of date, and therefore probably can't add to your 'BINARY_FILES' variable without editing the config file separately or setting the variable manually.

As for MiniB3D, as long as you download using the button on the side, it should be up to date. Sadly, Adam still hasn't patched that one collision file and its improper use of 'Private'. If it's already working for you, you're probably good as it is. Just make sure to update Monkey, and then see if it works.


En929(Posted 2016) [#22]
ImmutableOctet(SKNG), I went back and downloaded the current version of Monkey to see what happens. The version of Monkey that I had surely was outdate. And yes, I got the error that says:

" C:/MonkeyXFree84f/modules/minib3d/tmesh.monkey<29> : Error : Method TColTree.new() is private."

What do I do?

How do I change it to public? Do you know?


ImmutableOctet(SKNG)(Posted 2016) [#23]
@En929: Comment out this line. ("tcoltree.monkey"; 42)


En929(Posted 2016) [#24]
ImmutableOctet(SKNG), I'm sorry it took me a moment to reply. that worked. I got rid of the error with what you said. But, even though I downloaded the newest version of Monkey, I'm still having trouble loading my house.obj without referencing the "C:" drive specifically at first as in:

house = LoadMesh("C:/MonkeyX77a/house.obj")"

instead of:

"monkey://data/house.obj"

or simply putting:

"house.obj"


I don't know why. Everything else seems to be working ok. I could get the sprites just fine by ONLY writing something like

If Not TPixmap.PreLoadPixmap(["tree.png"])
Return
Endif

But, I can't do the same with my .obj files.


ratking(Posted 2016) [#25]
I had the same problem as you, that the .obj file wouldn't get copied to the build directory.

I solved it. I added

#BINARY_FILES += "*.obj"
#BINARY_FILES += "*.mat"
#BINARY_FILES += "*.b3d"


at the top of my main monkey file, and then I deleted my HTML5 build folder and compiled it again completely.

(Don't forget to put your house.obj back into the data folder of your project.)


En929(Posted 2016) [#26]
Ok, here is how I wrote it Ratking. Maybe I didn't put line that you mentioned in the correct spot



Strict
Import mojo
Import minib3d

'I wrote the "#BINARY_FILES"  line here

#BINARY_FILES += "*.obj"
#BINARY_FILES += "*.mat"
#BINARY_FILES += "*.b3d"

Class Game Extends App

	Field Camera:TCamera
	Field Light:TLight

	Field Started:Bool
	
	'I need help here
	Field house: TMesh

	Method OnCreate%()
		SetUpdateRate 30
		Return 0
	End


	Method OnUpdate%()
	
		If Not Started Then Return 0
		If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error ""
		If KeyDown(KEY_LEFT) Then TurnEntity(Camera, 0, 1, 0)
		If KeyDown(KEY_RIGHT) Then TurnEntity(Camera, 0, -1, 0)
		If KeyDown(KEY_UP) Then MoveEntity(Camera, 0, 0, 3)
		If KeyDown(KEY_DOWN) Then MoveEntity(Camera, 0, 0, -3)

		UpdateWorld()
		Return 0
	End

	
	Method Init:Void()		

		If Started Then Return
			Started = True	
			Local MovingObjects%=1	
			SetRender()		
			

		
			Camera = CreateCamera()
			Camera.CameraClsColor(0,0,80)
			Camera.MoveEntity 20,2,10

			house = LoadMesh("monkey://data/house.obj")
			house.PositionEntity -0.5,-2.5,8
			
			Light=CreateLight(1)
			'Light.PositionEntity -0.5,-2.5,8
			Light.MoveEntity -10,10,10
			Light.TurnEntity 35,-40,0
			
	

	End


	Method OnRender%()

		Init()
		RenderWorld()
		Return 0
	End
End




Function Main%()

	New Game
	Return 0
End






ratking(Posted 2016) [#27]
Your code works for me, as long as I have a "house.obj" in the .data folder.




En929(Posted 2016) [#28]
GUESS WHAT!!! I FINALLY got it to work!!! Here's what I did:

1. Yes, I downloaded the lateest version of Monkey i.e., the free version.
2. The file with the source code that I made was called “TestPracticeII.monkey
3. When I got the new version, the data folders to put my objects for example, my Meshes, etc. into, was named “TestPracticeII.datav84”
4. All I did was put all my Sprites and Meshes into the TestPracticeII.datav84 folder and renamed the folder “TestPracticeII.data”
5. It worked. That is, my code above worked with just the procedures that I named above.
6. I found that the objects were inside the TestPracticeII.buildv84 folder that the program itself put together (see my second procedure below)

Mannn, this took me a looooong time to get it to work. I didn’t want to respond until I made sure that I tried everything first. Plus, again I’m in graduate school so thus, I didn’t have a lot of chances to work. In school I'm doing project after project after project after project….

I think another way I could have made my meshes work is:

1. Go into the “TestPracticeII.buildv84” that my program created
2. Go into the “glfw3” folder
3. Go into the “gcc_winnt” folder
4. Go into the “DEBUG” folder
5. Go into the “data” folder
6. Paste my meshes and sprites inside of the data folder

Thus, I hope this post could help someone else if they have the same problem that I have. I’m glad I got it now. The only thing that I wish for now is that the mini3D works with HTML5 games because I like making web games. But, this is a start! Thanks for helping!!!