Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Making a 3D Human Model in Code

A topic by TatorTillInfinity created 62 days ago Views: 111
Viewing posts 1 to 1
Developer

Infinity Engine: Creating a Realistic Human Body Using Code

This guide shows you how to create a realistic humanoid body using basic 3D shapes in the Infinity Engine (using Ursina for 3D rendering). We will aim for a simple yet more realistic look, focusing on proportions and proper alignment for a human body.

Step 1: Install Required Libraries

Before starting, ensure that the Ursina library is installed.

bash
Copy code
pip install ursina 

Step 2: Set Up Your Environment

python
Copy code
from ursina import *  # Initialize Ursina Engine app = Ursina()  # Set the window size and parameters window.title = "Realistic Human Body" window.size = (800, 600) 

Step 3: Create the Head

We will use a sphere for the head. This sphere will be placed at the top of the body and will represent the person's head.

python
Copy code
# Create the head (sphere) head = Entity(model='sphere', color=color.peach, scale=(0.45, 0.45, 0.45), position=(0, 2.6, 0)) 
  • Model: The head is a sphere.
  • Scale: The sphere’s scale is (0.45, 0.45, 0.45) to resemble a realistic head size.
  • Position: The head is positioned above the torso at (0, 2.6, 0).

Step 4: Create the Torso

The torso is the central body part. We will use a cube with the right proportions to represent the body.

python
Copy code
# Create the torso (cube) torso = Entity(model='cube', color=color.blue, scale=(0.7, 1.5, 0.5), position=(0, 1.2, 0)) 
  • Model: A cube represents the torso.
  • Scale: The scale of (0.7, 1.5, 0.5) gives the torso a more realistic, elongated shape.
  • Position: The torso is placed just below the head at (0, 1.2, 0).

Step 5: Create the Arms

We will use cylinders for the arms, starting with the upper arms and then creating the lower arms. The arm proportions will be realistic based on human anatomy.

Upper Arms:

python
Copy code
# Create the upper arms (cylinders) upper_arm_left = Entity(model='cylinder', color=color.green, scale=(0.25, 0.8, 0.25), position=(-0.9, 1.7, 0)) upper_arm_right = Entity(model='cylinder', color=color.green, scale=(0.25, 0.8, 0.25), position=(0.9, 1.7, 0)) 
  • Model: Cylinders represent the upper arms.
  • Scale: The upper arm cylinders have a scale of (0.25, 0.8, 0.25) to match realistic upper arm proportions.
  • Position: These are positioned just below the torso to simulate the shoulder joint.

Lower Arms:

python
Copy code
# Create the lower arms (cylinders) lower_arm_left = Entity(model='cylinder', color=color.green, scale=(0.2, 0.8, 0.2), position=(-0.9, 0.3, 0)) lower_arm_right = Entity(model='cylinder', color=color.green, scale=(0.2, 0.8, 0.2), position=(0.9, 0.3, 0)) 
  • Model: The cylinders represent the lower arms.
  • Scale: The scale is slightly smaller, (0.2, 0.8, 0.2), to simulate the more slender look of forearms.
  • Position: These are placed below the upper arms to complete the arm structure.

Step 6: Create the Hands

We’ll use small spheres for the hands. These will give a basic, but more realistic, representation of the hands.

python
Copy code
# Create the hands (small spheres) hand_left = Entity(model='sphere', color=color.brown, scale=(0.2, 0.2, 0.2), position=(-0.9, -0.3, 0)) hand_right = Entity(model='sphere', color=color.brown, scale=(0.2, 0.2, 0.2), position=(0.9, -0.3, 0)) 
  • Model: Spheres represent the hands.
  • Scale: The hands are small with a scale of (0.2, 0.2, 0.2).
  • Position: The hands are placed at the end of the lower arms.

Step 7: Create the Legs

The legs will also be created using cylinders, starting with the upper legs and then creating the lower legs. The proportions are similar to the arms, but the upper legs will be slightly thicker.

Upper Legs:

python
Copy code
# Create the upper legs (cylinders) upper_leg_left = Entity(model='cylinder', color=color.red, scale=(0.35, 1, 0.35), position=(-0.5, -0.5, 0)) upper_leg_right = Entity(model='cylinder', color=color.red, scale=(0.35, 1, 0.35), position=(0.5, -0.5, 0)) 
  • Model: Cylinders represent the upper legs.
  • Scale: The upper legs are a bit thicker, with a scale of (0.35, 1, 0.35).
  • Position: The upper legs are positioned below the torso to resemble the pelvis.

