Important information: this site is currently scheduled to go offline indefinitely by end of the year.

granny engine .gr2 question

Post questions about game models here, or help out others!
mariokart64n
ultra-veteran
ultra-veteran
Posts: 586
Joined: Sun Jun 05, 2005 12:00 pm
Location: Ontario, Canada
Has thanked: 36 times
Been thanked: 243 times

Re: granny engine .gr2 question

Post by mariokart64n »

*BUMP*

I was having a problem getting GR2 files into 3dsmax, and the SMDs wouldnt import into the latest milkshape either. I tried to import the MS files into 3dsmax and some worked, and some didn't. problems were either out of memory, or a total crash of 3dsmax.

I created another script to import the MS files, seems to be easier on resources, as some outputed MS files from GRNReader were 50mb+
I suspect that was the reason behind max crashing. the script I made reads the outputed MS piece by piece, instead of trying to load 50MB into the interpreter at once O_o

Code: Select all

fsource = GetOpenFileName \
caption:"imports gr2.sm files" \
types: "GRN Reader MaxScript Dump(*gr2.ms)|*.MS|All files (*.*)|*.*|"
if (fsource!=undefined) AND ((doesFileExist fsource)==true) then(
f = fopen fsource "rb"
fext=           getFilenameType fsource
fpath=          getFilenamePath fsource
fbatch=         getFiles (fpath+"*"+fext)
fname=  getFilenameFile fsource
fsize=          getFileSize fsource
st = timestamp() --get start time in milliseconds
clearlistener()
openLog (fpath+fname+"_log.txt") mode:"w" outputOnly:true
print (fname+fext+"\n"+localTime+"\n")
--===========================================================================
undo off(

fn ReadFixedString bstream fixedLen =
(
	local str = ""
	strON=true
	floatnum=false
	for i = 1 to fixedLen do	(
		if strON==true do(
		str0=ReadByte bstream #unsigned
		if str0==0x2E do floatnum=true
		if str0==0x0D do (fseek bstream 1 #seek_cur)
-- 		if str0==0x2C do (fseek bstream -1 #seek_cur)
		if str0==0x5D do (fseek bstream -1 #seek_cur)
		if str0==0x5B do str0=0
		if str0==0x20 OR str0==0x0D OR str0==0x2C OR str0==0x5D
		then strON=false
		else str += bit.intAsChar str0
	))
	if floatnum==true then (str as float) else (str as integer)
)
with redraw off (
	
offsetArray=#()
	
do (
byte1 = readbyte f#unsigned
if (byte1==0x66) then(
byte2 = readbyte f#unsigned
if (byte2==0x6E) then(
byte3 = readbyte f#unsigned
if (byte3==0x20) then(
byte4 = readbyte f#unsigned
if (byte4==0x63) then(
byte5 = readbyte f#unsigned
if (byte5==0x72) then(
byte6 = readbyte f#unsigned
if (byte6==0x65) then(
byte7 = readbyte f#unsigned
if (byte7==0x61) then(
byte8 = readbyte f#unsigned
if (byte8==0x74) then(
append offsetArray (ftell f+27)
skip=false
))))))))) while (ftell f)!=fsize

for x =1 to offsetArray.count do(
vertArray=#()
faceArray=#()
uvwArray=#()
	
fseek f offsetArray[x] #seek_set
vertCount=readFixedString f 8
fseek f 0x09 #seek_cur
faceCount=readFixedString f 8
fseek f 18 #seek_cur
vertCount=readFixedString f 8
fseek f 19 #seek_cur
for y = 1 to vertCount do(
fseek f 13 #seek_cur
idx=readFixedString f 8;fseek f 1 #seek_cur
vx=(readFixedString f 10)*100
vy=(readFixedString f 10)*100
vz=(readFixedString f 10)*100
fseek f 18 #seek_cur
idx=readFixedString f 8;fseek f 1 #seek_cur
tu=readFixedString f 10
tv=readFixedString f 10
tw=readFixedString f 10
fseek f 18 #seek_cur
idx=readFixedString f 8;fseek f 1 #seek_cur
nx=readFixedString f 10
ny=readFixedString f 10
nz=readFixedString f 10
append vertArray[vx,vz,vy]
append uvwArray[tu,tv,tw]
fseek f 3 #seek_cur
	)
for y = 1 to faceCount do(
fseek f 13 #seek_cur
idx=readFixedString f 8;fseek f 1 #seek_cur
fa=readFixedString f 8
fb=readFixedString f 8
fc=readFixedString f 8
append faceArray[fc,fb,fa]
fseek f 3 #seek_cur
)
msh = mesh vertices:vertArray faces:faceArray
msh.numTVerts = vertArray.count
buildTVFaces msh
for j = 1 to vertArray.count     do setTVert  msh j uvwArray[j]
for j = 1 to faceArray.count   do setTVFace msh j faceArray[j]
)


--===========================================================================
Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))
gc()
fclose f
flushLog()
closeLog()
enableSceneRedraw()
Print ("Done! ("+((((timestamp())-st)/60)as string)+" Seconds)") --print time to finish
))) else (Print "Aborted.")
Maxscript and other finished work I've done can be found on my DeviantArt account
User avatar
Tosyk
double-veteran
double-veteran
Posts: 1027
Joined: Thu Oct 22, 2009 10:24 am
Location: Russia, Siberia
Has thanked: 269 times
Been thanked: 154 times
Contact:

Re: granny engine .gr2 question

Post by Tosyk »

mariokart64n wrote:*BUMP*

I was having a problem getting GR2 files into 3dsmax, and the SMDs wouldnt import into the latest milkshape either. I tried to import the MS files into 3dsmax and some worked, and some didn't. problems were either out of memory, or a total crash of 3dsmax.

I created another script to import the MS files, seems to be easier on resources, as some outputed MS files from GRNReader were 50mb+
I suspect that was the reason behind max crashing. the script I made reads the outputed MS piece by piece, instead of trying to load 50MB into the interpreter at once O_o
How to get *.gr2.ms?
Thank you for all you do here
my blog | my forum
angels85
ultra-n00b
Posts: 6
Joined: Tue Dec 06, 2011 11:22 pm

Re: granny engine .gr2 question

Post by angels85 »

Sorry


I have a BIG problem

i export gr2 file for metin2 game online and the new animation need of oversampling "0 s" but the exporter can be able to only "2,00000 s "

What Could i do? :[

Write me soon
Thanks
User avatar
Tosyk
double-veteran
double-veteran
Posts: 1027
Joined: Thu Oct 22, 2009 10:24 am
Location: Russia, Siberia
Has thanked: 269 times
Been thanked: 154 times
Contact:

Re: granny engine .gr2 question

Post by Tosyk »

just quick note.
i can not use methods in this thread and i found tool for converting gr2 to obj.
test it on Anno 1404 files, works fine
Thank you for all you do here
my blog | my forum
Axolotl
advanced
Posts: 44
Joined: Sun Nov 07, 2010 12:52 am
Has thanked: 5 times

Re: granny engine .gr2 question

Post by Axolotl »

Hi, recently tried to play with Everquest 2 files, here is the information that it uses granny engine.

Inside vpk archives, there are model files with extensions .draw .anim. .skeleton Both Granny1 & Granny2 viewers doesn't understand them as granny files.

So, did someone managed to import or convert these draw/anim files?

Here is the example of files
delium
n00b
Posts: 18
Joined: Mon Jun 14, 2010 11:26 am
Has thanked: 9 times
Been thanked: 3 times

Re: granny engine .gr2 question

Post by delium »

Look at this:

http://eq2.blazlabs.com/

in his eq2 lib is a loader for .draw / .anim files. a while ago i used this to create a model viewer.

VeRenderMesh.cs for draw files
VeAnimation.cs for anim files
VeSkeleton.cs for skel files

also take a look at Eq2Reader.cs because this class reads the "first part" of every file.
Axolotl
advanced
Posts: 44
Joined: Sun Nov 07, 2010 12:52 am
Has thanked: 5 times

Re: granny engine .gr2 question

Post by Axolotl »

Yes, I have seen this site, but i'm not a programmer :( , and the other thing that i'm interesting in possibility to import them in 3d application (3ds max, Blender), not just view them. Or at least to convert them in some format (.dae for example) that can be further loaded to these applications.

And so, if i'm undersstand right, these files are not granny format files?
delium
n00b
Posts: 18
Joined: Mon Jun 14, 2010 11:26 am
Has thanked: 9 times
Been thanked: 3 times

Re: granny engine .gr2 question

Post by delium »

Axolotl wrote:Yes, I have seen this site, but i'm not a programmer :( , and the other thing that i'm interesting in possibility to import them in 3d application (3ds max, Blender), not just view them. Or at least to convert them in some format (.dae for example) that can be further loaded to these applications.

And so, if i'm undersstand right, these files are not granny format files?
well thats not hard.. here is a first screen of my import skript. when it´s ready to use i will release it here.

on screen you can see the mesh of the Dragon Nagafen :)
Image
Axolotl
advanced
Posts: 44
Joined: Sun Nov 07, 2010 12:52 am
Has thanked: 5 times

Re: granny engine .gr2 question

Post by Axolotl »

Oh, that's will be great. Is your script can inmport only static mesh, or it will be support skinning and animation too? :)
angels85
ultra-n00b
Posts: 6
Joined: Tue Dec 06, 2011 11:22 pm

Re: granny engine .gr2 question

Post by angels85 »

Tosyk wrote:just quick note.
i can not use methods in this thread and i found tool for converting gr2 to obj.
test it on Anno 1404 files, works fine

Yes i know =)

