importing a 3d model from spline to three.js - three.js

I want to know if I can import a 3d model from spline to a three js project. If yes, how can I do it? I want to create a 3d model and include it in three js as a geo

Yes, you can, you can export it as .gltf in spline:
and then import it in three.js like this:
//import the loader from cdn or directly from three package
//import { GLTFLoader } from 'https://unpkg.com/three#0.126.0/examples/js/loaders/GLTFLoader.js'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
// Instantiate it
const gltfLoader = new GLTFLoader()
//Load it
gltfLoader.load(
'path of your model .gltf',
(gltf) =>
{
//add it to the scene
scene.add(gltf.scene.children[0])
}
)

Related

Dynamically change textures in three js for imported gltf model

No matter what I do, I cannot get a texture to update after importing a GLTF model using react-three fiber.
const { nodes, materials } = useGLTF("/glb4.glb");
const newtexture = useLoader(TextureLoader, "texture1.jpg");
newtexture.flipY = false;
Now I can do
let newmaterial = new THREE.MeshPhysicalMaterial({ map: newtexture});
to import it into the scene with
<mesh
geometry={nodes.Body_Front_Node.geometry}
material={newmaterial}
/>
However it results in a grey material without the texture. Even modifying the original gltf material with the new texture gives the same result.
Is there a way to update the texture of a gltf mode dynamically? Here is the full codesandbox: https://codesandbox.io/p/github/Mazzz-zzz/fabrigen/main?file=%2Fsrc%2FApp.js

Can I export a Spline gltf with textures and colors, to a three js scene?

I managed to import a spline object (.gltf) into my three js scene.
However, it does not import any textures, just the geometry.
Is there a way to do this?
gltfLoader.load(
'/models/room-spline.gltf',
(gltf) =>
{
gltf.scene.scale.set(0.025, 0.025, 0.025)
gltf.scene.position.set(0,2,0)
gltf.scene.rotation.set(0,3.5,0)
scene.add(gltf.scene)
}
)
This works for the geometry, but it does not import the textures...

A-Frame: Adding animationClip from another glb to one that has no animation

I have a gltf model without an animation that I've loaded in aframe, and I'd like to add an animation that is connected to a different model. I've written some javascript to pull in the animation data and even bind it to the original GLB using GLTF loader, but not sure how to replace the aframe entity beyond just replacing the url.
Any help on how to solve this, or if there's a more efficient way to do this would be much appreciated! 🙂
HTML code:
<a-entity gltf-model="https://cdn.theoasis.xyz/public/bollywoodified/01.glb" id="center" position="0 0.03 -1.6" rotation="0 0 0" scale="1.3 1.3 1.3" animation-mixer\>\</a-entity\>
Javascript code:
import { GLTFLoader } from 'https://cdn.skypack.dev/three#0.129.0/examples/jsm/loaders/GLTFLoader.js';
getAnimations('https://cdn.theoasis.xyz/glb/djland.glb');
function getAnimations(glb) {
const loader = new GLTFLoader();
loader.load(glb, function ( gltf ) {
loader.load(oasis_data.metadata[0].glb, function (data) {
data.animations = gltf.animations;
});
});
}
I tried to pull the animationClip from another glb and was successful, and then was able to replace the animation array on the intended glb with the one from the animated glb. But I do not know how to actually update the entity within AFrame, nor do i know if this is the most efficient solution!

How can I add textures to collada file (.dae) using THREE.js?

I need to display collada file (.dae) using three.js , i can load model but it display without textures , using this code
var loader = new THREE.ColladaLoader( loadingManager );
loader.options.convertUpAxis = true;
loader.load( './car.dae', function ( collada ) {
car = collada.scene;
car.material =
THREE.TextureLoader("../model/car_white.jpg");
i tried other codes ,only this code worked for model but without texture
need your support to add my texture.
Generally speaking, you can add textures to a model like this:
var textureLoader = new THREE.TextureLoader();
var texture = textureLoader.load('../model/car_white.jpg');
loader.load( './car.dae', function ( collada ) {
collada.scene.traverse(function (node) {
if (node.isMesh) {
node.material.map = texture;
}
});
});
Refer to the documentation for THREE.Material and THREE.TextureLoader for more information.
NOTE: As #gaitat mentioned in a comment, your texture may not be wrapped correctly on the model if they weren't designed for one another, and if the model isn't very simple. If that's the case, you probably need to add the texture in Blender (or other software) instead, where you can create UVs, and export the result.

Three.js import object from blender causes weird peeling of materials

I seem to have a problem importing a json object exported from Blender.
Everything seems to be working fine, but the materials aren't rendering correctly.
Does anyone have any idea as to why this peeling occurs?
I'm adding it simply via the ObjectLoader
function jsonLoad(url) {
var loader = new THREE.ObjectLoader();
loader.load(url, function (geometry, materials) {
scene.add(geometry);
});
}
Thank you very much in advance!

Resources