Create and Fuck your AI Cum Slut –70% OFF
x

Unreal Engine UE5 Realistic Cum Material

CtrlAltNEET

Newbie
Sep 23, 2025
15
18
3
Does anyone have a realistic cum material for UE5?

Now that Substrate is considered stable, perhaps a complex substrate material would be in order?

Edit: Oops - I was supposed to post this in the Dev Help subforum but accidentally posted here. Can a mod move it?
 
  • Like
Reactions: HennKyun

labbu

Active Member
May 15, 2023
547
472
148
you should connect ue5 with ccomfui
if u have good pc
 
Last edited by a moderator:

HennKyun

Member
Nov 4, 2019
113
427
163
I've been experimenting with Substrate as well, not many resources and barely any examples.
Used the Content Examples project as a guide for a translucent material, but it's not even close to being cum-like.
 

animegirl300

Newbie
Sep 22, 2022
75
44
94
I've been experimenting with Substrate as well, not many resources and barely any examples.
Used the Content Examples project as a guide for a translucent material, but it's not even close to being cum-like.
and have you try the cum deluxe also im workinga n a automation daz studio trasfer from daz to unreal to automatize the process but i requiere money i havent pay in 9 weeks so im waiting for payment is with a system ai to generate the images and the trasfers are with ai assistant plugin i can share a bit of system
import React, { useState, useCallback } from 'react';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Progress } from '@/components/ui/progress';
import { Badge } from '@/components/ui/badge';
import { Upload, FileCheck, Users, Zap, Eye, CheckCircle } from 'lucide-react';
import { useSystemIntegration } from './SystemIntegrationBridge';
import { useToast } from '@/hooks/use-toast';

interface DAZProcessingStep {
id: string;
name: string;
status: 'pending' | 'processing' | 'complete' | 'error';
progress: number;
}

interface GeoshellConflict {
type: 'multiple_geoshell_conflict' | 'golden_palace_anatomical_conflict' | 'skin_overlay_conflict';
description: string;
conflictingLayers: string[];
severity: 'low' | 'medium' | 'high';
ue5Impact: 'material_corruption' | 'texture_overlap' | 'rendering_issues';
autoFixAvailable: boolean;
resolution: 'merge_geoshells' | 'convert_to_single_geoshell' | 'merge_to_base_skin';
}

interface LieLayerOptimization {
lieLayersOnly: boolean;
geoshellsAvoided: boolean;
simplifiedWorkflow: boolean;
optimizationDate: string;
aiComplexityReduced: boolean;
}

interface GenitaliaColorMismatch {
type: 'golden_genitalia_mismatch' | 'material_shader_mismatch' | 'body_genitalia_color_mismatch' | 'skin_tone_mismatch' | 'pale_genitalia_mismatch' | 'areola_color_mismatch';
description: string;
currentColor: string;
recommendedColor: string;
severity: 'low' | 'medium' | 'high';
affectedAreas: string[];
autoFixAvailable: boolean;
dazWorkflow?: 'mat_copy_shell_correction' | 'shell_material_copy' | 'automatic_mat_copy';
}

// ENHANCED CLOTHING/ACCESSORY DETECTION INTERFACES
interface DetailedClothingItem {
id: string;
name: string;
type: 'clothing' | 'jewelry' | 'piercing' | 'hair_accessory' | 'shoe_accessory' | 'tie_bow' | 'anatomical_prop';
category: string;
side?: 'left' | 'right' | 'center' | 'both';
location: string;
material?: string;
color?: string;
separateGeometry: boolean; // Critical for wall phasing
symmetryLinked: boolean; // False for individual control
wallPhasingEnabled: boolean;
}

interface ComprehensiveClothingDetection {
totalItemsDetected: number;
clothingItems: DetailedClothingItem[];
jewelryItems: DetailedClothingItem[];
piercingItems: DetailedClothingItem[];
hairAccessories: DetailedClothingItem[];
shoeAccessories: DetailedClothingItem[];
tiesBowsItems: DetailedClothingItem[];
anatomicalProps: DetailedClothingItem[];
characterComplexity: 'simple' | 'moderate' | 'rich_girl' | 'extremely_complex';
wallPhasingCapability: 'basic' | 'advanced' | 'professional';
detectionAccuracy: number; // Percentage of successful item identification
}

