Trying to upload 3D Mesh/objects
Monkey Forums/Monkey Beginners/Trying to upload 3D Mesh/objects
| ||
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 |
| ||
You probably have to upload the .obj so someone can have a look at it. |
| ||
Let's see if this works. Here's the 3D object: https://drive.google.com/file/d/0ByiDhl3zSCYGLWxZTGJIUVV2eXM/view?usp=sharing |
| ||
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. |
| ||
Taumel, when I run the above code, I don't see the house that I made. I only see a cube. |
| ||
For me it tells me that loading the file fails, seems like the OBJ loader of miniB3D is broken?**File not found house.obj |
| ||
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. |
| ||
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. |
| ||
It's not finding the file. I forget why that happens, but try copying the files manually into the output folder. |
| ||
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. |
| ||
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. |
| ||
@En929: Have you tried using "data/house.obj" instead of just "house.obj"? |
| ||
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? |
| ||
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. |
| ||
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... |
| ||
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 |
| ||
Of course that doesn't make sense, because now the project won't work anywhere else than your computer. |
| ||
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. |
| ||
See Resource Paths in Monkey and try to use "monkey://data/house.obj" or "monkey://internal/house.obj". |
| ||
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. |
| ||
@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. |
| ||
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? |
| ||
@En929: Comment out this line. ("tcoltree.monkey"; 42) |
| ||
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. |
| ||
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.) |
| ||
Ok, here is how I wrote it Ratking. Maybe I didn't put line that you mentioned in the correct spotStrict 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 |
| ||
Your code works for me, as long as I have a "house.obj" in the .data folder. |
| ||
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!!! |