Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Niflib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Grant Kim
Niflib
Commits
57908221
Commit
57908221
authored
19 years ago
by
Amorilia
Browse files
Options
Downloads
Patches
Plain Diff
Starting to write code for exporting x*.kf and x*.nif files. (unfinished)
parent
a3bc46bc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
niflib.cpp
+78
-2
78 additions, 2 deletions
niflib.cpp
with
78 additions
and
2 deletions
niflib.cpp
+
78
−
2
View file @
57908221
...
@@ -322,8 +322,8 @@ vector<blk_ref> ReadNifList( string file_name ) {
...
@@ -322,8 +322,8 @@ vector<blk_ref> ReadNifList( string file_name ) {
return
blocks
;
return
blocks
;
}
}
//Writes a valid Nif File given a file name, a pointer to the root block of a file tree
//
Writes a valid Nif File given a file name, a pointer to the root block of a file tree
void
WriteNifTree
(
string
file_name
,
blk_ref
&
root_block
,
unsigned
int
version
)
{
void
Write
Raw
NifTree
(
string
file_name
,
blk_ref
&
root_block
,
unsigned
int
version
)
{
// Walk tree, resetting all block numbers
// Walk tree, resetting all block numbers
//int block_count = ResetBlockNums( 0, root_block );
//int block_count = ResetBlockNums( 0, root_block );
...
@@ -377,6 +377,7 @@ void WriteNifTree( string file_name, blk_ref & root_block, unsigned int version
...
@@ -377,6 +377,7 @@ void WriteNifTree( string file_name, blk_ref & root_block, unsigned int version
//Close file
//Close file
out
.
close
();
out
.
close
();
}
}
void
ReorderNifTree
(
vector
<
blk_ref
>
&
blk_list
,
blk_ref
block
)
{
void
ReorderNifTree
(
vector
<
blk_ref
>
&
blk_list
,
blk_ref
block
)
{
//Get internal interface
//Get internal interface
IBlockInternal
*
bk_intl
=
(
IBlockInternal
*
)
block
->
QueryInterface
(
BlockInternal
);
IBlockInternal
*
bk_intl
=
(
IBlockInternal
*
)
block
->
QueryInterface
(
BlockInternal
);
...
@@ -447,6 +448,81 @@ void BuildUpBindPositions( blk_ref block ) {
...
@@ -447,6 +448,81 @@ void BuildUpBindPositions( blk_ref block ) {
}
}
}
}
// Searches for the first block in the hierarchy of type block_name.
blk_ref
SearchNifTree
(
blk_ref
&
root_block
,
string
block_name
)
{
if
(
root_block
->
GetBlockType
()
==
block_name
)
return
root_block
;
list
<
blk_ref
>
links
=
root_block
->
GetLinks
();
for
(
list
<
blk_ref
>::
iterator
it
=
links
.
begin
();
it
!=
links
.
end
();
++
it
)
{
if
(
it
->
is_null
()
==
false
&&
(
*
it
)
->
GetParent
()
==
root_block
)
{
blk_ref
result
=
SearchNifTree
(
*
it
,
block_name
);
if
(
result
.
is_null
()
==
false
)
return
result
;
};
};
return
blk_ref
();
// return null block
};
// Returns all blocks in the tree of type block_name.
list
<
blk_ref
>
SearchAllNifTree
(
blk_ref
&
root_block
,
string
block_name
)
{
list
<
blk_ref
>
result
;
if
(
root_block
->
GetBlockType
()
==
block_name
)
result
.
push_back
(
root_block
);
list
<
blk_ref
>
links
=
root_block
->
GetLinks
();
for
(
list
<
blk_ref
>::
iterator
it
=
links
.
begin
();
it
!=
links
.
end
();
++
it
)
{
if
(
it
->
is_null
()
==
false
&&
(
*
it
)
->
GetParent
()
==
root_block
)
result
.
merge
(
SearchAllNifTree
(
*
it
,
block_name
)
);
};
return
result
;
};
// Writes valid XNif & XKf Files given a file name, and a pointer to the root block of the Nif file tree.
// (XNif and XKf file blocks are automatically extracted from the Nif tree if there are animation groups.)
void
WriteNifTree
(
string
file_name
,
blk_ref
&
root_block
,
unsigned
int
version
)
{
// Write the full Nif file.
WriteRawNifTree
(
file_name
,
root_block
,
version
);
// Do we have animation groups (a NiTextKeyExtraData block)?
// If so, write out XNif and XKf files.
blk_ref
txtkey_block
=
SearchNifTree
(
root_block
,
"NiTextKeyExtraData"
);
if
(
txtkey_block
.
is_null
()
==
false
)
{
// Create file names for the XKf and XNif files.
int
file_name_dot
=
file_name
.
rfind
(
"."
);
string
file_name_base
;
if
(
file_name_dot
!=
string
::
npos
)
file_name_base
=
file_name
.
substr
(
0
,
file_name_dot
);
else
file_name_base
=
file_name
;
string
xkf_name
=
"x"
+
file_name
+
".kf"
;
string
xnif_name
=
"x"
+
file_name
+
".nif"
;
// Create xkf root header.
blk_ref
xkf_root
=
CreateBlock
(
"NiSequenceStreamHelper"
);
// Link the NiTextKeyExtraData block to it.
xkf_root
[
"Extra Data"
]
=
txtkey_block
;
// Append NiNodes with a NiKeyFrameController as NiStringExtraData blocks.
list
<
blk_ref
>
nodes
=
SearchAllNifTree
(
root_block
,
"NiNode"
);
for
(
list
<
blk_ref
>::
iterator
it
=
nodes
.
begin
();
it
!=
nodes
.
end
();
)
if
(
(
*
it
)
->
GetAttr
(
"Controller"
).
is_null
()
)
it
=
nodes
.
erase
(
it
);
else
++
it
;
blk_ref
last_block
=
txtkey_block
;
for
(
list
<
blk_ref
>::
iterator
it
=
nodes
.
begin
();
it
!=
nodes
.
end
();
++
it
)
{
blk_ref
nodextra
=
CreateBlock
(
"NiStringExtraData"
);
nodextra
[
"String Data"
]
=
(
*
it
)
->
GetAttr
(
"Name"
);
last_block
[
"Next Extra Data"
]
=
nodextra
;
};
// Now add controllers & controller data...
// Now write it out...
//WriteRawNifTree( )
// Now construct the XNif file...
};
}
//Returns the total number of blocks in memory
//Returns the total number of blocks in memory
unsigned
int
BlocksInMemory
()
{
unsigned
int
BlocksInMemory
()
{
return
blocks_in_memory
;
return
blocks_in_memory
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment