Ember model mapping

From WorldForgeWiki
Jump to: navigation, search

This page is a work in progress,
meaning things are incomplete, unfinished, not fully thought out, might disappear again, and generally are subject to change.
Do not rely on any of this just yet!

Suggestion for a format for allowing models and their appearance in Ember to be defined using a rule graph system.

<modelmappings>
<!-- A simple case. We want the model "turnip" to be shown for the entity of type "turnip" -->
	<modelmapping name="turnip">
		<entitymatch>
			<case equals="turnip">
				<action type="display-model" modelname="turnip" />
			</case>
		</entitymatch>
	</modelmapping> 
	
<!-- For convenience we also provide the "automodelmapping" element, which maps a single model to an entity type of the same name. The result of this will be the same structure as the turnip. -->
	<automodelmapping name="acorn" />
	
<!-- The automodelmapping element also has an optional "modelname" attribute, which allows you to select a different model to map to the entity type. -->
	<automodelmapping name="carrot" modelname="carrot" />
	
	<!-- We want the model "boulder" to be used for the entity "boulder". However, there are four different boulder meshes, which the model defines as four different parts. Depending on attribute "style" a different part will be shown. We assume that "style" is one of "a", "b", "c" or "d". Since the parts in the model are defined to belong to the same group (not shown in this file), only one part will be shown at the same time. -->
	<modelmapping name="boulder">
		<entitymatch>
			<case equals="boulder">
				<action type="display-model" modelname="boulder" />
				<attributematch attribute="style" >
					<case equals="a">
						<action type="display-part" partname="boulderA" />
					</case>
					<case equals="b">
						<action type="display-part" partname="boulderB" />
					</case>
					<case equals="c">
						<action type="display-part" partname="boulderkC" />
					</case>
					<case equals="d">
						<action type="display-part" partname="boulderD" />
					</case>
				</attributematch>
			</case>
		</entitymatch>
	</modelmapping>
	
	<!-- An alternative to the previous boulder mapping is to instead have each boulder mesh in its own model file. The mapping would then be like this. -->
	<modelmapping name="boulder">
		<entitymatch>
			<case equals="boulder">
				<attributematch attribute="style" >
					<case equals="a">
						<action type="display-model" modelname="boulderA" />
					</case>
					<case equals="b">
						<action type="display-model" modelname="boulderB" />
					</case>
					<case equals="c">
						<action type="display-model" modelname="boulderkC" />
					</case>
					<case equals="d">
						<action type="display-model" modelname="boulderD" />
					</case>
				</attributematch>
			</case>
		</entitymatch>
	</modelmapping>
	
	<!-- We have three different types of oaks: large, young and saplings. The size (which we for simplicity assumes is a float) determines which of these we should show. Furthermore, the "style" attribute which variant of oak we should show (just as with the boulder).
		 -->
	<modelmapping name="oak">
		<entitymatch>
			<case equals="oak">
				<action type="display-model" modelname="oak" />
				<attributematch attribute="height">
					<case lesserequals="0.2">
						<action type="display-model" modelname="oak_sapling" />
						<attributematch attribute="style" >
							<case equals="a">
								<action type="display-part" partname="A" />
							</case>
							<case equals="b">
								<action type="display-part" partname="B" />
							</case>
							<case equals="c">
								<action type="display-part" partname="C" />
							</case>
							<case equals="d">
								<action type="display-part" partname="D" />
							</case>
						</attributematch>
					</case>
					<case lesserequals="0.5">
						<action type="display-model" modelname="oak_young" />
						<attributematch attribute="style" >
							<case equals="a">
								<action type="display-part" partname="A" />
							</case>
							<case equals="b">
								<action type="display-part" partname="B" />
							</case>
							<case equals="c">
								<action type="display-part" partname="C" />
							</case>
						</attributematch>
					</case>
					<case largerequals="1.0">
						<action type="display-model" modelname="oak" />
						<attributematch attribute="style" >
							<case equals="a">
								<action type="display-part" partname="A" />
							</case>
							<case equals="b">
								<action type="display-part" partname="B" />
							</case>
							<case equals="c">
								<action type="display-part" partname="C" />
							</case>
						</attributematch>
					</case>
				</attributematch> 
			</case>
		</entitymatch>
	</modelmapping>
	
	
	<!-- We'll use the "male" model for the entities of type "settler" or "butcher". Depending on what kind of entity is outfitted to the torso we'll show a shirt part. The shirts all belongs to the same group in the model, so only one will be shown at the same time.
		-->
	<modelmapping name="human">
		<entitymatch>
			<case equals="settler,butcher,merchant,mercenary">
				<action type="display-model" modelname="settler" />
				<outfitmatch attachment="torso">
					<case equals="shirt" >
						<attributematch attribute="style">
							<case equals="fine">
								<attributematch attribute="colour">
									<case equals="red">
										<action type="display-part" partname="fine_shirt/red" />
									</case>
									<case equals="blue">
										<action type="display-part" partname="fine_shirt/blue" />
									</case>
								</attributematch>
							</case>
							<case equals="ragged">
								<attributematch attribute="colour">
									<case equals="red">
										<action type="display-part" partname="ragged_shirt/red" />
									</case>
									<case equals="blue">
										<action type="display-part" partname="ragged_shirt/blue" />
									</case>
								</attributematch>
							</case>
						</attributematch>
					</case>
				</outfitmatch>
			</case>
		</entitymatch>
	</modelmapping>
</modelmappings>