3D Model - Fix Clipping?

S

Sypher714

Guest
So I figured out how to setup models finally and how to import them with textures woot!
But I ran into an issue, if i get too close to a wall or anything for example the model clips into the wall. It is probably something very simple I am leaving out, but is it a Layer issue or is it related to d3d_set_hidden?

Thanks in advance for responses.
Syph
 

Attachments

T

Tirous

Guest
You rendering the model in the world, if you dont want it to clip into stuff then you need to draw it last and disable depth testing/writing before you do it, then re-enable them afterwards
 
S

Sypher714

Guest
How would I go about doing that? Are you referring to d3d_start / d3d_end? or Z-Buffer? Was looking at the manual.

obj_gun
current depth - 1000

Draw Event
Code:
if loadmodel
{
if global.character = 4
{
    d3d_transform_set_identity()
    d3d_transform_set_rotation_z(obj_cam.direction - 90)
    d3d_transform_add_translation(obj_cam.x,obj_cam.y,obj_cam.z - 8)
    d3d_model_draw(vmodel2,5-xa-xax/12,-17+ya-yax/12,0.7,background_get_texture(bodgun))
    d3d_transform_set_identity()
}

if global.character = 6
{
    d3d_transform_set_identity()
    d3d_transform_set_rotation_z(obj_cam.direction - 90)
    d3d_transform_add_translation(obj_cam.x,obj_cam.y,obj_cam.z - 9)
    d3d_model_draw(vmodel,3.6-xa-xax/12,-17+ya-yax/12,0.7,background_get_texture(_1911body))
    d3d_transform_set_identity()
}
}
 
Last edited by a moderator:

Micah_DS

Member
I have yet to mess with this, but I believe 'd3d_set_zwriteenable(enable)' is the function you need here.

GM: Studio help said:
This function can be used to toggle on (true) and off (false) depth ordering using the z-buffer in 3D mode. The default value is that z-buffering is enabled.
 
M

Misty

Guest
Not sure that would work, it may make polygons in the model not clip themselves.

I say just draw it to a surface, then draw it in an ortho.
 

Roa

Member
Not sure that would work, it may make polygons in the model not clip themselves.

I say just draw it to a surface, then draw it in an ortho.
Dont ever use ortho. Orthorgraphic project is completely garbage. Its slow slow slow. Its literally like rendering your game twice if used incorrectly.

Use GUI_draw if anything.

You should be able to get away with d3d_set_hidden though.
 
M

Misty

Guest
Whenever I use it, I get no lag with it.

And if he uses d3d_hidden he may see the innards of the gun.
 
S

Sypher714

Guest
Attempts.

1. GUI_Draw
- Gun just shows up about the size of 2x6. Rotates when I do which is normal but it isn't positioned. Instead it is moving as if you made a room with no views, so the gun is showing as if someone had a 2D room trying to draw a model. As the view where the gun is supposed to be at is considered the 2D room being visible as a, surface i guess. Hopefully this response is understood.

2. d3d_set_zwritable.
- No results.

3. d3d_set_hidden
- Either makes all my walls see through if set on the gun object, but if i were to make another object it just makes the gun disappear.
 

Roa

Member
Whenever I use it, I get no lag with it.

And if he uses d3d_hidden he may see the innards of the gun.
I was pretty sure d3d_set_hidden worked on an object basis, and dd_set_zwriteenable worked on a polygon basis?
And yeah, ortho is a 3d perspective, with equal near and far frustum alignment. Its a 3d perspective without the vanishing point and its way way slower than the new GUI_draw event.
 
M

Misty

Guest
Attempts.

1. GUI_Draw
- Gun just shows up about the size of 2x6. Rotates when I do which is normal but it isn't positioned. Instead it is moving as if you made a room with no views, so the gun is showing as if someone had a 2D room trying to draw a model. As the view where the gun is supposed to be at is considered the 2D room being visible as a, surface i guess. Hopefully this response is understood.

2. d3d_set_zwritable.
- No results.

