Minor things worth mentioning

A refuge for those migrating from the fallen DXEditing.com and a place for general discussion relating to Deus Ex editing (coding, mapping, etc).
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

Current implementation of the replacements for the faulty TraceTexture.

Code: Select all

//
// Fixed and extended version of TraceTexture() which also returns
// the Texture hit (Hint: There are Sound properties on Texture).
//
native(3250) final iterator function TraceTextures
(
	Class<Actor> BaseClass,
	out Actor    HitActor,
	out Texture  Texture,
	out Name     TextureName,
	out Name     TextureGroup,
	out int      TextureFlags,
	out Vector   HitLocation,
	out Vector   HitNormal,
	Vector       TraceEnd,
	optional Vector TraceStart,
	optional Vector TraceExtent
);

//
// First Hit variant of TraceTextures.
// (The same as Trace is to TraceActors)
//
native(3251) final function Actor TraceSingleTexture
(
	Class<Actor> BaseClass,
	out Texture  Texture,
	out Name     TextureName,
	out Name     TextureGroup,
	out int      TextureFlags,
	out Vector   HitLocation,
	out Vector   HitNormal,
	Vector       TraceEnd,
	optional Vector TraceStart,
	optional bool bTraceActors,
	optional Vector TraceExtent
);

void AHXActor::execTraceTextures( FFrame& Stack, RESULT_DECL )
{
	guard(AHXActor::execTraceTextures);
	
	P_GET_CLASS(BaseClass);
	P_GET_OBJECT_REF(AActor,Actor);
	P_GET_OBJECT_REF(UTexture,Texture);
	P_GET_NAME_REF(TextureName);
	P_GET_NAME_REF(TextureGroup);
	P_GET_DWORD_REF(TextureFlags);
	P_GET_VECTOR_REF(HitLocation);
	P_GET_VECTOR_REF(HitNormal);
	P_GET_VECTOR(TraceEnd);
	P_GET_VECTOR_OPTX(TraceStart,Location);
	P_GET_VECTOR_OPTX(TraceExtent,FVector(0,0,0));
	P_FINISH;

	FMemMark MemMark( GMem );
	if ( !BaseClass )
		BaseClass = AActor::StaticClass();
	FCheckResult* Res = GetLevel()->MultiLineCheck( GMem, TraceEnd, TraceStart, TraceExtent, 1, Level, 0 );

	PRE_ITERATOR
	{
		if ( Res )
		{
			*Actor				= Res->Actor;
			*HitLocation	= Res->Location;
			*HitNormal		= Res->Normal;

			((UHXLevel*)GetLevel())->FindTexture( Res->Actor, Res->Location, Res->Item, *Texture, *TextureName, *TextureGroup, *TextureFlags );

			Res = Res->GetNext();
		}
		else
		{
			Stack.Code = &Stack.Node->Script( wEndOffset + 1 );
			*Actor        = NULL;
			*Texture      = NULL;
			*TextureName  = NAME_None;
			*TextureGroup = NAME_None;
			*TextureFlags = 0;
			break;
		}
	}
	POST_ITERATOR

	MemMark.Pop();
	unguardexec;
}


void AHXActor::execTraceSingleTexture( FFrame& Stack, RESULT_DECL )
{
	guard(AHXActor::execTraceSingleTexture);
	
	P_GET_CLASS(BaseClass);
	P_GET_OBJECT_REF(UTexture,Texture);
	P_GET_NAME_REF(TextureName);
	P_GET_NAME_REF(TextureGroup);
	P_GET_DWORD_REF(TextureFlags);
	P_GET_VECTOR_REF(HitLocation);
	P_GET_VECTOR_REF(HitNormal);
	P_GET_VECTOR(TraceEnd);
	P_GET_VECTOR_OPTX(TraceStart,Location);
	P_GET_UBOOL_OPTX(bTraceActors,bCollideActors);
	P_GET_VECTOR_OPTX(TraceExtent,FVector(0,0,0));
	P_FINISH;

	FCheckResult Res( 1.0 );
	GetLevel()->SingleLineCheck( Res, this, TraceEnd, TraceStart, bTraceActors ? TRACE_ProjTargets : TRACE_VisBlocking, TraceExtent, 0 );

  *(AActor**)Result = Res.Actor;
	*HitLocation      = Res.Location;
	*HitNormal        = Res.Normal;

	((UHXLevel*)GetLevel())->FindTexture( Res.Actor, Res.Location, Res.Item, *Texture, *TextureName, *TextureGroup, *TextureFlags );

	unguardexec;
}