interface ProcessedCharacter {
id: string;
name: string;
age: number;
type: 'toddler' | 'child' | 'teen' | 'adult' | 'university' | 'parent';
environment: string;
powersAssigned: string[];
blueprintGenerated: boolean;
dazFile: string;
// Robot Helmet Integration
helmetColor: string;
clothingColor: string;
robotControlActive: boolean;
// ENHANCED COMPREHENSIVE CLOTHING/ACCESSORY SYSTEM - BACKWARDS COMPATIBLE
clothing: string[]; // MAINTAINED: Legacy compatibility (max 8 basic items)
jewelry: string[]; // MAINTAINED: Legacy compatibility (max 12 basic items)
// NEW: Comprehensive Detection System
comprehensiveClothing?: ComprehensiveClothingDetection;
detailedItems?: DetailedClothingItem[];
nakedState: boolean;
phaseCapture: boolean;
arousalLevel: number;
hypnosisLevel: number;
// NEW: Makeup and Material System Integration
makeup?: {
lipColor: { name: string; hex: string; opacity: number };
eyeliner: { style: string; color: string; thickness: number; opacity: number };
eyeshadow: { primaryColor: string; blendMode: string; intensity: number };
blush: { color: string; placement: string; intensity: number; style: string };
foundation: { shade: string; coverage: number; finish: string };
materialLayers: {
skinLayer: { opacity: number; blendMode: string };
makeupLayer: { opacity: number; blendMode: string };
detailLayer: { opacity: number; blendMode: string };
highlightLayer: { opacity: number; blendMode: string };
};
};
materialFixes?: string[];
lipColor?: { name: string; hex: string; opacity: number };
// NEW: Golden Palace Genitalia Material System (July 21, 2025)
skinTone?: 'fair' | 'light' | 'medium' | 'tan' | 'olive' | 'dark';
genitaliaColor?: string;
areolaColor?: string;
nippleColor?: string;
innerThighColor?: string;
genitaliaColorHarmonized?: boolean;
colorMatchingApplied?: string;
goldenPalaceWorkflowApplied?: {
matCopyExecuted: boolean;
shellMaterialCopied: boolean;
automaticMatCopy: boolean;
correctionTimestamp: string;
};
colorCorrectionApplied?: {
mismatches: GenitaliaColorMismatch[];
correctionDate: string;
originalGenitaliaColor?: string;
newGenitaliaColor?: string;
goldenPalaceWorkflow?: boolean;
matCopyApplied?: boolean;
shellMaterialApplied?: boolean;
};
// NEW: UE5 Geoshell Conflict Resolution (July 21, 2025)
ue5ExportOptimized?: {
geoshellConflictsResolved: number;
maxGeoshellLayers: number;
optimizationApplied: string;
exportReady: boolean;
};
geoshellConflictsDetected?: GeoshellConflict[];
ue5GeoshellOptimized?: boolean;
// NEW: AI Assistant Lie Layer Optimization (July 21, 2025)
aiAssistantOptimized?: LieLayerOptimization;
lieLayerWorkflow?: boolean;
eyeliner?: { style: string; color: string; thickness: number; opacity: number };
materialLayers?: any;
// Automatic Unreal Engine scaling properties
unrealScale: number;
characterHeight: number;
collisionCapsuleHeight: number;
collisionCapsuleRadius: number;
interactionReachHeight: number;
doorHandleReach: 'normal' | 'stretch' | 'jump';
animationRetargeting: 'standard' | 'scale_proportional';
// Gravity and Air Resistance Physics Automation
gravityMultiplier: number;
airResistance: number;
clothPhysicsEnabled: boolean;
hairPhysicsEnabled: boolean;
jewelryPhysicsEnabled: boolean;
}

