Raised This Month: $51 Target: $400
 12% 

Detect skybox by trace?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lord Canistra
Senior Member
Join Date: Mar 2009
Location: Tallinn, Estonia
Old 06-30-2013 , 17:37   Detect skybox by trace?
Reply With Quote #1

Hello. I feel like I'm missing something fairly obvious, yet so far, it happens to be impossible to find a single clear solution to this particular task or any mean to detect a material or texture on a surface hit by trace.

What I want to do exactly is to run a trace from some point on a world surface under player's crosshair (no problem till this point) straight up, all the way to the first solid object in its way - and check if it's skybox or anything else.

Here comes the real trouble. I did not find anything inside sourcemod api to grab the name of material or texture, nor any way to fetch output from client console (if I were to somehow make client use mat_crosshair command). Skybox contents do not seem to be any different from general brushes (CONTENTS_SOLID) and this entity doesn't seem to work on tools/toolsskybox texture. Extensive search on forums yielded nothing but few threads on similar topics without resolution.

tl; dr - the ultimate goal is to detect whether some point has sky right above it. Any advice on that?
__________________

Last edited by Lord Canistra; 06-30-2013 at 17:55.
Lord Canistra is offline
necavi
Veteran Member
Join Date: Sep 2010
Old 07-01-2013 , 02:27   Re: Detect skybox by trace?
Reply With Quote #2

http://doc.sourcemod.net/api/index.p...d=show&id=232&
necavi is offline
Lord Canistra
Senior Member
Join Date: Mar 2009
Location: Tallinn, Estonia
Old 07-01-2013 , 03:24   Re: Detect skybox by trace?
Reply With Quote #3

...and? What's that link about?
__________________
Lord Canistra is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 07-01-2013 , 03:42   Re: Detect skybox by trace?
Reply With Quote #4

What if you use TR_GetEndPosition then add some sufficient, arbitrary distance to the up-vector and test it against TR_PointOutsideWorld?
__________________
11530 is offline
Lord Canistra
Senior Member
Join Date: Mar 2009
Location: Tallinn, Estonia
Old 07-01-2013 , 06:17   Re: Detect skybox by trace?
Reply With Quote #5

I had that idea, but the problem is, that "outside" seems to be inside every solid world brush. Or, in other words, in TR_PointOutsideWorld returns true for any point that makes TR_GetPointContents return CONTENTS_SOLID (0x1).

So in other words, I can't tell whether I hit absolute "ceiling" of the map or just some large solid brush, as well as tell whether it's covered in tools/toolsskybox texture (or any other texture which has %compilesky 1 option).
__________________
Lord Canistra is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 07-01-2013 , 14:50   Re: Detect skybox by trace?
Reply With Quote #6

try grabbing m_WorldMaxs (vector) from the world (entity 0) then instead of doing a trace upwards, try a trace from just above the worlds bounding box downwards. grab z coord from m_WorldMaxs and add lets say 100 to it then get the x/y from players crosshair coords and do a trace downwards, it may not work but its just an idea.
blodia is offline
Lord Canistra
Senior Member
Join Date: Mar 2009
Location: Tallinn, Estonia
Old 07-01-2013 , 16:01   Re: Detect skybox by trace?
Reply With Quote #7

It still won't tell me whether surface above is covered in sky material or not (it might as well be conrete ceiling in underground map or any other material). And the reason I'm trying to calculate sky visibility is the kind of effects I want to create - meteorite shower, LOIC ray upon given coordinates, stuff like that.

I tried to detect skybox by spawning projectiles like grenade_launcher_projectile in L4D2 - but to no avail, since "artificial" projectiles do not explode like those fired by weapons - and they do not disappear upon collision with skybox like exploding projectiles do.

In fact I'm just postponing my move onto a radical solution - to parse original .bsp file beforehand, find all planes that use sky material and store them separately for later fast lookup.

But that just... smells like a total overkill. I can do it, even though it will take quite some time. But I really hope that someone, somewhere, at least once thought it'd be nice to let SourceMod programmers to access at least some of BSP data.
__________________

Last edited by Lord Canistra; 07-01-2013 at 16:03.
Lord Canistra is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 07-01-2013 , 21:26   Re: Detect skybox by trace?
Reply With Quote #8

Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>
#include <smlib>

#pragma semicolon 1

public OnPluginStart(){

	RegConsoleCmd("testskybox", OnTest);

}

public Action:OnTest(client, args){

	if(IsLookingAtSkybox(client)){

		PrintToChatAll("Skybox~!");

	}else{

		PrintToChatAll("NOT SKYBOX!");

	}

}

bool:IsLookingAtSkybox(client){

	decl Float:pos[3], Float:ang[3];
	GetClientEyePosition(client, pos);
	GetClientEyeAngles(client, ang);
	TR_TraceRay(pos, ang, MASK_SOLID_BRUSHONLY, RayType_Infinite);
	if(TR_DidHit()){

		if(TR_GetEntityIndex() != 0){

			return false;

		}
		TR_GetEndPosition(pos);
		pos[2] += 100.0;
		ang[0] = -90.0;
		TR_TraceRay(pos, ang, MASK_SOLID_BRUSHONLY, RayType_Infinite);
		if(TR_DidHit()){

			return false;

		}else{

			return true;

		}

	}
	return false;

}
it's a little ugly and messed up. it will only work if it's the top of the skybox which is targeted and its lenght is lesser than 100 units(it can be adjusted). i have even tested it:


edit: decompiling the bsp and getting the planes out of the skybox sounds nicier(is this right? niceer, nicier, nicer, i dunno).
edit2: oh, look who i've found while playing(sucking at) osu:

that's you, isn't that?
__________________
sie sind das essen und wir sind die jäger!

Last edited by Bimbo1; 07-02-2013 at 02:54.
Bimbo1 is offline
Lord Canistra
Senior Member
Join Date: Mar 2009
Location: Tallinn, Estonia
Old 07-03-2013 , 18:14   Re: Detect skybox by trace?
Reply With Quote #9

Sorry, I appreciate you trying to help, but it just doesn't do the trick. Imagine having that sky "ceiling" you point at on the second screenshot covered in some concrete texture - this code will output the same result.

This task seems to be impossible to complete off the bat with SM API or existing extensions, so I just moved on to writing small VBSP analyzer to fetch required data from .bsp files - just like you said, it is way "nicer", even though it's a heavy artillery approach.

Also. Uh. It must be some impostor witch. I suck at Osu so bad I can't survive for half a minute on easy. Why would I put myself on a showcase in that despicable game?!
__________________
Lord Canistra is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 07-03-2013 , 19:06   Re: Detect skybox by trace?
Reply With Quote #10

you are right, that script may fail in several maps in several parts. but, i just found another problem that might make your work way harder(ok, maybe not so much harder) than it should be. there's another texture called player clip, which may makes you trace a ray at skybox with nothing visible on the way and get returned a position of the player clip, and not the skybox. and even after checking if there's an skybox right above the player clip, you would have to create the meteorite shower beneath the player clip(unless you would make it not collidable with the player clip).
maybe creating an extesnsion to get the texture returned from the trace ray is a good idea. i'm not sure if it's possible, though.


haha, that really is a despicable game. it drains too much time in my life.
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode