The saturn ring is a ringGemoetry. It should have shadow in the red zone. Its material is meshStandardMaterial. Here is the code:
const ringTextureLoader = new THREE.TextureLoader();
const ringTexture = ringTextureLoader.load(/assets/${name}.png
);
ringTexture.colorSpace = THREE.SRGBColorSpace;// 不然颜色会泛白
const ringGeometry = new THREE.RingGeometry(innerRadius, outerRadius, 128);
// from THREE.js forum: https://discourse.threejs.org/t/applying-a-texture-to-a-ringgeometry/9990
var pos = ringGeometry.attributes.position;
var v3 = new THREE.Vector3();
var center = (innerRadius + outerRadius) * 0.5;
for (let i = 0; i < pos.count; i++) {
v3.fromBufferAttribute(pos, i);
ringGeometry.attributes.uv.setXY(i, v3.length() < center ? 0 : 1, 1);
}
//
const ringMaterial = new THREE.MeshStandardMaterial({
map: ringTexture,
side: THREE.DoubleSide,
transparent: true
});
const ring = new THREE.Mesh(ringGeometry, ringMaterial);
ring.castShadow = true;
ring.receiveShadow = true;
ring.rotation.x = Math.PI / 3;
return ring;
Is the SphereGeometry
which is acting as the planet Jupiter casting the shadow itself? Example:
Jupiter.castShadow = true;
Yes, it is. And it’s Saturn actually
const createPlanet = (name, radius) => {
const texture = new THREE.TextureLoader().load(/assets/${name}.jpg
);
texture.colorSpace = THREE.SRGBColorSpace;
const geometry = new THREE.SphereGeometry(radius, 64, 64);
//const material = new THREE.MeshBasicMaterial({ map: texture });
const material = new THREE.MeshStandardMaterial({ map: texture });
const mesh = new THREE.Mesh(geometry, material);
mesh.name = name;
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
};
Oh well guess I have to study the planets again. Never mind do you have any sandbox that I can take a look at?
1 Like
I’m a beginner, I don’t know how to do it. But I can give you my source code.
solar.zip (7.1 MB)
You just duplicate your code in this codesandbox.io this way anyone can access and see your code while its up and running.
1 Like
The sandbox you made doesn’t have textures applied on the planets and also I cant seem to find any planet with the stone ring around it.
Try it now, I fixed the problem.
IC the ring around planet Saturn is receiving the shadows but not the shadow of the planet in between. Its only receiving the global shadows. Just have to make the local shadows to have their effect to on the child mesh
What should I do exactly?
Give me some time and I’ll take a look