I just import model: character + skin and after i apply texture.....but the exporter in gr2 files for new "ANIMATION" is wrong =(

i know that the original export cost 12500 USD o.o and only one Private-server(metin2mester.hu) in the world can be able to export with this proprety (oversampling 0 s).

Would you try to create a tool or modify this exporter, i will be very happy =) ^^

this is the Gr2 model viewer, you can use to see proprety of animation (oversampling -.-" ) xD
Last edited by Mr.Mouse on Sat Feb 23, 2013 11:39 pm, edited 1 time in total.
Reason: malicious links
Axolotl
advanced
Posts: 44
Joined: Sun Nov 07, 2010 12:52 am
Has thanked: 5 times

Re: granny engine .gr2 question

Post by Axolotl »

delium wrote:
Axolotl wrote:Yes, I have seen this site, but i'm not a programmer :( , and the other thing that i'm interesting in possibility to import them in 3d application (3ds max, Blender), not just view them. Or at least to convert them in some format (.dae for example) that can be further loaded to these applications.

And so, if i'm undersstand right, these files are not granny format files?
well thats not hard.. here is a first screen of my import skript. when it´s ready to use i will release it here.

on screen you can see the mesh of the Dragon Nagafen :)
Hi, Delium, is there any progress with the script?
johnwhile
ultra-n00b
Posts: 7
Joined: Tue Nov 29, 2011 7:44 pm