// Find the FBspNode for Point.
INT UHXModel::FindNode( INT iPlane, FVector Point )
{
	guard(UHXModel::FindNode);

	INT Index = iPlane;

	while ( Index!=INDEX_NONE )
	{
		FBspNode& Node = Nodes(Index);

		if ( Node.iSurf!=INDEX_NONE )
		{
			UBOOL Valid = 1;
			FLOAT OldPlaneDot = 0.0f;

			// Check for NumVertices == 0
			if ( Node.NumVertices )
			{
				for ( INT i = 0; i < Node.NumVertices && Valid; i++ )
				{
					// Get Points.
					FVector& A = Points(Verts(Node.iVertPool + i).pVertex);
					FVector& B = Points(Verts(Node.iVertPool + ((i+1) % Node.NumVertices)).pVertex);

					// Now build a plane.
					FPlane Plane( A, (B-A)^FVector( Node.Plane.X, Node.Plane.Y, Node.Plane.Z ) );

					// Now check Point against this plane.
					FLOAT PlaneDot = Plane.PlaneDot( Point );
					
						// Sign changed, check next FBspNode.
					if ( OldPlaneDot * PlaneDot < 0.0f )
						Valid = 0;
					// Sign stayed the same, everything is fine.
					else
						OldPlaneDot = PlaneDot;
				}
				if ( Valid ) // Passed check.
					return Index;
			}
		}
		Index = Node.iPlane;
	}
	return INDEX_NONE;
	unguard;
}

void UHXLevel::FindTexture( AActor* Actor, FVector Location, INT Item, UTexture*& Texture, FName& TextureName, FName& TextureGroup, DWORD& TextureFlags )
{
	guard(UHXLevel::FindTexture);

	// Reset.
	Texture      = NULL;
	TextureName  = NAME_None;
	TextureGroup = NAME_None;
	TextureFlags = 0;

	// LevelInfo hit.
	if ( Actor && Actor->Level && Actor->Level==Actor )
	{
		Item = ((UHXModel*)Model)->FindNode( Item, Location );

		if ( Item!=INDEX_NONE )
		{
			FBspNode& Node = Model->Nodes(Item);

			if ( Node.iSurf!=INDEX_NONE )
			{
				FBspSurf& Surf = Model->Surfs(Node.iSurf);
				if ( Surf.Texture )
				{
					Texture     = Surf.Texture;
					TextureName = Surf.Texture->GetFName();
					if ( Surf.Texture->GetOuter() && Surf.Texture->GetOuter()->GetOuter() )
						TextureGroup = Surf.Texture->GetOuter()->GetFName();
				}
				TextureFlags = Surf.PolyFlags;
			}
		}
	}
	else if ( Actor && Actor->Brush )
	{
		FBspNode& Node = Actor->Brush->Nodes(Item);
		FBspSurf& Surf = Actor->Brush->Surfs(Node.iSurf);
		if ( Surf.Texture )
		{
			Texture     = Surf.Texture;
			TextureName = Surf.Texture->GetFName();
			if ( Surf.Texture->GetOuter() && Surf.Texture->GetOuter()->GetOuter() )
				TextureGroup = Surf.Texture->GetOuter()->GetFName();
		}
		TextureFlags = Surf.PolyFlags;
	}
	unguard;
}
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

The crash for logging > 1023 characters seems to be first limited by FOutputDeviceFile's usage of too small buffers with unsafe appSprintf(). FOutputDevice::Log()'s do not impose any limitation, but FOutputDevice::Logf()'s do choke on more then 4095 characters. The last thing needs to be addressed by using a safer variant (or limiting wrapper) for FOutputDevice::Logf(). By using a snprintf file approach inside FOutputDeviceFile you can make FOutputDevice::Log()'s always safe to use - even it's usage in already compiled code, though the formated variants keep beeing limited to 4095 chars, but it is at least a significant improvement. You can basically easy pull in your FOutputDeviceFile replacement by using your own Launcher.
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Cybernetic pig
Illuminati
Posts: 2284
Joined: Thu Mar 08, 2012 3:21 am

Re: Minor things worth mentioning

Post by Cybernetic pig »

Hanfling wrote:Current implementation of the replacements for the faulty TraceTexture.
This is in DXHeaders? How would one implement this, by including modified DXheaders in the download?
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

Mh no basically it is rewritten. You would need in any case to compile a native package. Whether to put them in as new functions (having static versions of them is helpful if you need to use it from outside), or one replaces the old TraceTexture in the native tables (thats what I do in Revision). However, keep in mind that the functions above do have an additional out parameter (the texture itsself). So that would need to be removed. I can gather up some resources about native programming for UE1 later.

/edit:
I might make a GameEngine class in which pulls in a few of the things/fixes I have done. Probaly easier to use.
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

How to start a server when compiling:

Code: Select all

//=============================================================================
// Rebuild imports for: CoreTexMisc
//=============================================================================
class CoreTexMiscRes extends Object;

#exec macro ..\CoreTexMisc\Classes\CoreTexMiscRes.uc

