XNA curve import from Maya? - xna

I am trying to import a movement curve from Maya into my XNA game, but I cannot figure out how. Basically I want to catch the curve by it's name, and look up its values at different points of time.
Are curves exported into FBX at all? And, if not, then how to catch it?
Edit: Maya can export to Maya ASCII, and I tried to parse it, but I am not sure what formula I should use to recreate the curve.
Here is a Maya ASCII segment defining a typical curve:
createNode transform -name "curve1";
createNode nurbsCurve -name "curveShape1" -parent "curve1";
setAttr -keyable off ".visibility";
setAttr ".cached" -type "nurbsCurve"
3 11 0 no 3
16 0 0 0 1 2 3 4 5 6 7 8 9 10 11 11 11
14
-4.9774564508407968 0 -6.8331005825440476
-5.5957526204336077 0 -5.5944567905896161
-6.8323449596191823 0 -3.1171692066807277
-5.6935230034445992 0 3.3047128765440847
-1.6528787527978079 0 8.8676235621397499
7.5595909161095838 0 10.325347443191644
9.2297347448508607 0 8.5586791722955731
10.0730315036276 0 0.93412333819133941
5.9770106513247976 0 3.7809964481624871
2.9006817236214149 0 -3.3327711853359037
11.373191256465434 0 -4.6672854260704906
4.5697574985247682 0 -14.178349348937205
2.4191279569332935 0 -11.415532638650156
1.3438131861375628 0 -10.034124283506653
;
I managed to find the file format reference somewhere, the important info here is the knot indexes (16 0 0 0 1 2 3 4 5 6 7 8 9 10 11 11 11) and the coordinates (all lines containing three numbers).
But, I still have no idea how to recreate the curve. I googled a lot for nurbscurves, bsplines etc, but could not successfully match the result in Maya with any code I could find.

I've achieved this in 3dsmax by exporting the curve in Ascii format and parsing the text manually, does Maya have any such exporter?

Related

Which Feature Selection Techniques for NLP is this represent

I have a dataset that came from NLP for technical documents
my dataset has 60,000 records
There are 30,000 features in the dataset
and the value is the number of repetitions that word/feature appeared
here is a sample of the dataset
RowID Microsoft Internet PCI Laptop Google AWS iPhone Chrome
1 8 2 0 0 5 1 0 0
2 0 1 0 1 1 4 1 0
3 0 0 0 7 1 0 5 0
4 1 0 0 1 6 7 5 0
5 5 1 0 0 5 0 3 1
6 1 5 0 8 0 1 0 0
-------------------------------------------------------------------------
Total 9,470 821 5 107 4,605 719 25 8
Appearance
There are some words that only appeared less than 10 times in the whole dataset
The technique is to select only words/features that appeared in the dataset for more than a certain number (say 100)
what is this technique called? the one that only uses features that in total appeared more than a certain number.
This technique for feature selection is rather trivial so I don't believe it has a particular name beyond something intuitive like "low-frequency feature filtering", "k-occurrence feature filtering" "top k-occurrence feature selection" in the machine learning sense; and "term-frequency filtering" and "rare word removal" in the Natural Language Processing (NLP) sense.
If you'd like to use more sophisticated means of feature selection, I'd recommend looking into the various supervised and unsupervised methods available. Cai et al. [1] provide a comprehensive survey, if you can't access the article, then this page by JavaTPoint covers some of the supervised methods. A quick web search for supervised/unsupervised feature selection also yields many good blogs, most of which make use of the sciPy and sklean Python libraries.
References
[1] Cai, J., Luo, J., Wang, S. and Yang, S., 2018. Feature selection in machine learning: A new perspective. Neurocomputing, 300, pp.70-79.

Calculate Positional Difference based on row for string values for two tables

Table 1:
Position
Team
1
MCI
2
LIV
3
MAN
4
CHE
5
LEI
6
AST
7
BOU
8
BRI
9
NEW
10
TOT
Table 2
Position
Team
1
LIV
2
MAN
3
MCI
4
CHE
5
AST
6
LEI
7
BOU
8
TOT
9
BRI
10
NEW
Output I'm looking for is
Position difference = 10 as that is the total of the positional difference. How can I do this in excel/google sheets? So the positional difference is always a positive even if it goes up or down. Think of it as a league table.
Table 2 New (using formula to find positional difference):
Position
Team
Positional Difference
1
LIV
1
2
MAN
1
3
MCI
2
4
CHE
0
5
AST
1
6
LEI
1
7
BOU
0
8
TOT
2
9
BRI
1
10
NEW
1
Try this:
=IFNA(ABS(INDEX(A:B,MATCH(E2,B:B,0),1)-D2),"-")
Assuming that table 1 is at columns A:B:

The Difference between One Hot Encoding and LabelEncoder?

I am working on a ML problem to predict house prices and Zip Code is one feature which will be useful. I am also trying to use Random Forest Regressor to predict the log of the price.
However, should I use One Hot Encoding or Label Encoder for Zip Code? Because I have about 2000 Zip Codes in my dataset and performing One Hot Encoding will expand the columns significantly.
https://datascience.stackexchange.com/questions/9443/when-to-use-one-hot-encoding-vs-labelencoder-vs-dictvectorizor
To rephrase: does it make sense to use LabelEncoder instead of One Hot Encoding on Zip Codes
Like the link says:
LabelEncoder can turn [dog,cat,dog,mouse,cat] into [1,2,1,3,2], but
then the imposed ordinality means that the average of dog and mouse is
cat. Still there are algorithms like decision trees and random forests
that can work with categorical variables just fine and LabelEncoder
can be used to store values using less disk space.
And yes, you are right, when you have 2000 categories for zip codes, one hot may blow up your feature set massively. In many cases when I had such problems, I opted for binary encoding and it worked out fine most of the times and hence is worth a shot for you perhaps.
Imagine you have 9 features, and you mark them from 1 to 9 and now binary encode them, you will get:
cat 1 - 0 0 0 1
cat 2 - 0 0 1 0
cat 3 - 0 0 1 1
cat 4 - 0 1 0 0
cat 5 - 0 1 0 1
cat 6 - 0 1 1 0
cat 7 - 0 1 1 1
cat 8 - 1 0 0 0
cat 9 - 1 0 0 1
There you go, you overcome the LabelEncoder problem, and you also get 4 feature columns instead of 8 unlike one hot encoding. This is the basic intuition behind Binary Encoder.
**PS:** Give 2 power 11 is 2048 and you have 2000 categories for zipcodes, you can reduce your feature columns to 11 instead of 1999 in the case of one hot encoding!

