Invisible Entities

Blitz3D Forums/Blitz3D Programming/Invisible Entities

I've decided to make a new thread on my previous problem, because I had no help with it before. Anyway...

I have a level file, "lvl0.op" and it tells the code to load in all the objects and level data. Here's what it looks like:
0
data\media\levels\articbase2.b3d
15
10
16
1
1
1
createobject
crate
crate1
data\media\models\objects\crate\Crate.3ds
0
9
1
31
1
1
0
0
0
.07
.07
.07
0
0
0
createobject
crate
crate2
data\media\models\objects\crate\Crate.3ds
0
12
1
31
1
0
0
0
0
.07
.07
.07
0
30
0
createobject
crate
crate3
data\media\models\objects\crate\Crate.3ds
0
10
3.1
31
1
0
0
0
0
.07
.07
.07
0
-30
0


When it says "createobject," that tells the code to load in an object. The objects load fine, except for they are completely invisible - I know that because you can see collisions against them.

Below are the "LoadLevel" and "CreateObject" functions:
Function LoadLevel(filepath$)
	
	lvl.level = New level
	file = OpenFile(filepath$)
	lvl\title$ = ReadLine(file)
	lvl\id = ReadLine(file)
	lvl\mesh = LoadMesh(ReadLine(file))
	EntityType lvl\mesh, LEVEL_COL
	camerax = ReadLine(file)
	cameray = ReadLine(file)
	cameraz = ReadLine(file)
	EntityParent w_pistol, camera
	TranslateEntity w_pistol, 1.8, -1.6, 2
	RotateEntity w_pistol, 0, 180, 0
	PositionEntity camera, camerax, cameray, cameraz
	CameraRange camera, .01, 1000
	lvlsx# = ReadLine(file)
	lvlsy# = ReadLine(file)
	lvlsz# = ReadLine(file)
	ScaleEntity lvl\mesh, lvlsx#, lvlsy#, lvlsz#
	
	Repeat
		If Lower(ReadLine$(file))="createobject"
			obj_type$ = ReadLine$(file)
			name$ = ReadLine$(file)
			obj_mesh$ = ReadLine$(file)
			el_dest = ReadLine(file)
			x = ReadLine(file)
			y = ReadLine(file)
			z = ReadLine(file)
			alpha = ReadLine(file)
			shine = ReadLine(file)
			xv = ReadLine(file)
			yv = ReadLine(file)
			zv = ReadLine(file)
			sx = ReadLine(file)
			sy = ReadLine(file)
			sz = ReadLine(file)
			rx = ReadLine(file)
			ry = ReadLine(file)
			rz = ReadLine(file)
			CreateObject(obj_type$, name$, obj_mesh$, el_dest, x, y, z, alpha, shine, xv, yv, zv, sx, sy, sz, rx, ry, rz)
		EndIf
	Until Eof(file)
	CloseFile file
	
	
End Function


