Comments (5)
I see. viewer.getScene() method will return a JSC3D.Scene object which is
currently used, or null if nothing is loaded in advance. If you want to load a
model at runtime, then the viewer.replaceSceneFromUrl() method will be very
handy.
You can use mesh.setTexture() to change texture of a mesh. However at most
cases you should encapsulate that in a callback method because loading texture
from the network is an asynchronous task. You can overwrite texture.onready to
achieve this. The following snippet demonstrates how to change texture at
runtime, assuming there is only one mesh in the scene:
// create a new Texture instance
var myTexture = new JSC3D.Texture;
// setup the handler which will be called when texture is ready
myTexture.onready = function() {
// assume a single model has already been loaded
var scene = viewer.getScene();
var myMesh = scene.getChildren()[0];
// set texture to the model
myMesh.setTexture(this);
// notify viewer to deliver a new frame
viewer.update();
}
// begin to load this texture from a given url
myTexture.createFromUrl('.../my_texture_image.jpg');
That's it.
Transparency is already supported at both material and texture level. For
material, the material.transparency property controls the opacity of the
attaching mesh. For texture, If a texture image contains alpha channel, it will
be automatically adopted in the texture (only png supports alpha channel). When
a texture is loaded, the texture.hasTransparency property indicates whether it
is transparent. Both will additively affect the rendering of the attaching mesh.
Please use the svn repository to get the latest code. The one in the download
section is very dated :-)
Original comment by [email protected]
on 15 Oct 2012 at 4:49
from jsc3d.
Thank you for your prompt reply! Sadly, I'm no closer to getting any texture or
material changes in my .obj file.
I've uploaded a stripped back example showing the problem here:
http://www.mindat.org/3d/
I'm sure it's something simple I'm forgetting, but I have tried a lot of
different things :)
Jolyon
Original comment by [email protected]
on 15 Oct 2012 at 8:02
from jsc3d.
Hi, Jolyon:
I took a look into the model file brilliant.obj used in your demo. It seems
that it does not defines any texture coordinate. A mesh should contains texture
coordinates to enable texture mapping. Please refer to this document
http://en.wikipedia.org/wiki/Wavefront_.obj_file for detailed info on obj file
format.
Original comment by [email protected]
on 16 Oct 2012 at 3:27
from jsc3d.
Hi,
I have very similar problem. I believe this issue is due to slow model loading.
It seems like if there were two threads which I thought is not possible with
JavaScript.
However, if the code above is called, the getScene() can really return null.
If I tried to debug the code and the same code worked. The only difference was
stepping every single command. I use Firefox.
Try to use timeout function to load the teture or some button..
Original comment by [email protected]
on 27 Dec 2012 at 10:21
from jsc3d.
I just added this code for delay and setting the texture works fine for me:
setTimeout( function () {
setTexture(viewer,"modules/mod_3dmodelview/demo/test.jpg",true);
},1000);
calling my function setTexture directly resolves in error as the function
getScene() inside the function will return null as the scene is still not
loaded.
Why is it, I do not know. Is there better way to handle that problem?
Original comment by [email protected]
on 27 Dec 2012 at 10:28
from jsc3d.
Related Issues (20)
- model exported from Maya is not showing textures
- Error Generated When Identifying Canvas by Class
- CTM loader not working on IE11 HOT 1
- Transparent texture render ok in canvas but not in webgl HOT 1
- Mesh transformation working ok in canvas but not in webgl HOT 1
- Memory leak?
- texture loading HOT 1
- Product automatic rotation. HOT 1
- How to load 3ds with bmp file as texture? HOT 4
- Get the volume of loaded models
- ghh_slid
- add a image to .obj file
- Problem loading viewerA scene into viewerB scene HOT 1
- multiple viewers sharing scene HOT 1
- Scroll in newer Firefox HOT 1
- Loading .obj file - No image with no error message
- .obj models on usb flashdisk rendered in xulrunner
- Hide/show models with chechbutton (jsc3d)
- how to get a 3d point when you have canvas 2d point?
- suspect CSS syntax change
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsc3d.