Re: granny engine .gr2 question

Post by johnwhile »

HI, i ask here because in whole internet I didn't find someone who know something about granny2 engine.
In a game the animation of model are stored as .Raw format of .Gr2 format, i made a little test to convert gr2 into raw with granny2.dll, i compipled this code in cpp and c:
http://dl.dropbox.com/u/47659776/scambi ... %2B%2B.zip

I downloaded from internet the granny sdk to understand something more and to get the header granny2.h. There are write that raw format is a simple decompressed gr2 format for slow pc or to customize their own game but not more... I know that .anim format contain only animation, the 3d mesh are stored in another format (that i already know). I know very well 3dstudio maxscript so isn't a problem import it or also use a c# dll into maxscript.

I read , but i don't undestand now extract and reimport these animation data.

Can someone help me please ? I don't know which way to turn :urg:
BigRegOne
ultra-n00b
Posts: 1
Joined: Fri May 18, 2012 9:32 am

Re: granny engine .gr2 question

Post by BigRegOne »

Image HI

Here is a link to a topic where an importer / exporter for. GR2 used in Silent Hunter 5 (exports in. OBJ) it is not finished yet, but already very promising : http://www.subsim.com/radioroom/showthread.php?t=188290
johnwhile
ultra-n00b
Posts: 7
Joined: Tue Nov 29, 2011 7:44 pm

Re: granny engine .gr2 question

Post by johnwhile »

very good work, but can we have a source code purely related to gr2 dll functions to understand also for other works ? :wink:
User avatar
Pesmontis
beginner
Posts: 33
Joined: Sun Jun 20, 2010 5:10 pm
Location: The Netherlands
Been thanked: 9 times
Contact:

