threejs load big stl file - three.js

I want to use threejs to display the stl, I read some sample online.
The problem is that my stl files are quite big(binary format: 28mb), it takes too long to load.
Is that possible to load part of stl file and display a basic shape, then to load the rest of file?

Make sure that you working with bufferedgeometry, and take a look at setDraRange, which set limit for drawing vertices, so create some setInteraval where you increase count of items(position, normals) to be produced in Webgl context.

Related

best way to load big model in ThreeJs And how to Release the cache in ThreeJs

question 1:
In My Application I used JsonLoader to load my model about 65MB with .js format, it's takes 10 second . it's too long for us. does any way to load big models? or any better loader or better format?
question 2:
it's about threeJs,In my case, i uesed remove() function to remove model from scene,but the cache doesn't release immediately in browser ,it's takes more than 20 second to be free; how could i do ? this is my code: this.scene.remove(i); i is my model.
JSON is a very heavy format. Try using OBJ or glTF. THREE.js has loaders for each of them in its examples.
Regarding memory release, this is inherent to JavaScript, which uses garbage collection to release memory. (Here's an MDN article on JavaScript memory management.) Just like Java, this happens "once in a while," so you just have to wait for it to happen.
Q1: OpenCTM is also a good compression format, but is, however, limited to single triangle meshes. So, you can't store whole scenes with it. But it is also possible to choose a lossy compression which results in a very high compression rate. There are also examples for three.js: https://threejs.org/examples/#webgl_loader_ctm
Q2:
If you want to really remove your model, you need to call dispose() on the geometry object to remove the object from memory (materials and textures also have a dispose method).
Docs are saying: https://threejs.org/docs/index.html#api/core/BufferGeometry
.dispose ()
Disposes the object from memory.
You need to call this when you want the bufferGeometry removed while the application is running.

CAD secondary development

I got some taught about the CAD secondary development.I use a dll 'Teigha' to analysis the dwg file. But there no have any API can get the CAD drawing's xrefs ,so How to got the drawing's xrefs.
I tried to get the xrefs's path and analysis it as a normal drawing(I save the xrefs data to the main drawing (I think when I finished it and it can become one drawing )) but I got nothing.Why?
Then I found even though I got the all data(main drawing and xrefs) I still cannot get the correct data because the xrefs in the main drawing cant copy paste .I cannot get these change,Only I can got the origin xrefs.
So what can I do ?
In Teigha, you must use the OdDbXrefGraph.getFrom method to obtain the graph of the Xrefs. After that, you can explore the graph in a way similar to this.

Creating a SWC image/file library at runtime using external files

I'm working on a Flash GUI project which has many images need to be dynamically loaded at runtime.
Problem:
Currently everytime a class initializes, it loads its assets (images) from HDD, but that usually takes too long (for example: I have a list of 100 items, each item has the same background, which is a PNG image stored on HDD, but it has to load the image 100 times from HDD to render the list, because the item's class gets to be initialized 100 times). Also, I want assets to be hidden from the users, so I want to pack it up somehow, into a single file.
Solution:
I think of SWC. I heard it's sort of library for Flash. But I have almost no experience on working with SWC. And there are too many images, would take very long to manually import and put class name for each of them in the FLA library. But I already have an XML file which stores the class names and the path to each class' assets. So I can load all the images into a variable, but I don't know how to actually write that variable into a SWC file on HDD to load it later as a library.
[MyButton.png] --load to RAM--> [myButton:Bitmap] --write to SWC file on HDD--> [Assets.swc] --import the SWC file at runtime--> [addChild(assets.myButton)]
The text in bold is the part I'm missing.
Thanks for your time! Any help is greatly appreciated.
SWC is a file that you "precompile" it's pretty much the same as a swf, but really nothing that you "create on the fly". The biggest difference is that a swc is something that is "compiled into" an swf and not loaded dynamically. That is, you can't load a swc-file during runtime, it is provided during compile time.
So, every picture added to the swc will increase its' size, the good thing is that it can be shared between different swf-files.
Now, correct me if I understood you wrong, but it seems like you reload the picture from hard drive whenever that picture is used? So 100 instances of "Ball" which is linked to the picture "Ball.png" would load that file 100 times?
If that is the case, why not just create an ImageManager and let that one keep one instance of the loaded images and then share it among all the instances that uses that image?
AFAIK there is no easy way to do this, however I wrote a blog post (since I couldn't find a better way to give you that solution) if you are interested in an example with caching loaded images.
It's pretty naive and revolves around a static ImageManager, loading only images, caching them by their url-id and then providing a new instance of the bitmapdata if they are allready loaded. However, it works like a charm and it is WAY MORE efficient than always loading the image from hard drive.
You can find the blog post here: http://messer1024.blogspot.se/2012/12/caching-loaded-images-in-as3.html

Directly using typed arrays for attributes in three.js

Is it possible to directly use TypedArrays in three.js for custom attributes? I'm downloading a binary model format from a server, and the data is directly stored into a Float32Array. Since this is the format required by gl.bufferdata, it seems wasteful to create THREE.Vector3 objects, which only get stored back into a new Float32Array inside WebGLRenderer.js.
As a possibly unrelated issue/bug, I've profiled this binary model loading in Chrome and noticed that 60% of the time is spent in the garbage collector. This is seriously bogging down the model loading, since there are over 100k vertices in this model. This only started happening since v49 I believe. Any insight?
You can use BufferGeometry. Sadly we don't have many examples of how to use that one yet. Only CTMLoader is using it at this point. Maybe it can serve as good reference for you?

Best image format for uncompressed textures?

I am in the process of selecting an image format that will be used as the storage format for all in-house textures.
The format will be used as a source format from which compressed textures for different platforms and configurations will be generated, and so needs to cover all possible texture types (2D, cube, volymetric, varying number of mip-maps, floating point pixel formats, etc.) and be completely lossless.
In addition the format has to be able to keep a bit of metadata.
Currently a custom format is used for this, but a commonly available format will be easier to work with for the artists since its viewable in most image editors.
I have thought of using DDS, but this format does not support metadata as far as I can see.
All suggestions appreciated!
With your requirements you should stay with your selfmade format. I don't know about any image-format besides DDS that supports volumetric and cube-textures. Unfortunately DDS does not support meta-data.
The closest thing you can find is TIFF. It does not directly support cube-maps or volumetric textures, but it supports any number of sub-images. That way you could re-use the sub-images as slices or cube-sides.
TIFF also has a very good support for custom meta-data. The libtiff image reading/writing library works pretty good. It looks a bit archaic if you come from a OO side, but it gets it's job done.
Nils
When peeking inside various games' resources I found out that most of them store textures (I don't know whether they're compressed or not) in TGA
TIFF would probably be your closest bet for a format which supports arbitrary meta-data and multiple frames, but I think you are better off keeping the assets (in this case, images) separate from how they are converted and utilized in your engine.
Keep images in 32 bit PNG format, and put type- and meta information in XML. That keeps your data human viewable, readable and editable. Obscure custom formats are for engines, not people.
Stick with whatever your artists work with.
If you are a windows/mac shop and use
photoshop stick with .psd
If you are a unix shop and use gimp
stick with .xcf
These formats will store layers and all the stuff your artists need and are used to.
Since your artists will be creating loads of assets make their life as easy as possible,
even if it means to write some extra code.
Put the meta data (whatever it may be) somewhere "along" the images if the native format (psd/xcf) doesn't support it.
For stuff like cube maps, mipmaps (if not generated by the converter) stick to naming guidlines or guidlines on how to put them into one file.
Depending on what tool you use to create the volumetric stuff, just stick with that tools native format.
While writing custom formats for the target is usually a good idea,
writing custom formats for artists results in mayhem...
My experience with DDS is that it is a poorly documented and difficult format to work with and offers few advantages. It is generally simpler to just store a master file for each image class that has references to the source images that make it up ( i.e. 6 faces for a cube map, an arbitrary number of slices for a volume texture ) as well as any other useful meta-data. It's always going to be a good idea to keep the meta-data in a seperate file ( or in a database ) as you do not want to be loading large numbers of images when carryong out searches, populating browsers, etc. It also makes sense to seperate your source image format ( tiff, tga, jpeg, dds ... ) from your "meta-format" ( cube, volume ... ) since you may well find that you need to use lossy compression to support HDR formats or very large source volume data.
Have you tried PNG? http://java.sun.com/javase/6/docs/api/javax/imageio/metadata/doc-files/png_metadata.html
As an alternative solution, maybe spend some time writing a plugin for a Free Image Editor for your file format? I've never done it before, so I don't know the work involved, but there is boatloads of example code out there for you.

Resources