OpenCV's createsamples tool fails to use all samples when converting info file to vec file

I've created an info text file by using opencv_annotation tool, with around 300 image, and some contain multiple ROIs (Region of Interests). The following is an example output of the file, with dots indicating many lines with the same format:
positives\1\105.png 1 9 10 17 14
...
positives\2\003.png 2 14 2 5 7 11 18 8 9
...
positives\3\045.png 3 21 9 7 9 13 10 9 11 7 15 6 7
However, opencv_annotation then crashes, with the error assertion failed (ssize.area() > 0) ..., and only a fraction (~200 out of ~600) of the ROIs in the info text file were placed into the vec file, verified by how opencv_traincascade reports insufficient samples when using the parameter -numPos 500 when attempting to use the vec file.
Why does this occur, and how can I fix it?
The cause of this is that a ROI that was improperly defined while creating the samples.
In my specific case, this specific line was found:
positives\2\005.png 2 9 6 6 7 0 0 0 0
Recall how the format of these files:
[filename] [# of objects] [[x y width height] [... 2nd object] ...]
In my case, the specified region had a width and length of 0 pixels, which causes opencv_createsamples to crash with the very error. Simply removing the object data and decrementing the [# of objects] by one solved this issue, like so:
positives\2\005.png 1 9 6 6 7
Additionally, one should also look out for values that reach out of bounds, such as the following:
positives\2\005.png 2 9 6 6 7 -5 0 3 2
positives\2\005.png 2 9 6 6 7 30 30 200 300
positives\2\005.png 2 9 6 6 7 35 35 3 5
In the first example, no point should be negative. In the second example, our .png file is only 32 x 32 pixels large, so a ROI cannot have a width and height of 200 and 300, respectively. Finally, in the last example, the x and y positions are out of bounds of our image.

Exporting blender model to iOS and create physics body along the vertices

I am into my first 3D game. I am using blender to create my model, using bullet for physics, and Isgl3D game engine.
So far, I am able to
Create models in blender
Export it to iPhone using Isgl3D libraries and show them.
Create physics bodies along the vertices of this models (for simple
models like cube and sphere.)
Now I want to create some complex irregular models and create physics rigid bodies along the vertices of that model. From my research, I found btTriangleMesh and btBvhTriangleMeshShape which can be used to create complex physics rigid bodies.
I found this thread, where bullet physics bodies are created along the vertices of a model exported from blender using POD importer. But they use btConvexHullShape to create the rigid body, which may not work in my case because my requirement has irregular complex models.
So I was trying to create a btTriangleMesh along the vertices of my model, so that I can create a btBvhTriangleMeshShape to create my rigid body.
So for starters I exported a cube (default blender cube, placed at origin) to understand how the vertices are stored in the Isgl3dMeshNode structure. This is my code
Isgl3dPODImporter * podImporter = [Isgl3dPODImporter
podImporterWithFile:#"simpleCube.pod"];
NSLog(#"number of meshes : %d", podImporter.numberOfMeshes);
[podImporter buildSceneObjects];
[podImporter addMeshesToScene:self.scene];
Isgl3dMeshNode * ground = [podImporter meshNodeWithName:#"Cube"];
btCollisionShape *groundShape = [self getCollisionShapeForNode:ground];
and my getCollisionShapeForNode method is
- (btCollisionShape*) getCollisionShapeForNode: (Isgl3dMeshNode*)node{
int numVertices = node.mesh.numberOfVertices;
NSLog(#"no of vertices : %d", numVertices);
NSLog(#"no of indices : %d", node.mesh.numberOfElements);
unsigned char * indices = node.mesh.indices;
btCollisionShape* collisionShape = nil;
btTriangleMesh* triangleMesh = new btTriangleMesh();
for (int i = 0; i < node.mesh.numberOfElements; i+=3) {
NSLog(#"%d %d %d", indices[i], indices[i+1], indices[i+2]);
}
}
And the NSLog statement prints..
number of meshes : 1
no of vertices : 24
no of indices : 36
and indices printed as
20 0 21
0 22 0
20 0 22
0 23 0
16 0 17
0 18 0
16 0 18
0 19 0
12 0 13
0 14 0
12 0 14
0 15 0
I am not sure I understand how the above given indices (and the vertices it points to) constitute 12 triangles (two in each phase) in the cube. I expect indices to be something like this (given below)
20 21 22 //phase 6
20 22 23
16 17 18 //phase 5
16 18 19
12 13 14 //phase 4
12 14 15
8 9 10 //phase 3
8 10 11
4 5 6 //phase 2
4 6 7
0 1 2 //phase 1
0 2 3
Probably I am missing something obvious. But I am stuck on this for sometime.
Anyone know how indices exported from .POD file differ from normal triangle indices. No way I could make a cube from the indices as it printed right now.
An additional question, Has anyone has an example code that creates triangle mesh to create physics rigid body.

Resources