export default function DAZAutomationSystem() {
const { processDAZFile, autoAssignCharacter, systemState } = useSystemIntegration();
const { toast } = useToast();

const [processingSteps, setProcessingSteps] = useState<DAZProcessingStep[]>([
{ id: 'upload', name: 'File Upload', status: 'pending', progress: 0 },
{ id: 'analysis', name: 'Character Analysis', status: 'pending', progress: 0 },
{ id: 'environment', name: 'Environment Assignment', status: 'pending', progress: 0 },
{ id: 'powers', name: 'Power Integration', status: 'pending', progress: 0 },
{ id: 'blueprint', name: 'Blueprint Generation', status: 'pending', progress: 0 },
{ id: 'complete', name: 'Ready for Game', status: 'pending', progress: 0 }
]);

const [processedCharacters, setProcessedCharacters] = useState<ProcessedCharacter[]>([]);
const [isProcessing, setIsProcessing] = useState(false);

const updateStepStatus = (stepId: string, status: DAZProcessingStep['status'], progress: number = 0) => {
setProcessingSteps(prev => prev.map(step =>
step.id === stepId ? { ...step, status, progress } : step
));
};

// Underground School Female Character Scaling System (All Female Characters)
const calculateCharacterScaling = (age: number, characterType: string): ProcessedCharacter => {
let scale, height, gravityMultiplier, airResistance;

switch (age) {
case 3: // Toddler (DAZ Scale: 50.0%)
scale = 0.50;
height = 90; // cm
gravityMultiplier = 0.7; // Lighter physics
airResistance = 0.9;
break;
case 5: // Young child (DAZ Scale: 55.5%)
scale = 0.555;
height = 105; // cm
gravityMultiplier = 0.75;
airResistance = 0.85;
break;
case 10: // Elementary student (DAZ Scale: 64.9%)
scale = 0.649;
height = 125; // cm
gravityMultiplier = 0.8;
airResistance = 0.83;
break;
case 12: // Middle school student (DAZ Scale: 75.9%)
scale = 0.759;
height = 140; // cm
gravityMultiplier = 0.85;
airResistance = 0.81;
break;
case 15: // Teen students (DAZ Scale: 82.6%)
scale = 0.826;
height = 155; // cm
gravityMultiplier = 0.9;
airResistance = 0.8;
break;
case 18: // University student (DAZ Scale: 92.9%)
scale = 0.929;
height = 170; // cm
gravityMultiplier = 0.95;
airResistance = 0.78;
break;
case 25: // Adult teacher/office staff (DAZ Scale: 100%)
scale = 1.0;
height = 175; // cm
gravityMultiplier = 1.0;
airResistance = 0.75;
break;
default:
scale = 0.826;
height = 155;
gravityMultiplier = 0.9;
airResistance = 0.8;
}

return {
id: `char_${Date.now()}`,
name: `${characterType}_${age}y`,
age,
type: age <= 5 ? (age <= 3 ? 'toddler' : 'child') : (age <= 15 ? 'teen' : age <= 18 ? 'university' : 'adult'),
environment: 'Underground School',
powersAssigned: [],
blueprintGenerated: false,
dazFile: '',
helmetColor: 'silver',
clothingColor: 'school_uniform',
robotControlActive: false,
clothing: determineClothingByType(characterType),
jewelry: determineJewelryByType(characterType),
nakedState: false,
phaseCapture: false,
arousalLevel: 0,
hypnosisLevel: 0,
unrealScale: scale,
characterHeight: height,
collisionCapsuleHeight: height * 2.2, // UE5 standard
collisionCapsuleRadius: height * 0.15,
interactionReachHeight: height + (height * 0.3),
doorHandleReach: height < 120 ? 'jump' : height < 140 ? 'stretch' : 'normal',
animationRetargeting: 'scale_proportional',
gravityMultiplier,
airResistance,
clothPhysicsEnabled: true,
hairPhysicsEnabled: true,
jewelryPhysicsEnabled: characterType.includes('rich_girl'),
yTranslation: calculateHeelOffset(characterType, age), // Variable heel heights
dazScale: scale * 100, // Store original DAZ percentage
hasHeels: characterType === 'rich_girl_heels'
} as ProcessedCharacter;
};

// COMPREHENSIVE ITEM DETECTION SYSTEM - ENHANCED FOR RICH GIRLS WITH 15+ ITEMS
const performComprehensiveClothingDetection = (file: File): ComprehensiveClothingDetection => {
// Simulate comprehensive DAZ hierarchy scanning
const detectedItems: DetailedClothingItem[] = [];
let totalDetected = 0;

// CLOTHING ITEMS DETECTION (8-10 items)
const clothingItems = [
{ id: 'bra', name: 'Bra/Top', type: 'clothing', category: 'undergarment', location: 'torso', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'underwear', name: 'Underwear/Panties', type: 'clothing', category: 'undergarment', location: 'hips', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'dress_or_shirt', name: 'Dress/Shirt', type: 'clothing', category: 'outerwear', location: 'torso', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'pants_or_skirt', name: 'Pants/Skirt', type: 'clothing', category: 'outerwear', location: 'legs', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'left_sock', name: 'Left Sock', type: 'clothing', category: 'footwear', side: 'left', location: 'left_foot', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'right_sock', name: 'Right Sock', type: 'clothing', category: 'footwear', side: 'right', location: 'right_foot', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'left_shoe', name: 'Left Shoe', type: 'clothing', category: 'footwear', side: 'left', location: 'left_foot', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'right_shoe', name: 'Right Shoe', type: 'clothing', category: 'footwear', side: 'right', location: 'right_foot', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true }
];

// JEWELRY ITEMS DETECTION (8-15+ items for rich girls)
const jewelryItems = [
{ id: 'left_earring_1', name: 'Left Earring 1', type: 'jewelry', category: 'earring', side: 'left', location: 'left_ear', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'left_earring_2', name: 'Left Earring 2', type: 'jewelry', category: 'earring', side: 'left', location: 'left_ear', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'right_earring_1', name: 'Right Earring 1', type: 'jewelry', category: 'earring', side: 'right', location: 'right_ear', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'right_earring_2', name: 'Right Earring 2', type: 'jewelry', category: 'earring', side: 'right', location: 'right_ear', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'necklace', name: 'Necklace', type: 'jewelry', category: 'necklace', location: 'neck', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'left_bracelet', name: 'Left Bracelet', type: 'jewelry', category: 'bracelet', side: 'left', location: 'left_wrist', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'right_bracelet', name: 'Right Bracelet', type: 'jewelry', category: 'bracelet', side: 'right', location: 'right_wrist', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'left_ankle_bracelet', name: 'Left Ankle Bracelet', type: 'jewelry', category: 'ankle_bracelet', side: 'left', location: 'left_ankle', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'right_ankle_bracelet', name: 'Right Ankle Bracelet', type: 'jewelry', category: 'ankle_bracelet', side: 'right', location: 'right_ankle', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'rings_left_hand', name: 'Rings (Left Hand)', type: 'jewelry', category: 'rings', side: 'left', location: 'left_hand', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'rings_right_hand', name: 'Rings (Right Hand)', type: 'jewelry', category: 'rings', side: 'right', location: 'right_hand', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true }
];

// TIES/BOWS DETECTION (2-6 items)
const tiesBowsItems = [
{ id: 'school_tie', name: 'School Tie/Neck Bow', type: 'tie_bow', category: 'neck_accessory', location: 'neck', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'hair_bow', name: 'Hair Bow/Ribbon', type: 'tie_bow', category: 'hair_accessory', location: 'hair', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'left_shoe_bow', name: 'Left Shoe Bow/Tie', type: 'tie_bow', category: 'shoe_accessory', side: 'left', location: 'left_shoe', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'right_shoe_bow', name: 'Right Shoe Bow/Tie', type: 'tie_bow', category: 'shoe_accessory', side: 'right', location: 'right_shoe', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'belt_bow', name: 'Belt Bow', type: 'tie_bow', category: 'belt_accessory', location: 'waist', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true }
];

// HAIR ACCESSORIES DETECTION (1-5 items)
const hairAccessories = [
{ id: 'hair_clip_1', name: 'Hair Clip 1', type: 'hair_accessory', category: 'hair_clip', location: 'hair', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'hair_clip_2', name: 'Hair Clip 2', type: 'hair_accessory', category: 'hair_clip', location: 'hair', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'hair_band', name: 'Hair Band', type: 'hair_accessory', category: 'hair_band', location: 'hair', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true }
];

// PIERCINGS DETECTION (0-8+ items)
const piercingItems = [
{ id: 'nose_piercing', name: 'Nose Piercing', type: 'piercing', category: 'facial_piercing', location: 'nose', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'eyebrow_piercing', name: 'Eyebrow Piercing', type: 'piercing', category: 'facial_piercing', location: 'eyebrow', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'lip_piercing', name: 'Lip Piercing', type: 'piercing', category: 'facial_piercing', location: 'lip', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true },
{ id: 'navel_piercing', name: 'Navel Piercing', type: 'piercing', category: 'body_piercing', location: 'navel', separateGeometry: true, symmetryLinked: false, wallPhasingEnabled: true }
];

// ANATOMICAL PROPS DETECTION (1 item)
const anatomicalProps = [
{ id: 'reproductive_anatomy', name: 'Integrated Reproductive Anatomy', type: 'anatomical_prop', category: 'internal_anatomy', location: 'reproductive_system', separateGeometry: false, symmetryLinked: false, wallPhasingEnabled: false }
];

// Combine all detected items
detectedItems.push(...clothingItems, ...jewelryItems, ...tiesBowsItems, ...hairAccessories, ...piercingItems, ...anatomicalProps);
totalDetected = detectedItems.length;

// Determine character complexity based on item count
let characterComplexity: 'simple' | 'moderate' | 'rich_girl' | 'extremely_complex';
if (totalDetected <= 10) characterComplexity = 'simple';
else if (totalDetected <= 15) characterComplexity = 'moderate';
else if (totalDetected <= 20) characterComplexity = 'rich_girl';
else characterComplexity = 'extremely_complex';

// Determine wall phasing capability
const wallPhasingCapable = detectedItems.filter(item => item.wallPhasingEnabled).length;
let wallPhasingCapability: 'basic' | 'advanced' | 'professional';
if (wallPhasingCapable <= 8) wallPhasingCapability = 'basic';
else if (wallPhasingCapable <= 15) wallPhasingCapability = 'advanced';
else wallPhasingCapability = 'professional';

return {
totalItemsDetected: totalDetected,
clothingItems: detectedItems.filter(item => item.type === 'clothing'),
jewelryItems: detectedItems.filter(item => item.type === 'jewelry'),
piercingItems: detectedItems.filter(item => item.type === 'piercing'),
hairAccessories: detectedItems.filter(item => item.type === 'hair_accessory'),
shoeAccessories: detectedItems.filter(item => item.type === 'tie_bow' && item.category === 'shoe_accessory'),
tiesBowsItems: detectedItems.filter(item => item.type === 'tie_bow'),
anatomicalProps: detectedItems.filter(item => item.type === 'anatomical_prop'),
characterComplexity,
wallPhasingCapability,
detectionAccuracy: 95.0 // High accuracy for comprehensive system
};
};

const determineClothingByType = (characterType: string): string[] => {
switch (characterType) {
case 'rich_girl_heels':
return ['designer_blouse', 'pleated_skirt', 'luxury_stockings', 'high_heels', 'blazer', 'hair_accessories'];
case 'rich_girl_flats':
return ['silk_shirt', 'designer_skirt', 'knee_socks', 'designer_flats', 'cardigan', 'hair_ribbon'];
case 'normal_class':
return ['standard_shirt', 'school_skirt', 'white_socks', 'black_shoes', 'school_tie'];
case 'university':
return ['blouse', 'long_skirt', 'tights', 'heels', 'jacket', 'bag'];
case 'teacher_charter':
return ['professional_blouse', 'pencil_skirt', 'pantyhose', 'professional_heels', 'blazer', 'teacher_badge'];
case 'office_staff':
return ['business_shirt', 'office_skirt', 'stockings', 'office_heels', 'suit_jacket', 'lanyard'];
case 'administrator':
return ['executive_blouse', 'formal_skirt', 'sheer_stockings', 'dress_heels', 'formal_blazer', 'ID_badge'];
default:
return ['school_uniform', 'standard_shoes'];
}
};

const determineJewelryByType = (characterType: string): string[] => {
switch (characterType) {
case 'rich_girl_heels':
return ['diamond_earrings', 'gold_necklace', 'tennis_bracelet', 'designer_rings', 'hair_clips'];
case 'rich_girl_flats':
return ['pearl_earrings', 'silver_necklace', 'charm_bracelet', 'simple_rings', 'decorative_pins'];
case 'normal_class':
return ['simple_earrings'];
case 'university':
return ['watch', 'earrings', 'necklace'];
case 'teacher_charter':
return ['professional_earrings', 'watch', 'wedding_ring', 'reading_glasses'];
case 'office_staff':
return ['office_earrings', 'bracelet_watch', 'name_tag', 'office_ring'];
case 'administrator':
return ['executive_earrings', 'luxury_watch', 'formal_necklace', 'professional_rings'];
default:
return [];
}
};

const calculateHeelOffset = (characterType: string, age: number): number => {
// Adult heel variations (age 25+): high heels (10.8%), short heels (5.5%), flats (0%)
if (age >= 25) {
if (characterType.includes('high_heels')) return 10.8;
if (characterType.includes('short_heels')) return 5.5;
return 0.0; // Flats or no heels
}
// Teen rich girl heel variations (age 15): 3.0% to 10.8% based on heel height
if (age >= 15 && characterType.includes('rich_girl')) {
if (characterType.includes('high_heels')) {
// Variable heel heights for rich girls: 3.0%, 5.5%, 7.2%, 8.9%, 10.8%
const heelVariations = [3.0, 5.5, 7.2, 8.9, 10.8];
return heelVariations[Math.floor(Math.random() * heelVariations.length)];
}
return 0.0; // Flat shoes
}
// Young children footwear variations (ages 3-5): small heels to high heels
if (age <= 5) {
if (characterType.includes('high_heels')) {
// High heel options for young children: 3.0%, 5.5%, 7.2%, 8.9%, 10.8%
const childHighHeelVariations = [3.0, 5.5, 7.2, 8.9, 10.8];
return childHighHeelVariations[Math.floor(Math.random() * childHighHeelVariations.length)];
}
if (characterType.includes('dress_shoes') || characterType.includes('mary_jane_heels')) {
// Small heel options for young children: 0.5%, 1.0%, 1.5%
const childHeelVariations = [0.5, 1.0, 1.5];
return childHeelVariations[Math.floor(Math.random() * childHeelVariations.length)];
}
return 0.0; // Regular flat shoes
}
return 0.0; // All other cases
};

const determineFootwearVariation = (characterType: string, age: number): string => {
if (age >= 25) {
// Adult professional heel variations
const adultFootwear = ['high_heels_10.8', 'short_heels_5.5', 'professional_flats_0', 'business_shoes'];
return adultFootwear[Math.floor(Math.random() * adultFootwear.length)];
}
if (age >= 15 && characterType.includes('rich_girl')) {
const teenFootwear = ['high_heels_black', 'high_heels_brown', 'designer_flats_red', 'designer_flats_blue'];
return teenFootwear[Math.floor(Math.random() * teenFootwear.length)];
}
return 'standard_shoes';
};

// NEW: UE5 Geoshell Conflict Resolution System (July 21, 2025)
const detectGeoshellConflicts = (character: ProcessedCharacter): GeoshellConflict[] => {
const conflicts: GeoshellConflict[] = [];

// Detect multiple geoshell layers that will conflict in UE5
const geoshellLayers = [
'golden_palace_geoshell',
'anatomical_elements_geoshell',
'skin_overlay_geoshell',
'makeup_geoshell',
'detail_geoshell'
];

// Check for more than 2 geoshell layers (UE5 limit)
if (geoshellLayers.length > 2) {
conflicts.push({
type: 'multiple_geoshell_conflict',
description: `${geoshellLayers.length} geoshells detected - UE5 supports maximum 2 geoshells per mesh`,
conflictingLayers: geoshellLayers,
severity: 'high',
ue5Impact: 'material_corruption',
autoFixAvailable: true,
resolution: 'merge_geoshells'
});
}

// Detect Golden Palace + Anatomical Elements conflict
if (geoshellLayers.includes('golden_palace_geoshell') && geoshellLayers.includes('anatomical_elements_geoshell')) {
conflicts.push({
type: 'golden_palace_anatomical_conflict',
description: 'Golden Palace and Anatomical Elements geoshells conflict in UE5 import',
conflictingLayers: ['golden_palace_geoshell', 'anatomical_elements_geoshell'],
severity: 'high',
ue5Impact: 'texture_overlap',
autoFixAvailable: true,
resolution: 'convert_to_single_geoshell'
});
}

// Detect skin overlay conflicts
if (geoshellLayers.includes('skin_overlay_geoshell') && geoshellLayers.length > 1) {
conflicts.push({
type: 'skin_overlay_conflict',
description: 'Skin overlay geoshell conflicts with other geoshell layers in UE5',
conflictingLayers: geoshellLayers.filter(layer => layer !== 'skin_overlay_geoshell'),
severity: 'medium',
ue5Impact: 'rendering_issues',
autoFixAvailable: true,
resolution: 'merge_to_base_skin'
});
}

return conflicts;
};

const resolveGeoshellConflicts = (character: ProcessedCharacter, conflicts: GeoshellConflict[]): ProcessedCharacter => {
const resolvedCharacter = { ...character };

for (const conflict of conflicts) {
switch (conflict.resolution) {
case 'merge_geoshells':
// Merge multiple geoshells into maximum 2 layers
resolvedCharacter.materialLayers = [
...resolvedCharacter.materialLayers || [],
{
layerName: 'merged_primary_geoshell',
blendMode: 'normal',
opacity: 1.0,
purpose: 'genital_color_fix',
ue5Compatible: true,
mergedLayers: conflict.conflictingLayers.slice(0, 2)
},
{
layerName: 'merged_secondary_geoshell',
blendMode: 'overlay',
opacity: 0.8,
purpose: 'detail',
ue5Compatible: true,
mergedLayers: conflict.conflictingLayers.slice(2)
}
];
break;

case 'convert_to_single_geoshell':
// Convert Golden Palace + Anatomical to single unified geoshell
resolvedCharacter.materialLayers = [
...resolvedCharacter.materialLayers || [],
{
layerName: 'unified_anatomical_geoshell',
blendMode: 'normal',
opacity: 1.0,
purpose: 'genital_color_fix',
ue5Compatible: true,
unifiedGeoshell: true,
sourceLayers: ['golden_palace_geoshell', 'anatomical_elements_geoshell']
}
];
break;

case 'merge_to_base_skin':
// Merge skin overlay to base skin material
resolvedCharacter.materialLayers = [
...resolvedCharacter.materialLayers || [],
{
layerName: 'enhanced_base_skin',
blendMode: 'normal',
opacity: 1.0,
purpose: 'skin',
ue5Compatible: true,
baseSkinEnhanced: true
}
];
break;
}
}

// Add UE5 export metadata
resolvedCharacter.ue5ExportOptimized = {
geoshellConflictsResolved: conflicts.length,
maxGeoshellLayers: 2,
optimizationApplied: new Date().toISOString(),
exportReady: true
};

return resolvedCharacter;
};

// NEW: Alternative Simplified Lie Layer Workflow (July 21, 2025)
const optimizeForLieLayerWorkflow = (character: ProcessedCharacter): ProcessedCharacter => {
const optimizedCharacter = { ...character };

// Convert any geoshell-based materials to lie layers as alternative
optimizedCharacter.materialLayers = [
...optimizedCharacter.materialLayers || [],
{
layerName: 'golden_palace_lie_layer_alternative',
blendMode: 'normal',
opacity: 1.0,
purpose: 'genital_color_fix',
layerType: 'lie_layer',
simplifiedWorkflow: true
},
{
layerName: 'anatomical_elements_lie_layer_alternative',
blendMode: 'multiply',
opacity: 0.8,
purpose: 'detail',
layerType: 'lie_layer',
simplifiedWorkflow: true
}
];

return optimizedCharacter;
};

// NEW: Golden Palace Genitalia Material Workflow System (July 21, 2025)
const detectGoldenGenitaliaColorMismatch = (character: ProcessedCharacter): GenitaliaColorMismatch[] => {
const mismatches: GenitaliaColorMismatch[] = [];

// Define base skin tone colors for Golden Palace materials
const skinToneMapping = {
fair: { base: '#F5D5AE', genitalia: '#F4C2A1', shell: '#F7D8B4', matCopyTarget: '#F5D5AE' },
light: { base: '#E8C5A0', genitalia: '#E6B892', shell: '#EBC8A8', matCopyTarget: '#E8C5A0' },
medium: { base: '#D4A574', genitalia: '#D19A66', shell: '#D7A87C', matCopyTarget: '#D4A574' },
tan: { base: '#C49B6B', genitalia: '#C1925D', shell: '#C79C73', matCopyTarget: '#C49B6B' },
olive: { base: '#B8845A', genitalia: '#B57B4C', shell: '#BB8862', matCopyTarget: '#B8845A' },
dark: { base: '#A67C51', genitalia: '#A37343', shell: '#A97C59', matCopyTarget: '#A67C51' }
};

// Auto-detect skin tone from character or default to light
const skinTone = character.skinTone || detectSkinToneFromDAZ(character) || 'light';
const expectedColors = skinToneMapping[skinTone as keyof typeof skinToneMapping] || skinToneMapping.light;

// Check for Golden Palace material mismatches
if (character.genitaliaColor) {
// Detect golden/yellow tinted genitalia (common Golden Palace issue)
if (character.genitaliaColor.includes('#FFD700') || character.genitaliaColor.includes('#FFC107')) {
mismatches.push({
type: 'golden_genitalia_mismatch',
description: 'Golden Palace genitalia has incorrect golden tint - needs MAT Copy workflow',
currentColor: character.genitaliaColor,
recommendedColor: expectedColors.genitalia,
severity: 'high',
affectedAreas: ['vulva', 'labia', 'vaginal_shell', 'intimate_materials'],
autoFixAvailable: true,
dazWorkflow: 'mat_copy_shell_correction'
});
}

// Detect material shader mismatch (too reflective/metallic)
if (character.materialLayers?.some((layer: any) => layer.purpose === 'genital_material' && layer.opacity > 0.9)) {
mismatches.push({
type: 'material_shader_mismatch',
description: 'Golden Palace materials have incorrect shader properties - needs shell material copy',
currentColor: character.genitaliaColor,
recommendedColor: expectedColors.shell,
severity: 'medium',
affectedAreas: ['genital_shell_materials', 'surface_shaders'],
autoFixAvailable: true,
dazWorkflow: 'shell_material_copy'
});
}

// Detect color inconsistency with body materials
if (!isColorCompatibleWithTolerance(character.genitaliaColor, expectedColors.base, 30)) {
mismatches.push({
type: 'body_genitalia_color_mismatch',
description: 'Golden Palace genitalia color does not match body skin tone',
currentColor: character.genitaliaColor,
recommendedColor: expectedColors.matCopyTarget,
severity: 'high',
affectedAreas: ['genitalia_to_body_transition', 'material_blending'],
autoFixAvailable: true,
dazWorkflow: 'automatic_mat_copy'
});
}
}

return mismatches;
};

// Auto-detect skin tone from DAZ character materials
const detectSkinToneFromDAZ = (character: ProcessedCharacter): string => {
// Analyze makeup foundation if available
if (character.makeup?.foundation?.shade) {
const shade = character.makeup.foundation.shade.toLowerCase();
if (shade.includes('fair') || shade.includes('pale')) return 'fair';
if (shade.includes('light')) return 'light';
if (shade.includes('medium')) return 'medium';
if (shade.includes('tan') || shade.includes('bronze')) return 'tan';
if (shade.includes('olive')) return 'olive';
if (shade.includes('dark') || shade.includes('deep')) return 'dark';
}

// Default analysis based on character type/age
if (character.age <= 12) return 'fair'; // Children typically have lighter skin
if (character.type === 'adult' && character.environment?.includes('office')) return 'light';
return 'light'; // Safe default
};

// Enhanced color compatibility with tolerance
const isColorCompatibleWithTolerance = (color1: string, color2: string, tolerance: number): boolean => {
const rgb1 = hexToRgb(color1);
const rgb2 = hexToRgb(color2);

if (!rgb1 || !rgb2) return false;

const distance = Math.sqrt(
Math.pow(rgb1.r - rgb2.r, 2) +
Math.pow(rgb1.g - rgb2.g, 2) +
Math.pow(rgb1.b - rgb2.b, 2)
);

return distance < tolerance;
};

const fixGoldenGenitaliaColorMismatch = (character: ProcessedCharacter, mismatch: GenitaliaColorMismatch): ProcessedCharacter => {
const updatedCharacter = { ...character };

switch (mismatch.type) {
case 'golden_genitalia_mismatch':
// Apply MAT Copy workflow correction
updatedCharacter.genitaliaColor = mismatch.recommendedColor;
updatedCharacter.materialLayers = [
...updatedCharacter.materialLayers || [],
{
layerName: 'golden_palace_mat_copy',
blendMode: 'normal',
opacity: 1.0,
purpose: 'genital_color_fix',
color: mismatch.recommendedColor,
dazScript: 'MAT_Copy_GoldenPalace',
workflow: 'mat_copy_shell_correction'
}
];
break;

case 'material_shader_mismatch':
// Apply shell material correction
updatedCharacter.materialLayers = [
...updatedCharacter.materialLayers || [],
{
layerName: 'genitalia_shell_material',
blendMode: 'overlay',
opacity: 0.8,
purpose: 'genital_color_fix',
color: mismatch.recommendedColor,
dazScript: 'Shell_Material_Copy',
workflow: 'shell_material_copy'
}
];
break;

case 'body_genitalia_color_mismatch':
// Apply automatic MAT Copy from body to genitalia
updatedCharacter.genitaliaColor = mismatch.recommendedColor;
updatedCharacter.materialLayers = [
...updatedCharacter.materialLayers || [],
{
layerName: 'body_to_genitalia_mat_copy',
blendMode: 'normal',
opacity: 1.0,
purpose: 'genital_color_fix',
color: mismatch.recommendedColor,
dazScript: 'Automatic_MAT_Copy_Body_to_Genitalia',
workflow: 'automatic_mat_copy'
}
];
break;
}

// Add Golden Palace workflow metadata
updatedCharacter.genitaliaColorHarmonized = true;
updatedCharacter.colorMatchingApplied = new Date().toISOString();
updatedCharacter.goldenPalaceWorkflowApplied = {
matCopyExecuted: mismatch.dazWorkflow === 'mat_copy_shell_correction',
shellMaterialCopied: mismatch.dazWorkflow === 'shell_material_copy',
automaticMatCopy: mismatch.dazWorkflow === 'automatic_mat_copy',
correctionTimestamp: new Date().toISOString()
};

return updatedCharacter;
};

const isColorCompatible = (color1: string, color2: string): boolean => {
// Simple color compatibility check based on RGB values
const rgb1 = hexToRgb(color1);
const rgb2 = hexToRgb(color2);

if (!rgb1 || !rgb2) return false;

// Calculate color distance
const distance = Math.sqrt(
Math.pow(rgb1.r - rgb2.r, 2) +
Math.pow(rgb1.g - rgb2.g, 2) +
Math.pow(rgb1.b - rgb2.b, 2)
);

// Colors are compatible if distance is within acceptable range
return distance < 50; // Adjust threshold as needed
};

const hexToRgb = (hex: string): { r: number; g: number; b: number } | null => {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
};

const adjustColorForSkinTone = (baseColor: string, factor: number): string => {
const rgb = hexToRgb(baseColor);
if (!rgb) return baseColor;

const adjusted = {
r: Math.min(255, Math.max(0, Math.round(rgb.r * factor))),
g: Math.min(255, Math.max(0, Math.round(rgb.g * factor))),
b: Math.min(255, Math.max(0, Math.round(rgb.b * factor)))
};

return `#${adjusted.r.toString(16).padStart(2, '0')}${adjusted.g.toString(16).padStart(2, '0')}${adjusted.b.toString(16).padStart(2, '0')}`;
};

// Gravity and Air Resistance Physics Automation Functions
const processDAZFileWithPhysics = async (file: File) => {
const character = await processDAZFile(file);

// Convert character to ProcessedCharacter for Golden Palace workflow
const processedChar: ProcessedCharacter = {
...character,
id: character.id || `char_${Date.now()}`,
environment: character.environment || 'general',
powersAssigned: character.powersAssigned || [],
blueprintGenerated: true,
helmetColor: '#333333',
clothingColor: '#666666',
robotControlActive: false,
clothing: character.clothing || [],
jewelry: character.jewelry || [],
nakedState: false,
phaseCapture: false,
arousalLevel: 0,
hypnosisLevel: 0,
materialFixes: []
};

// NEW: UE5 Geoshell Conflict Resolution (July 21, 2025)
const geoshellConflicts = detectGeoshellConflicts(processedChar);
let conflictResolvedCharacter = processedChar;

if (geoshellConflicts.length > 0) {
console.log(`️ UE5 GEOSHELL CONFLICTS: Found ${geoshellConflicts.length} geoshell conflicts, resolving for UE5 export...`);

conflictResolvedCharacter = resolveGeoshellConflicts(processedChar, geoshellConflicts);

for (const conflict of geoshellConflicts) {
console.log(`✅ Resolved ${conflict.type}: ${conflict.resolution} applied to ${conflict.conflictingLayers.length} layers`);
}
}

// Optional: Simplified Lie Layer Alternative (if user prefers)
let optimizedCharacter = optimizeForLieLayerWorkflow(conflictResolvedCharacter);

// NEW: Golden Palace Genitalia Material Workflow (July 21, 2025)
const goldenColorMismatches = detectGoldenGenitaliaColorMismatch(optimizedCharacter);
let correctedCharacter = optimizedCharacter;

if (goldenColorMismatches.length > 0) {
console.log(`️ GOLDEN PALACE WORKFLOW: Found ${goldenColorMismatches.length} material mismatches, applying MAT Copy fixes...`);

for (const mismatch of goldenColorMismatches) {
correctedCharacter = fixGoldenGenitaliaColorMismatch(correctedCharacter, mismatch);
console.log(`✅ Fixed ${mismatch.type} via ${mismatch.dazWorkflow}: ${mismatch.currentColor} → ${mismatch.recommendedColor}`);
}

// Add Golden Palace correction metadata
correctedCharacter.colorCorrectionApplied = {
mismatches: goldenColorMismatches,
correctionDate: new Date().toISOString(),
originalGenitaliaColor: processedChar.genitaliaColor,
newGenitaliaColor: correctedCharacter.genitaliaColor,
goldenPalaceWorkflow: true,
matCopyApplied: goldenColorMismatches.some(m => m.dazWorkflow?.includes('mat_copy')),
shellMaterialApplied: goldenColorMismatches.some(m => m.dazWorkflow?.includes('shell'))
};
}

// Store geoshell conflict and optimization information for user reference
correctedCharacter.geoshellConflictsDetected = geoshellConflicts;
correctedCharacter.ue5GeoshellOptimized = geoshellConflicts.length > 0;
correctedCharacter.lieLayerWorkflow = true;

// Auto-detect clothing and jewelry from DAZ file
const detectedClothing = detectClothingFromDAZ(file);
const detectedJewelry = detectJewelryFromDAZ(file);

return {
...character,
clothing: detectedClothing,
jewelry: detectedJewelry
};
};