/*
RELAUNCH SERVER DXMP_Smuggler -hax0r
*/

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

defaultproperties
{
}
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
User avatar
Bird
NSF
Posts: 86
Joined: Sat Sep 19, 2009 3:24 pm
Location: between your synaptic gap

Re: Minor things worth mentioning

Post by Bird »

Much appreciated!
User avatar
Bogie
UNATCO
Posts: 201
Joined: Fri Jul 10, 2015 1:23 am
Location: Canada

Re: Minor things worth mentioning

Post by Bogie »

I just came across this launcher. I like it!
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

http://coding.hanfling.de/ChequeShot0001.png

That screen looks somewhat interesting. And no, thats not a bug, it was a test for my fallback texture. so i can handle the case if either the texture format/size is not supported or plain unknown gracefully.

Fun fact:
UE seems to store data disguised as mip maps from <4x4 down to 1x1 for DXT1 textures. However, lowest mipmap size for DXT1 is the size of a single block, which is 4x4, so the data is plain garbage.
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

While working on my *.3ds exporter I found a major design flaw in 3ds2unr/3ds2de. Basically it has some vertex aliasing functionality, which might basically be a good idea to safe some storage space, however the way it is implemented is unfit for meshes with more then one animation frame. The more animation frames, the more likely the issue occurs. 3ds2unr basically aliases all vertices out of all animation, but the proper way would be to build an vertex aliasing set for each animation frame and just use the intersection of all the per frame intersection sets to do the aliasing. However this requires a major refactoring of 3ds2unr/de and for now I basically took the functionality out and unless your 3D program writes three vertices per face and does not use shared vertices it is basically not needed or desired at all. So unless your 3D program does this shit on export (which it really should not!) there is no disadvantage.

I also fixed the issue where the documentation states O (the letter) but 3ds2de used 0 (the number) for modulated surfaces. For backward compatibility both O and 0 do work now.

Download:
http://coding.hanfling.de/3ds2de_novertalias.zip

/update
Merge 3ds2unr and 3ds2de source into a single codebase. Compiled binaries and MSVC6 source:
http://coding.hanfling.de/3ds2unr-20160117.zip

Updated source to build with MSVC2013 without binaries:
http://coding.hanfling.de/3ds2unr-20160117-1.zip
Last edited by Hanfling on Sun Jan 17, 2016 1:41 pm, edited 1 time in total.
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

LWO23D surface flags

Post by Hanfling »

Like 3ds2unr/de LWO23D.exe uses a similar system to derive the james mesh triangle type, and hence the polyflags flags for the triangle out of parts of the material name. If the material contains a substring in the form _XY the flags do get added. Here is a list:

Base types, mutally exclusive:
_CL - "Masked", sets PF_TwoSided | PF_Masked.
_DD - "NormalTwoSided", sets PF_TwoSided.
_LU - "Translucent", sets PF_TwoSided | PF_Translucent.
_MD - "Modulate", sets PF_TwoSided | PF_Modulated.
_PH - "Placeholder", sets PF_TwoSided | PF_Invisible (weapon triangle).

Additional FX flags.
_UL - "Unlit", sets PF_Unlit.
_RF - "Environment", sets PF_Environment.
_FL - "Flat", sets PF_Flat.
_NS - "NoSmooth", sets PF_NoSmooth.

Example:
A material name of Embla_CL_UL would make it masked, two sided and unlit (PF_TwoSided | PF_Masked | PF_Unlit).
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

Turns out that the #exec MESH SEQUENCE command never actually performs any sanity checks on whether the indexed animation frames are actually backed up by data. Even worse, there doesn't seem to be any checks for it when rendering, so crashes might or might not occur. Be warned. I figured that out after a few hours cracking my head why DeusExItems.Sword3rd crashes my 3DS exporter without any apparent reason. The 'On' and 'Off' animations (e.g. animation frame with index 1 and 2) are not stored inside the Mesh.
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

There is a bug regarding fatness with mirrors: http://coding.hanfling.de/fatness_mirror_bug.png
Seems to be the same sort of issue like it was for decals not showing up in mirrors (not proper handling of cross product when Frame->Mirror==-1.0f). Though with a bit of browsing through UnMeshRnLod.h it looks like a more severe issue as the normals appear to be flipped in this case, so more then just fatness...
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

So I wrote a commandlet to extract all mip map levels out of a given texture. Seems like buildin BMP exporter is broken for 1x1 and 2x2 size mipmaps and the buildin PCX at least for 1x1.

Image
No a huge suprise that this causes heavy aliasing and moire.
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Minor things worth mentioning

Post by Hanfling »

While working on improving my bitmap font exporter I ended up writing this line:

Code: Select all

guard(HandleTTF);
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Post Reply