static VBlock CollapseEntity(VBlock entity, int fixupStyle, string instanceName, Vector3 instanceOrigin, Vector3 instanceAngles, ref int highID) { VBlock collapsedEntity = entity.DeepClone(); var targetNameProperty = collapsedEntity.Body.Where(node => node.Name == "targetname" && node.GetType() == typeof(VProperty)).Select(node => node as VProperty).FirstOrDefault(); var solids = entity.Body.Where(node => node.Name == "solid" && node is VBlock).Cast<VBlock>(); var relativeEntityPositionProperty = collapsedEntity.Body.Where(node => node.Name == "origin" && node.GetType() == typeof(VProperty)).Select(node => node as VProperty).FirstOrDefault(); var relativeEntityAngleProperty = collapsedEntity.Body.Where(node => node.Name == "angles" && node.GetType() == typeof(VProperty)).Select(node => node as VProperty).FirstOrDefault(); var relativeEntityPosition = new Vector3(relativeEntityPositionProperty?.Value ?? "0 0 0"); var relativeEntityAngle = new Vector3(relativeEntityAngleProperty?.Value ?? "0 0 0"); if (relativeEntityPositionProperty != null) { var newEntityPosition = relativeEntityPosition.Clone(); newEntityPosition.Rotate(instanceAngles); newEntityPosition.Offset(instanceOrigin); relativeEntityPositionProperty.Value = newEntityPosition.ToString(); } if (relativeEntityAngleProperty != null) { var newEntityAngle = relativeEntityAngle.Clone(); newEntityAngle.AddAngles(instanceAngles); relativeEntityAngleProperty.Value = newEntityAngle.ToString(); } collapsedEntity.ReID(ref highID); // Collapse the entity's sub solids foreach (var solid in solids) { entity.Body[entity.Body.IndexOf(solid)] = CollapseSolid(solid, ref highID); } // Rename Entity if (targetNameProperty != null && !targetNameProperty.Value.Contains("@")) { if (fixupStyle == 0) targetNameProperty.Value = instanceName + "-" + targetNameProperty.Value; // Prefix else if (fixupStyle == 1) targetNameProperty.Value = targetNameProperty.Value + "-" + instanceName; // Postfix } return collapsedEntity; }
static VBlock CollapseSolid(VBlock solid, ref int highID) { // TODO: transform solid return solid.DeepClone(); }