Jump to content
Search Community

Make three.js object invisible

nofear87 test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I have used the following code to create a mesh object

var defaultPartGeometry = new THREE.BoxGeometry(0.5, 0.5, 0.5);
var defaultPartMaterial = new THREE.MeshBasicMaterial({color: 0xff0000, wireframe: false});
default = new THREE.Mesh(defaultPartGeometry, defaultPartMaterial); 
default.position.set(0,0.25,0); 
scene.add(default)

How can I make this invisible? Setting the opacity for this object to null did not work.

 

I adress the object by its ID and then try to set the opacity (I also have tried to adress the material (object.material))

object = .scene.getObjectByName(ID);
tweens.push(tl.to(object, 2, {opacity: 0}, e.time));

Tween the position is working:

tweens.push(tl.to(object.position, 2, {x: target.X, z: target.Y}, e.time))

Hope you can help.

Link to comment
Share on other sites

nofear87, Like OSUblake advised above have you checked the ThreeJS docs? :

 

http://threejs.org/docs/#Reference/Materials/Material

http://threejs.org/docs/#Reference/Renderers/WebGLRenderer

 

taken form the ThreeJS docs:
 

.opacity

Float in the range of 0.0 - 1.0 indicating how transparent the material is. A value of 0.0 indicates fully transparent, 1.0 is fully opaque. If transparent is not set to true for the material, the material will remain fully opaque and this value will only affect its color.
 
Default is 1.0.
 

 .transparent

Defines whether this material is transparent. This has an effect on rendering as transparent objects need special treatment and are rendered after non-transparent objects. For a working example of this behavior, check the WebGLRenderer code.
When set to true, the extent to which the material is transparent is controlled by setting opacity.
 
Default is false.

 

Also GSAP can tween any javascript numerical object so why not just pass in your ThreeJS material object into GSAP and animate the opacity:

// GSAP parameters for to() method .. takes an object
TweenMax.to(object, duration, properties);

// maybe something like this
yourMeshObject.material.transparent = true;
TweenMax.to(yourMeshObject.material, 1, {opacity: 0});

I haven't tested the above  :blink:  ..but based on the ThreeJS docs you have to set the material transparent flag to true like Blake advised above. And then try to pass the object and property you want animated to GSAP.

 

I hope this helps :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...