Lower Legs:

python
Copy code
# Create the lower legs (cylinders) lower_leg_left = Entity(model='cylinder', color=color.red, scale=(0.25, 1, 0.25), position=(-0.5, -2, 0)) lower_leg_right = Entity(model='cylinder', color=color.red, scale=(0.25, 1, 0.25), position=(0.5, -2, 0)) 
  • Model: The lower legs are also cylinders.
  • Scale: The scale is smaller, (0.25, 1, 0.25), to simulate the slimmer shape of lower legs.
  • Position: These are positioned just below the upper legs.

Step 8: Create the Feet

We’ll use small spheres for the feet as well. This gives a basic foot representation.

python
Copy code
# Create the feet (small spheres) foot_left = Entity(model='sphere', color=color.brown, scale=(0.25, 0.25, 0.25), position=(-0.5, -3, 0)) foot_right = Entity(model='sphere', color=color.brown, scale=(0.25, 0.25, 0.25), position=(0.5, -3, 0)) 
  • Model: Spheres represent the feet.
  • Scale: The feet are slightly larger than the hands, with a scale of (0.25, 0.25, 0.25).
  • Position: The feet are placed below the lower legs to simulate a standing position.

Step 9: Combining and Animating the Model

At this point, the model is composed of all major body parts. You can combine them and animate specific parts. For example, you can rotate the arms or legs to simulate walking.

python
Copy code
def update():     # Simple animation: rotate the arms     upper_arm_left.rotation_x += 10 * time.dt     upper_arm_right.rotation_x += 10 * time.dt     upper_leg_left.rotation_x += 5 * time.dt     upper_leg_right.rotation_x += 5 * time.dt 

This update function animates the arms and legs slightly to create movement over time.

Complete Example

Here’s the complete code to create a simple yet realistic humanoid character:

python
Copy code
from ursina import *  # Initialize Ursina Engine app = Ursina()  # Create the head head = Entity(model='sphere', color=color.peach, scale=(0.45, 0.45, 0.45), position=(0, 2.6, 0))  # Create the torso torso = Entity(model='cube', color=color.blue, scale=(0.7, 1.5, 0.5), position=(0, 1.2, 0))  # Create the upper arms upper_arm_left = Entity(model='cylinder', color=color.green, scale=(0.25, 0.8, 0.25), position=(-0.9, 1.7, 0)) upper_arm_right = Entity(model='cylinder', color=color.green, scale=(0.25, 0.8, 0.25), position=(0.9, 1.7, 0))  # Create the lower arms lower_arm_left = Entity(model='cylinder', color=color.green, scale=(0.2, 0.8, 0.2), position=(-0.9, 0.3, 0)) lower_arm_right = Entity(model='cylinder', color=color.green, scale=(0.2, 0.8, 0.2), position=(0.9, 0.3, 0))  # Create the hands hand_left = Entity(model='sphere', color=color.brown, scale=(0.2, 0.2, 0.2), position=(-0.9, -0.3, 0)) hand_right = Entity(model='sphere', color=color.brown, scale=(0.2, 0.2, 0.2), position=(0.9, -0.3, 0))  # Create the upper legs upper_leg_left = Entity(model='cylinder', color=color.red, scale=(0.35, 1, 0.35), position=(-0.5, -0.5, 0)) upper_leg_right = Entity(model='cylinder', color=color.red, scale=(0.35, 1, 0.35), position=(0.5, -0.5, 0))  # Create the lower legs lower_leg_left = Entity(model='cylinder', color=color.red, scale=(0.25, 1, 0.25), position=(-0.5, -2, 0)) lower_leg_right = Entity(model='cylinder', color=color.red, scale=(0.25, 1, 0.25), position=(0.5, -2, 0))  # Create the feet foot_left = Entity(model='sphere', color=color.brown, scale=(0.25, 0.25, 0.25), position=(-0.5, -3, 0)) foot_right = Entity(model='sphere', color=color.brown, scale=(0.25, 0.25, 0.25), position=(0.5, -3, 0))  # Animation def update():     # Simple animation for the arms and legs     upper_arm_left.rotation_x += 10 * time.dt     upper_arm_right.rotation_x += 10 * time.dt     upper_leg_left.rotation_x += 5 * time.dt     upper_leg_right.rotation_x += 5 * time.dt  # Run the application app.run() 

Step 10: Final Thoughts

By adjusting the proportions, scale, and adding movement to different body parts, you can achieve a simple yet realistic humanoid model. For true realism, however, 3D modeling tools would be required to design detailed models, and then you can import them into your engine.