Pharmacology practicals are hard to practise. Students usually watch one demonstration, copy the readings and move on. At CologyLabs we started by recording 55+ practicals as guided videos for B.Pharm and B.V.Sc students. That fixed visibility, but students were still watching, not doing.

So for Phase 2 we're turning those experiments into an interactive 3D lab in the browser: the student walks around the lab, picks up the animal, weighs it, calculates a dose, injects it and runs a test like the rotarod. This post walks through how we're structuring that with React Three Fiber, drei and plain Three.js concepts.

The stack

  • React Three Fiber (R3F) for a declarative scene graph inside React
  • @react-three/drei for helpers like useGLTF, PointerLockControls and Html
  • GLTF/GLB models for the lab, apparatus and rigged animals, made by our 3D designer
  • A small state store for the experiment (current step, animal weight, dose, results). The examples below use Zustand, but any store works.

1. Loading the lab and a rigged animal

Every asset is a GLB. Rigged animals ship with their animations (idle, walk, struggle), which we drive with useAnimations.

import { useGLTF, useAnimations } from '@react-three/drei' import { useEffect, useRef } from 'react' export function Rat({ action = 'Idle', ...props }) { const group = useRef() const { scene, animations } = useGLTF('/models/rat.glb') const { actions } = useAnimations(animations, group) useEffect(() => { actions[action]?.reset().fadeIn(0.3).play() return () => actions[action]?.fadeOut(0.3) }, [action, actions]) return <primitive ref={group} object={scene} {...props} /> } useGLTF.preload('/models/rat.glb') 

Preloading matters: students shouldn't see an empty bench while a 5 MB model streams in.

2. Modelling the experiment as steps

A practical is really a state machine. Making that explicit keeps the 3D code simple: each object only needs to know whether it's interactive in the current step.

import { create } from 'zustand' export const STEPS = ['pickAnimal', 'weigh', 'calculateDose', 'inject', 'rotarod', 'record'] export const useExperiment = create((set, get) => ({ step: 'pickAnimal', weightG: null, doseMl: null, next: () => { const i = STEPS.indexOf(get().step) set({ step: STEPS[Math.min(i + 1, STEPS.length - 1)] }) }, setWeight: (weightG) => set({ weightG }), setDose: (doseMl) => set({ doseMl }), })) 

3. Weighing and dose calculation

When the animal is placed on the balance, we generate a realistic weight within a range and show it on the balance's display using drei's <Html>. The student then has to calculate the volume to inject themselves, and we check it:

// dose in mg/kg, concentration in mg/mL, weight in grams export function expectedVolumeMl(doseMgPerKg, concMgPerMl, weightG) { const doseMg = doseMgPerKg * (weightG / 1000) return doseMg / concMgPerMl } export function isDoseCorrect(answerMl, expectedMl, tolerance = 0.05) { return Math.abs(answerMl - expectedMl) <= expectedMl * tolerance } 

Getting this wrong doesn't end the experiment. Instead, the result later shows what an under- or overdose would do, which turns a mistake into a lesson.

4. The injection interaction (raycasting)

This is the interaction students care about most. The syringe follows the pointer, and on click we raycast from the camera to find whether the needle hit a valid injection zone on the animal mesh.

import { useThree } from '@react-three/fiber' import * as THREE from 'three' export function useInjection(targetRef, onHit) { const { camera, pointer } = useThree() const raycaster = new THREE.Raycaster() return () => { raycaster.setFromCamera(pointer, camera) const hits = raycaster.intersectObject(targetRef.current, true) const zone = hits.find(h => h.object.userData.injectionZone) if (zone) onHit(zone.object.userData.injectionZone, zone.point) } } 

The injection zones are just invisible meshes parented to the animal's bones, tagged in Blender with custom properties (injectionZone: 'ip', for example). Because they're parented to bones, they move correctly when the rigged animal moves.

5. Running the test

For the rotarod, the rod's angular speed increases over time, and the animal's "time to fall" is designed to be computed from the drug and dose the student actually gave. The fall itself is an animation clip, so the student sees the effect rather than just reading a number.

Performance notes

  • Use Draco-compressed GLBs and useGLTF's Draco loader to cut model sizes.
  • Keep one shared Raycaster and only raycast against objects that are interactive in the current step.
  • Use <Suspense> with a lightweight loader so the scene appears step by step.
  • Test on low-end laptops early. College lab machines are rarely powerful.

What's next

The web version comes first, followed by a mobile app. If you're building educational 3D experiences, or you teach pharmacology and want to try the virtual lab, you can find us at cologylabs.com.

I'd love to hear how others handle interactive steps and grading in 3D learning tools. Let me know in the comments.