Re: granny engine .gr2 question

Post by Pesmontis »

I've been doing quite a bit of work on extracting models and animations from GR2 files. For instance, I've updated code from grnreader, to work with granny2.dll v2.7.0.28, and I've combined grnreader code with code from NWN2Utils v2.0.1 (the source of the Expotron plugin).

For one specific game, I've tested many kinds of 'granny_curve_data' structures, to be able to extract animations properly.
My code includes new definitions for functions like '_GrannyCurveGetDataTypeDefinition', '_GrannyEvaluateCurveAtT', '_GrannyCurveGetDataTypeDefinition', '_GrannyCurveGetKnotCount', '_GrannyCurveExtractKnotValue', '_GrannyCurveExtractKnotValues'.
I've also implemented 'GrannyGetModelInitialPlacement4x4'.

Here's a listing of newly implemented functions (compare grnreader source):

Code: Select all

// Sept.02, 2010: The animations don't have the parameter TrackGroups_count;
//                 I assume this is equal to one in case the parameter is missing,
//                OR the function 'GrannyFindTrackGroupForModel' should be used (Granny SDK **);
//					( bool GrannyFindTrackGroupForModel( granny_animation const * Animation, char const * ModelName, granny_int32 * TrackGroupIndex ); );
//
//*(void**)&_GrannyFindTrackGroupForModel = GetProcAddress(GrannyDLL, "_GrannyFindTrackGroupForModel@12");
//int (__stdcall *_GrannyFindTrackGroupForModel) (int, int, int);
FUNC(bool, GrannyFindTrackGroupForModel, (t_Animations* anim, char* modelName, int* trackGroupIndex));

//------------------------------//
// Sept.04, 2010 (Granny2 SDK);
//granny_data_type_definition const * GrannyCurveGetDataTypeDefinition( granny_curve2 const * Curve );
FUNC(granny_data_type_definition*, GrannyCurveGetDataTypeDefinition, (granny_curve2* curve));
FUNC(void, GrannyEvaluateCurveAtT, (granny_int32 dimension, bool normalize, bool backwardsLoop, granny_curve2* curve, bool forwardLoop, granny_real32 curveDuration, granny_real32 t, granny_triple resultTriple, granny_triple identityVector));

//------------------------------//
// Added, Sept.24, 2011;
FUNC(granny_real32, GrannyCurveExtractKnotValue, (granny_curve2* curve, granny_int32 knotIndex, granny_real32* controlResult, granny_real32 const* identityVector));
FUNC(void, GrannyCurveExtractKnotValues, (granny_curve2* curve, granny_int32 knotIndexStart, granny_int32 knotCount, granny_real32* knotResults, granny_real32 * controlResults, granny_real32 const* identityVector));

//------------------------------//
// Added Sept.06, 2010;
FUNC(void, GrannyFreeFile, (GrannyFile* pFile));
FUNC(int, GrannyCurveGetKnotCount, (granny_curve2* pCurve));	// SDK: granny_int32x GrannyCurveGetKnotCount(granny_curve2 const * Curve);
//FUNC(int, GrannyCurveGetDimension, (granny_curve2* pCurve));	// SDK: granny_int32x GrannyCurveGetDimension(granny_curve2 const * Curve);

FUNC(bool, GrannyFindBoneByName, (granny_skeleton* skel, char* boneName, granny_int32* boneIndex));

//------------------------------//
// Added Sept.25, 2010;
FUNC(void, GrannyGetModelInitialPlacement4x4, (t_Models* model, granny_real32* placement4x4));
In the code I'm using there are TWO definitions of the struct 'granny_transform', one for animation data and one for model/skeleton/bone data:

Code: Select all

// ONLY USED FOR SKELETON / BONES (*** !!! ***);
struct granny_transform_simple { granny_int32 Type; float v[3]; float q[4]; float m[3][3]; };

Code: Select all

// Sept. 02, 2010 (Granny SDK):	// ONLY USED FOR ANIM.TRANSFORM TRACKS (*** !!! ***);
struct granny_transform
{
    granny_uint32 Flags;
    granny_triple Position;
    granny_quad Orientation;
    granny_triple ScaleShear[3];
};
Post Reply