3. d3d_set_hidden
- Either makes all my walls see through if set on the gun object, but if i were to make another object it just makes the gun disappear.
You need to create a second 3d projection with the same attributes as the cam projection, and render that to a surface.

Like
surface_set_target(surf)
d3d_set_projection(x,y,z...
draw_gun_model
surface_reset_target

The in o_ortho,
draw the 2d surface in Draw Gui or d3d_set_projection_ortho
 
  • Like
Reactions: Roa
I

icuurd12b42

Guest
You have to call d3d_set_hidden(false) only with the drawing of your main character.

camera object depth 1000000 draw
d3d_start
set hidden on
set culling on
set projection

player draw, depth 0
set hidden off
draw character
set hidden on
 
S

Sypher714

Guest
You have to call d3d_set_hidden(false) only with the drawing of your main character.

camera object depth 1000000 draw
d3d_start
set hidden on
set culling on
set projection

player draw, depth 0
set hidden off
draw character
set hidden on
The player object is the camera. I still don't understand but I attempted to do the set hidden and such to the Cam, then to gun object after failure from cam attempt. Both resulted in the same problem. all it did was made me see through everything, as everything was drawn inside out. Most the depth in this project is in the negatives except the Cam and Minimap.
 
I

icuurd12b42

Guest
>>The player object is the camera.

And that's what everyone does wrong.

How can your camera be your player, when it (the camera) draws first to set the projection and everything needs to draw with hidden ON before your player and his equipment, which has to draw with hidden off so the his gun is not culled with intersecting facets previously drawn... Player needs to draw last because the game content need to be there!

If you turn off hidden for everything then of course things will all go out of whack. if the first thing you draw is the player and his gun even with hidden off, the rest of the things drawn after will still interfere, hidden on or off.
 
M

Misty

Guest
Right, the player should be linked to the camera, but not the camera...It makes things harder on later in the game, like 3rd person view and spec cam....you should set the camera to the players eyexyz, but not make the camera the same object as the player....

Also I don't think d3d_hidden works on a per_object basis but a per vertex, I am 90 percent sure if you enable it you will see the inside of your gun...
 
S

Sypher714

Guest
>>The player object is the camera.

And that's what everyone does wrong.

How can your camera be your player, when it (the camera) draws first to set the projection and everything needs to draw with hidden ON before your player and his equipment, which has to draw with hidden off so the his gun is not culled with intersecting facets previously drawn... Player needs to draw last because the game content need to be there!

If you turn off hidden for everything then of course things will all go out of whack. if the first thing you draw is the player and his gun even with hidden off, the rest of the things drawn after will still interfere, hidden on or off.
So I did seperate Camera and Player objects. Camera follows player etc. The outcome is the same, everything is drawn in reverse (floors, boxes) but not walls for some reason. Should all the other content be same depth as player? Model still clips.

EDIT: Issue fixed. Nothing that I can see so far is drawn in reverse or is see through. Model is still clipping though.

Right, the player should be linked to the camera, but not the camera...It makes things harder on later in the game, like 3rd person view and spec cam....you should set the camera to the players eyexyz, but not make the camera the same object as the player....

Also I don't think d3d_hidden works on a per_object basis but a per vertex, I am 90 percent sure if you enable it you will see the inside of your gun...
Yes the hidden I recall making my gun draw inside out looking wonky. But that problem does not occur anymore with separate Cam & Player object.
 

Attachments

Last edited by a moderator:
M

Misty

Guest
Show us your code please.

We need the gun code, the wall code, and the camera code...And we also need the depth of the gun, wall, and camera.


And be more specific when you say clips. Do you mean it goes through walls, or the back of the gun is clipped out by the znear?
 
S

Sypher714

Guest
Show us your code please.

We need the gun code, the wall code, and the camera code...And we also need the depth of the gun, wall, and camera.


And be more specific when you say clips. Do you mean it goes through walls, or the back of the gun is clipped out by the znear?
The clipping is how it shows in the very first post.


Objects. NOTE: I will only be posting one of the wall objects since there is multiple, but they all run same code, same depth but different XYZ values. And anything referring to obj_cam is referring to Player Object, I just have not renamed it yet. So in any of the code or object lists, obj_cam is Player. and cam_obj is Camera.


wall_hor (depth = -2)
Code:
[Create Event]
seen = false

[Step Event]
if !collision_line(x, y, obj_player.x, obj_player.y, par_wall, false, true)
{
    if (point_distance(x,y,obj_player.x,obj_player.y)<300)
    {
    if !seen
    {
        seen = true
        sprite_index = hor_wall;
    }
    }
}

[Draw]
draw_self() //This is required to show in Minimap
d3d_draw_block(x-16,y-2,0,x+16,y+2,64,background_get_texture(global.walltex),1,1);

draw_set_alpha(1)



gun (depth = -1) -- Model draws in this object.

Code:
[Create]


alarm[7] = room_speed * 1

fire = 0
nearexit = false
alarm[1] = room_speed * 1
showmsg = false
jumpscare = false
fogmin = 0
fogdist = 256

damage_alpha = 0;

//Message Byte
msgbyte = "hello"
msgcolor = c_white

//Sway?
xax = 0
yax = 0
sprangle = 0

xmax = 20
ymax = 20

///Bob?
bob_up = true
bob_speed = 2.5


[Step]
///Reposition Weapon Sprite

if xax > 0
{
    xax = 0
}

if yax > 0
{
    yax = 0
}

if xax < -10
{
    xax = -10
}

if yax < -10
{
    yax = -10
}

if xax > 10
{
    xax = 10
}

if yax > 10
{
    yax = 10
}

if damage_alpha > 0
{
    damage_alpha -= 0.04
}


[Draw]
if global.character = 2
{
    d3d_transform_set_identity()
    d3d_transform_set_rotation_z(obj_cam.direction - 90)
    d3d_transform_add_translation(obj_cam.x,obj_cam.y,obj_cam.z - 8)
    d3d_model_draw(axemdl,3.6,-17,0.7,background_get_texture(_axebody))
    d3d_transform_set_identity()
}

if global.character = 4
{
    d3d_transform_set_identity()
    d3d_transform_set_rotation_z(obj_cam.direction - 90)
    d3d_transform_add_translation(obj_cam.x,obj_cam.y,obj_cam.z - 8)
    d3d_model_draw(vmodel2,5-xa-gun.xax/12,-17+ya-gun.yax/12,0.7,background_get_texture(bodgun))
    d3d_transform_set_identity()
}

if global.character = 6
{
    d3d_transform_set_identity()
    d3d_transform_set_rotation_z(obj_cam.direction - 90)
    d3d_transform_add_translation(obj_cam.x,obj_cam.y,obj_cam.z - 9)
    d3d_model_draw(vmodel,3.6-xa-gun.xax/12,-17+ya-gun.yax/12,0.7,background_get_texture(_1911body))
    d3d_transform_set_identity()


[Draw GUI]
  d3d_set_projection_ortho(xax,yax,1280,800,sprangle);  //I use this first to apply Weapon Sway / Bobbing to the 2D image. applies to Model since it uses the variables.
  d3d_set_fog(0,0,0,0);
  d3d_set_lighting(false)
  d3d_set_hidden(false);
  //Set Damage Effect First
  draw_set_alpha(damage_alpha);
  draw_sprite(hud_hurt,-1,0,0);
  draw_set_alpha(1);
  draw_sprite(global.wep_spr,fire,0,0);   //Draw 2D weapon if Model is not present with Character.

  d3d_set_projection_ortho(0,0,1280,800,0); //Set another projection for HUD. Disables bobbing and sway for HUD elements.
  //Drawing HUD
  draw_sprite(hud_test,global.character,0,0);
  draw_set_blend_mode(bm_add)
  draw_sprite(crosshair,global.cHair,640,400);
  draw_set_blend_mode(bm_normal)
  draw_set_font(font0);
  draw_set_halign(fa_center)
  draw_text(640,10,""+string(global.pscore)+"#X - "+string(xa)+"#Y - "+string(ya))
  if global.multiplier > 1
  {
    draw_text(640,10,"###Multiplier X"+string(global.multiplier))
  }
  //draw level name
  draw_set_color(c_white)
  draw_set_font(font3)
  draw_set_halign(fa_left)
  draw_text(2,24,"Level: "+string(global.levelname));
  //continue regular draw
  draw_set_font(font0)
  draw_set_halign(fa_left)
  draw_text(90,740,""+string(global.player_hp)+"#"+string(global.difficulty))
  draw_text(1150,760,""+string(global.keys))
  draw_text(1150,720,""+string(global.potions))
  //Drawing Scare HUD
  if jumpscare
  {
    draw_sprite(hud_scare,-1,0,0);
  }
  //Drawing Finish HUD
  if global.levelbeat
  {
    draw_sprite(hud_showinfo,-1,0,0);
    draw_set_halign(fa_left)
    draw_text(830,100,"LEVEL COMPLETE##Enemies Remaining: "+string(global.enemycount)+"#Secrets Found: "+string(global.secretsopen)+"/"+string(global.secrets)+"##Get ready!!")
  }
  draw_set_alpha(1);
  //Notifications
  draw_set_halign(fa_center)
  if showmsg
  {
        draw_set_color(c_black);
        draw_text(642,578,""+string(msgbyte))
        draw_set_alpha(0.5);
        draw_set_color(msgcolor);
        draw_text(640,576,""+string(msgbyte))
        draw_set_color(c_white);
        draw_set_alpha(1);
  }
    draw_set_color(c_white);
    d3d_set_hidden(true);
    d3d_set_lighting(true)
    d3d_set_fog(true,c_black,fogmin,fogdist);
[/B]
}


cam_obj
(depth = 1000000)
Code:
[Create]


d3d_start();
d3d_set_hidden(true);
d3d_set_culling(true);

pitch=0;
z = 19

{
  global.camsin = sin(direction*pi/180);
  global.camcos = cos(direction*pi/180);
}


[Step]
///Direction and Pitch (obj_cam is player obj, rename later!)
with(obj_cam)
{
   direction -= (display_mouse_get_x() -display_get_width()/2)/10;
   pitch += (display_mouse_get_y() -display_get_height()/2)/10;
   pitch = max(min(pitch,100),-100);
   display_mouse_set(display_get_width()/2,display_get_height()/2);
}

[Draw]  -- same as Step, not sure if this is correct but cam works.
///The Camera
with (obj_cam)
{
   var xx, yy, r;
   xx = x + cos(direction * pi / 180);
   yy = y - sin(direction * pi / 180);
   r = view_wview[0] / view_hview[0];
   d3d_set_projection_ext(x, y, z, xx, yy, z, 0, 0, 1, 60, r, 1, 16000);
}
d3d_set_hidden(false)
d3d_set_culling(false)
 
Last edited by a moderator:
I

icuurd12b42

Guest
first, you should not call d3d_start and set the setting in the create. this should be in the draw
second, why are you doing with(obj_cam) inside the obj_cam_draw (superfluous)
third, you ARE drawing everything with hidden OFF as your second to last line in you draw clearly states.
 
S

Sypher714

Guest
first, you should not call d3d_start and set the setting in the create. this should be in the draw
second, why are you doing with(obj_cam) inside the obj_cam_draw (superfluous)
third, you ARE drawing everything with hidden OFF as your second to last line in you draw clearly states.
So I noticed, I applied d3d_set_hidden(true) before draw and False after for each of the objects that should project onto screen.

Now, the gun STILL clips if i have the hidden set to true before draw and false AFTER.
But if I don't set any of it into the gun, it does not clip with anything in the world, but it is drawn inside out.

This is somewhat progress to me, just have to figure out the rest now, so curiosity will play a role here since I am still learning at this.
 

Attachments

Last edited by a moderator:
I

icuurd12b42

Guest
when you draw a model with hidden off, the facets in the model that draw last may be overwrite the facets already written. if these are further away the will erase the ones nearer... turn culling on to limit the damage... or sort the facets with a tool like gmmodelfix
 
Top