Function CreateObject(type_of_object$, name$, filepath$, elevator_destination#=0, x=0, y=0, z=0, alpha#=1.0, shininess#=0.0, xv#=0, yv#=0, zv#=0, scalex#=1, scaley#=1, scalez#=1, rx#=0, ry#=0, rz#=0)
	
	;create object
	newObject.obj = New obj
	
	newObject\obj_type$ = type_of_object$
	newObject\name$ = name$
	newObject\entity = CreateCube()
	newObject\x = x
	newObject\y = y
	newObject\z = z
	newObject\alpha# = alpha#
	newObject\shininess = shininess#
	newObject\x_vel# = xv#
	newObject\y_vel# = yv#
	newObject\z_vel# = zv#
	newObject\el_dest# = elevator_destination#
	
	;build object
	EntityAlpha newObject\entity, newObject\alpha#
	EntityShininess newObject\entity, shininess#
	PositionEntity newObject\entity, newObject\x, newObject\y, newObject\z
	ScaleEntity newObject\entity, scalex#, scaley#, scalez#
	RotateEntity newObject\entity, rx#, ry#, rz#
	
	;assign collisions
	Select newObject\obj_type$
	
		Case "crate"
			EntityType newObject\entity, OBJECT_COL
		Case "car"
			EntityType newObject\entity, VEHICLECOL
		Case "door"
			EntityType newObject\entity, DOOR_COL
		Case "elevator"
			EntityType newObject\entity, LIFT_COL
		Case "computer"
			EntityType newObject\entity, OBJECT_COL
		Case "oil"
			EntityType newObject\entity, OBJECT_COL
		Case "keypad"
			EntityType newObject\entity, OBJECT_COL
		Case "glass"
			EntityType newObject\entity, GLASS_COL
		Case "enemy"
			EntityType newObject\entity, ENEMY_COL
		Case "misc"
			EntityType newObject\entity, OBJECT_COL
			
	End Select 
	
	
End Function 


How would I make the entities visible?

CreateObject(obj_type$, name$, obj_mesh$, el_dest, x, y, z, alpha, shine, xv, yv, zv, sx, sy, sz, rx, ry, rz)
It looks like you forgot a float # on alpha in your function call defining it as an int.

Your symptoms suggest a Alpha problem. One number misplaced in your load could throw off the alpha setting in the object creation. A integer 1 counts as a float 1. so, I would say the alpha is being set to 0.

The alpha level is how transparent an entity is. A value of 1 will mean the entity is opaque. A value of 0 will mean the entity is completely transparent, i.e. invisible. Values between 0 and 1 will cause varying amount of transparency. This is useful for imitating the look of objects such as glass and other translucent materials.

An EntityAlpha value of 0 is especially useful as Blitz3D will not render entities with such a value, but will still involve the entities in collision tests. This is unlike HideEntity, which doesn't involve entities in collisions.

Yes, I understand alpha. ;)

I know it is an alpha problem - but I've gone over the code a bajillion times and it seems as though I've made the alpha "1." I even changed this line:
newObject\alpha# = alpha#

to:
newObject\alpha# = 1

And it still remained invisible.

how about changing this line:
EntityAlpha newObject\entity,1


OK, I got it working - turns out they were scaled SOOOO small I couldn't see them. :P

Sorry for wasting your time!

I'm assuming you've loaded the shapes in the past and they where visible.

Try this code for example. As is, the value of alpha is set to a float and called as an int resulting in 0. Change the value to 1 (in the function call) without the . and it will show sollid. Change the value back to .5 and add # to alpha# in each case and you will see a tranparent cube.
Graphics3D 640,480
SetBuffer BackBuffer()
cam=CreateCamera()
light=CreateLight()
cube=CreateCube()
ScaleEntity cube,2,2,2
cube2=create_the_cube(cube,.5)
;cube2=create_the_cube(cube,1)
While Not KeyHit(1)

PointEntity cam,cube2
RenderWorld
;Text 10,10,"alpha "+ alpha#
;Text 10,30,"alpha# "+alpha# 
Flip 
Wend
End

Function create_the_cube(cube,alpha)
cube2=CopyEntity (cube) 
EntityAlpha cube,alpha
PositionEntity cube,0,0,10
Return cube2 
End Function  


Also, just a suggestion,
everytime you load something and you asign an EntityType to it,
you better add a ResetEntity() command at the end of the loading process,
just to be sure the entity won't collide with anything else when you move
and position it at its default position.

bye!

Eurythmia: Would it still be a problem if I called my collisions AFTER loading the object?

"OK, I got it working - turns out they were scaled SOOOO small I couldn't see them. :P "

Glad to here I'm not the only one to do that.

"Would it still be a problem if I called my collisions AFTER loading the object? "

I don't know for sure, it just happened to me once that the player got fixed inside a room when I loaded and reposition it,... after that day I always have a ResetEntity() command after loading stuff, just in case :)

Paolo.

OK. Thanks.

I'm also having a problem with collisions to the level. For some odd reason, the player goes through the level. I'm pretty sure it is some sort of stupid mistake, but I can't figure it out.

make sure the player is a meter or so above the ground when the game starts. And yes, to prevent collision problems while loading the level meshes enable collision AFTER loading.

OK. Thanks, jfk.