Point Cache Reader errors.

Hey guys, I’m new here and was upset about the fact that there is no vertex modeling - so some friendly folks led me to listener’s older post about a Point Cache Reader script that would allow me to use my vertex modeling.

To give a short point of what I’m making, I have a ship (Like the 1800’s style ones), and it has sails. The sails would be difficult at best to bone-animate, and as you know Unity has no native vertex modeling capabilities, so 3DS Max’s wind simulations don’t carry over.

Alright then to the problem…

On listener’s 2nd page, someone modified his script to close the filestream at the end, to avoid the Sharing Violation error. However, I’m using this script on multiple sails and it gives me the sharing violation error. Not sure how to avoid that.

In addition, the single sail that doesn’t have the sharing violation error (being the initial sail) has a different error:

“EndOfStreamException: Failed to read past end of stream.
System.IO.BinaryReader.FillBuffer (Int32 numBytes)
System.IO.BinaryReader.ReadSingle ()
PointCacheReader.ParsePCFile () (at Assets/CacheFile/PointCacheReader.cs:251)
PointCacheReader.Start () (at Assets/CacheFile/PointCacheReader.cs:95)”

I don’t really do coding, I’m more animating and modeling, so I’m not really sure what this means to be honest.

Thanks for your help!

The single sail error looks like you are trying to read more data from the file than it contains. I would guess your pc2 file’s format doesn’t match what the reader is expecting. Is there any way you can find out the exact binary format it is being saved in? If so, you could modify the reader to match.

If you mean the extension, it’s saved in .bytes.

I was instructed to put it in the .bytes format by the creator of the script, so I had the assumption it would work just fine. Perhaps I misread something.

As for the sharing violation, try changing fs.Close() to binReader.Close().

No, not the extension. I mean the actual contents of the binary file. I don’t know how you’re generating the pc2 file, but if there are any differences in order or data type of the bytes from what the reader expects, it’s going to fail. How is it being created?

The error is still popping up - and I just realized I didn’t specify this before…the error indicates this line:

  1. FileStream fs = new FileStream(filePath, FileMode.Open);

Edit @above: I put a modifier on my sails in 3ds Max, and recorded the animation there. From there I exported the animation as .pc2 and imported it to Unity, where I changed it to .bytes.

The binary file contains (when opened) characters that have no meaning to me;

  1. P
  2. Á|ŒÁ¹/ÁÜ

Which repeats a few times then changes to different symbols, then goes back to the line 2 symbols.

That’s odd it should be closing the stream. Well a workaround would be to duplicate your point stream file for each sail so it wouldn’t try accessing the same one twice. Another thing you could try is to wrap the filestream code with using { } instead of doing the close at the end. See msdn for how to use using. Sorry I’m typing on a tablet so copying and pasting is tough.

Ok, I only asked because if you had the file format spec you could make sure the reader is expecting the same data you’re inputting. How about the version of you 3DSMax and your pc2 exporter? Do they match the ones used by the author? I did see a post in that thread mentioning using a new version of the exporter for Max 2013 users.

So, wrap line 179 with { } and take out the closing line?

Otherwise, how would one go about duplicating the file for each sail?

Sorry, I’m terribly ignorant when it comes to scripting.

Edit@above: My 3DS Max is the student license (not trial) 2013 version. As for the pc2 exporter, I only saved the .pc2 file from inside Max and moved it into the Assets file for Unity - I don’t believe I “exported” it persay. Did I miss a step?

Oi I wish I was at a PC.

There is a keyword in c# called using. It will automatically close the stream. See the example near the bottom http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx Try to duplicate that.

using (FileStream fs = new FileStream(filePath, FileMode.Open)) {
   //... insert all code in section...
  fileParsed = true;
}

You can get rid of the fs.Close();

Just make a copy of the pc2 file and give it a different name. Use one on sail 1 and the copy on sail 2. Kind of a waste of memory, but its probably the easiest way if you don’t know C# that well.

As for the export, saving the pc2 is “exporting.” I didn’t realize max could save it without an exporter plugin or something. Anyway, did you see this post
http://forum.unity3d.com/threads/130564-Point-Cache-reader?p=953035&viewfull=1#post953035 It mentions an update for Max2013 users.

Okay the copy pasting worked great for the sharing violations, at least I can do something.

I must have implemented your code wrong, I got this:

Assets/CacheFile/PointCacheReader.cs(267,26): error CS0136: A local variable named fs' cannot be declared in this scope because it would give a different meaning to fs’, which is already used in a `parent’ scope to denote something else

I’m really sorry I’m like a monkey in a new world here. I put that code at the end, replacing fs.Close();

Do I take out the extra “fileParsed = true;” as well? That came right before the fs.Close();

At least I’ll be the most comedic troubleshooting case in your career.

:slight_smile: That’s okay. We’ve all been there. I’ll never try to use a tablet for things involving programming code again, that’s for sure. :stuck_out_tongue: Yay for keyboards!

