How do I implement physics attributes into an already made 3D model? - directx-11

If I create a 3d model with c++ and directx, how do I implement the physics engine (let's say havok) to use that 3d model and add physics and collision properties?

Related

Modifying the length of different bodyparts in three.js

I have a model of a human body, I am able to load that in threejs with the obj loader. Now after loading the model in threejs I need to do some post-processing like
scaling the length of arm
scaling the length of leg
Is it possible to do that, how can I do that ? I know that obj file store the necessary information to create meshes(i.e. vertices and faces) moreover material information if required. Can we add any extra information to achieve this?
You want to rig your model. You need to define the skeleton, and Three.js can then use "bones" to scale, position and stretch aspects of your mesh. A simple example of a rigged model in three.js is here:
https://threejs.org/docs/#api/objects/SkinnedMesh
Rigging your model in blender is available as a tutorial here: https://www.youtube.com/watch?v=eEqB-eKcv7k&index=15&list=PLOGomoq5sDLutXOHLlESKG2j9CCnCwVqg

Should I bake model in Blender before importing it into Unity?

As in the title, when is it important to bake texture for the (Blender) model to use it in a mobile game and what are the benefits from baking for performance ? Is there any problem if I didn't bake it and I use the texture directly on my model in my game ?
There is baking in Unity and baking in blender. Your question seems to be about baking in blender before importing model into Unity and this answer will cover that.
how to benefit from baking for performance ?
Baking model in blender before importing it into Unity has nothing to do with performance. See below for why and when you should bake your model.
is there any problem if i didn't bake it and i use the texture
directly to my model in my game ?
It depends. If you have a model in blender with just one basic or simple material and a texture then you do not need to bake your model.
If you have a model in blender with advanced materials or material networks then you must bake the model before importing into Unity. Material network is when you have material that is connected to many nodes to form a procedural texture. Below is an example of a material network in Blender:
There is no way to import that material in Unity.If you try, it won't look like the-same thing it would when rendered in Blender. This is why you bake the texture. When you bake it, everything in that material will be converted or flattened to an image/texture. That texture is what you can use in Unity to make it look like what it would have looked liked in Blender.
Also, baking is used to generate other specials maps like Occlusion, Normal, Alpha and Emission maps that you need to plug to the Unity material. You can also bake your Blender light into the texture.

Rendering 3D points with THREE.Points

Basically, I want to take a model, create a point cloud of the model and have the models move around. I could populate the models and move them around on the CPU, but I want to find a way to handle the animation on the GPU instead.
So I was thinking of using a THREE.Points object and associating a mesh with each point. I know you can associate a sprite with each point in a THREE.Points object, as seen in this example:
https://threejs.org/examples/?q=point#webgl_points_sprites
Is there a way to associate a mesh (namely, an imported model) with each point, so that I can animate the vertices (and thus, the models) on the GPU with a vertex shader?
Yes there is a way. You should look into the THREE.InstancedBufferGeometry

Boundary representation in ThreeJS

I have been using ThreeJS for building my own web based CAD frontend. The API has amazing capabilities. My intent is to integrate the physics of the ThreeJS interface with a different product and sadly, the only supported common CAD format is STL.
One of the most important inputs in FEA is the boundaries. In my case, they would be the faces of a 3d model, which can be arbitrary shapes and not triangles. Apparently, ThreeJS considers a Face3 as a face.
For example:
a model converted from STL
This representation is also called as Boundary Representation.
Is there any way to get these faces in ThreeJS?
I tried the RayCaster but it did not work and my intent is to get a list of all the faces from the model beforehand.
Many Thanks

Convert THREE.js scene to CANNON.js world

I have a basic THREE.js scene, created in Blender, including cubes and rotated planes. Is there any way that I can automatically convert this THREE.js scene into a CANNON.js world ?
Thanks
Looking at the Three.js Blender exporter, it looks like it only exports mesh data, no information about mathematical shapes (boxes, planes, spheres etc) that Cannon.js needs to work. You could try to import your meshes directly into Cannon.js, using its Trimesh class, but this would sadly only work for collisions against spheres and planes.
What you need to feed Cannon.js is mathematical geometry data, telling it which of your triangles in your mesh that represent a box (or plane) and where its center of mass is.
A common (manual) workflow for creating 3D WebGL physics, is importing the 3D models into a WebGL-enabled game engine (like Unity, Goo Create or PlayCanvas). In the game engine you can add collider shapes to your models (boxes, planes, spheres, etc), so the physics engine can work efficiently. You can from there preview your physics simulation and export a complete WebGL experience.
Going to post another answer since there are a few new options to consider here...
I wrote a simple mesh2shape(...) helper that can convert (one object at a time) from THREE.Mesh to CANNON.Shape objects. It doesn't support certain features, such as heightmaps/terrain.
Example:
var shape = mesh2shape(object3D, {type: mesh2shape.Type.BOX})
There is a (experimental!) BLENDER_physics extension for the glTF format to include physics data with a model. You could add physics data in Blender, export to glTF, and then modify THREE.GLTFLoader to pass along the physics data to your application, helping you construct CANNON.js objects.

Resources