model viewer, command line use, request to expert

Blitz3D Forums/Blitz3D Programming/model viewer, command line use, request to expert

muddle(Posted 2007) [#1]
This may be useful information to some people. Apologies if it is already well known, I am still fairly new to blitz

I have been frustrated by programs that aim to display 3d models.
They are often slow to use or rely on awkward file selection, or have parameters fixed that I do not like.

I thought it might be better to use the familiar windows explorer to move through directories and just click on any 3d file for a quick view.
A windows programmer suggested the command line would be the way to go, and it turned out that Blitz 'commandline' string holds the full file heirachy and it can ( or should) load the model selected.
EXCEPT THAT ... 2 hours of testing and complete frustration later it finally dawned that ( despite expectation and appearances during tests!) the quotation marks in the command line string were being retained and doubling the quote marks the final 'load mesh' string . Grrr.

The modification of the initial string, as in the simple program included at the end of this post, solved the problem.

The program may also be useful for the way it uses an inertia effect with object rotations.

Feel free to use and add any extra modifiers as desired.

If you wanted to avoid associating x and 3ds files with this sort of program you could perhaps call windows explorer from within a new version and get the command line that way. Perhaps it is best to stay simple, as the point of this was to quickly skip through files.

--------------------------------------------

One problem emerged in viewing models and I would appreciate it if an expert could tell me if there is a way to make 'transparency' in standard 3ds model texture work properly in blitz.
As far as i can tell, a one sided transparent texture appears transparent from that side only. From the other side it appears opaque.
eg. a cockpit canopy is 'see thru' on one side, but what you also see is whatever base colour was used on the other side of the canopy.
You can use a double sided transparent texture, but that simply means you 'see thru' to the base colour even on near faces .. NO transparency.
Transparency in .X file textures work perfectly well with blitz, so it is something of a puzzle.

Any suggestions for a cure?

Cheers David L.
================== basic program follows below =====================


; 'Quickview' .. by David Lawrence june 2007.
; you need to make it into an executable and 'associate' the exe. with X or 3ds files in windows explorer for it to work.

Graphics3D 800, 600, 0, 2

SetBuffer BackBuffer()
cam=CreateCamera ()
light=CreateLight()

TurnEntity light,60,70,0

CameraClsColor cam,100, 105,90 ; background colour
AmbientLight 150,150,150 ; degree of shadow dark

PositionEntity cam, 0,0,0
CameraRange cam, .1,70000
CameraZoom cam, 1.8

init$=CommandLine$()

; to remove quotes
length=Len(init$)
If length =0 Then length =5 ; (to avoid errors when testing non executable)
less = length -1
more=length-2
temp$= Right$(init$,less)
final$=Left$(temp$,more)


model= LoadMesh (final$)
;model= LoadMesh ("modelofyourown.x"); (this line used for non exe testing)

widf#= MeshWidth(model)
hite#= MeshHeight(model)

If (hite*.75) > widf
dist#= hite# *1.7 *-1
Else
dist#= widf*1.7 *-1
EndIf

hold#=dist#

change#=dist#/150
abit#=0
xr#=0:yr#=0:zr#=0:


frameTimer=CreateTimer(40)
.beginloop
;--------------------START LOOP =========================


While Not KeyHit(1)

dist#=dist#+abit#
abit#=abit#*.76
PositionEntity cam, 0,(hite#/2),dist#

zr#=zr#+roll#
roll#=roll#*.8

yr#=yr#+spin#
spin#=spin# *.8
RotateEntity model,xr#,yr#,zr#

RenderWorld

Color 255,255,255
Text 20,5,"Turn model left/right arrow keys"
Text 20,20,"Roll model < > keys"
Text 500, 5, "Zoom IN ... up arrow key "
Text 500, 20, "Zoom OUT .. down arrow key "

Text 20, 580, "RESET TO INITIAL STATE .. R "
Text 500, 580, "toggle wireframe .. space "
Color 255,100,100
Text 20,110,"Triangles.."+TrisRendered()
Text 20, 130, "height ..." + hite#
Text 20,150, "width .. " + widf#

If KeyHit(1) End
If KeyHit(28) End
If KeyDown(200) abit#=abit#-change# ; zoom out on Arrows
If KeyDown(208) abit#=abit#+change# ; zoom in
If KeyDown(203) spin#=spin#+.5 ; turning on arrow L, R
If KeyDown(205) spin#=spin#-.5
If KeyDown(51) roll#=roll#-.5; < roll
If KeyDown(52) roll#=roll#+ .5; >

If KeyDown(19) xr#=0:yr#=0:zr#=0:dist#=hold#:abit#=0:roll#=0


If KeyHit( 57 )=True Then enable=1-enable
WireFrame enable

WaitTimer(frameTimer)
Flip

Wend
; ----------------------------------------- loop end ------------------------------


Filax(Posted 2007) [#2]
Removed... Sorry for the post.


John Blackledge(Posted 2007) [#3]
Nice one, Filax.


muddle(Posted 2007) [#4]
Thanks for the link to your model viewer Filax..
Impressive, and professional looking I must say.

By the way, it warns that it only loads 3ds, X and blitz models. but evidently doesn't recognise the X files, at least not on my computer, refusing to load them..
I am not worried as I will probably stick with my cheap and nasty - but very quick to use - viewer. Perhaps add a few features or mouse control as the urge strikes.

It did occur to me that it would be convenient if your viewer used the size of an object to set view distance ( or scale ) upon loading .
Just a convenience. Oh .. and perhaps have the axes representation toggle with the grid? Small models were a bit overwhelmed.

I'm glad to see that someone else likes a neutral gray for a background ! Perhaps a viewer for wider use could have a preference setting for a few things like that? Perhaps for lighting as well. Some prefer side light, others front or directly above. Perhaps fog as well. etc.

A more ambitious project has occured to me, to make a browser that loads all models in a directory and presents a sort of scaled thumbnail gallery from which you select one to focus on. Slower to initially load, but very quick in skipping from one to another.


Oh well. Thank you again. I am going to assume that no one has an explanation or cure for the lack of standard texture transparency with 3DS files in blitz ???

regards David L.


jfk EO-11110(Posted 2007) [#5]
Muddle, you may use the forum tags "code" for sourcecode. There is a little problem with your viewer, it initializes 3D, then loads the model, doesnīt check if it exists and/or is valid at all. You should do it the other way:

check if the file exists
init 3D scene
load model
check if it is loaded (handle <>0)
...

There is a dll that can be used with userlib decls in Blitz3D, itīs called "bless" and allows to use Dragndrop for the Blitz window:
http://www.blitzbasic.com/Community/posts.php?topic=34205

Draging a file to the icon of a blitz app will give you the file path in the command$, yes, BUT it will be the old-dos name of the file. This may become a problem if you want to save an edited file.

As for the Transparency problem, I never experienced such a problem. Not sure what you are talking about. "Transparency Textures"? There are Alpha Textures and Masked textures.

I wasnīt aware of a 3ds feature that allows to set the alpha flag for a texture. With the B3D format you can set all the flags: Brush alpha, Vertex Alpha, and of course, the texture alpha loading flag. Using Texture alpha I never had any problem with one-side-opaque geometry, as you described. Of course you need to set the brush FX flag 16 so itīs gonna be rendered from both sides.


muddle(Posted 2007) [#6]
Hmm, yes, jfk EO-11110 , it is standard to check for the file etc. and I could have changed to that after the initial experiments .. ( It was necessary to have a screen at first so as to find out what on earth was going on with the strings. )
However, there is no problem with the way it is.
It is opened by a click on a file, and closed imediately after .. then you click another file. It does not have to deal with or survive an error. If the file is faulty, you simply get the usual blitz error .. which is all the info you are going to get anyway without a large amount of file analysing.

I just found it really satisfying that such simple code allowed very quick viewing from windows explorer . The thing could be built up, if someone wanted, into a comprehensive file modifier/viewer to their own taste, but then it would have to have error handling and much more.

About the 'transparency question' . Yes, one can use blitz commands in a program to show specified individual meshes and textures as one requires, it all seems to work correctly. The odd results only occur with models made with 3d modellers which include the settings in the file.. Well, supposedly include.

The modellers which I have been testing for compatibility with Blitz and Dark basic, most commonly use the term ' transparency' . It can be called opacity or translucence. One uses 'alpha' settings rather than transparency. But they all set this 'transparency' in the standard 0 - 1 range as does Blitz for alpha, and the effect is the same. One concludes it is a matter of convention in the naming.

And further testing has shown that it is not just blitz that handles 3ds transparency oddly. Some of the modellers themsleves do not display it upon reload .. AFTER saving the model.
Seems a fairly odd situation. Not easily solvable.

So I give up. For my own program efforts I can use X files, though they are quite large Ascii files on these modellers . Or else use 3ds models broken into groups , with specified settings for alpha (or whatever) applied by program. Then use and blitz parent/child to get the desired final appearance.

Thanks for responses in any case. cheers. David L.


Filax(Posted 2007) [#7]
jfk EO-11110 : It's not to bug users posts with my 'bigger
car' :/ Sorry for the link. I thought give a service for the
blitz user's.

I'm a little bit tired by the forum kids mentality, all that
i make become a fault... sigh... For this reason, i less
often come.


Damien Sturdy(Posted 2007) [#8]
Eh, I think you took that a little hard Filax. your link was clearly useful. :)


TheSin(Posted 2007) [#9]
i also agree with cygnus, i found your link useful.
I also agree with what you just posted too, filax.


jfk EO-11110(Posted 2007) [#10]
Filax don't be a Sissy :) It wasn't a big deal. Of course your tool is useful as all your contributions to the community. And we know about the high quality of your work.

But imagine I'd post a screenshot of my game in your game release thread.


Barnabius(Posted 2007) [#11]
C'mon Filax, don't take it that hard. It's not all of us that think the same. So someone doesn't like your link. So what. The rest of us are quite happy and that particular app you created was very useful for me. I now use it for most of my model viewing needs. It's quick and it does the job very well. Most people on these forums like and appreciate your work.

At least I know I do.

Barney