So do you have the 3DSMax 2013 product update 2? That post mentioned it fixed something with the pc2 file saving. http://www.autodesk.com/3dsmax-updates Did it solve the EndOfStreamException error?

Try this version. It just uses the “using” keyword and adds a little try/catch statement to catch any exceptions and tell you what happened. You’ll have to go back to using the same pc2 file for both sails to test if this works. (This is trying to solve the sharing violation error, not the EndOfStreamException error.)

[code deleted] for the right final code, see this post by listener

You can try this new version I made which no longer uses file streams and a string path. Instead it uses a TextAsset file. So get your FILENAME.bytes file in Unity and drag it onto pointCacheFile and run it. There should no longer be file sharing issues when using the same file. Note: I didn’t test this as I don’t have a mesh and pc2 file to play with.

Also I read in the thread that its very important your model in 3DSMax and in Unity have exactly the same number of verts. You might want to make sure Unity didn’t do any optimization on your mesh. Look at the mesh asset in the inspector and it will tell you how many verts it has.

Edit: Made a tiny code change…

[code deleted] for the right final code, see this post by listener

@Dressman - Make sure you have the updates to 3DS Max mentioned above, they were saving pc2 files with 64 bit ints instead of 32 bit ints in their pc2 files that is fixed with the updates. Also as guavaman says for the script you are using you will need to make sure you have the exact same vertex counts in your max mesh as the unity mesh and that the Unity exporter doesn’t reorder anything such tri order or optimize out any vertices. And if your meshhas an kind fo smoothing groups or fancy uv’s then Unity will change your mesh on import and the point cache script will fail. The script you are using is nice handy free system but it can break very easily.

I still had the EndOfStreamException error, until I used your new code. Now the only thing is the unassigned PointCacheFile, which I assume was the cause for this direction:

This direction kind of confused me; my .bytes file is named “PointCacheFile”, the only other thing I have near that name is the script, named “PointCacheReader”. I don’t have a 3rd asset.

As for this, my sails seem to go by a case-by-case basis. Some of them are exactly the same in vertices, while others have different amounts. Curious.
My run-of-the-mill sails have a steady 20 vertices, in both Max and Unity. However, the more uniquely or complexly shaped ones have many more vertices in Unity than Max. The front sail has 11 verts in Max, with 33 in Unity; while the back sail has the normal 20 vertices in Max but a whopping 78 in Unity. I’m assuming it’s Unity’s automatic importation that changes them so radically based on their various forms.

I’m not exactly sure how to adjust that, but worst case scenario the majority of the sails will move if the script is successful, lol.

Thanks again~

Edit@above: I am currently updating from 1 ~ 5 (apparently I didn’t even have 1 - either that or it gives no error when you try to re-install an update).

As above, I reported my vert count for the models. It’s the same for some, but not for the more complexly-shaped sails. I don’t think they use fancy UVs - they’re pretty basic materials. Certainly not smoothing modifiers.

Thanks for your contribution - I’ll really have to find some time to learn C# so that I can diagnose these things without being a bother.

You’re not getting the EndOfStreamException because my script is quitting before even getting to the processing because you don’t have a .bytes file attached to your monobehaviour. (And it will never give an EndOfStreamException either because I’m not using a stream and I’ve included some exception code that will give you a more meaningful message if you should try to go past the end of the file.)

So here’s how apply the pc2 binary to your sail object:

  • Take the pc2 file you made from max, put it in a folder under Assets in Unity.
  • Rename the pc2 file to something.bytes
  • Open the editor and select your game object that has the PointCacheReader assigned to it.
  • Find your something.bytes in the inspector and drag it onto your sail object in the field labeled “Point Cache File”

I have had problems with uv counts and verts in exported fbx files from Maya as well. It was quite a nightmare trying to map vertex colors to my objects because of the discrepency. I never found a perfect solution. But in your case, check the manual on Mesh importing. Specifically, Mesh Compression, Mesh Optimization, and Normals (import). There may be others. Export your object from 3DSMax, reimport with various settings and see if you can get the verts to match. The animations will never work if the vert counts don’t match perfectly. Also, you could try exporting from 3DS in various other formats compatible with Unity and see if that helps. Also check your options in your FBX exporter and see if you can find any way to disable optimization, etc.

I would also recommend checking your FBX in MeshLab which might tell you whether the vertex optimization is happening in Unity or Max.

Do you have an example fbx and point cache file?

You know what? Discard all that code above it’s wrong. I was going on the assumption that the correct script to start from was on page 2 of the Point Cache Reader thread that you linked to in your first post. Actually that’s the wrong one to use – it’s based on the older version that uses filestreams. Listener already made a version that uses a TextAsset and drag and drop. We were using the wrong script. I loaded it and everything works with a test pc2 and model someone sent me.

Use the code from this post